diff --git a/README.md b/README.md index 42a1f04..f2cbfaf 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,43 @@ -# Arduino AVR Boards +# cezerio blocks Arduino Core -[![Check Arduino status](https://github.com/arduino/ArduinoCore-avr/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino/ArduinoCore-avr/actions/workflows/check-arduino.yml) -[![Compile Examples status](https://github.com/arduino/ArduinoCore-avr/actions/workflows/compile-platform-examples.yml/badge.svg)](https://github.com/arduino/ArduinoCore-avr/actions/workflows/compile-platform-examples.yml) -[![Spell Check status](https://github.com/arduino/ArduinoCore-avr/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino/ArduinoCore-avr/actions/workflows/spell-check.yml) +cezerio blocks, designed and manufactured in Turkey, have a powerful MCU and unique design. It allows the users in all levels (beginners to professionals) to build and code own robots in the fields of Electronics, Internet of Things (IoT) and Artificial Intelligence (AI). -This repository contains the source code and configuration files of the Arduino AVR Boards -[platform](https://arduino.github.io/arduino-cli/latest/platform-specification/). +### Installation Instructions +JSON index file: `https://raw.githubusercontent.com/cezer-io/cezerio-blocks-arduino/main/package_cezerio_blocks_index.json` +- Install the latest [Arduino IDE](https://www.arduino.cc/en/software). +- Start Arduino IDE and open Preferences window. +- Copy the JSON index file link above into Additional Board Manager URLs field. +- Open Boards Manager from Tools > Board menu and install "cezerio blocks". +- Select "cezerio blocks" from Tools > Board menu after installation. + +### Development Status + + [![Release Version](https://img.shields.io/github/v/release/cezer-io/cezerio-blocks-arduino?color=880414)](https://github.com/cezer-io/cezerio-blocks-arduino/releases/latest/) [![Release Date](https://img.shields.io/github/release-date/cezer-io/cezerio-blocks-arduino?color=487c17)](https://github.com/cezer-io/cezerio-blocks-arduino/releases/latest/) [![Downloads](https://img.shields.io/github/downloads/cezer-io/cezerio-blocks-arduino/latest/total?color=167cc9)](https://github.com/cezer-io/cezerio-blocks-arduino/releases/latest/) [![Downloads](https://img.shields.io/github/downloads/cezer-io/cezerio-blocks-arduino/total?color=167cc9)](https://github.com/cezer-io/cezerio-blocks-arduino/releases/latest/) + +### IDs +Each input and output block has an ID to communicate with brain block. + + | ID | | + | :--- | :--- | + | BALANCE BLOCK | 0x010 | + | DETECT BLOCK | 0x020 | + | EYE BLOCK | 0x030 | + | GESTURE BLOCK | 0x040 | + | KNOB BLOCK | 0x050 | + | MIC BLOCK | 0x060 | + | PHOTO BLOCK | 0x070 | + | TEMP BLOCK | 0x080 | + | TILT BLOCK | 0x090 | + | COLOUR BLOCK | 0x0A0 | + | SLIDE BLOCK | 0x0B0 | + | FOLLOW BLOCK | 0x0C0 | + | 360 BLOCK | 0x0D0 | + | BIPP BLOCK | 0x0E0 | + | COLOR BLOCK | 0x0F0 | + | GRIPP BLOCK | 0x100 | + | LEVEL BLOCK | 0x110 | + | LIGHT BLOCK | 0x120 | + | LINK BLOCK | 0x130 | + | MOTION BLOCK | 0x140 | + | ROLL BLOCK | 0x150 | + | BIRRR BLOCK | 0x160 | diff --git a/boards.txt b/boards.txt index 8deea83..fc3d2b5 100644 --- a/boards.txt +++ b/boards.txt @@ -1,4 +1,4 @@ -# See: https://arduino.github.io/arduino-cli/latest/platform-specification/ +# See: https://github.com/cezer-io/cezerio-blocks-arduino ############################################################## diff --git a/libraries/CezerioBlocks/examples/AskID/AskID.ino b/libraries/CezerioBlocks/examples/AskID/AskID.ino new file mode 100644 index 0000000..5eb3c77 --- /dev/null +++ b/libraries/CezerioBlocks/examples/AskID/AskID.ino @@ -0,0 +1,30 @@ +#include "cezerioBlocks.h" + +unsigned char timerFlag = 0; + +void setup() +{ + initCezerioBlocks(); +} + +void loop() +{ +#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) + if(!digitalRead(CAN_INT)) + { + } +#endif + + if(timerFlag) + { + Serial.println(getBlockID(),HEX); + timerFlag = 0; + } +} + +#if defined(TIMER_INTERRUPT_ENABLE) +ISR(TIMER1_COMPA_vect) +{ + timerFlag = 1; +} +#endif diff --git a/libraries/CezerioBlocks/examples/Chariot/Chariot.ino b/libraries/CezerioBlocks/examples/Bluetooth/Chariot/Chariot.ino similarity index 94% rename from libraries/CezerioBlocks/examples/Chariot/Chariot.ino rename to libraries/CezerioBlocks/examples/Bluetooth/Chariot/Chariot.ino index f5a324d..02dd5cb 100644 --- a/libraries/CezerioBlocks/examples/Chariot/Chariot.ino +++ b/libraries/CezerioBlocks/examples/Bluetooth/Chariot/Chariot.ino @@ -1,7 +1,7 @@ /********************************************** CHARIOT ******************************************/ /* 2xMotionBlock, 1xCubeBlock, 1xMainBlock, 1xDetectBlock, 1xLightBlock, 1xBippBlock */ -#include "SmartBlockFunctions.h" +#include "cezerioBlocks.h" #include "DataTransferFunctions.h" unsigned char timerFlag = 0; @@ -9,105 +9,105 @@ extern unsigned char resolvePacketFlag; extern capturedPacketType capturedPacket; void setup() -{ - initSmartBlocks(); +{ + initCezerioBlocks(); initSmartBlue(); } void loop() { -#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) +#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) if(!digitalRead(CAN_INT)) { - + } #endif if(timerFlag) { - + timerFlag = 0; } - getSmartBlueData(); + getSmartBlueData(); if(resolvePacketFlag) { switch(capturedPacket.data_packet.packet_id) - { + { case BLE_ROBOT_NAME: // gelen robot id "0x00" ve data değeri "0xFF" ise robot id'sini gönderir if(capturedPacket.data_packet.robot_id == 0x00 && capturedPacket.data_packet.data[0] == 0xFF) { sendChariotData(BLE_ROBOT_NAME, 0xFF); } - break; - + break; + case BLE_MOVE_FORWARD: setMotion(0x140, motorDirectionForward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionForward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_BACKWARD: setMotion(0x140, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_RIGHT: setMotion(0x140,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141,motorDirectionForward,(capturedPacket.data_packet.data[0])/2,motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_LEFT: setMotion(0x140,motorDirectionForward,(capturedPacket.data_packet.data[0])/2,motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_FORWARD_RIGHT: setMotion(0x140,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141,motorDirectionForward,(capturedPacket.data_packet.data[0])*0.75,motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_FORWARD_LEFT: setMotion(0x140,motorDirectionForward,(capturedPacket.data_packet.data[0])*0.75,motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_BACKWARD_RIGHT: setMotion(0x140, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionBackward, (capturedPacket.data_packet.data[0])*0.75, motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_BACKWARD_LEFT: setMotion(0x140, motorDirectionBackward, (capturedPacket.data_packet.data[0])*0.75, motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Right Wheel*/ break; - - case BLE STOP: + + case BLE_STOP: setMotion(0x140, motorDirectionForward, 0, motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionForward, 0, motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_TURN_360CW: setMotion(0x140, motorDirectionForward, 255, motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionBackward, 255, motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_TURN_360CCW: setMotion(0x140, motorDirectionBackward, 255, motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionForward, 255, motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_DETECT_DATA: sendChariotData(BLE_DETECT_DATA, getDetect(0x020)); break; - + case BLE_BIPP: setBipp(0x0E0,capturedPacket.data_packet.data[0]); break; - + case BLE_LIGHT: setLight(0x120,capturedPacket.data_packet.data[0]); break; - + } } } diff --git a/libraries/CezerioBlocks/examples/Flying_Car/Flying_Car.ino b/libraries/CezerioBlocks/examples/Bluetooth/Flying_Car/Flying_Car.ino similarity index 94% rename from libraries/CezerioBlocks/examples/Flying_Car/Flying_Car.ino rename to libraries/CezerioBlocks/examples/Bluetooth/Flying_Car/Flying_Car.ino index c9cda4b..16ebb46 100644 --- a/libraries/CezerioBlocks/examples/Flying_Car/Flying_Car.ino +++ b/libraries/CezerioBlocks/examples/Bluetooth/Flying_Car/Flying_Car.ino @@ -1,7 +1,7 @@ /********************************************** FLYING_CAR ******************************************/ /* 3xMotionBlock, 3xCubeBlock, 1xMainBlock, 1xDetectBlock, 1xLightBlock, 1xBippBlock */ -#include "SmartBlockFunctions.h" +#include "cezerioBlocks.h" #include "DataTransferFunctions.h" unsigned char timerFlag = 0; @@ -9,110 +9,110 @@ extern unsigned char resolvePacketFlag; extern capturedPacketType capturedPacket; void setup() -{ - initSmartBlocks(); +{ + initCezerioBlocks(); initSmartBlue(); } void loop() { -#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) +#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) if(!digitalRead(CAN_INT)) { - + } #endif if(timerFlag) { - + timerFlag = 0; } - getSmartBlueData(); + getSmartBlueData(); if(resolvePacketFlag) { switch(capturedPacket.data_packet.packet_id) - { + { case BLE_ROBOT_NAME: // gelen robot id "0x00" ve data değeri "0xFF" ise robot id'sini gönderir if(capturedPacket.data_packet.robot_id == 0x00 && capturedPacket.data_packet.data[0] == 0xFF) { sendFlyingCarData(BLE_ROBOT_NAME, 0xFF); } - break; - + break; + case BLE_MOVE_FORWARD: setMotion(0x140, motorDirectionForward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionForward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_BACKWARD: setMotion(0x140, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_RIGHT: setMotion(0x140,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141,motorDirectionForward,(capturedPacket.data_packet.data[0])/2,motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_LEFT: setMotion(0x140,motorDirectionForward,(capturedPacket.data_packet.data[0])/2,motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_FORWARD_RIGHT: setMotion(0x140,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141,motorDirectionForward,(capturedPacket.data_packet.data[0])*0.75,motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_FORWARD_LEFT: setMotion(0x140,motorDirectionForward,(capturedPacket.data_packet.data[0])*0.75,motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_BACKWARD_RIGHT: setMotion(0x140, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionBackward, (capturedPacket.data_packet.data[0])*0.75, motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_BACKWARD_LEFT: setMotion(0x140, motorDirectionBackward, (capturedPacket.data_packet.data[0])*0.75, motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Right Wheel*/ break; - - case BLE STOP: + + case BLE_STOP: setMotion(0x140, motorDirectionForward, 0, motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionForward, 0, motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_TURN_360CW: setMotion(0x140, motorDirectionForward, 255, motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionBackward, 255, motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_TURN_360CCW: setMotion(0x140, motorDirectionBackward, 255, motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionForward, 255, motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_FLIP: setMotion(0x142, motorDirectionForward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Propeller*/ break; - + case BLE_DETECT_DATA: sendFlyingCarData(BLE_DETECT_DATA, getDetect(0x020)); break; - + case BLE_BIPP: setBipp(0x0E0,capturedPacket.data_packet.data[0]); break; - + case BLE_LIGHT: setLight(0x120,capturedPacket.data_packet.data[0]); break; - + } } } diff --git a/libraries/CezerioBlocks/examples/Roller/Roller.ino b/libraries/CezerioBlocks/examples/Bluetooth/Roller/Roller.ino similarity index 93% rename from libraries/CezerioBlocks/examples/Roller/Roller.ino rename to libraries/CezerioBlocks/examples/Bluetooth/Roller/Roller.ino index 42b33c2..4622fba 100644 --- a/libraries/CezerioBlocks/examples/Roller/Roller.ino +++ b/libraries/CezerioBlocks/examples/Bluetooth/Roller/Roller.ino @@ -1,7 +1,7 @@ /********************************************** ROLLER ******************************************/ /* 2xMotionBlock, 2xCubeBlock, 1xMainBlock */ -#include "SmartBlockFunctions.h" +#include "cezerioBlocks.h" #include "DataTransferFunctions.h" unsigned char timerFlag = 0; @@ -9,93 +9,93 @@ extern unsigned char resolvePacketFlag; extern capturedPacketType capturedPacket; void setup() -{ - initSmartBlocks(); +{ + initCezerioBlocks(); initSmartBlue(); } void loop() { -#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) +#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) if(!digitalRead(CAN_INT)) { - + } #endif if(timerFlag) { - + timerFlag = 0; } - getSmartBlueData(); + getSmartBlueData(); if(resolvePacketFlag) { switch(capturedPacket.data_packet.packet_id) - { + { case BLE_ROBOT_NAME: // gelen robot id "0x00" ve data değeri "0xFF" ise robot id'sini gönderir if(capturedPacket.data_packet.robot_id == 0x00 && capturedPacket.data_packet.data[0] == 0xFF) { sendRollerData(BLE_ROBOT_NAME, 0xFF); } - break; - + break; + case BLE_MOVE_FORWARD: setMotion(0x140, motorDirectionForward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionForward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_BACKWARD: setMotion(0x140, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_RIGHT: setMotion(0x140,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141,motorDirectionForward,(capturedPacket.data_packet.data[0])/2,motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_LEFT: setMotion(0x140,motorDirectionForward,(capturedPacket.data_packet.data[0])/2,motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_FORWARD_RIGHT: setMotion(0x140,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141,motorDirectionForward,(capturedPacket.data_packet.data[0])*0.75,motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_FORWARD_LEFT: setMotion(0x140,motorDirectionForward,(capturedPacket.data_packet.data[0])*0.75,motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_BACKWARD_RIGHT: setMotion(0x140, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionBackward, (capturedPacket.data_packet.data[0])*0.75, motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_MOVE_BACKWARD_LEFT: setMotion(0x140, motorDirectionBackward, (capturedPacket.data_packet.data[0])*0.75, motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Right Wheel*/ break; - - case BLE STOP: + + case BLE_STOP: setMotion(0x140, motorDirectionForward, 0, motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionForward, 0, motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_TURN_360CW: setMotion(0x140, motorDirectionForward, 255, motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionBackward, 255, motorDriverEnable); /*Front_Right Wheel*/ break; - + case BLE_TURN_360CCW: setMotion(0x140, motorDirectionBackward, 255, motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionForward, 255, motorDriverEnable); /*Front_Right Wheel*/ break; - + } } } diff --git a/libraries/CezerioBlocks/examples/SendReceiveBluetooth/SendReceiveBluetooth.ino b/libraries/CezerioBlocks/examples/Bluetooth/SendReceiveBluetooth/SendReceiveBluetooth.ino similarity index 77% rename from libraries/CezerioBlocks/examples/SendReceiveBluetooth/SendReceiveBluetooth.ino rename to libraries/CezerioBlocks/examples/Bluetooth/SendReceiveBluetooth/SendReceiveBluetooth.ino index b3fba89..163c0e2 100644 --- a/libraries/CezerioBlocks/examples/SendReceiveBluetooth/SendReceiveBluetooth.ino +++ b/libraries/CezerioBlocks/examples/Bluetooth/SendReceiveBluetooth/SendReceiveBluetooth.ino @@ -1,22 +1,4 @@ -/* - SendReceiveBluetooth.ino - 2017 Copyright (c) RFtek Electronics Ltd. All right reserved. - - Authors : Huseyin Ulvi AYDOGMUS, Ozgur BOSTAN - Date : 2017-04-28 - - This sketch is a demo template for the logical operations of - SmartBlock Bluetooth functions. - - the SmartBlocks: 2x Knob Block, 1x Detect Block (Input Blocks) - 2x Lıght Block, 1x Bipp Block, 1x Motion Block (Output Blocks) - - Note: Any of the interrupt capabilities can be used by uncommenting the - #define statements (TIMER and/or CAN RECEIVE interrupt) - -*/ - -#include "SmartBlockFunctions.h" +#include "cezerioBlocks.h" #include "DataTransferFunctions.h" unsigned char timerFlag = 0; @@ -24,43 +6,43 @@ extern unsigned char resolvePacketFlag; extern capturedPacketType capturedPacket; void setup() -{ - initSmartBlocks(); +{ + initCezerioBlocks(); initSmartBlue(); } void loop() { -#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) +#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) if(!digitalRead(CAN_INT)) { - + } #endif if(timerFlag) { - + timerFlag = 0; } - getSmartBlueData(); + getSmartBlueData(); if(resolvePacketFlag) { switch(capturedPacket.data_packet.packet_id) - { + { case BLE_ROBOT_NAME: // gelen robot id "0x00" ve data değeri "0xFF" ise robot id'sini gönderir if(capturedPacket.data_packet.robot_id == 0x00 && capturedPacket.data_packet.data[0] == 0xFF) { sendRollerData(BLE_ROBOT_NAME, 0xFF); } - - break; + + break; case BLE_MOVE_FORWARD: - + break; case BLE_MOVE_BACKWARD: @@ -84,7 +66,7 @@ void loop() break; case BLE_MOVE_FORWARD_LEFT: - + break; case BLE_MOVE_BACKWARD_RIGHT: @@ -120,7 +102,7 @@ void loop() break; case BLE_FLIP: - + break; case BLE_STOP: @@ -262,9 +244,9 @@ void loop() break; default: - + break; - } + } resolvePacketFlag = 0; } @@ -276,6 +258,3 @@ ISR(TIMER1_COMPA_vect) timerFlag = 1; } #endif -/********************************************************************************************************* - END FILE -*********************************************************************************************************/ diff --git a/libraries/CezerioBlocks/examples/Truck/Truck.ino b/libraries/CezerioBlocks/examples/Bluetooth/Truck/Truck.ino similarity index 96% rename from libraries/CezerioBlocks/examples/Truck/Truck.ino rename to libraries/CezerioBlocks/examples/Bluetooth/Truck/Truck.ino index 2275207..330ed51 100644 --- a/libraries/CezerioBlocks/examples/Truck/Truck.ino +++ b/libraries/CezerioBlocks/examples/Bluetooth/Truck/Truck.ino @@ -1,7 +1,7 @@ /********************************************** TRUCK ******************************************/ /* 4xMotionBlock, 2xCubeBlock, 1xMainBlock, 1xDetectBlock, 1xLightBlock, 1xBippBlock */ -#include "SmartBlockFunctions.h" +#include "cezerioBlocks.h" #include "DataTransferFunctions.h" unsigned char timerFlag = 0; @@ -9,127 +9,127 @@ extern unsigned char resolvePacketFlag; extern capturedPacketType capturedPacket; void setup() -{ - initSmartBlocks(); +{ + initCezerioBlocks(); initSmartBlue(); } void loop() { -#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) +#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) if(!digitalRead(CAN_INT)) { - + } #endif if(timerFlag) { - + timerFlag = 0; } - getSmartBlueData(); + getSmartBlueData(); if(resolvePacketFlag) { switch(capturedPacket.data_packet.packet_id) - { + { case BLE_ROBOT_NAME: // gelen robot id "0x00" ve data değeri "0xFF" ise robot id'sini gönderir if(capturedPacket.data_packet.robot_id == 0x00 && capturedPacket.data_packet.data[0] == 0xFF) { sendTruckData(BLE_ROBOT_NAME, 0xFF); } - break; - + break; + case BLE_MOVE_FORWARD: setMotion(0x140, motorDirectionForward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionForward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Right Wheel*/ setMotion(0x142, motorDirectionForward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Back_Left Wheel*/ setMotion(0x143, motorDirectionForward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Back_Right Wheel*/ break; - + case BLE_MOVE_BACKWARD: setMotion(0x140, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Right Wheel*/ setMotion(0x142, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Back_Left Wheel*/ setMotion(0x143, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Back_Right Wheel*/ break; - + case BLE_MOVE_RIGHT: setMotion(0x140,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141,motorDirectionForward,(capturedPacket.data_packet.data[0])/2,motorDriverEnable); /*Front_Right Wheel*/ setMotion(0x142,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Back_Left Wheel*/ setMotion(0x143,motorDirectionForward,(capturedPacket.data_packet.data[0])/2,motorDriverEnable); /*Back_Right Wheel*/ break; - + case BLE_MOVE_LEFT: setMotion(0x140,motorDirectionForward,(capturedPacket.data_packet.data[0])/2,motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Front_Right Wheel*/ setMotion(0x142,motorDirectionForward,(capturedPacket.data_packet.data[0])/2,motorDriverEnable); /*Back_Left Wheel*/ setMotion(0x143,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Back_Right Wheel*/ break; - + case BLE_MOVE_FORWARD_RIGHT: setMotion(0x140,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141,motorDirectionForward,(capturedPacket.data_packet.data[0])*0.75,motorDriverEnable); /*Front_Right Wheel*/ setMotion(0x142,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Back_Left Wheel*/ setMotion(0x143,motorDirectionForward,(capturedPacket.data_packet.data[0])*0.75,motorDriverEnable); /*Back_Right Wheel*/ break; - + case BLE_MOVE_FORWARD_LEFT: setMotion(0x140,motorDirectionForward,(capturedPacket.data_packet.data[0])*0.75,motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Front_Right Wheel*/ setMotion(0x142,motorDirectionForward,(capturedPacket.data_packet.data[0])*0.75,motorDriverEnable); /*Back_Left Wheel*/ setMotion(0x143,motorDirectionForward,capturedPacket.data_packet.data[0],motorDriverEnable); /*Back_Right Wheel*/ break; - + case BLE_MOVE_BACKWARD_RIGHT: setMotion(0x140, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionBackward, (capturedPacket.data_packet.data[0])*0.75, motorDriverEnable); /*Front_Right Wheel*/ setMotion(0x142, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Back_Left Wheel*/ setMotion(0x143, motorDirectionBackward, (capturedPacket.data_packet.data[0])*0.75, motorDriverEnable); /*Back_Right Wheel*/ break; - + case BLE_MOVE_BACKWARD_LEFT: setMotion(0x140, motorDirectionBackward, (capturedPacket.data_packet.data[0])*0.75, motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Front_Right Wheel*/ setMotion(0x142, motorDirectionBackward, (capturedPacket.data_packet.data[0])*0.75, motorDriverEnable); /*Back_Left Wheel*/ setMotion(0x143, motorDirectionBackward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Back_Right Wheel*/ break; - - case BLE STOP: + + case BLE_STOP: setMotion(0x140, motorDirectionForward, 0, motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionForward, 0, motorDriverEnable); /*Front_Right Wheel*/ setMotion(0x142, motorDirectionForward, 0, motorDriverEnable); /*Back_Left Wheel*/ setMotion(0x143, motorDirectionForward, 0, motorDriverEnable); /*Back_Right Wheel*/ break; - + case BLE_TURN_360CW: setMotion(0x140, motorDirectionForward, 255, motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionBackward, 255, motorDriverEnable); /*Front_Right Wheel*/ setMotion(0x142, motorDirectionForward, 255, motorDriverEnable); /*Back_Left Wheel*/ setMotion(0x143, motorDirectionBackward, 255, motorDriverEnable); /*Back_Right Wheel*/ break; - + case BLE_TURN_360CCW: setMotion(0x140, motorDirectionBackward, 255, motorDriverEnable); /*Front_Left Wheel*/ setMotion(0x141, motorDirectionForward, 255, motorDriverEnable); /*Front_Right Wheel*/ setMotion(0x142, motorDirectionBackward, 255, motorDriverEnable); /*Back_Left Wheel*/ setMotion(0x143, motorDirectionForward, 255, motorDriverEnable); /*Back_Right Wheel*/ break; - + case BLE_DETECT_DATA: sendTruckData(BLE_DETECT_DATA, getDetect(0x020)); break; - + case BLE_BIPP: setBipp(0x0E0,capturedPacket.data_packet.data[0]); break; - + case BLE_LIGHT: setLight(0x120,capturedPacket.data_packet.data[0]); break; - + } } } diff --git a/libraries/CezerioBlocks/examples/Windmill/Windmill.ino b/libraries/CezerioBlocks/examples/Bluetooth/Windmill/Windmill.ino similarity index 87% rename from libraries/CezerioBlocks/examples/Windmill/Windmill.ino rename to libraries/CezerioBlocks/examples/Bluetooth/Windmill/Windmill.ino index 9648d5c..36b4a55 100644 --- a/libraries/CezerioBlocks/examples/Windmill/Windmill.ino +++ b/libraries/CezerioBlocks/examples/Bluetooth/Windmill/Windmill.ino @@ -1,7 +1,7 @@ /********************************************** WINDMILL ******************************************/ /* 1xMotionBlock, 3xCubeBlock, 1xMainBlock, 1xDetectBlock, 1xLightBlock, 1xBippBlock, 1xLevelBlock, 1xMicBlock, 1xPhotoBlock, 1xKnobBlock */ -#include "SmartBlockFunctions.h" +#include "cezerioBlocks.h" #include "DataTransferFunctions.h" unsigned char timerFlag = 0; @@ -9,69 +9,70 @@ extern unsigned char resolvePacketFlag; extern capturedPacketType capturedPacket; void setup() -{ - initSmartBlocks(); +{ + initCezerioBlocks(); initSmartBlue(); } void loop() { -#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) +#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) if(!digitalRead(CAN_INT)) { - + } #endif if(timerFlag) { - + timerFlag = 0; } - getSmartBlueData(); + getSmartBlueData(); if(resolvePacketFlag) { switch(capturedPacket.data_packet.packet_id) - { + { case BLE_ROBOT_NAME: // gelen robot id "0x00" ve data değeri "0xFF" ise robot id'sini gönderir if(capturedPacket.data_packet.robot_id == 0x00 && capturedPacket.data_packet.data[0] == 0xFF) { sendWindmillData(BLE_ROBOT_NAME, 0xFF); } - break; - + break; + case BLE_FLIP: setMotion(0x142, motorDirectionForward, capturedPacket.data_packet.data[0], motorDriverEnable); /*Propeller*/ break; - + case BLE_BIPP: setBipp(0x0E0,capturedPacket.data_packet.data[0]); break; - + case BLE_LIGHT: setLight(0x120,capturedPacket.data_packet.data[0]); break; - + case BLE_LEVEL: setLevel(0x110,capturedPacket.data_packet.data[0]); break; - + case BLE_DETECT_DATA: sendWindmillData(BLE_DETECT_DATA, getDetect(0x020)); break; - + case BLE_PHOTO_DATA: sendWindmillData(BLE_PHOTO_DATA, getPhoto(0x070)); - break; - + break; + case BLE_MIC_DATA: sendWindmillData(BLE_MIC_DATA, getMic(0x060)); - break; - + break; + case BLE_KNOB_DATA: sendWindmillData(BLE_KNOB_DATA, getKnob(0x050)); break; + } } } diff --git a/libraries/CezerioBlocks/examples/Level/Level.ino b/libraries/CezerioBlocks/examples/Level/Level.ino new file mode 100644 index 0000000..717315f --- /dev/null +++ b/libraries/CezerioBlocks/examples/Level/Level.ino @@ -0,0 +1,37 @@ +#include "cezerioBlocks.h" + +#define knob 0x050 +#define level 0x110 + +unsigned char timerFlag = 0; + +void setup() +{ + initCezerioBlocks(); +} + +void loop() +{ +#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) + if(!digitalRead(CAN_INT)) + { + + } +#endif + + if(timerFlag) + { + + unsigned char knobValue = getKnob(knob); + setLevel(level,knobValue); + + timerFlag = 0; + } +} + +#if defined(TIMER_INTERRUPT_ENABLE) +ISR(TIMER1_COMPA_vect) +{ + timerFlag = 1; +} +#endif diff --git a/libraries/CezerioBlocks/examples/MotionDetector/MotionDetector.ino b/libraries/CezerioBlocks/examples/MotionDetector/MotionDetector.ino new file mode 100644 index 0000000..91e72c7 --- /dev/null +++ b/libraries/CezerioBlocks/examples/MotionDetector/MotionDetector.ino @@ -0,0 +1,46 @@ +#include "cezerioBlocks.h" + +#define bipp 0x0E0 +#define gesture 0x040 + +unsigned char timerFlag = 0; + +void setup() +{ + initCezerioBlocks(); +} + +void loop() +{ +#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) + if(!digitalRead(CAN_INT)) + { + + } +#endif + +if(timerFlag) +{ +unsigned char hareket = getGesture(gesture); + + if (hareket == 1) + { + setBipp(bipp, 1); + hareket = getGesture(gesture); + } + else + { + setBipp(bipp, 0); + hareket = getGesture(gesture); + } + + timerFlag = 0; + } +} + +#if defined(TIMER_INTERRUPT_ENABLE) +ISR(TIMER1_COMPA_vect) +{ + timerFlag = 1; +} +#endif diff --git a/libraries/CezerioBlocks/examples/NightLamb/NightLamb.ino b/libraries/CezerioBlocks/examples/NightLamb/NightLamb.ino new file mode 100644 index 0000000..4788d77 --- /dev/null +++ b/libraries/CezerioBlocks/examples/NightLamb/NightLamb.ino @@ -0,0 +1,45 @@ +#include "cezerioBlocks.h" + +#define photo 0x070 +#define light 0x120 + +unsigned char timerFlag = 0; + +void setup() +{ + initCezerioBlocks(); +} + +void loop() +{ +#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) + if(!digitalRead(CAN_INT)) + { + + } +#endif + + if(timerFlag) + { + + unsigned char photoLevel = getPhoto(photo); + + if(photoLevel>=200) + { + setLight(light, HIGH); + } + else + { + setLight(light, LOW); + } + + timerFlag = 0; + } +} + +#if defined(TIMER_INTERRUPT_ENABLE) +ISR(TIMER1_COMPA_vect) +{ + timerFlag = 1; +} +#endif diff --git a/libraries/CezerioBlocks/examples/Runner/Runner.ino b/libraries/CezerioBlocks/examples/Runner/Runner.ino index d79a400..7352625 100644 --- a/libraries/CezerioBlocks/examples/Runner/Runner.ino +++ b/libraries/CezerioBlocks/examples/Runner/Runner.ino @@ -1,50 +1,23 @@ -/* - SmartBlockSTM32ArduinoDemo.ino - 2017 Copyright (c) RFtek Electronics Ltd. All right reserved. - - Authors : Huseyin Ulvi AYDOGMUS, Ozgur BOSTAN - Date : 2017-03-21 - - This sketch is a demo template for the logical operations of - SmartBlock functions. SmartBlockFunctions.cpp v1.1.0 is used. - - the SmartBlocks: 2x Detect Block (Input Blocks) - 2x Motion Block (Output Blocks) - - Note: Any of the interrupt capabilities can be used by uncommenting the - #define statements (TIMER and/or CAN RECEIVE interrupt) - -*/ - -#include "SmartBlockFunctions.h" +#include "cezerioBlocks.h" #define blackDetect 0x020 #define redDetect 0x021 -#define knob 0x050 -#define mic 0x060 -#define photo 0x070 -#define bipp 0x0E0 -#define level 0x110 -#define light 0x120 #define purpleMotor 0x140 #define orangeMotor 0x141 -#define redMotor 0x142 -#define blueMotor 0x143 -#define propellerMotor 0x144 unsigned char timerFlag = 0; void setup() -{ - initSmartBlocks(); +{ + initCezerioBlocks(); } void loop() { -#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) +#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) if(!digitalRead(CAN_INT)) { - + } #endif @@ -64,11 +37,16 @@ void loop() setMotion(purpleMotor, motorDirectionForward, 255, motorDriverEnable); setMotion(orangeMotor, motorDirectionForward, 255, motorDriverEnable); } - else() + else if(forwardObject>=1 && backwardObject>=1) { setMotion(purpleMotor, motorDirectionForward, 0, motorDriverEnable); setMotion(orangeMotor, motorDirectionForward, 0, motorDriverEnable); } + else + { + setMotion(purpleMotor, motorDirectionForward, 255, motorDriverEnable); + setMotion(orangeMotor, motorDirectionBackward, 255, motorDriverEnable); + } timerFlag = 0; } } @@ -79,6 +57,3 @@ ISR(TIMER1_COMPA_vect) timerFlag = 1; } #endif -/********************************************************************************************************* - END FILE -*********************************************************************************************************/ diff --git a/libraries/CezerioBlocks/examples/SendReceive/SendReceive.ino b/libraries/CezerioBlocks/examples/SendReceive/SendReceive.ino index b0098e1..0d14d2d 100644 --- a/libraries/CezerioBlocks/examples/SendReceive/SendReceive.ino +++ b/libraries/CezerioBlocks/examples/SendReceive/SendReceive.ino @@ -1,36 +1,18 @@ -/* - SendReceive.ino - 2017 Copyright (c) RFtek Electronics Ltd. All right reserved. - - Authors : Huseyin Ulvi AYDOGMUS, Ozgur BOSTAN - Date : 2017-03-21 - - This sketch is a demo template for the logical operations of - SmartBlock functions. SmartBlockFunctions.cpp v1.3.0 is used. - - the SmartBlocks: 2x Knob Block, 1x Detect Block (Input Blocks) - 1x Lıght Block, 1x Bipp Block, 1x Motion Block (Output Blocks) - - Note: Any of the interrupt capabilities can be used by uncommenting the - #define statements (TIMER and/or CAN RECEIVE interrupt) - -*/ - -#include "SmartBlockFunctions.h" +#include "cezerioBlocks.h" unsigned char timerFlag = 0; void setup() -{ - initSmartBlocks(); +{ + initCezerioBlocks(); } void loop() { -#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) +#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) if(!digitalRead(CAN_INT)) { - + } #endif @@ -38,10 +20,10 @@ void loop() { unsigned char motorSpeed = getKnob(MESSAGE_ID_KNOB_BLOCK); setMotion(MESSAGE_ID_MOTION_BLOCK, motorDirectionForward, motorSpeed, motorDriverEnable); - + unsigned char ledState = (getKnob(MESSAGE_ID_KNOB_BLOCK + 1) < 0x7F) ? 0 : 1; setLight(MESSAGE_ID_LIGHT_BLOCK, ledState); - + unsigned char buzzerState = !getDetect(MESSAGE_ID_DETECT_BLOCK); setBipp(MESSAGE_ID_BIPP_BLOCK, buzzerState); @@ -55,6 +37,3 @@ ISR(TIMER1_COMPA_vect) timerFlag = 1; } #endif -/********************************************************************************************************* - END FILE -*********************************************************************************************************/ diff --git a/libraries/CezerioBlocks/examples/Sensormatic/Sensormatic.ino b/libraries/CezerioBlocks/examples/Sensormatic/Sensormatic.ino index 665390b..1e96ad9 100644 --- a/libraries/CezerioBlocks/examples/Sensormatic/Sensormatic.ino +++ b/libraries/CezerioBlocks/examples/Sensormatic/Sensormatic.ino @@ -1,49 +1,26 @@ -/* - SmartBlockSTM32ArduinoDemo.ino - 2017 Copyright (c) RFtek Electronics Ltd. All right reserved. - - Authors : Huseyin Ulvi AYDOGMUS, Ozgur BOSTAN - Date : 2017-03-21 - - This sketch is a demo template for the logical operations of - SmartBlock functions. SmartBlockFunctions.cpp v1.1.0 is used. - - the SmartBlocks: 1x KnobBlock, 1x PhotoBlock, 1x MicBlock (Input Blocks) - 1x LıghtBlock, 1xBippBlock, 1xLevelBlock, 1x MotionBlock (Output Blocks) +#include "cezerioBlocks.h" - Note: Any of the interrupt capabilities can be used by uncommenting the - #define statements (TIMER and/or CAN RECEIVE interrupt) -*/ - -#include "SmartBlockFunctions.h" - -#define blackDetect 0x020 -#define redDetect 0x021 #define knob 0x050 #define mic 0x060 #define photo 0x070 #define bipp 0x0E0 -#define level 0x110 +#define level 0x110 #define light 0x120 -#define purpleMotor 0x140 -#define orangeMotor 0x141 -#define redMotor 0x142 -#define blueMotor 0x143 #define propellerMotor 0x144 unsigned char timerFlag = 0; void setup() -{ - initSmartBlocks(); +{ + initCezerioBlocks(); } void loop() { -#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) +#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) if(!digitalRead(CAN_INT)) { - + } #endif @@ -52,26 +29,26 @@ void loop() unsigned char motorSpeed = getKnob(knob); unsigned char photoLevel = getPhoto(photo); unsigned char soundLevel = getMic(mic); - - if(photoLevel<15) + + if(photoLevel>200) { setMotion(propellerMotor, motorDirectionForward, motorSpeed, motorDriverDisable); - setLight(light, 1); - setLevel(level,motorSpeed); + setLight(light, 1); + setLevel(level,motorSpeed); } - if(photoLevel>=15) + if(photoLevel<=200) { setMotion(propellerMotor, motorDirectionForward, motorSpeed, motorDriverEnable); - setLight(light, 0); + setLight(light, 0); setLevel(level,soundLevel); } - if(soundLevel>10) + if(soundLevel>200 || soundLevel<100) { setBipp(bipp,1); setLevel(level,soundLevel); } - if(soundLevel<=10) + else { setBipp(bipp,0); } @@ -85,7 +62,3 @@ ISR(TIMER1_COMPA_vect) timerFlag = 1; } #endif - -/********************************************************************************************************* - END FILE -*********************************************************************************************************/ diff --git a/libraries/CezerioBlocks/examples/ShakyMic/ShakyMic.ino b/libraries/CezerioBlocks/examples/ShakyMic/ShakyMic.ino new file mode 100644 index 0000000..f231c84 --- /dev/null +++ b/libraries/CezerioBlocks/examples/ShakyMic/ShakyMic.ino @@ -0,0 +1,48 @@ +#include "cezerioBlocks.h" + +#define mic 0x060 +#define birr 0x160 + +unsigned char timerFlag = 0; + +void setup() +{ + initCezerioBlocks(); +} + +void loop() +{ +#if defined(CAN_RECEIVE_INTERRUPT_ENABLE) + if(!digitalRead(CAN_INT)) + { + + } +#endif + + if(timerFlag) + { + + unsigned char micValue = getMic(mic); + Serial.println(micValue); + + if(micValue >= 200|| micValue <= 100) + { + setBirrr(birr, motorDirectionForward, 255, motorDriverEnable); + delay(1500); + } + else + { + setBirrr(birr, motorDirectionForward, 0, motorDriverEnable); + delay(1000); + } + + timerFlag = 0; + } +} + +#if defined(TIMER_INTERRUPT_ENABLE) +ISR(TIMER1_COMPA_vect) +{ + timerFlag = 1; +} +#endif diff --git a/libraries/CezerioBlocks/keywords.txt b/libraries/CezerioBlocks/keywords.txt index 3fda369..8285a8f 100644 --- a/libraries/CezerioBlocks/keywords.txt +++ b/libraries/CezerioBlocks/keywords.txt @@ -1,6 +1,6 @@ createDataRequestPacket KEYWORD2 getInputDataAndDriveOutput KEYWORD2 -initSmartBlocks KEYWORD2 +initCezerioBlocks KEYWORD2 initSmartBlue KEYWORD2 getAcc KEYWORD2 diff --git a/libraries/CezerioBlocks/library.properties b/libraries/CezerioBlocks/library.properties index 39eb92d..dd0b0eb 100644 --- a/libraries/CezerioBlocks/library.properties +++ b/libraries/CezerioBlocks/library.properties @@ -1,9 +1,9 @@ -name=the SmartBlock Brain +name=cezerio Blocks version=1.0.1 -author=the SmartBlock Inc. -maintainer=the SmartBlock Inc. -sentence=Main operataional block of the SmartBlock +author=cezerio Blocks +maintainer=cezerio Blocks +sentence=Main operataional block of cezerio Blocks paragraph=Main block gets data from sensor blocks and directs them to actuator blocks with meaningful operational functions. category=Uncategorized -url=https://www.thesmartblock.net +url=https://github.com/cezer-io/cezerio-blocks-arduino architectures=avr diff --git a/libraries/CezerioBlocks/src/DataTransferFunctions.cpp b/libraries/CezerioBlocks/src/DataTransferFunctions.cpp index 3c1cd0d..5158c63 100644 --- a/libraries/CezerioBlocks/src/DataTransferFunctions.cpp +++ b/libraries/CezerioBlocks/src/DataTransferFunctions.cpp @@ -1,30 +1,8 @@ -/* - DataTransferFunctions.cpp - 2017 Copyright (c) RFtek Electronics Ltd. All right reserved. - - Authors : Huseyin Ulvi AYDOGMUS, Ozgur BOSTAN - Date : 2017-04-27 - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110- - 1301 USA -*/ - #include "DataTransferFunctions.h" unsigned char resolvePacketFlag = 0; /** - * @brief Capture packet from Serial Data + * @brief Capture packet from Serial Data * @param None * @retval None */ @@ -33,9 +11,9 @@ void captureData(capturedPacketType* capturedPacket, const unsigned char capturedDataSize) { unsigned char i = 0; - + for(i = 0; i < capturedDataSize; i++) - { + { switch(capturedPacket->data_capture_status) { case CAPTURE_START: @@ -50,15 +28,15 @@ void captureData(capturedPacketType* capturedPacket, capturedPacket->data_capture_status = CAPTURE_START; capturedPacket->data_counter = 0; } - + break; } - + case CAPTURE_ROBOT_ID: { capturedPacket->data_packet.robot_id = capturedData[i]; capturedPacket->data_capture_status = CAPTURE_PACKET_ID; - + break; } @@ -66,51 +44,51 @@ void captureData(capturedPacketType* capturedPacket, { capturedPacket->data_packet.packet_id = capturedData[i]; capturedPacket->data_capture_status = CAPTURE_DATA; - + break; } - + case CAPTURE_DATA: { capturedPacket->data_packet.data[capturedPacket->data_counter] = capturedData[i]; capturedPacket->data_counter++; - + if(capturedPacket->data_counter >= 1) { capturedPacket->data_capture_status = CAPTURE_STOP; } - + break; - } - + } + case CAPTURE_STOP: { if(STOP_BYTE == capturedData[i]) { capturedPacket->data_packet.stop_byte = capturedData[i]; - - // packet resolve + + // packet resolve //resolvePacket(&(capturedPacket->data_packet)); resolvePacketFlag = 1; } - + capturedPacket->data_capture_status = CAPTURE_START; capturedPacket->data_counter = 0; - + break; } - + default: { capturedPacket->data_capture_status = CAPTURE_START; capturedPacket->data_counter = 0; } } - } + } } /** - * @brief Pack data with a given format + * @brief Pack data with a given format * @param None * @retval None */ @@ -123,22 +101,22 @@ void packData(dataPacketType* data_packet, unsigned char robotID, unsigned char } /** - * @brief Resolve captured Serial Data + * @brief Resolve captured Serial Data * @param None * @retval None */ void resolvePacket(const dataPacketType* capturedPacket) { dataPacketType packet = {0}; - + switch(capturedPacket->packet_id) - { + { case BLE_ROBOT_NAME: - - break; + + break; case BLE_MOVE_FORWARD: - + break; case BLE_MOVE_BACKWARD: @@ -158,7 +136,7 @@ void resolvePacket(const dataPacketType* capturedPacket) break; case BLE_MOVE_FORWARD_LEFT: - + break; case BLE_MOVE_BACKWARD_RIGHT: @@ -334,7 +312,7 @@ void resolvePacket(const dataPacketType* capturedPacket) break; default: - + break; } } diff --git a/libraries/CezerioBlocks/src/DataTransferFunctions.h b/libraries/CezerioBlocks/src/DataTransferFunctions.h index 3dfa13e..49d8f75 100644 --- a/libraries/CezerioBlocks/src/DataTransferFunctions.h +++ b/libraries/CezerioBlocks/src/DataTransferFunctions.h @@ -1,24 +1,3 @@ -/* - DataTransferFunctions.h - 2017 Copyright (c) RFtek Electronics Ltd. All right reserved. - - Authors : Huseyin Ulvi AYDOGMUS, Ozgur BOSTAN - Date : 2017-04-27 - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110- - 1301 USA -*/ #ifndef DATATRANSFERFUNCTIONS_H_ #define DATATRANSFERFUNCTIONS_H_ @@ -56,7 +35,7 @@ enum dataRobotIDs ARM, LOADER, SNAKE, - EXCAVATOR, + EXCAVATOR, MAZER }; @@ -115,7 +94,7 @@ enum dataPacketIDs }; /********************************************************************************************************* - * Structs + * Structs *********************************************************************************************************/ typedef struct @@ -135,7 +114,7 @@ typedef struct } capturedPacketType; /********************************************************************************************************* - * DataTransferFunctions + * DataTransferFunctions *********************************************************************************************************/ diff --git a/libraries/CezerioBlocks/src/SmartBlockFunctions.cpp b/libraries/CezerioBlocks/src/cezerioBlocks.cpp similarity index 81% rename from libraries/CezerioBlocks/src/SmartBlockFunctions.cpp rename to libraries/CezerioBlocks/src/cezerioBlocks.cpp index e7f89ae..2e838e9 100644 --- a/libraries/CezerioBlocks/src/SmartBlockFunctions.cpp +++ b/libraries/CezerioBlocks/src/cezerioBlocks.cpp @@ -1,66 +1,4 @@ -/* - SmartBlockFunctions.cpp - 2017 Copyright (c) RFtek Electronics Ltd. All right reserved. - - Authors : Huseyin Ulvi AYDOGMUS, Ozgur BOSTAN - Date : 2017-03-20 - Version : 1.0.0 - - generic function for data request - - generic function for data receive and data sent - - main functions for output blocks - - Date : 2017-03-21 - Version : 1.1.0 - - generic function for data request - - generic function for data receive and data sent - - main functions for output blocks (removed) - - block specific functions for both input and output blocks added - - Date : 2017-03-22 - Version : 1.2.0 - - initSmartBlocks() function added to simplfy startup process - - Date : 2017-03-23 - Version : 1.2.1 - - minor change; timer and can interrupt definitions moved to - "SmartBlockFunctions.h" from "SmartBlockFunctions.cpp" - - Date : 2017-03-30 - Version : 1.2.2 - - new blocks and related functions added (TILT, COLOUR, SLIDE, FOLLOW, BIRRR) - - Date : 2017-04-03 - Version : 1.3.0 - - new library added for BLUE BLOCK (SoftwareSerial) - - Date : 2017-04-27 - Version : 1.4.0 - - new library added for bluetooth communication (DataTransferFunctions) - - functions: getSmartBlueData, sendSmartBlueData - - Date : 2017-04-28 - Version : 1.4.1 - - new functions added for bluetooth communication (DataTransferFunctions) - - new example sketch: SendReceiveBluetooth.ino - - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110- - 1301 USA -*/ - -#include "SmartBlockFunctions.h" +#include "cezerioBlocks.h" #include "SoftwareSerial.h" #include "DataTransferFunctions.h" @@ -75,30 +13,30 @@ SoftwareSerial theSmartBlue(8, 9); // Set Software TX-RX to pins 8-9, instan capturedPacketType capturedPacket; /********************************************************************************************************* - * INIT FUNCTIONS + * INIT FUNCTIONS *********************************************************************************************************/ /** - * @brief Initialization for the blocks to be ready for operation + * @brief Initialization for the blocks to be ready for operation * @param None * @retval None */ -void initSmartBlocks(void) +void initCezerioBlocks(void) { Serial.begin(UART_BAUD_RATE); - + // Initialize MCP2515 running at 16MHz with a baudrate of 1000kb/s and the masks and filters disabled. if(CAN.begin(MCP_ANY, CAN_1000KBPS, MCP_16MHZ) == CAN_OK) Serial.println("MCP2515 Initialized Successfully!"); else Serial.println("Error Initializing MCP2515..."); - + CAN.setMode(MCP_NORMAL); // Set operation mode to normal so the MCP2515 sends acks to received data. - + #if defined(CAN_RECEIVE_INTERRUPT_ENABLE) pinMode(CAN_INT, INPUT); // Configuring pin for /INT input -#endif +#endif Serial.println("MCP2515 Library Receive Example..."); @@ -117,7 +55,7 @@ void initSmartBlocks(void) } /** - * @brief Initialization for BLUE BLOCK to be ready for operation + * @brief Initialization for BLUE BLOCK to be ready for operation * @param None * @retval None */ @@ -127,12 +65,12 @@ void initSmartBlue(void) } /********************************************************************************************************* - * BLE FUNCTIONS + * BLE FUNCTIONS *********************************************************************************************************/ /** - * @brief Get data from bluetooth device + * @brief Get data from bluetooth device * @param None * @retval None */ @@ -148,12 +86,12 @@ void getSmartBlueData(void) } /** - * @brief Send data to bluetooth device + * @brief Send data to bluetooth device * @param None * @retval None */ void sendSmartBlueData(unsigned char robotID, unsigned char packetID, unsigned char data) -{ +{ theSmartBlue.write('$'); theSmartBlue.write(robotID); theSmartBlue.write(packetID); @@ -162,7 +100,7 @@ void sendSmartBlueData(unsigned char robotID, unsigned char packetID, unsigned c } /** - * @brief Send Roller data to bluetooth device + * @brief Send Roller data to bluetooth device * @param None * @retval None */ @@ -172,7 +110,7 @@ void sendRollerData(unsigned char packetID, unsigned char data) } /** - * @brief Send Chariot data to bluetooth device + * @brief Send Chariot data to bluetooth device * @param None * @retval None */ @@ -182,7 +120,7 @@ void sendChariotData(unsigned char packetID, unsigned char data) } /** - * @brief Send Sumo data to bluetooth device + * @brief Send Sumo data to bluetooth device * @param None * @retval None */ @@ -192,7 +130,7 @@ void sendSumoData(unsigned char packetID, unsigned char data) } /** - * @brief Send Balance data to bluetooth device + * @brief Send Balance data to bluetooth device * @param None * @retval None */ @@ -202,7 +140,7 @@ void sendBalanceData(unsigned char packetID, unsigned char data) } /** - * @brief Send Windmill data to bluetooth device + * @brief Send Windmill data to bluetooth device * @param None * @retval None */ @@ -212,7 +150,7 @@ void sendWindmillData(unsigned char packetID, unsigned char data) } /** - * @brief Send FlyingCar data to bluetooth device + * @brief Send FlyingCar data to bluetooth device * @param None * @retval None */ @@ -222,7 +160,7 @@ void sendFlyingCarData(unsigned char packetID, unsigned char data) } /** - * @brief Send Spindle data to bluetooth device + * @brief Send Spindle data to bluetooth device * @param None * @retval None */ @@ -232,7 +170,7 @@ void sendSpindleData(unsigned char packetID, unsigned char data) } /** - * @brief Send Truck data to bluetooth device + * @brief Send Truck data to bluetooth device * @param None * @retval None */ @@ -242,7 +180,7 @@ void sendTruckData(unsigned char packetID, unsigned char data) } /** - * @brief Send Tank data to bluetooth device + * @brief Send Tank data to bluetooth device * @param None * @retval None */ @@ -252,7 +190,7 @@ void sendTankData(unsigned char packetID, unsigned char data) } /** - * @brief Send LineTracker data to bluetooth device + * @brief Send LineTracker data to bluetooth device * @param None * @retval None */ @@ -262,7 +200,7 @@ void sendLineTrackerData(unsigned char packetID, unsigned char data) } /** - * @brief Send Arm data to bluetooth device + * @brief Send Arm data to bluetooth device * @param None * @retval None */ @@ -272,7 +210,7 @@ void sendArmData(unsigned char packetID, unsigned char data) } /** - * @brief Send Loader data to bluetooth device + * @brief Send Loader data to bluetooth device * @param None * @retval None */ @@ -282,7 +220,7 @@ void sendLoaderData(unsigned char packetID, unsigned char data) } /** - * @brief Send Snake data to bluetooth device + * @brief Send Snake data to bluetooth device * @param None * @retval None */ @@ -292,7 +230,7 @@ void sendSnakeData(unsigned char packetID, unsigned char data) } /** - * @brief Send Excavator data to bluetooth device + * @brief Send Excavator data to bluetooth device * @param None * @retval None */ @@ -302,7 +240,7 @@ void sendExcavatorData(unsigned char packetID, unsigned char data) } /** - * @brief Send Mazer data to bluetooth device + * @brief Send Mazer data to bluetooth device * @param None * @retval None */ @@ -312,11 +250,11 @@ void sendMazerData(unsigned char packetID, unsigned char data) } /********************************************************************************************************* - * GENERIC FUNCTIONS + * GENERIC FUNCTIONS *********************************************************************************************************/ /** - * @brief Sends data request for input blocks + * @brief Sends data request for input blocks * @param INPUT BLOCK MESSAGE IDs * @retval None */ @@ -327,14 +265,14 @@ void createDataRequestPacket(unsigned int inputBlockMessageId) } /** - * @brief Reads values from input blocks and drives + * @brief Reads values from input blocks and drives output blocks with these data based on message IDs * @param None * @retval None */ void getInputDataAndDriveOutput(void) { - unsigned char motorSpeed = 0; + unsigned char motorSpeed = 0; unsigned char motorAngle = 0; unsigned char ledState = 0; unsigned char redLedState = 0; @@ -342,89 +280,89 @@ void getInputDataAndDriveOutput(void) unsigned char blueLedState = 0; unsigned char buzzerState = 0; unsigned char barGraphData = 0; - + CAN.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s) - + switch(rxId) { case MESSAGE_ID_BALANCE_BLOCK: - + break; - + case MESSAGE_ID_BALANCE_BLOCK + 1: - + break; - + case MESSAGE_ID_DETECT_BLOCK: - + break; - + case MESSAGE_ID_DETECT_BLOCK + 1: - + break; - + case MESSAGE_ID_EYE_BLOCK: - + break; - + case MESSAGE_ID_EYE_BLOCK + 1: - + break; - + case MESSAGE_ID_GESTURE_BLOCK: - + break; - + case MESSAGE_ID_GESTURE_BLOCK + 1: - + break; - + case MESSAGE_ID_KNOB_BLOCK: - + break; - + case MESSAGE_ID_KNOB_BLOCK + 1: - + break; - + case MESSAGE_ID_MIC_BLOCK: - + break; - + case MESSAGE_ID_MIC_BLOCK + 1: - + break; - + case MESSAGE_ID_PHOTO_BLOCK: - + break; - + case MESSAGE_ID_PHOTO_BLOCK + 1: - + break; - + case MESSAGE_ID_TEMP_BLOCK: - + break; - + case MESSAGE_ID_TEMP_BLOCK + 1: - + break; - + default: break; } } /** - * @brief Converts ASCII numbers to hex (integer value) + * @brief Converts ASCII numbers to hex (integer value) * @param Captured ASCII data * @retval Converted hex value */ unsigned char asciiToHex(unsigned char asciiData) { unsigned char hexData = 0; - + if((asciiData >= 0x30) && (asciiData <= 0x39)) { hexData = asciiData - 0x30; @@ -434,7 +372,7 @@ unsigned char asciiToHex(unsigned char asciiData) } /** - * @brief Converts hex (integer value) numbers to ASCII + * @brief Converts hex (integer value) numbers to ASCII * @param Captured hex data * @retval Converted ASCII value */ @@ -451,7 +389,7 @@ unsigned char hexToAscii(unsigned char hexData) } /********************************************************************************************************* - * INPUT FUNCTIONS + * INPUT FUNCTIONS *********************************************************************************************************/ /** @@ -462,14 +400,14 @@ unsigned char hexToAscii(unsigned char hexData) int* getAcc(unsigned int balanceBlockID) { createDataRequestPacket(balanceBlockID); - + CAN.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s) CAN.readMsgBuf(&rxId, &len, rx2Buf); // Read data: len = data length, buf = data byte(s) static int accData[3]; accData[0] = (rxBuf[3] << 8) + rxBuf[4]; accData[1] = (rxBuf[5] << 8) + rxBuf[6]; accData[2] = (rxBuf[7] << 8) + rx2Buf[0]; - + return accData; } @@ -481,14 +419,14 @@ int* getAcc(unsigned int balanceBlockID) int* getGyro(unsigned int balanceBlockID) { createDataRequestPacket(balanceBlockID); - + CAN.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s) CAN.readMsgBuf(&rxId, &len, rx2Buf); // Read data: len = data length, buf = data byte(s) static int gyroData[3]; gyroData[0] = (rx2Buf[1] << 8) + rx2Buf[2]; gyroData[1] = (rx2Buf[3] << 8) + rx2Buf[4]; gyroData[2] = (rx2Buf[5] << 8) + rx2Buf[6]; - + return gyroData; } @@ -500,10 +438,10 @@ int* getGyro(unsigned int balanceBlockID) unsigned char getDetect(unsigned int detectBlockID) { createDataRequestPacket(detectBlockID); - + CAN.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s) unsigned char irData = rxBuf[3]; - + return irData; } @@ -515,10 +453,10 @@ unsigned char getDetect(unsigned int detectBlockID) unsigned char getEye(unsigned int eyeBlockID) { createDataRequestPacket(eyeBlockID); - + CAN.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s) unsigned char ultrasonicData = rxBuf[3]; - + return ultrasonicData; } @@ -530,10 +468,10 @@ unsigned char getEye(unsigned int eyeBlockID) unsigned char getGesture(unsigned int gestureBlockID) { createDataRequestPacket(gestureBlockID); - + CAN.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s) unsigned char pirData = rxBuf[3]; - + return pirData; } @@ -545,10 +483,10 @@ unsigned char getGesture(unsigned int gestureBlockID) unsigned char getKnob(unsigned int knobBlockID) { createDataRequestPacket(knobBlockID); - + CAN.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s) unsigned char knobData = rxBuf[3]; - + return knobData; } @@ -560,10 +498,10 @@ unsigned char getKnob(unsigned int knobBlockID) unsigned char getMic(unsigned int micBlockID) { createDataRequestPacket(micBlockID); - + CAN.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s) unsigned char micData = rxBuf[3]; - + return micData; } @@ -575,10 +513,10 @@ unsigned char getMic(unsigned int micBlockID) unsigned char getPhoto(unsigned int photoBlockID) { createDataRequestPacket(photoBlockID); - + CAN.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s) unsigned char photoData = rxBuf[3]; - + return photoData; } @@ -590,10 +528,10 @@ unsigned char getPhoto(unsigned int photoBlockID) unsigned char getTemp(unsigned int tempBlockID) { createDataRequestPacket(tempBlockID); - + CAN.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s) unsigned char tempData = rxBuf[3]; - + return tempData; } @@ -605,10 +543,10 @@ unsigned char getTemp(unsigned int tempBlockID) unsigned char getTilt(unsigned int tiltBlockID) { createDataRequestPacket(tiltBlockID); - + CAN.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s) unsigned char tiltData = rxBuf[3]; - + return tiltData; } @@ -620,10 +558,10 @@ unsigned char getTilt(unsigned int tiltBlockID) //unsigned char getTemp(unsigned int tempBlockID) //{ // createDataRequestPacket(tempBlockID); -// +// // CAN.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s) // unsigned char tempData = rxBuf[3]; -// +// // return tempData; //} @@ -635,10 +573,10 @@ unsigned char getTilt(unsigned int tiltBlockID) unsigned char getSlide(unsigned int slideBlockID) { createDataRequestPacket(slideBlockID); - + CAN.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s) unsigned char sliderData = rxBuf[3]; - + return sliderData; } @@ -650,20 +588,20 @@ unsigned char getSlide(unsigned int slideBlockID) unsigned char getFollow(unsigned int followBlockID) { createDataRequestPacket(followBlockID); - + CAN.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s) unsigned char irData = rxBuf[3]; - + return irData; } /********************************************************************************************************* - * OUTPUT FUNCTIONS + * OUTPUT FUNCTIONS *********************************************************************************************************/ /** * @brief Sets DC motor speed and direction values for 360 BLOCK - * @param MESSAGE_ID_360_BLOCK + * @param MESSAGE_ID_360_BLOCK motorDirection : forward or backward motorSpeed : PWM value (0x00 - 0xFF) motorEnable : enable or disable @@ -678,7 +616,7 @@ void set360(unsigned int motor360BlockID, unsigned char motorDirection, unsigned /** * @brief Sets buzzer state for BIPP BLOCK * @param MESSAGE_ID_BIPP_BLOCK - buzzerState : "0" or "1" + buzzerState : "0" or "1" * @retval None */ void setBipp(unsigned int bippBlockID, unsigned char buzzerState) @@ -717,7 +655,7 @@ void setGrip(unsigned int gripBlockID, unsigned char motorAngle, unsigned char m /** * @brief Sets bar graph level value for LEVEL BLOCK * @param MESSAGE_ID_LEVEL_BLOCK - barGraphData : 0x00 - 0xFF + barGraphData : 0x00 - 0xFF * @retval None */ void setLevel(unsigned int levelBlockID, unsigned char barGraphData) @@ -753,7 +691,7 @@ void setLink(unsigned int linkBlockID, unsigned char motorAngle, unsigned char m /** * @brief Sets DC motor speed and direction values for MOTION BLOCK - * @param MESSAGE_ID_MOTION_BLOCK + * @param MESSAGE_ID_MOTION_BLOCK motorDdirection : forward or backward motorSpeed : PWM value (0x00 - 0xFF) motorEnable : enable or disable @@ -767,7 +705,7 @@ void setMotion(unsigned int motionBlockID, unsigned char motorDirection, unsigne /** * @brief Sets DC motor speed and direction values for ROLL BLOCK - * @param MESSAGE_ID_ROLL_BLOCK + * @param MESSAGE_ID_ROLL_BLOCK motorDdirection : forward or backward motorSpeed : PWM value (0x00 - 0xFF) motorEnable : enable or disable @@ -781,7 +719,7 @@ void setRoll(unsigned int rollBlockID, unsigned char motorDirection, unsigned ch /** * @brief Sets DC motor speed and direction values for BIRRR BLOCK - * @param MESSAGE_ID_BIRRR_BLOCK + * @param MESSAGE_ID_BIRRR_BLOCK motorDdirection : forward or backward motorSpeed : PWM value (0x00 - 0xFF) motorEnable : enable or disable @@ -793,6 +731,22 @@ void setBirrr(unsigned int birrrBlockID, unsigned char motorDirection, unsigned CAN.sendMsgBuf(birrrBlockID, 0, 7, sendData); } +void createBlockDataRequestPacket(unsigned int requestMessageId) +{ + unsigned char sendData[4] = {SYNC_BYTE_START, 0x04, 0x00, SYNC_BYTE_STOP}; + CAN.sendMsgBuf(requestMessageId, 0, 4, sendData); +} + +uint16_t getBlockID() +{ + createBlockDataRequestPacket(MESSAGE_ID_REQUEST); + + CAN.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s) + unsigned char messageIDH = rxBuf[3]; + unsigned char messageIDL = rxBuf[4]; + + return (messageIDH << 8 | messageIDL); +} /********************************************************************************************************* * END FILE *********************************************************************************************************/ diff --git a/libraries/CezerioBlocks/src/SmartBlockFunctions.h b/libraries/CezerioBlocks/src/cezerioBlocks.h similarity index 83% rename from libraries/CezerioBlocks/src/SmartBlockFunctions.h rename to libraries/CezerioBlocks/src/cezerioBlocks.h index 3cae861..3dc9996 100644 --- a/libraries/CezerioBlocks/src/SmartBlockFunctions.h +++ b/libraries/CezerioBlocks/src/cezerioBlocks.h @@ -1,26 +1,5 @@ -/* - SmartBlockFunctions.h - 2017 Copyright (c) RFtek Electronics Ltd. All right reserved. - - Authors : Huseyin Ulvi AYDOGMUS, Ozgur BOSTAN - Date : 2017-03-20 - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110- - 1301 USA -*/ -#ifndef SMARTBLOCKFUNCTIONS_H_ -#define SMARTBLOCKFUNCTIONS_H_ +#ifndef CEZERIOBLOCKS_H_ +#define CEZERIOBLOCKS_H_ #include "mcp_can.h" @@ -74,27 +53,29 @@ #define MESSAGE_ID_LEVEL_BLOCK 0x110 #define MESSAGE_ID_LIGHT_BLOCK 0x120 #define MESSAGE_ID_LINK_BLOCK 0x130 -#define MESSAGE_ID_MOTION_BLOCK 0x140 +#define MESSAGE_ID_MOTION_BLOCK 0x140 #define MESSAGE_ID_ROLL_BLOCK 0x150 #define MESSAGE_ID_BIRRR_BLOCK 0x160 /********************************************************************************************************* - * Variables + * Variables *********************************************************************************************************/ /********************************************************************************************************* - * SmartBlockFunctions + * Functions *********************************************************************************************************/ -/* GENERIC FUNCTIONS */ +/* GENERIC FUNCTIONS */ void createDataRequestPacket(unsigned int blockMessageId); void getInputDataAndDriveOutput(void); unsigned char asciiToHex(unsigned char asciiData); unsigned char hexToAscii(unsigned char hexData); /* INIT FUNCTIONS */ -void initSmartBlocks(void); +void initCezerioBlocks(void); void initSmartBlue(void); +void createBlockDataRequestPacket(unsigned int requestMessageId); +uint16_t getBlockID(); /* BLE FUNCTIONS */ void getSmartBlueData(void); diff --git a/libraries/CezerioBlocks/src/mcp_can.cpp b/libraries/CezerioBlocks/src/mcp_can.cpp index 1e166a8..404005d 100644 --- a/libraries/CezerioBlocks/src/mcp_can.cpp +++ b/libraries/CezerioBlocks/src/mcp_can.cpp @@ -1,26 +1,3 @@ -/* - mcp_can.cpp - 2012 Copyright (c) Seeed Technology Inc. All right reserved. - 2014 Copyright (c) Cory J. Fowler All Rights Reserved. - - Author: Loovee - Contributor: Cory J. Fowler - 2014-9-16 - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110- - 1301 USA -*/ #include "mcp_can.h" #define spi_readwrite SPI.transfer @@ -30,7 +7,7 @@ ** Function name: mcp2515_reset ** Descriptions: Performs a software reset *********************************************************************************************************/ -void MCP_CAN::mcp2515_reset(void) +void MCP_CAN::mcp2515_reset(void) { MCP2515_SELECT(); spi_readwrite(MCP_RESET); @@ -42,7 +19,7 @@ void MCP_CAN::mcp2515_reset(void) ** Function name: mcp2515_readRegister ** Descriptions: Read data register *********************************************************************************************************/ -INT8U MCP_CAN::mcp2515_readRegister(const INT8U address) +INT8U MCP_CAN::mcp2515_readRegister(const INT8U address) { INT8U ret; @@ -66,7 +43,7 @@ void MCP_CAN::mcp2515_readRegisterS(const INT8U address, INT8U values[], const I spi_readwrite(MCP_READ); spi_readwrite(address); // mcp2515 has auto-increment of address-pointer - for (i=0; i 0) { #if DEBUG_MODE - Serial.print("Entering Configuration Mode Failure...\r\n"); + Serial.print("Entering Configuration Mode Failure...\r\n"); #endif return res; } @@ -530,7 +507,7 @@ INT8U MCP_CAN::mcp2515_init(const INT8U canIDMode, const INT8U canSpeed, const I MCP_RXB_RX_ANY); break; /* The followingn two functions of the MCP2515 do not work, there is a bug in the silicon. - case (MCP_STD): + case (MCP_STD): mcp2515_modifyRegister(MCP_RXB0CTRL, MCP_RXB_RX_MASK | MCP_RXB_BUKT_MASK, MCP_RXB_RX_STD | MCP_RXB_BUKT_MASK ); @@ -538,7 +515,7 @@ INT8U MCP_CAN::mcp2515_init(const INT8U canIDMode, const INT8U canSpeed, const I MCP_RXB_RX_STD); break; - case (MCP_EXT): + case (MCP_EXT): mcp2515_modifyRegister(MCP_RXB0CTRL, MCP_RXB_RX_MASK | MCP_RXB_BUKT_MASK, MCP_RXB_RX_EXT | MCP_RXB_BUKT_MASK ); @@ -546,29 +523,29 @@ INT8U MCP_CAN::mcp2515_init(const INT8U canIDMode, const INT8U canSpeed, const I MCP_RXB_RX_EXT); break; */ - case (MCP_STDEXT): + case (MCP_STDEXT): mcp2515_modifyRegister(MCP_RXB0CTRL, MCP_RXB_RX_MASK | MCP_RXB_BUKT_MASK, MCP_RXB_RX_STDEXT | MCP_RXB_BUKT_MASK ); mcp2515_modifyRegister(MCP_RXB1CTRL, MCP_RXB_RX_MASK, MCP_RXB_RX_STDEXT); break; - + default: -#if DEBUG_MODE +#if DEBUG_MODE Serial.print("`Setting ID Mode Failure...\r\n"); -#endif +#endif return MCP2515_FAIL; break; -} +} - res = mcp2515_setCANCTRL_Mode(mcpMode); + res = mcp2515_setCANCTRL_Mode(mcpMode); if(res) { -#if DEBUG_MODE +#if DEBUG_MODE Serial.print("Returning to Previous Mode Failure...\r\n"); -#endif +#endif return res; } @@ -588,7 +565,7 @@ void MCP_CAN::mcp2515_write_id( const INT8U mcp_addr, const INT8U ext, const INT canid = (uint16_t)(id & 0x0FFFF); - if ( ext == 1) + if ( ext == 1) { tbufdata[MCP_EID0] = (INT8U) (canid & 0xFF); tbufdata[MCP_EID8] = (INT8U) (canid >> 8); @@ -598,14 +575,14 @@ void MCP_CAN::mcp2515_write_id( const INT8U mcp_addr, const INT8U ext, const INT tbufdata[MCP_SIDL] |= MCP_TXB_EXIDE_M; tbufdata[MCP_SIDH] = (INT8U) (canid >> 5 ); } - else + else { tbufdata[MCP_SIDH] = (INT8U) (canid >> 3 ); tbufdata[MCP_SIDL] = (INT8U) ((canid & 0x07 ) << 5); tbufdata[MCP_EID0] = 0; tbufdata[MCP_EID8] = 0; } - + mcp2515_setRegisterS( mcp_addr, tbufdata, 4 ); } @@ -620,7 +597,7 @@ void MCP_CAN::mcp2515_write_mf( const INT8U mcp_addr, const INT8U ext, const INT canid = (uint16_t)(id & 0x0FFFF); - if ( ext == 1) + if ( ext == 1) { tbufdata[MCP_EID0] = (INT8U) (canid & 0xFF); tbufdata[MCP_EID8] = (INT8U) (canid >> 8); @@ -630,7 +607,7 @@ void MCP_CAN::mcp2515_write_mf( const INT8U mcp_addr, const INT8U ext, const INT tbufdata[MCP_SIDL] |= MCP_TXB_EXIDE_M; tbufdata[MCP_SIDH] = (INT8U) (canid >> 5 ); } - else + else { tbufdata[MCP_EID0] = (INT8U) (canid & 0xFF); tbufdata[MCP_EID8] = (INT8U) (canid >> 8); @@ -638,7 +615,7 @@ void MCP_CAN::mcp2515_write_mf( const INT8U mcp_addr, const INT8U ext, const INT tbufdata[MCP_SIDL] = (INT8U) ((canid & 0x07) << 5); tbufdata[MCP_SIDH] = (INT8U) (canid >> 3 ); } - + mcp2515_setRegisterS( mcp_addr, tbufdata, 4 ); } @@ -657,7 +634,7 @@ void MCP_CAN::mcp2515_read_id( const INT8U mcp_addr, INT8U* ext, INT32U* id ) *id = (tbufdata[MCP_SIDH]<<3) + (tbufdata[MCP_SIDL]>>5); - if ( (tbufdata[MCP_SIDL] & MCP_TXB_EXIDE_M) == MCP_TXB_EXIDE_M ) + if ( (tbufdata[MCP_SIDL] & MCP_TXB_EXIDE_M) == MCP_TXB_EXIDE_M ) { /* extended id */ *id = (*id<<2) + (tbufdata[MCP_SIDL] & 0x03); @@ -676,9 +653,9 @@ void MCP_CAN::mcp2515_write_canMsg( const INT8U buffer_sidh_addr) INT8U mcp_addr; mcp_addr = buffer_sidh_addr; mcp2515_setRegisterS(mcp_addr+5, m_nDta, m_nDlc ); /* write data bytes */ - + if ( m_nRtr == 1) /* if RTR set bit in byte */ - m_nDlc |= MCP_RTR_MASK; + m_nDlc |= MCP_RTR_MASK; mcp2515_setRegister((mcp_addr+4), m_nDlc ); /* write the RTR and DLC */ mcp2515_write_id(mcp_addr, m_nExtFlg, m_nID ); /* write CAN id */ @@ -726,7 +703,7 @@ INT8U MCP_CAN::mcp2515_getNextFreeTXBuf(INT8U *txbuf_n) /* get N ctrlval = mcp2515_readRegister( ctrlregs[i] ); if ( (ctrlval & MCP_TXB_TXREQ_M) == 0 ) { *txbuf_n = ctrlregs[i]+1; /* return SIDH-address of Buffer*/ - + res = MCP2515_OK; return res; /* ! function exit */ } @@ -757,7 +734,7 @@ INT8U MCP_CAN::begin(INT8U idmodeset, INT8U speedset, INT8U clockset) res = mcp2515_init(idmodeset, speedset, clockset); if (res == MCP2515_OK) return CAN_OK; - + return CAN_FAILINIT; } @@ -774,11 +751,11 @@ INT8U MCP_CAN::init_Mask(INT8U num, INT8U ext, INT32U ulData) res = mcp2515_setCANCTRL_Mode(MODE_CONFIG); if(res > 0){ #if DEBUG_MODE - Serial.print("Entering Configuration Mode Failure...\r\n"); + Serial.print("Entering Configuration Mode Failure...\r\n"); #endif return res; } - + if (num == 0){ mcp2515_write_mf(MCP_RXM0SIDH, ext, ulData); @@ -787,11 +764,11 @@ INT8U MCP_CAN::init_Mask(INT8U num, INT8U ext, INT32U ulData) mcp2515_write_mf(MCP_RXM1SIDH, ext, ulData); } else res = MCP2515_FAIL; - + res = mcp2515_setCANCTRL_Mode(mcpMode); if(res > 0){ #if DEBUG_MODE - Serial.print("Entering Previous Mode Failure...\r\nSetting Mask Failure...\r\n"); + Serial.print("Entering Previous Mode Failure...\r\nSetting Mask Failure...\r\n"); #endif return res; } @@ -815,14 +792,14 @@ INT8U MCP_CAN::init_Mask(INT8U num, INT32U ulData) res = mcp2515_setCANCTRL_Mode(MODE_CONFIG); if(res > 0){ #if DEBUG_MODE - Serial.print("Entering Configuration Mode Failure...\r\n"); + Serial.print("Entering Configuration Mode Failure...\r\n"); #endif return res; } - + if((num & 0x80000000) == 0x80000000) ext = 1; - + if (num == 0){ mcp2515_write_mf(MCP_RXM0SIDH, ext, ulData); @@ -831,11 +808,11 @@ INT8U MCP_CAN::init_Mask(INT8U num, INT32U ulData) mcp2515_write_mf(MCP_RXM1SIDH, ext, ulData); } else res = MCP2515_FAIL; - + res = mcp2515_setCANCTRL_Mode(mcpMode); if(res > 0){ #if DEBUG_MODE - Serial.print("Entering Previous Mode Failure...\r\nSetting Mask Failure...\r\n"); + Serial.print("Entering Previous Mode Failure...\r\nSetting Mask Failure...\r\n"); #endif return res; } @@ -859,11 +836,11 @@ INT8U MCP_CAN::init_Filt(INT8U num, INT8U ext, INT32U ulData) if(res > 0) { #if DEBUG_MODE - Serial.print("Enter Configuration Mode Failure...\r\n"); + Serial.print("Enter Configuration Mode Failure...\r\n"); #endif return res; } - + switch( num ) { case 0: @@ -893,19 +870,19 @@ INT8U MCP_CAN::init_Filt(INT8U num, INT8U ext, INT32U ulData) default: res = MCP2515_FAIL; } - + res = mcp2515_setCANCTRL_Mode(mcpMode); if(res > 0) { #if DEBUG_MODE - Serial.print("Entering Previous Mode Failure...\r\nSetting Filter Failure...\r\n"); + Serial.print("Entering Previous Mode Failure...\r\nSetting Filter Failure...\r\n"); #endif return res; } #if DEBUG_MODE Serial.print("Setting Filter Successfull!\r\n"); #endif - + return res; } @@ -917,7 +894,7 @@ INT8U MCP_CAN::init_Filt(INT8U num, INT32U ulData) { INT8U res = MCP2515_OK; INT8U ext = 0; - + #if DEBUG_MODE Serial.print("Starting to Set Filter!\r\n"); #endif @@ -925,14 +902,14 @@ INT8U MCP_CAN::init_Filt(INT8U num, INT32U ulData) if(res > 0) { #if DEBUG_MODE - Serial.print("Enter Configuration Mode Failure...\r\n"); + Serial.print("Enter Configuration Mode Failure...\r\n"); #endif return res; } - + if((num & 0x80000000) == 0x80000000) ext = 1; - + switch( num ) { case 0: @@ -962,19 +939,19 @@ INT8U MCP_CAN::init_Filt(INT8U num, INT32U ulData) default: res = MCP2515_FAIL; } - + res = mcp2515_setCANCTRL_Mode(mcpMode); if(res > 0) { #if DEBUG_MODE - Serial.print("Entering Previous Mode Failure...\r\nSetting Filter Failure...\r\n"); + Serial.print("Entering Previous Mode Failure...\r\nSetting Filter Failure...\r\n"); #endif return res; } #if DEBUG_MODE Serial.print("Setting Filter Successfull!\r\n"); #endif - + return res; } @@ -991,7 +968,7 @@ INT8U MCP_CAN::setMsg(INT32U id, INT8U rtr, INT8U ext, INT8U len, INT8U *pData) m_nDlc = len; for(i = 0; i