├── LICENSE
├── README.md
├── examples
├── 01.LedBrightnessControl
│ └── 01.LedBrightnessControl.ino
├── 02.Terminal
│ └── 02.Terminal.ino
├── 03.Gamepad
│ └── 03.Gamepad.ino
├── 04.PinStateMonitor
│ └── 04.PinStateMonitor.ino
├── 05.Motor Control
│ └── AllMotors
│ │ └── AllMotors.ino
├── 06.Inputs
│ └── 06.Inputs.ino
├── 07.Camera
│ ├── captureImages
│ │ └── captureImages.ino
│ └── recordVideos
│ │ └── recordVideos.ino
├── 08.Phone Sensor
│ ├── Accelerometer
│ │ └── Accelerometer.ino
│ ├── Barometer
│ │ └── Barometer.ino
│ ├── GPS
│ │ └── GPS.ino
│ ├── Gyroscope
│ │ └── Gyroscope.ino
│ ├── Light
│ │ └── Light.ino
│ ├── Magnetometer
│ │ └── Magnetometer.ino
│ ├── Proximity
│ │ └── Proximity.ino
│ ├── Sound
│ │ └── Sound.ino
│ └── Temperature
│ │ └── Temperature.ino
├── 10.IOT
│ ├── DataLogger
│ │ └── DataLogger.ino
│ ├── Notification
│ │ └── Notification.ino
│ └── SMS
│ │ └── SMS.ino
└── 11.Music
│ └── 11.Music.ino
├── keywords.txt
├── library.properties
└── src
├── CameraModule.cpp
├── CameraModule.h
├── CircularBuffer.h
├── ColorDetectorModule.cpp
├── ColorDetectorModule.h
├── DabbleESP32.cpp
├── DabbleESP32.h
├── DabbleInputs.cpp
├── DabbleInputs.h
├── DabblePrint.cpp
├── DabblePrint.h
├── DabblePrintln.cpp
├── DabblePrintln.h
├── DataLoggerModule.cpp
├── DataLoggerModule.h
├── GamePadModule.cpp
├── GamePadModule.h
├── IncludedModulesDefines.h
├── InternetModule.cpp
├── InternetModule.h
├── LedControlModule.cpp
├── LedControlModule.h
├── ModuleIds.h
├── ModuleIncludes.h
├── ModuleInstantiation.h
├── ModuleParent.cpp
├── ModuleParent.h
├── ModuleSelection.h
├── MusicModule.cpp
├── MusicModule.h
├── NotifyAndSMSModule.cpp
├── NotifyAndSMSModule.h
├── PinMonitorModule.cpp
├── PinMonitorModule.h
├── SensorModule.cpp
├── SensorModule.h
├── TerminalModule.cpp
├── TerminalModule.h
├── esp32BLEUtilities.cpp
├── esp32BLEUtilities.h
├── motorControls.cpp
└── motorControls.h
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Whether you’re a student, a teacher, or a hobbyist, Dabble is the perfect place for all your DIYing needs. It transforms your Smartphone into a virtual I/O device and lets you control hardware via Bluetooth, communicate with it, access sensors like accelerometer, GPS, proximity and other features of your Smartphone. It also provides you with dedicated projects compatible with Scratch and Arduino to help you learn by doing. Currently Dabble is avaiable for Android users(coming soon for iPhone users) and its is supported on Android version 5.0.0 and above. One can download the app from Google PlayStore with this link given below. [https://play.google.com/store/apps/details?id=io.dabbleapp]
2 |
3 | The app is designed to provide data of certain features of your smartphone to evive and microcontroller boards like Arduino Uno, Nano and Mega and ESP32.It also allows you to control them by your Smartphone. The app communicates with these boards via bluetooth modules like HC-05, HC-06 and HM-10 in case of Arduino boards and with built-in bluetooth for ESP32. This repository consists of library required on your board side for communication with app using BLE on ESP32. Dabble consists of various modules that allows you to control your hardware and access various smartphone features. A brief description of each module is mentioned below:
4 |
5 | 1) Led Brightness Control: This module allows you to control digital pin of your hardware through mobile. You can make pins HIGH or LOW, can also change its PWM if PWM functionailty is supported on that pin. You can use this module to control LED brightness and carry other such activities.
6 | 2) Terminal: Send and receive text and voice commands over Bluetooth between your hardware and smartphone.
7 | 3) Gamepad: Control devices in analog (Joystick), digital, and accelerometer mode.
8 | 4) Pin State Monitor: Remotely monitor the live status of devices and debug them.
9 | 5) Motor Control: Control actuators such as the DC motor and servo motor.
10 | 6) Inputs: Provide analog and digital inputs via buttons, knobs, and switches.
11 | 7) Camera: Use the camera of your Smartphone for taking photos and videos and colour detection.
12 | 8) Phone Sensor: Access different sensors of your Smartphone such as the accelerometer, gyroscope, proximity sensor,magnetometer, light meter, sound meter, GPS, temperature sensor, and barometer to make projects and conduct experiments.
13 | 9) Oscilloscope: Visualise and analyse the input and output signals given to the device using the oscilloscope module.
14 | 10) IoT: This module consist of Data Logger Module. Module to publish and fetch data will be available soon.
15 | 11) Music: Receive commands from the device and play tones, songs, or other recorded files on your Smartphone.
16 | 12) Projects: Make dedicated projects to experience different concepts of the real world first-hand.
17 | Dabble Library
18 | As per the module set present in Dabble app the library is also structured in same way. This library is for ESP32. It consists of certain examples codes which will help you in getting started with various Dabble modules. To explore more about Dabble, goto [https://thestempedia.com/docs/dabble/getting-started-with-dabble/]
19 |
--------------------------------------------------------------------------------
/examples/01.LedBrightnessControl/01.LedBrightnessControl.ino:
--------------------------------------------------------------------------------
1 | /*
2 | This is Led brightness control example for ESP32 that uses LED Brightness Control Module in Dabble app.
3 | This module allows you to control state of pin. You can make pin HIGH or LOW or can also assign any PWM
4 | value to it.
5 |
6 | NOTE: As in esp32 any channel can be configured as a PWM channel hence any first eight pins controlled by Module
7 | will be treated as PWM and others will be treated as normal digital pins.
8 |
9 |
10 | You can reduce the size of library compiled by enabling only those modules that you want to
11 | use.For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
12 |
13 | Explore more on: https://thestempedia.com/docs/dabble/getting-started-with-dabble/
14 | */
15 | #define CUSTOM_SETTINGS
16 | #define INCLUDE_LEDCONTROL_MODULE
17 | #include
18 | unsigned long lasttime=0;
19 | void setup() {
20 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
21 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
22 | }
23 |
24 | void loop() {
25 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
26 | //uncomment if you want to check if paramters read correctly
27 | /*Serial.print("Led:");
28 | Serial.print(LedControl.getpinNumber());
29 | Serial.print('\t');
30 | Serial.print("State:"); //0 if led is Off. 1 if led is On.
31 | Serial.print(LedControl.getpinState());
32 | Serial.print('\t');
33 | Serial.print("Brightness:");
34 | Serial.println(LedControl.readBrightness());*/
35 | }
36 |
--------------------------------------------------------------------------------
/examples/02.Terminal/02.Terminal.ino:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | Terminal Module is like a chat box. It allows you to send and receive commands between your
4 | board and smartphone.
5 |
6 | You can reduce the size of library compiled by enabling only those modules that you
7 | want to use. For this first define CUSTOM_SETTINGS followed by defining
8 | INCLUDE_modulename.
9 |
10 | Explore more on: https://thestempedia.com/docs/dabble/terminal-module/
11 | */
12 | #define CUSTOM_SETTINGS
13 | #define INCLUDE_TERMINAL_MODULE
14 | #include
15 | String Serialdata = "";
16 | bool dataflag = 0;
17 | void setup() {
18 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
19 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
20 | }
21 |
22 | void loop() {
23 |
24 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
25 | while (Serial.available() != 0)
26 | {
27 | Serialdata = String(Serialdata + char(Serial.read()));
28 | dataflag = 1;
29 | }
30 | if (dataflag == 1)
31 | {
32 | Terminal.print(Serialdata);
33 | Serialdata = "";
34 | dataflag = 0;
35 | }
36 | if (Terminal.available() != 0)
37 | {
38 | while (Terminal.available() != 0)
39 | {
40 | Serial.write(Terminal.read());
41 | }
42 | Serial.println();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/examples/03.Gamepad/03.Gamepad.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Gamepad module provides three different mode namely Digital, JoyStick and Accerleometer.
3 |
4 | You can reduce the size of library compiled by enabling only those modules that you want to
5 | use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
6 |
7 | Explore more on: https://thestempedia.com/docs/dabble/game-pad-module/
8 | */
9 | #define CUSTOM_SETTINGS
10 | #define INCLUDE_GAMEPAD_MODULE
11 | #include
12 | void setup() {
13 | // put your setup code here, to run once:
14 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
15 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
16 | }
17 |
18 | void loop() {
19 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
20 | Serial.print("KeyPressed: ");
21 | if (GamePad.isUpPressed())
22 | {
23 | Serial.print("Up");
24 | }
25 |
26 | if (GamePad.isDownPressed())
27 | {
28 | Serial.print("Down");
29 | }
30 |
31 | if (GamePad.isLeftPressed())
32 | {
33 | Serial.print("Left");
34 | }
35 |
36 | if (GamePad.isRightPressed())
37 | {
38 | Serial.print("Right");
39 | }
40 |
41 | if (GamePad.isSquarePressed())
42 | {
43 | Serial.print("Square");
44 | }
45 |
46 | if (GamePad.isCirclePressed())
47 | {
48 | Serial.print("Circle");
49 | }
50 |
51 | if (GamePad.isCrossPressed())
52 | {
53 | Serial.print("Cross");
54 | }
55 |
56 | if (GamePad.isTrianglePressed())
57 | {
58 | Serial.print("Triangle");
59 | }
60 |
61 | if (GamePad.isStartPressed())
62 | {
63 | Serial.print("Start");
64 | }
65 |
66 | if (GamePad.isSelectPressed())
67 | {
68 | Serial.print("Select");
69 | }
70 | Serial.print('\t');
71 |
72 | int a = GamePad.getAngle();
73 | Serial.print("Angle: ");
74 | Serial.print(a);
75 | Serial.print('\t');
76 | int b = GamePad.getRadius();
77 | Serial.print("Radius: ");
78 | Serial.print(b);
79 | Serial.print('\t');
80 | float c = GamePad.getXaxisData();
81 | Serial.print("x_axis: ");
82 | Serial.print(c);
83 | Serial.print('\t');
84 | float d = GamePad.getYaxisData();
85 | Serial.print("y_axis: ");
86 | Serial.println(d);
87 | Serial.println();
88 | }
89 |
--------------------------------------------------------------------------------
/examples/04.PinStateMonitor/04.PinStateMonitor.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Pin State Monitor is made for monitoring status of analog and digital pins of your board.
3 | In this example bluetooth is to be connected on HardwareSerial0 for Uno and Nano Boards.
4 |
5 | NOTE: State for only following pins can be seen on Pin State Monitor:
6 | | Screen Name | GPIO Pins |
7 | | Digital | 2,4,5,12,13,14,15,16,17,18,19,21 |
8 | | | 23,25,26,27 |
9 | | Analog | 32,33,34,35,36,39 |
10 |
11 | You can reduce the size of library compiled by enabling only those modules that you want
12 | to use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
13 |
14 | Explore more on: https://thestempedia.com/docs/dabble/pin-state-monitor-module/
15 | */
16 |
17 | #define CUSTOM_SETTINGS
18 | #define INCLUDE_PINMONITOR_MODULE
19 | #include
20 |
21 |
22 | void setup() {
23 | /*
24 | NOTE: PinMonitor only displays status of the pins of your board. It does not configure pinMode of the pins.
25 | So if there is any necessity to define pinMode then declare it setup as per requirement.
26 | */
27 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
28 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
29 | }
30 |
31 | void loop() {
32 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
33 | PinMonitor.sendDigitalData();
34 | PinMonitor.sendAnalogData();
35 | delayMicroseconds(20);
36 | }
37 |
--------------------------------------------------------------------------------
/examples/05.Motor Control/AllMotors/AllMotors.ino:
--------------------------------------------------------------------------------
1 | /*
2 | MotorControl Module is used to control actuators like DC motors and Servos.
3 |
4 | NOTE: If you are interested in using any other pin as PWM pin then use led channels
5 | from channel 4 onwards on ESP32.Because first four channels are for controlling motor and servo from
6 | Motor control module of Dabble.
7 |
8 |
9 | You can reduce the size of library compiled by enabling only those modules that you want to
10 | use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
11 |
12 | Explore more on: https://thestempedia.com/docs/dabble/motor-control-module/
13 |
14 | */
15 | #define CUSTOM_SETTINGS
16 | #define INCLUDE_MOTORCONTROL_MODULE
17 | #include
18 |
19 |
20 | uint8_t pinServo1 = 4;
21 | uint8_t pinServo2 = 5;
22 | uint8_t pwmMotor1 = 12;
23 | uint8_t dir1Motor1 = 13;
24 | uint8_t dir2Motor1 = 14;
25 | uint8_t pwmMotor2 = 21;
26 | uint8_t dir1Motor2 = 22;
27 | uint8_t dir2Motor2 = 23;
28 |
29 | void setup() {
30 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
31 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
32 | }
33 |
34 | void loop() {
35 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile. //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
36 | Controls.runServo1(pinServo1);
37 | Controls.runServo2(pinServo2);
38 | Controls.runMotor1(pwmMotor1,dir1Motor1,dir2Motor1);
39 | Controls.runMotor2(pwmMotor2,dir1Motor2,dir2Motor2);
40 | }
41 |
--------------------------------------------------------------------------------
/examples/06.Inputs/06.Inputs.ino:
--------------------------------------------------------------------------------
1 | /*
2 | DabbleInputs module of your smartphone consists of two potentiometers, two slideswitches and two push button.
3 |
4 | You can reduce the size of library compiled by enabling only those modules that you want to
5 | use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
6 |
7 | Explore more on: https://thestempedia.com/docs/dabble/input-module/
8 | */
9 | #define CUSTOM_SETTINGS
10 | #define INCLUDE_DABBLEINPUTS_MODULE
11 | #include
12 | void setup() {
13 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
14 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
15 | }
16 |
17 | void loop() {
18 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
19 |
20 | Serial.print("Pot1:");
21 | Serial.print(Inputs.getPot1Value());
22 | Serial.print('\t');
23 | Serial.print("Pot2:");
24 | Serial.print(Inputs.getPot2Value());
25 | Serial.print('\t');
26 | Serial.print("SS1:");
27 | Serial.print(Inputs.getSlideSwitch1Value());
28 | Serial.print('\t');
29 | Serial.print("SS2:");
30 | Serial.print(Inputs.getSlideSwitch2Value());
31 | Serial.print('\t');
32 | Serial.print("TS1:");
33 | Serial.print(Inputs.getTactileSwitch1Value());
34 | Serial.print('\t');
35 | Serial.print("TS2:");
36 | Serial.print(Inputs.getTactileSwitch2Value());
37 | Serial.println();
38 | }
39 |
--------------------------------------------------------------------------------
/examples/07.Camera/captureImages/captureImages.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Camera Module allows you to click images and take videos from smartphone by sending commands from your hardware.
3 | This function demonstrates functions available in library for camera module.
4 |
5 | Open Serial monitor and follow the instructions printed there to take images and videos in different cases.
6 |
7 | You can reduce the size of library compiled by enabling only those modules that you want
8 | to use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
9 |
10 | Explore more on: https://thestempedia.com/docs/dabble/camera-module-photos-videos/
11 | */
12 | #define CUSTOM_SETTINGS
13 | #define INCLUDE_CAMERA_MODULE
14 | #include
15 |
16 | void setup() {
17 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
18 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
19 | printMessage();
20 | }
21 |
22 | void loop() {
23 | //upload code and open serial monitor (reset your board once if you cannot see any message printed on Serial Monitor)
24 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
25 |
26 | char a = processSerialdata();
27 | if( a == '1')
28 | {
29 | Camera.setParameters(FRONT,OFF,HIGH_QUALITY,0); //Camera Direction, Flash, quality, Zoom(from 0 to 100%)
30 | Camera.captureImage();
31 | }
32 | if( a == '2')
33 | {
34 | Camera.flipTo(REAR);
35 | Camera.flashMode(OFF);
36 | Camera.setQuality(LOW_QUALITY);
37 | Camera.captureImage();
38 | }
39 | if(a == '3')
40 | {
41 | Camera.flipTo(REAR);
42 | Camera.setQuality(HIGH_QUALITY);
43 | Camera.zoom(50);
44 | Camera.captureImage();
45 | }
46 |
47 |
48 | }
49 |
50 | void printMessage()
51 | {
52 | Serial.println("Enter any number between 1 to 3 for executing task corresponding to that number: ");
53 | Serial.println("Tasks executed on sending different numbers are as followed: ");
54 | Serial.println("1 - Take a high quality image from front camera with no flash and no zoom.");
55 | Serial.println("2 - Take a low quality image from rear camera with Off flash and no zoom");
56 | Serial.println("3 - Take a 50% zoomed image from Rear camera with high quality");
57 | }
58 |
59 | char processSerialdata()
60 | {
61 | if(Serial.available()!=0)
62 | {
63 | return Serial.read();
64 | }
65 | else
66 | {
67 | return '0';
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/examples/07.Camera/recordVideos/recordVideos.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Camera Module allows you to click images and videos from smartphone by sending commands from your board.
3 | This function demonstrates functions available in library for camera module.
4 |
5 | Open Serial monitor and follow the instructions printed there to take videos in different settings of camera.
6 |
7 | You can reduce the size of library compiled by enabling only those modules that you want
8 | to use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
9 |
10 | Explore more on: https://thestempedia.com/docs/dabble/camera-module-photos-videos/
11 | */
12 | #define CUSTOM_SETTINGS
13 | #define INCLUDE_CAMERA_MODULE
14 | #include
15 |
16 | void setup() {
17 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
18 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
19 | printMessage();
20 | }
21 |
22 | void loop() {
23 | //upload code and open serial monitor (reset your board if you cannot se any message printed on Serial Monitor)
24 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
25 | char a = processSerialdata();
26 | if( a == '1')
27 | {
28 | Camera.setParameters(FRONT,OFF,HIGH_QUALITY,0); //Direction , Flash, Quality, zoom(0-100%)
29 | Camera.startRecording();
30 | }
31 | if( a == '2')
32 | {
33 | Camera.flipTo(REAR);
34 | Camera.flashMode(AUTO);
35 | Camera.setQuality(LOW_QUALITY);
36 | Camera.startRecording();
37 | }
38 | if(a == '3')
39 | {
40 | Camera.flipTo(REAR);
41 | Camera.setQuality(HIGH_QUALITY);
42 | Camera.zoom(50);
43 | Camera.startRecording();
44 | }
45 |
46 | if(a == '4')
47 | {
48 | Camera.stopRecording();
49 | }
50 |
51 |
52 | }
53 |
54 | void printMessage()
55 | {
56 | Serial.println("Enter any number between 1 to 4 for executing task corresponding to that number: ");
57 | Serial.println("Tasks executed on sending different numbers are as followed: ");
58 | Serial.println("1 - Take a high quality video from front camera with no flash and no zoom.");
59 | Serial.println("2 - Take a low quality video from rear camera with Auto flash");
60 | Serial.println("3 - Take a 50% zoomed image from Rear camera with high quality");
61 | Serial.println("4 - Stop video recording");
62 | }
63 |
64 | char processSerialdata()
65 | {
66 | if(Serial.available()!=0)
67 | {
68 | return Serial.read();
69 | }
70 | else
71 | {
72 | return '0';
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/examples/08.Phone Sensor/Accelerometer/Accelerometer.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Accelerometer block of Phone sensor module allows you to access your smartphone's accelerometer values.
3 |
4 | You can reduce the size of library compiled by enabling only those modules that you wan to
5 | use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
6 |
7 | Explore more on: https://thestempedia.com/docs/dabble/phone-sensors-module/
8 | */
9 | #define CUSTOM_SETTINGS
10 | #define INCLUDE_SENSOR_MODULE
11 | #include
12 |
13 |
14 | void setup() {
15 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
16 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
17 | }
18 |
19 | void loop() {
20 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
21 | print_Accelerometer_data();
22 | }
23 |
24 | void print_Accelerometer_data()
25 | {
26 | Serial.print("X_axis: ");
27 | Serial.print(Sensor.getAccelerometerXaxis(), 4);
28 | Serial.print('\t');
29 | Serial.print("Y_axis: ");
30 | Serial.print(Sensor.getAccelerometerYaxis(), 4);
31 | Serial.print('\t');
32 | Serial.print("Z_axis: ");
33 | Serial.println(Sensor.getAccelerometerZaxis(), 4);
34 | Serial.println();
35 | }
36 |
--------------------------------------------------------------------------------
/examples/08.Phone Sensor/Barometer/Barometer.ino:
--------------------------------------------------------------------------------
1 | /*
2 | If your smartphone has Barometer sensor support then this code helps in accessing that sensor's value through Dabble app.
3 |
4 | You can reduce the size of library compiled by enabling only those modules that you want to
5 | use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
6 |
7 | Explore more on: https://thestempedia.com/docs/dabble/phone-sensors-module/
8 | */
9 | #define CUSTOM_SETTINGS
10 | #define INCLUDE_SENSOR_MODULE
11 | #include
12 |
13 |
14 | void setup() {
15 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
16 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
17 | }
18 |
19 | void loop() {
20 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
21 | print_Barometer_data();
22 | }
23 |
24 | void print_Barometer_data()
25 | {
26 | Serial.print("Barometer: ");
27 | Serial.println(Sensor.getBarometerPressure(), 7);
28 | Serial.println();
29 | }
30 |
--------------------------------------------------------------------------------
/examples/08.Phone Sensor/GPS/GPS.ino:
--------------------------------------------------------------------------------
1 | /*
2 | This module helps you in accessing GPS values of our smartphone.
3 |
4 | You can reduce the size of library compiled by enabling only those modules that you want
5 | to use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
6 |
7 | Explore more on: https://thestempedia.com/docs/dabble/phone-sensors-module/
8 | */
9 | #define CUSTOM_SETTINGS
10 | #define INCLUDE_SENSOR_MODULE
11 | #include
12 |
13 |
14 | void setup() {
15 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
16 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
17 | }
18 |
19 | void loop() {
20 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
21 | print_GPS_data();
22 | }
23 |
24 |
25 | void print_GPS_data()
26 | {
27 | Serial.print("Longitude: ");
28 | Serial.print(Sensor.getGPSlongitude(), 7);
29 | Serial.print('\t');
30 | Serial.print('\t');
31 | Serial.print("Latitude: ");
32 | Serial.println(Sensor.getGPSLatitude(), 7);
33 | Serial.println();
34 | }
35 |
--------------------------------------------------------------------------------
/examples/08.Phone Sensor/Gyroscope/Gyroscope.ino:
--------------------------------------------------------------------------------
1 | /*
2 | With this block of phone sensor module you can access gyroscope values of your smartphone.
3 | Gyroscope gives you angular acceleration in x,y and z axis.
4 |
5 | You can reduce the size of library compiled by enabling only those modules that you want
6 | to use. For this first define CUSTOM_SETTINGS followed by defining
7 | INCLUDE_modulename.
8 |
9 | Explore more on: https://thestempedia.com/docs/dabble/phone-sensors-module/
10 | */
11 | #define CUSTOM_SETTINGS
12 | #define INCLUDE_SENSOR_MODULE
13 | #include
14 |
15 |
16 | void setup() {
17 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
18 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
19 | }
20 |
21 | void loop() {
22 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
23 | print_Gyroscope_data();
24 | }
25 |
26 | void print_Gyroscope_data()
27 | {
28 | Serial.print("X-axis: ");
29 | Serial.print(Sensor.getGyroscopeXaxis());
30 | Serial.print('\t');
31 | Serial.print("Y-axis: ");
32 | Serial.print(Sensor.getGyroscopeYaxis());
33 | Serial.print('\t');
34 | Serial.print("Z-axis: ");
35 | Serial.println(Sensor.getGyroscopeZaxis());
36 | Serial.println();
37 | }
38 |
--------------------------------------------------------------------------------
/examples/08.Phone Sensor/Light/Light.ino:
--------------------------------------------------------------------------------
1 | /*
2 | This block gives light intensity sensed by smartphone.
3 |
4 | You can reduce the size of library compiled by enabling only those modules that you want to
5 | use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
6 |
7 | Explore more on: https://thestempedia.com/docs/dabble/phone-sensors-module/
8 | */
9 | #define CUSTOM_SETTINGS
10 | #define INCLUDE_SENSOR_MODULE
11 | #include
12 |
13 |
14 | void setup() {
15 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
16 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
17 | }
18 |
19 | void loop() {
20 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
21 | print_Light_data();
22 | }
23 |
24 | void print_Light_data()
25 | {
26 | Serial.print("LIGHT: ");
27 | Serial.println(Sensor.getLightIntensity(), 7);
28 | Serial.println();
29 | }
30 |
--------------------------------------------------------------------------------
/examples/08.Phone Sensor/Magnetometer/Magnetometer.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Magnetometer block helps in accessing your mobile's magnetometer.
3 |
4 | You can reduce the size of library compiled by enabling only those modules that you want
5 | to use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
6 |
7 | Explore more on: https://thestempedia.com/docs/dabble/phone-sensors-module/
8 | */
9 | #define CUSTOM_SETTINGS
10 | #define INCLUDE_SENSOR_MODULE
11 | #include
12 |
13 |
14 | void setup() {
15 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
16 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
17 | }
18 |
19 | void loop() {
20 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
21 | print_Magnetometer_data();
22 | }
23 |
24 | void print_Magnetometer_data()
25 | {
26 | Serial.print("X-axis: ");
27 | Serial.print(Sensor.getMagnetometerXaxis(), 7);
28 | Serial.print('\t');
29 | Serial.print("Y-axis: ");
30 | Serial.print(Sensor.getMagnetometerYaxis(), 7);
31 | Serial.print('\t');
32 | Serial.print("Z-axis: ");
33 | Serial.println(Sensor.getMagnetometerZaxis(), 7);
34 | Serial.println();
35 | }
36 |
--------------------------------------------------------------------------------
/examples/08.Phone Sensor/Proximity/Proximity.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Proximity block allows to access proximity sensor of your mobile. This sensor in mobile
3 | phone gives two different values depending on the fact is object is near or far. You will get
4 | 0 reading when object is very close to phone and any random number if object is far.
5 |
6 | You can reduce the size of library compiled by enabling only those modules that you want
7 | to use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
8 |
9 | Explore more on: https://thestempedia.com/docs/dabble/phone-sensors-module/
10 | */
11 | #define CUSTOM_SETTINGS
12 | #define INCLUDE_SENSOR_MODULE
13 | #include
14 |
15 |
16 | void setup() {
17 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
18 | Dabble.begin("MyEsp32"); ////set bluetooth name of your device
19 | }
20 |
21 | void loop() {
22 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
23 | print_Proximity_data();
24 | }
25 |
26 | void print_Proximity_data()
27 | {
28 | Serial.print("Distance: ");
29 | Serial.println(Sensor.getProximityDistance(), 7);
30 | Serial.println();
31 | }
32 |
--------------------------------------------------------------------------------
/examples/08.Phone Sensor/Sound/Sound.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Sound sensor gives decibal value of sound that is sensed by your mobile's microphone.
3 |
4 | You can reduce the size of library compiled by enabling only those modules that you want
5 | to use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
6 |
7 | Explore more on: https://thestempedia.com/docs/dabble/phone-sensors-module/
8 | */
9 | #define CUSTOM_SETTINGS
10 | #define INCLUDE_SENSOR_MODULE
11 | #include
12 |
13 | void setup() {
14 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
15 | Dabble.begin("Myesp32"); //set bluetooth name of your device
16 | }
17 |
18 | void loop() {
19 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
20 | print_Sound_data();
21 | }
22 |
23 | void print_Sound_data()
24 | {
25 | Serial.print("SOUND: ");
26 | Serial.println(Sensor.getSoundDecibels(), 3);
27 | Serial.println();
28 | }
29 |
--------------------------------------------------------------------------------
/examples/08.Phone Sensor/Temperature/Temperature.ino:
--------------------------------------------------------------------------------
1 | /*
2 | If there is temperature sensor in your smartphone then you can access it through this example.
3 |
4 | You can reduce the size of library compiled by enabling only those modules that you want
5 | to use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
6 |
7 | Explore more on: https://thestempedia.com/docs/dabble/phone-sensors-module/
8 | */
9 | #define CUSTOM_SETTINGS
10 | #define INCLUDE_SENSOR_MODULE
11 | #include
12 |
13 |
14 | void setup() {
15 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
16 | Dabble.begin("MyEsp32"); //Enter baudrate of your bluetooth.Connect bluetooth on Bluetooth port present on evive.
17 | }
18 |
19 | void loop() {
20 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
21 | print_Temperature_data();
22 | }
23 |
24 | void print_Temperature_data()
25 | {
26 | Serial.print("TEMPERATURE: ");
27 | Serial.println(Sensor.getTemperature(), 7);
28 | Serial.println();
29 | }
30 |
--------------------------------------------------------------------------------
/examples/10.IOT/DataLogger/DataLogger.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Data Logger module helps you in storing data in form of .csv file.
3 | Later you can open this file to view your stored data.
4 |
5 | You can reduce the size of library compiled by enabling only those modules that you want to
6 | use.For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
7 |
8 | Explore more on: https://thestempedia.com/docs/dabble/
9 | */
10 | #define CUSTOM_SETTINGS
11 | #define INCLUDE_SENSOR_MODULE
12 | #define INCLUDE_DATALOGGER_MODULE
13 | #include
14 | bool isFileOpen = true;
15 | uint8_t closeFileSignalPin = 2; //this pin is internally pulled up and a push button grounded on one side is connected to pin so that pin detects low logic when push button is pressed.
16 |
17 | void initializeFile(){
18 | Serial.println("Initialize");
19 | DataLogger.createFile("Microphone");
20 | DataLogger.createColumn("Decibel");
21 | }
22 |
23 | void setup() {
24 | pinMode(closeFileSignalPin,INPUT_PULLUP);
25 | Serial.begin(115200); // make sure your Serial Monitor is also set at this baud rate.
26 | Dabble.begin("Myesp32"); //set bluetooth name of your device
27 | DataLogger.sendSettings(&initializeFile);
28 | }
29 |
30 | void loop() {
31 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
32 | if( isFileOpen == true)
33 | {
34 | print_Sound_data();
35 | DataLogger.send("Decibel",Sensor.getdata_Sound());
36 | }
37 | if((digitalRead(closeFileSignalPin) == LOW) && isFileOpen == true)
38 | {
39 | isFileOpen = false;
40 | DataLogger.stop();
41 | }
42 | }
43 |
44 | void print_Sound_data()
45 | {
46 | Serial.print("SOUND: ");
47 | Serial.println(Sensor.getdata_Sound(), 3);
48 | Serial.println();
49 | }
--------------------------------------------------------------------------------
/examples/10.IOT/Notification/Notification.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Notification module can be used for notifying your mobile about status of various activities happening on your hardware.
3 | In this example a push button is connected to a digital pin. And mobile is notified about how many times that push button
4 | is pressed.
5 |
6 | You can reduce the size of library compiled by enabling only those modules that you want to
7 | use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
8 |
9 | Explore more on: https://thestempedia.com/docs/dabble/
10 | */
11 |
12 | #define CUSTOM_SETTINGS
13 | #define INCLUDE_NOTIFICATION_MODULE
14 | #include
15 | uint8_t pushButtonPin = 2;
16 | int counts = 0;
17 |
18 | void setup() {
19 | Serial.begin(115200);
20 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
21 | pinMode(pushButtonPin, INPUT_PULLUP); //Since pin is internally pulled up hence connect one side of push button to ground so whenever button is pushed pin reads LOW logic.
22 | Dabble.waitForAppConnection(); //waiting for App to connect
23 | Notification.clear(); //clear previous notifictions
24 | Notification.setTitle("Button Counts"); //Enter title of your notification
25 | }
26 |
27 | void loop() {
28 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
29 | if (digitalRead(pushButtonPin) == LOW)
30 | {
31 | counts++;
32 | delay(1000); //debounce delay
33 | }
34 | Notification.notifyPhone(String("Button has been pressed ") + counts + String (" time"));
35 | }
36 |
--------------------------------------------------------------------------------
/examples/10.IOT/SMS/SMS.ino:
--------------------------------------------------------------------------------
1 | /*
2 | SMS module uses your smartphone to send SMS based on events occuring in your hardware board.
3 |
4 | You can reduce the size of library compiled by enabling only those modules that you want to
5 | use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
6 |
7 | Explore more on: https://thestempedia.com/docs/dabble/
8 | */
9 |
10 | #define CUSTOM_SETTINGS
11 | #define INCLUDE_SMS_MODULE
12 | #include
13 | uint8_t pushButtonPin = 2;
14 |
15 | void setup() {
16 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
17 | pinMode(pushButtonPin, INPUT_PULLUP); //Since pin is internally pulled up hence connect one side of push button to ground so whenever button is pushed pin reads LOW logic.
18 | }
19 |
20 | void loop() {
21 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
22 | if(digitalRead(pushButtonPin) == LOW)
23 | {
24 | SMS.sendMessage("0123456789","Buenas Noches"); //Contact Number, message content
25 | delay(1000); //debounce delay
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/examples/11.Music/11.Music.ino:
--------------------------------------------------------------------------------
1 | /*
2 | This code demonstrates how to use music module. Here a push button is used for playing and stopping music in smartphone.
3 | A push button is connected on an internally pulled up digital pin. And a change in state of pin is read.
4 | With every press on push button state of music module will be toggled.If no music is played by music module then
5 | command to play music module will be sent and if currently music is being played then it will be stopped.
6 |
7 | You can reduce the size of library compiled by enabling only those modules that you want to
8 | use. For this first define CUSTOM_SETTINGS followed by defining INCLUDE_modulename.
9 |
10 | Explore more on: https://thestempedia.com/docs/dabble/
11 |
12 | */
13 | #define CUSTOM_SETTINGS
14 | #define INCLUDE_MUSIC_MODULE
15 | #include
16 |
17 | bool playMusic = false;
18 | uint8_t musicSignalPin = 2;
19 | bool currentStatusOfPin = 0, prevStatusOfPin = 0; //status of musicSignalPin
20 | bool musicIsOn = false;
21 |
22 | void setup() {
23 | pinMode(musicSignalPin, INPUT_PULLUP);
24 | Dabble.begin("MyEsp32"); //set bluetooth name of your device
25 | }
26 |
27 | void loop() {
28 | Dabble.processInput(); //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
29 | currentStatusOfPin = digitalRead(musicSignalPin);
30 | if (currentStatusOfPin == 0 && prevStatusOfPin == 1) //detecting change in state of pin due to push button
31 | {
32 | delay(500); // debouncedelay
33 | playMusic = !(playMusic);
34 | }
35 | if (playMusic == true)
36 | {
37 | if (musicIsOn == false)
38 | {
39 | Music.play("A4"); //assigned key for Piano Note A4
40 | Music.addToQueue("B4"); //assigned key for Piano Note B4
41 | Music.addToQueue("C4"); //assigned key for Piano Note C4
42 | Music.addToQueue("D4"); //assigned key for Piano Note D4
43 | Music.addToQueue("E4"); //assigned key for Piano Note E4
44 | Music.addToQueue("F4"); //assigned key for Piano Note F4
45 | Music.addToQueue("G4"); //assigned key for Piano Note G4
46 | Music.addToQueue("C5"); //assigned key for Piano Note C5 //Select your own music files, assign them key and write this key as written here for various piano notes.
47 | musicIsOn = true;
48 | }
49 | }
50 | if (playMusic == false)
51 | {
52 | Music.stop();
53 | musicIsOn = false;
54 | }
55 | prevStatusOfPin = currentStatusOfPin;
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/keywords.txt:
--------------------------------------------------------------------------------
1 | #######################################
2 | # Syntax Coloring Map For Dabble
3 | #######################################
4 |
5 | #######################################
6 | # Datatypes (KEYWORD1)
7 | #######################################
8 | DabbleESP32 KEYWORD1
9 | Dabble KEYWORD1
10 | LedControl KEYWORD1
11 | GamePad KEYWORD1
12 | Inputs KEYWORD1
13 | Terminal KEYWORD1
14 | PinMonitor KEYWORD1
15 | Internet KEYWORD1
16 | Sensor KEYWORD1
17 | IOT KEYWORD1
18 | Camera KEYWORD1
19 | ColorDetector KEYWORD1
20 | DataLogger KEYWORD1
21 | Controls KEYWORD1
22 | #######################################
23 | # Functions (KEYWORD2)
24 | #######################################
25 | readBrightness KEYWORD2
26 | getpinState KEYWORD2
27 | getpinNumber KEYWORD2
28 | getx_axis KEYWORD2
29 | gety_axis KEYWORD2
30 | getAngle KEYWORD2
31 | getRadius KEYWORD2
32 | isStartPressed KEYWORD2
33 | isSelectPressed KEYWORD2
34 | isCirclePressed KEYWORD2
35 | isCrossPressed KEYWORD2
36 | isSquarePressed KEYWORD2
37 | isTrianglePressed KEYWORD2
38 | isLeftPressed KEYWORD2
39 | isRightPressed KEYWORD2
40 | isUpPressed KEYWORD2
41 | isDownPressed KEYWORD2
42 | defineServopins KEYWORD2
43 | motorControls KEYWORD2
44 | getpwm_Motor1 KEYWORD2
45 | getpwm_Motor2 KEYWORD2
46 | runMotor1 KEYWORD2
47 | runMotor2 KEYWORD2
48 | runServo1 KEYWORD2
49 | runServo2 KEYWORD2
50 | sendpinsStatus KEYWORD2
51 | sendanalogData KEYWORD2
52 | sendDigitalData KEYWORD2
53 | sendAnalogData KEYWORD2
54 | getvalue_Pot1 KEYWORD2
55 | getvalue_Pot2 KEYWORD2
56 | getStatus_SlideSwitch1 KEYWORD2
57 | getStatus_SlideSwitch2 KEYWORD2
58 | getStatus_TactileSwitch1 KEYWORD2
59 | getStatus_TactileSwitch2 KEYWORD2
60 | getdata_Accelerometer_xaxis KEYWORD2
61 | getdata_Accelerometer_yaxis KEYWORD2
62 | getdata_Accelerometer_zaxis KEYWORD2
63 | getdata_Gyroscope_xaxis KEYWORD2
64 | getdata_Gyroscope_yaxis KEYWORD2
65 | getdata_Gyroscope_zaxis KEYWORD2
66 | getdata_Magnetometer_xaxis KEYWORD2
67 | getdata_Magnetometer_yaxis KEYWORD2
68 | getdata_Magnetometer_zaxis KEYWORD2
69 | getdata_Proximity KEYWORD2
70 | getdata_Light KEYWORD2
71 | getdata_Sound KEYWORD2
72 | getdata_Temperature KEYWORD2
73 | getdata_Barometer KEYWORD2
74 | getdata_GPS_longitude KEYWORD2
75 | getdata_GPS_latitude KEYWORD2
76 | getangle_Servo1 KEYWORD2
77 | getangle_Servo2 KEYWORD2
78 | send_channel_data KEYWORD2
79 | setParameters KEYWORD2
80 | captureImage KEYWORD2
81 | startRecording KEYWORD2
82 | stopRecording KEYWORD2
83 | flashMode KEYWORD2
84 | setQuality KEYWORD2
85 | zoom KEYWORD2
86 | flipTo KEYWORD2
87 | getRedColor KEYWORD2
88 | getGreenColor KEYWORD2
89 | getBlueColor KEYWORD2
90 | setCalculationMode KEYWORD2
91 | setGridSize KEYWORD2
92 | setColorScheme KEYWORD2
93 | getGridSize KEYWORD2
94 | getColorScheme KEYWORD2
95 | getCalculationMode KEYWORD2
96 | sendSettings KEYWORD2
97 | checkColor KEYWORD2
98 | getColorError KEYWORD2
99 | getGrayScaleColor KEYWORD2
100 | createFile KEYWORD2
101 | createColumn KEYWORD2
102 | send KEYWORD2
103 | stop KEYWORD2
104 | sendMessage KEYWORD2
105 | setTitle KEYWORD2
106 | notifyPhone KEYWORD2
107 | clear KEYWORD2
108 | setDataSpeed KEYWORD2
109 | play KEYWORD2
110 | addToQueue KEYWORD2
111 | stop KEYWORD2
112 | getAccelerometerXaxis KEYWORD2
113 | getAccelerometerYaxis KEYWORD2
114 | getAccelerometerZaxis KEYWORD2
115 | getGyroscopeXaxis KEYWORD2
116 | getGyroscopeYaxis KEYWORD2
117 | getGyroscopeZaxis KEYWORD2
118 | getMagnetometerXaxis KEYWORD2
119 | getMagnetometerYaxis KEYWORD2
120 | getMagnetometerZaxis KEYWORD2
121 | getProximityDistance KEYWORD2
122 | getLightIntensity KEYWORD2
123 | getSoundDecibels KEYWORD2
124 | getTemperature KEYWORD2
125 | getBarometerPressure KEYWORD2
126 | getGPSlongitude KEYWORD2
127 | getGPSlatitude KEYWORD2
128 | getXaxisData KEYWORD2
129 | getYaxisData KEYWORD2
130 | #######################################
131 | # Constants And Literals (LITERAL1)
132 | #######################################
133 | REAR LITERAL1
134 | FRONT LITERAL1
135 | HIGH_QUALITY LITERAL1
136 | LOW_QUALITY LITERAL1
137 | AUTO LITERAL1
138 | OFF LITERAL1
139 | ON LITERAL1
140 | RED LITERAL1
141 | BLUE LITERAL1
142 | GREEN LITERAL1
143 | YELLOW LITERAL1
144 | VIOLET LITERAL1
145 | FROM_DABBLE_FOLDER LITERAL1
146 | INCLUDE_INTERNET_MODULE LITERAL1
147 | INCLUDE_OSCILLOSCOPE_MODULE LITERAL1
148 | INCLUDE_MOTORCONTROL_MODULE LITERAL1
149 | INCLUDE_PINMONITOR_MODULE LITERAL1
150 | INCLUDE_DABBLEINPUTS_MODULE LITERAL1
151 | INCLUDE_GAMEPAD_MODULE LITERAL1
152 | INCLUDE_IOT_MODULE LITERAL1
153 | INCLUDE_SENSOR_MODULE LITERAL1
154 | INCLUDE_TERMINAL_MODULE LITERAL1
155 | INCLUDE_CAMERA_MODULE LITERAL1
156 | INCLUDE_LEDCONTROL_MODULE LITERAL1
157 | INCLUDE_COLORDETECTOR_MODULE LITERAL1
158 | INCLUDE_DATALOGGER_MODULE LITERAL1
159 | INCLUDE_SMS_MODULE LITERAL1
160 | INCLUDE_NOTIFICATION_MODULE LITERAL1
161 | INCLUDE_MUSIC_MODULE LITERAL1
162 | RGB_3BIT LITERAL1
163 | RGB_15BIT LITERAL1
164 | RGB_24BIT LITERAL1
165 | GRAYSCALE_1BIT LITERAL1
166 | GRAYSCALE_4BIT LITERAL1
167 | GRAYSCALE_8BIT LITERAL1
168 | GRID_3x3 LITERAL1
169 | GRID_1x1 LITERAL1
170 | GRID_5x5 LITERAL1
171 | DOMINANT LITERAL1
172 | AVERAGE LITERAL1
173 | NORMAL LITERAL1
174 | CUSTOM_SETTINGS LITERAL1
175 |
176 |
177 |
178 |
179 |
--------------------------------------------------------------------------------
/library.properties:
--------------------------------------------------------------------------------
1 | name=DabbleESP32
2 | version=1.6.1
3 | author=STEMpedia
4 | maintainer=Mimansa Maheshwari , Dhrupal Shah
5 | sentence=Dabble is a library to interface ESP32 with Dabble Smartphone app on Arduino IDE.
6 | paragraph=Dabble app transforms a Smartphone into a virtual I/O device. It communicates with hardware like Espressif ESP32 board using in-built Bluetooth (BLE) or evive, and Arduino boards (Uno, Mega, and Nano) using Bluetooth modules like HC-05, HC-06 or HM-10 (BT 2.0, 4.0 or BLE). The app consists of modules that provide access to different functionalities of the smartphone like sensors (accelerometer, GPS, mic, etc.), camera, internet, etc. and consists of certain user interfaces for hardware control and project-making.
7 | category=Communication
8 | url=https://thestempedia.com/product/dabble
9 | architectures=esp32
10 | includes=DabbleESP32.h
11 |
--------------------------------------------------------------------------------
/src/CameraModule.cpp:
--------------------------------------------------------------------------------
1 | #define FROM_DABBLE_LIBRARY
2 | #include "DabbleESP32.h"
3 | #include "CameraModule.h"
4 |
5 | CameraModule::CameraModule(): ModuleParent(CAMERA_ID)
6 | {
7 |
8 | }
9 | void CameraModule::setParameters(uint8_t rotateTo,uint8_t flashmode, uint8_t quality,uint8_t zoomvalue)
10 | {
11 |
12 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&rotateTo));
13 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&flashmode));
14 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&quality));
15 | Dabble.sendModuleFrame(CAMERA_ID,0,0x02,1,new FunctionArg(1,&zoomvalue));
16 | }
17 | void CameraModule::captureImage()
18 | {
19 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&captureimage));
20 | }
21 |
22 | void CameraModule::startRecording()
23 | {
24 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&startVideo));
25 | }
26 |
27 | void CameraModule::stopRecording()
28 | {
29 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&stopVideo));
30 | }
31 |
32 | void CameraModule::flashMode(uint8_t a)
33 | {
34 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&a));
35 | }
36 |
37 | void CameraModule::setQuality(uint8_t a)
38 | {
39 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&a));
40 | }
41 |
42 | void CameraModule::zoom(uint8_t a)
43 | {
44 | Dabble.sendModuleFrame(CAMERA_ID,0,0x02,1,new FunctionArg(1,&a));
45 | }
46 |
47 | void CameraModule::flipTo(uint8_t direction)
48 | {
49 | if(direction == 1) //Rear
50 | {
51 | direction = 0x05;
52 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&direction));
53 | }
54 | else if(direction == 2) //Front
55 | {
56 | direction = 0x04;
57 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&direction));
58 | }
59 | else
60 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&direction));
61 | }
62 |
63 | void CameraModule::cameraAction(uint8_t a)
64 | {
65 | if(a == 1)
66 | {
67 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&captureimage));
68 | }
69 | if(a == 2)
70 | {
71 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&startVideo));
72 | }
73 | if(a == 3)
74 | {
75 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&stopVideo));
76 | }
77 | }
78 |
79 | void CameraModule::cameraConfig(uint8_t flash,uint8_t quality,uint8_t zoom)
80 | {
81 | if(flash == 1) //On
82 | {
83 | flash = 0x06;
84 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&flash));
85 | }
86 | else if(flash == 2) //Auto
87 | {
88 | flash = 0x07;
89 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&flash));
90 | }
91 | else if(flash == 3) //Off
92 | {
93 | flash = 0x08;
94 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&flash));
95 | }
96 |
97 | if(quality == 1)
98 | {
99 | quality = 0x09; //High
100 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&quality));
101 | }
102 | else if(quality == 2)
103 | {
104 | quality = 0x0A; //Low
105 | Dabble.sendModuleFrame(CAMERA_ID,0,0x01,1,new FunctionArg(1,&quality));
106 | }
107 | Dabble.sendModuleFrame(CAMERA_ID,0,0x02,1,new FunctionArg(1,&zoom));
108 | }
109 |
--------------------------------------------------------------------------------
/src/CameraModule.h:
--------------------------------------------------------------------------------
1 | #ifndef CameraModule_h
2 | #define CameraModule_h
3 | #include "ModuleParent.h"
4 |
5 | #define REAR 0x05
6 | #define FRONT 0x04
7 |
8 | #define ON 0x06
9 | #define OFF 0x08
10 | #define AUTO 0x07
11 |
12 | #define HIGH_QUALITY 0x09
13 | #define LOW_QUALITY 0x0A
14 |
15 |
16 |
17 | class CameraModule:public ModuleParent
18 | {
19 | public:
20 | CameraModule();
21 |
22 | //Arduino
23 | void setParameters(uint8_t,uint8_t,uint8_t,uint8_t); //Direction,flash,quality,zoom
24 | void captureImage(); //Camera Direction
25 | void startRecording();
26 | void stopRecording();
27 | void flashMode(byte); //On, Off, Auto
28 | void setQuality(uint8_t); //High, Low
29 | void zoom(uint8_t); // enter zoom in % from 1 to 100.
30 |
31 | //Arduino and Pictoblox
32 | void flipTo(uint8_t); //1 Front 2 Rear
33 |
34 | //Pictoblox
35 | void cameraAction(uint8_t); //1 captureImage,2 startVideo,3 stopVideo
36 | void cameraConfig(uint8_t,uint8_t,uint8_t);//flash,quality,zoom
37 | private:
38 | uint8_t captureimage = 0x01;
39 | uint8_t startVideo = 0x02;
40 | uint8_t stopVideo = 0x03;
41 | };
42 | extern CameraModule Camera;
43 | #endif
44 |
--------------------------------------------------------------------------------
/src/CircularBuffer.h:
--------------------------------------------------------------------------------
1 | /*
2 | CircularBuffer.h - circular buffer library for Arduino.
3 |
4 | Copyright (c) 2009 Hiroki Yagita.
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining
7 | a copy of this software and associated documentation files (the
8 | 'Software'), to deal in the Software without restriction, including
9 | without limitation the rights to use, copy, modify, merge, publish,
10 | distribute, sublicense, and/or sell copies of the Software, and to
11 | permit persons to whom the Software is furnished to do so, subject to
12 | the following conditions:
13 |
14 | The above copyright notice and this permission notice shall be
15 | included in all copies or substantial portions of the Software.
16 |
17 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 | #ifndef CIRCULARBUFFER_h
26 | #define CIRCULARBUFFER_h
27 | #include
28 |
29 | template
30 | class CircularBuffer {
31 | public:
32 | CircularBuffer() :
33 | wp_(buf_), rp_(buf_), tail_(buf_+Size), remain_(0) {}
34 | ~CircularBuffer() {}
35 | void push(T value) {
36 | if(remain_==Size)return;
37 | *wp_++ = value;
38 | remain_++;
39 | if (wp_ == tail_) wp_ = buf_;
40 | }
41 | T pop() {
42 | T result = *rp_++;
43 | remain_--;
44 | if (rp_ == tail_) rp_ = buf_;
45 | return result;
46 | }
47 | int remain() const {
48 | return remain_;
49 | }
50 |
51 | private:
52 | T buf_[Size];
53 | T *wp_;
54 | T *rp_;
55 | T *tail_;
56 | uint16_t remain_;
57 | };
58 |
59 | #endif
--------------------------------------------------------------------------------
/src/ColorDetectorModule.cpp:
--------------------------------------------------------------------------------
1 | #define FROM_DABBLE_LIBRARY
2 | #include "DabbleESP32.h"
3 | #include "ColorDetectorModule.h"
4 | int checksettings=0;
5 |
6 | float idealColorValue[5][3] ={ {255, 0, 0}, //RGB for red
7 | {0, 255, 0}, //RGB for Green
8 | {0, 0, 255}, //RGB for Blue
9 | {255, 242, 0}, //RGB for Yellow
10 | {148, 0, 211}, //RGB for Violet
11 | };
12 |
13 | ColorDetectorModule::ColorDetectorModule():ModuleParent(COLORDETECTOR_ID),ColorPrediction()
14 | {
15 | }
16 |
17 | void ColorDetectorModule::sendSettings(void(*function)(void))
18 | {
19 | checksettingsCallBack=true;
20 | settingsCallBack = function;
21 | }
22 | void ColorDetectorModule::sendSettings(uint8_t Grid,uint8_t calcMode,uint8_t ColorScheme)
23 | {
24 | checksettings =3;
25 | #ifdef DEBUG
26 | Serial.print("Settings Callback: ");
27 | Serial.println(checksettings);
28 | #endif
29 | if(Grid == 1) //1x1
30 | {
31 | gridSize = 1;
32 | }
33 | else if(Grid == 2) //3x3
34 | {
35 | gridSize = 3;
36 | }
37 | else if(Grid == 3) //5x5
38 | {
39 | gridSize = 5;
40 | }
41 | if(calcMode == 1) //Dominant
42 | {
43 | calculationMode = 1;
44 | }
45 | else if(calcMode == 2) // Average
46 | {
47 | calculationMode = 2;
48 | }
49 | if(ColorScheme == 6 ) //GRAYSCALE_1BIT
50 | {
51 | colorScheme = 1 ;
52 | }
53 | else if(ColorScheme == 5 ) //GRAYSCALE_4BIT
54 | {
55 | colorScheme = 4;
56 | }
57 | else if(ColorScheme == 4 ) //GRAYSCALE_8BIT
58 | {
59 | colorScheme = 8 ;
60 | }
61 | else if(ColorScheme == 3 ) //Rgb_3bit
62 | {
63 | colorScheme = 3 ;
64 | }
65 | else if(ColorScheme == 2 ) //Rgb_15bit
66 | {
67 | colorScheme = 15 ;
68 | }
69 | else if(ColorScheme == 1) //Rgb_24bit
70 | {
71 | colorScheme = 24;
72 | }
73 |
74 | }
75 | void ColorDetectorModule::processData()
76 | {
77 | if(checksettings != 0)
78 | {
79 | if(checksettings == 3)
80 | {
81 | Dabble.sendModuleFrame(COLORDETECTOR_ID,0,COLOR_SCHEME,1,new FunctionArg(1,&colorScheme));
82 | checksettings = 2;
83 | }
84 | else if(checksettings == 2)
85 | {
86 | Dabble.sendModuleFrame(COLORDETECTOR_ID,0,GRID_SETTING,1,new FunctionArg(1,&gridSize));
87 | checksettings =1;
88 | }
89 | else if(checksettings == 1)
90 | {
91 | Dabble.sendModuleFrame(COLORDETECTOR_ID,0,COLOR_CALCULATION_TYPE,1,new FunctionArg(1,&calculationMode));
92 | checksettings =0;
93 | }
94 | }
95 |
96 | if(checksettingsCallBack == true)
97 | {
98 | checksettingsCallBack=false;
99 | (*settingsCallBack)();
100 | }
101 |
102 | byte functionID = getDabbleInstance().getFunctionId();
103 | if(functionID == COLOR_DATA )
104 | {
105 |
106 | //Second arg line onwards color values are stored.
107 | if(currentArgnumber != getDabbleInstance().getArgumentNo())
108 | {
109 | if(currentArgnumber!=0)
110 | {
111 | for (int i = 0; i < currentArgnumber-1; i++)
112 | {
113 | delete [] colorArray[i];
114 | }
115 | delete [] colorArray;
116 | }
117 | colorArray = new uint8_t*[getDabbleInstance().getArgumentNo()-1];
118 | for (int i = 0; i < getDabbleInstance().getArgumentNo()-1; i++) //color values comes from second line
119 | {
120 | colorArray[i] = new uint8_t[3];
121 | }
122 | }
123 | currentArgnumber=getDabbleInstance().getArgumentNo();
124 | for (int i = 1; i < getDabbleInstance().getArgumentNo(); i++) //color values comes from second line
125 | {
126 | for (int j = 0; j < 3; j++)
127 | {
128 | colorArray[i-1][j] = getDabbleInstance().getArgumentData(i)[j];
129 | #ifdef DEBUG
130 | Serial.print(colorArray[i-1][j]);
131 | Serial.print(" ");
132 | #endif
133 | }
134 | #ifdef DEBUG
135 | Serial.println();
136 | #endif
137 | }
138 | }
139 | }
140 | void ColorDetectorModule::setColorScheme(byte bitScheme)
141 | {
142 | Dabble.sendModuleFrame(COLORDETECTOR_ID,0,COLOR_SCHEME,1,new FunctionArg(1,&bitScheme));
143 | }
144 |
145 | void ColorDetectorModule::setGridSize(byte gridsize)
146 | {
147 | Dabble.sendModuleFrame(COLORDETECTOR_ID,0,GRID_SETTING,1,new FunctionArg(1,&gridsize));
148 | }
149 |
150 | void ColorDetectorModule::setCalculationMode(byte calculationMode)
151 | {
152 | Dabble.sendModuleFrame(COLORDETECTOR_ID,0,COLOR_CALCULATION_TYPE,1,new FunctionArg(1,&calculationMode));
153 | }
154 |
155 | int ColorDetectorModule::getRedColor()
156 | {
157 | if(currentArgnumber !=0 )
158 | {
159 | return colorArray[0][0];
160 | }
161 | else
162 | {
163 | return -1;
164 | }
165 | }
166 |
167 | int ColorDetectorModule::getGreenColor()
168 | {
169 | if(currentArgnumber !=0 )
170 | {
171 | return colorArray[0][1];
172 | }
173 | else
174 | {
175 | return -1;
176 | }
177 | }
178 |
179 | int ColorDetectorModule::getBlueColor()
180 | {
181 | if(currentArgnumber !=0 )
182 | {
183 | return colorArray[0][2];
184 | }
185 | else
186 | {
187 | return -1;
188 | }
189 | }
190 |
191 |
192 | int ColorDetectorModule::getRedColor(byte row, byte col)
193 | {
194 | if(currentArgnumber!=0)
195 | {
196 | if(row == 0)
197 | {
198 | return colorArray[col][0];
199 | }
200 | else if(row == 1)
201 | {
202 | return colorArray[(currentArgnumber/gridSize)+col][0];
203 | }
204 | else if(row == 2)
205 | {
206 | return colorArray[((currentArgnumber/gridSize)*2)+col][0];
207 | }
208 | else if(row == 3)
209 | {
210 | return colorArray[((currentArgnumber/gridSize)*3)+col][0];
211 | }
212 | else if(row == 4)
213 | {
214 | return colorArray[((currentArgnumber/gridSize)*4)+col][0];
215 | }
216 | }
217 | else
218 | {
219 | return -1;
220 | }
221 | }
222 |
223 | int ColorDetectorModule::getGreenColor(byte row, byte col)
224 | {
225 | if(currentArgnumber!=0)
226 | {
227 | if(row == 0)
228 | {
229 | return colorArray[col][1];
230 | }
231 | else if(row == 1)
232 | {
233 | return colorArray[(currentArgnumber/gridSize)+col][1];
234 | }
235 | else if(row == 2)
236 | {
237 | return colorArray[((currentArgnumber/gridSize)*2)+col][1];
238 | }
239 | else if(row == 3)
240 | {
241 | return colorArray[((currentArgnumber/gridSize)*3)+col][1];
242 | }
243 | else if(row == 4)
244 | {
245 | return colorArray[((currentArgnumber/gridSize)*4)+col][1];
246 | }
247 | }
248 | else
249 | {
250 | return -1;
251 | }
252 | }
253 | int ColorDetectorModule::getBlueColor(byte row, byte col)
254 | {
255 | if(currentArgnumber!=0)
256 | {
257 | if(row == 0)
258 | {
259 | return colorArray[col][2];
260 | }
261 | else if(row == 1)
262 | {
263 | return colorArray[(currentArgnumber/gridSize)+col][2];
264 | }
265 | else if(row == 2)
266 | {
267 | return colorArray[((currentArgnumber/gridSize)*2)+col][2];
268 | }
269 | else if(row == 3)
270 | {
271 | return colorArray[((currentArgnumber/gridSize)*3)+col][2];
272 | }
273 | else if(row == 4)
274 | {
275 | return colorArray[((currentArgnumber/gridSize)*4)+col][2];
276 | }
277 | }
278 | else
279 | {
280 | return -1;
281 | }
282 | }
283 |
284 | uint8_t ColorDetectorModule::getGridSize()
285 | {
286 | return getDabbleInstance().getArgumentData(0)[2];;
287 | }
288 |
289 | uint8_t ColorDetectorModule::getColorScheme()
290 | {
291 | return getDabbleInstance().getArgumentData(0)[0];;
292 | }
293 |
294 | uint8_t ColorDetectorModule::getCalculationMode()
295 | {
296 | return getDabbleInstance().getArgumentData(0)[1];;
297 | }
298 |
299 | int ColorDetectorModule::getColorValue(uint8_t colorName,uint8_t Row,uint8_t Col)
300 | {
301 | if(gridSize == 3 && (Row < 3 && Col < 3))
302 | {
303 | if(colorName == 1) //Red
304 | {
305 | return getRedColor(Row,Col);
306 | }
307 | else if(colorName == 2) //Green
308 | {
309 | return getGreenColor(Row,Col);
310 | }
311 | else if(colorName == 3) //Blue
312 | {
313 | return getBlueColor(Row,Col);
314 | }
315 | else if(colorName == 4) //Black
316 | {
317 | if((colorScheme == GRAYSCALE_1BIT) || (colorScheme == GRAYSCALE_4BIT) || (colorScheme == GRAYSCALE_8BIT))
318 | return getRedColor(Row,Col);
319 | else
320 | return -1;
321 | }
322 | }
323 | else if(gridSize == 5 && (Row<5 && Col<5))
324 | {
325 | if(colorName == 1) //Red
326 | {
327 | return getRedColor(Row,Col);
328 | }
329 | else if(colorName == 2) //Green
330 | {
331 | return getGreenColor(Row,Col);
332 | }
333 | else if(colorName == 3) //Blue
334 | {
335 | return getBlueColor(Row,Col);
336 | }
337 | else if(colorName == 4) //Black
338 | {
339 | if((colorScheme == GRAYSCALE_1BIT) || (colorScheme == GRAYSCALE_4BIT) || (colorScheme == GRAYSCALE_8BIT))
340 | return getRedColor(Row,Col);
341 | else
342 | return -1;
343 | }
344 | }
345 | else if(gridSize == 1 && (Row<1 && Col<1))
346 | {
347 | if(colorName == 1) //Red
348 | {
349 | return getRedColor();
350 | }
351 | else if(colorName == 2) //Green
352 | {
353 | return getGreenColor();
354 | }
355 | else if(colorName == 3) //Blue
356 | {
357 | return getBlueColor();
358 | }
359 | else if(colorName == 4) //Black
360 | {
361 | if((colorScheme == GRAYSCALE_1BIT) || (colorScheme == GRAYSCALE_4BIT) || (colorScheme == GRAYSCALE_8BIT))
362 | return getRedColor();
363 | else
364 | return -1;
365 | }
366 | }
367 | else
368 | {
369 | return -1;
370 | }
371 |
372 | }
373 |
374 | int ColorDetectorModule::getGrayScaleColor(byte row,byte col)
375 | {
376 | if(currentArgnumber!=0 && (colorScheme == GRAYSCALE_1BIT || colorScheme == GRAYSCALE_4BIT || colorScheme == GRAYSCALE_8BIT))
377 | {
378 | if(row == 0)
379 | {
380 | return colorArray[col][0];
381 | }
382 | else if(row == 1)
383 | {
384 | return colorArray[(currentArgnumber/gridSize)+col][0];
385 | }
386 | else if(row == 2)
387 | {
388 | return colorArray[((currentArgnumber/gridSize)*2)+col][0];
389 | }
390 | else if(row == 3)
391 | {
392 | return colorArray[((currentArgnumber/gridSize)*3)+col][0];
393 | }
394 | else if(row == 4)
395 | {
396 | return colorArray[((currentArgnumber/gridSize)*4)+col][0];
397 | }
398 | }
399 | else
400 | {
401 | return -1;
402 | }
403 | }
404 |
405 | ColorPrediction::ColorPrediction(){
406 | min_deviation = 255;
407 | }
408 |
409 | bool ColorPrediction::checkColor(int *colorValue, uint8_t colorName)
410 | {
411 | if((colorValue[0]==-1) || (colorValue[1]==-1) || (colorValue[2]==-1))
412 | {
413 | return 0;
414 | }
415 | else{
416 | min_deviation = 255;
417 | for(int i = 0;i<5;i++)
418 | {
419 | deviation = sqrt((sq(idealColorValue[i][0] - colorValue[0]) + sq(idealColorValue[i][1] - colorValue[1]) + sq(idealColorValue[i][2] - colorValue[2])) / 3);
420 | if(min_deviation>deviation)
421 | {
422 | min_deviation = deviation;
423 | colorFlag = i+1;
424 | }
425 | }
426 | if(colorFlag == colorName)
427 | return 1;
428 | else
429 | return 0;
430 | }
431 | }
432 |
433 | float ColorPrediction::getColorError(uint8_t *colorValue,uint8_t *referenceValue)
434 | {
435 | if((colorValue[0]==-1) || (colorValue[1]==-1) || (colorValue[2]==-1))
436 | {
437 | return -1;
438 | }
439 | else
440 | {
441 | deviation = sqrt((sq(referenceValue[0] - colorValue[0]) + sq(referenceValue[1] - colorValue[1]) + sq(referenceValue[2] - colorValue[2])) / 3);
442 | return deviation;
443 | }
444 | }
445 |
--------------------------------------------------------------------------------
/src/ColorDetectorModule.h:
--------------------------------------------------------------------------------
1 | #ifndef ColorDetectorModule_H_
2 | #define ColorDetectorModule_H_
3 |
4 | #include "ModuleParent.h"
5 |
6 | //Function Id
7 | #define GRID_SETTING 0x01
8 | #define COLOR_CALCULATION_TYPE 0x02 // for Dominant or average
9 | #define COLOR_SCHEME 0x03 // bit size of color
10 | #define COLOR_DATA 0x04
11 |
12 |
13 | //Literals
14 | #define RGB_3BIT 3
15 | #define RGB_15BIT 15
16 | #define RGB_24BIT 24
17 |
18 | #define GRAYSCALE_1BIT 1
19 | #define GRAYSCALE_4BIT 4
20 | #define GRAYSCALE_8BIT 8
21 |
22 | //#define GRID_5x1 0x04
23 | #define GRID_3x3 0x03
24 | #define GRID_1x1 0x01
25 | #define GRID_5x5 0x05
26 |
27 | #define DOMINANT 0x01
28 | #define AVERAGE 0x02
29 |
30 | #define RED 0x01
31 | #define GREEN 0x02
32 | #define BLUE 0x03
33 | #define YELLOW 0x04
34 | #define VIOLET 0x05
35 |
36 | class ColorPrediction
37 | {
38 | public:
39 | ColorPrediction();
40 | bool checkColor(int *colorValue,uint8_t colorName);
41 | float getColorError(uint8_t *colorValue,uint8_t *referenceValue);
42 | int colorFlag=0;
43 | float min_deviation = 255;
44 | float deviation = 0;
45 | };
46 |
47 | class ColorDetectorModule:public ModuleParent, public ColorPrediction
48 | {
49 | public:
50 | ColorDetectorModule();
51 | //Arduino
52 | void setColorScheme(byte);
53 | void setGridSize(byte);
54 | void setCalculationMode(byte);
55 | int getRedColor();
56 | int getBlueColor();
57 | int getGreenColor();
58 | int getRedColor(byte,byte); //for different blocks of grid
59 | int getBlueColor(byte,byte); //for different blocks of grid
60 | int getGreenColor(byte,byte); //for different blocks of grid
61 | uint8_t getGridSize();
62 | uint8_t getColorScheme();
63 | uint8_t getCalculationMode();
64 | int getGrayScaleColor(byte,byte);
65 | void sendSettings(void(*)(void));
66 |
67 | //Pictoblox
68 | void sendSettings(uint8_t,uint8_t,uint8_t);
69 | int getColorValue(uint8_t,uint8_t,uint8_t);
70 |
71 | private:
72 | void processData();
73 | void (*settingsCallBack)(void);
74 | bool checksettingsCallBack;
75 | uint8_t** colorArray;
76 | uint8_t currentArgnumber=0;
77 | uint8_t gridSize=0;
78 | uint8_t colorScheme=0;
79 | uint8_t calculationMode=0;
80 | };
81 | extern ColorDetectorModule ColorDetector;
82 | #endif
--------------------------------------------------------------------------------
/src/DabbleESP32.cpp:
--------------------------------------------------------------------------------
1 |
2 | #define FROM_DABBLE_LIBRARY
3 |
4 | #include "stdarg.h"
5 |
6 | #include "DabbleESP32.h"
7 |
8 | bool callBackForDataLogger = false;
9 | void (*dataLoggerCallBack)(void);
10 |
11 | bool DabbleClass::isInit=false;
12 | bool DabbleClass::isSws=false;
13 | byte DabbleClass::ModulesCounter=0;
14 | unsigned long DabbleClass::lastTimeFrameSent=0;
15 | unsigned long DabbleClass::argumentDataBytesTimeReceived=0;
16 | bool DabbleClass::inACallback=false;
17 | bool DabbleClass::callbacksInterrupts=false;
18 | bool DabbleClass::isFirstFrame=false;
19 | ModuleParent * DabbleClass::ModulesArray[]={0};
20 | //byte DabbleClass::requestsCounter=0;
21 | //HttpRequest ** DabbleClass::requestsArray=0;
22 |
23 |
24 | uint8_t FrameLimits[4][18] = {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}, //Module-ID
25 | {3, 3, 2, 3, 9, 4, 2, 0, 2, 3, 3, 4, 6, 5, 3, 1, 1, 3}, //Funtcion_ID
26 | {1, 1,255, 1, 3, 1, 1, 0, 2, 1, 1, 26, 2, 1, 1, 2, 1, 100}, //Arg1
27 | {5, 2,255, 32, 4, 2, 1, 0, 4, 2, 1, 3, 50, 255, 1, 1, 2, 255}}; //Arg2
28 | //Class Constructor
29 | DabbleClass::DabbleClass()
30 | {
31 | Module=0;
32 | verificationByte=0;
33 | functions=0;
34 | counter=0;
35 | argumentcounter=0;
36 | datalengthcounter=0;
37 | argumentnumber=0;
38 | argumentsize=0;
39 | endFrame=0;
40 | numberOfDataMalloced=0;
41 | isArgumentsNumberMalloced=false;
42 | isArgumentLengthMalloced=false;
43 | callbacksInterrupts=false;
44 | framestart =false;
45 | isDabbleConnected =false;
46 | isAppConnectionCallBack = false;
47 | isModuleFrameCallback = false;
48 | isSerialDataCallback = false;
49 | dontDelay = false;
50 |
51 | }
52 |
53 | //Library Starter
54 | void DabbleClass::begin(std::string bleName)
55 | {
56 | esp32ble.begin(String(bleName.c_str()));
57 | // esp32ble.begin(bleName);
58 | init();
59 | }
60 |
61 | //Blocking function
62 | void DabbleClass::waitForAppConnection()
63 | {
64 | isDabbleConnected = false;
65 |
66 | while(!isDabbleConnected)
67 | {
68 | Dabble.processInput();
69 | }
70 |
71 | }
72 |
73 | void DabbleClass::init()
74 | {
75 | isInit=true;
76 | sendModuleFrame(Dabble_ID,0,CHECK_CONNECTION,0);
77 | /*if(requestsArray!=0){
78 | for(int i=0;isendInitFrame();
80 | free(requestsArray);
81 | requestsCounter=0;
82 | }*/
83 | }
84 |
85 | //Library Starter
86 |
87 | void DabbleClass::addToModulesArray(ModuleParent * Module)
88 | {
89 | if(ModulesCounter==MODULE_NO) return;
90 | ModulesArray[ModulesCounter++] = Module;
91 |
92 | }
93 | // #ifdef INTERNET_Module
94 | /*void DabbleClass::addToUnSentRequestsArray(HttpRequest * request)
95 | {
96 | if(requestsCounter==MAX_NO_OF_REQUESTS) return;
97 | if(requestsCounter<=0)
98 | requestsArray=(HttpRequest**)malloc(sizeof(HttpRequest*)*MAX_NO_OF_REQUESTS);
99 | requestsArray[requestsCounter++] = request;
100 | }*/
101 | // #endif
102 | bool DabbleClass::isInitialized()
103 | {
104 | return isInit;
105 | }
106 |
107 | bool DabbleClass::isSoftwareSerial()
108 | {
109 | return isSws;
110 | }
111 |
112 | void DabbleClass::setOnNewModuleFrame(void (*userFunction)(byte ModuleID, byte functionID, byte argNo,byte *argumentL,byte **arguments))
113 | {
114 | isModuleFrameCallback=true;
115 | ModuleFrameCallback=userFunction;
116 | }
117 |
118 | void DabbleClass::setOnNewSerialData(void (*userFunction)(byte))
119 | {
120 | isSerialDataCallback=true;
121 | serialDataCallback=userFunction;
122 | }
123 | void DabbleClass::appWrite(byte command)
124 | {
125 | if(isInit){
126 | esp32ble.write(command);
127 | #ifdef DEBUG
128 | Serial.print("Sent: ");
129 | Serial.println(command,HEX);
130 | #endif
131 | }
132 | if(!dontDelay)
133 | {
134 | ::delay(2);
135 | }
136 | }
137 |
138 | //Frame Sender for Output Modules
139 | void DabbleClass::sendModuleFrame(byte ModuleID, byte instanceID, byte functionID, byte argNo, ...)
140 | {
141 | unsigned long mill=millis()+1;
142 | unsigned long localLastTimeFrameSent=lastTimeFrameSent;
143 | if(ModuleID!=Dabble_ID&&isFirstFrame&&localLastTimeFrameSent&&(mill-localLastTimeFrameSent)available())
150 | TempDabble.processInput(TempDabble.DabbleSerial->read());
151 | }
152 | ModuleParent::unSetDabbleInstance();
153 | }else*/
154 | while((millis()<(TIME_GAP+localLastTimeFrameSent))||framestart)
155 | {
156 | if(esp32ble.available())
157 | Dabble.processInput(esp32ble.read());
158 | }
159 | }
160 |
161 | isFirstFrame=true;
162 | va_list arguments ;
163 | va_start (arguments,argNo);
164 | appWrite((byte)START_OF_FRAME);
165 | //appWrite(LIBRARY_VERSION);
166 | appWrite(ModuleID);
167 | //appWrite(getVerificationByte());
168 | appWrite(functionID);
169 | appWrite(argNo);
170 | //appWrite(255-argNo);
171 |
172 |
173 | for (int i=0 ; igetLength());
177 |
178 | //appWrite(255-(temp->getLength()));
179 |
180 | for (int j=0 ; jgetLength() ; j++)
181 | {
182 | byte* tempData=temp->getData();
183 | appWrite(tempData[j]);
184 | }
185 | delete(temp);
186 | }
187 | appWrite((byte)END_OF_FRAME);
188 | va_end(arguments);
189 | if(ModuleID!=Dabble_ID)lastTimeFrameSent=millis()+1;
190 | #ifdef DEBUG
191 | Serial.println();
192 | #endif
193 | }
194 |
195 | void DabbleClass::sendModuleFrame(byte ModuleID, byte instanceID, byte functionID, byte argNo, FunctionArg ** arguments)
196 | {
197 | unsigned long mill=millis()+1;
198 | unsigned long localLastTimeFrameSent=lastTimeFrameSent;
199 | if(ModuleID!=Dabble_ID&&isFirstFrame&&localLastTimeFrameSent&&(mill-localLastTimeFrameSent)available())
206 | TempDabble.processInput(TempDabble.DabbleSerial->read());
207 | }
208 | ModuleParent::unSetDabbleInstance();
209 | }else*/
210 | while((millis()<(TIME_GAP+localLastTimeFrameSent))||framestart)
211 | {
212 | if(esp32ble.available())
213 | Dabble.processInput(esp32ble.read());
214 | }
215 | }
216 |
217 | isFirstFrame=true;
218 | appWrite((byte)START_OF_FRAME);
219 | //appWrite(LIBRARY_VERSION);
220 | appWrite(ModuleID);
221 | //appWrite(getVerificationByte());
222 | appWrite(functionID);
223 | appWrite(argNo);
224 | //appWrite(255-argNo);
225 |
226 | for (int i=0 ; igetLength());
229 | //appWrite(255-(arguments[i]->getLength()));
230 | for (int j=0 ; jgetLength() ; j++)
231 | {
232 | byte* tempData=arguments[i]->getData();
233 | appWrite(tempData[j]);
234 | }
235 | }
236 | appWrite((byte)END_OF_FRAME);
237 | if(ModuleID!=Dabble_ID)lastTimeFrameSent=millis()+1;
238 | #ifdef DEBUG
239 | Serial.println();
240 | #endif
241 | }
242 | bool DabbleClass::isAppConnected()
243 | {
244 | return isDabbleConnected;
245 | }
246 | void DabbleClass::setOnAppConnected(void (*userFunction)(bool isAppConnected))
247 | {
248 | isAppConnectedCallBack = userFunction;
249 | isAppConnectionCallBack = true;
250 | }
251 | //Module_ID Getter
252 | byte DabbleClass::getModuleId()
253 | {
254 | return Module;
255 | }
256 |
257 | //Funtcion_ID Getter
258 | byte DabbleClass::getFunctionId()
259 | {
260 | return functions;
261 | }
262 | //ArgumentsNumber Getter
263 | byte DabbleClass::getArgumentNo()
264 | {
265 | return argumentnumber;
266 | }
267 | //ArgumentLength Getter
268 | byte DabbleClass::getArgumentLength(byte x)
269 | {
270 | return argumentL[x];
271 | }
272 | byte DabbleClass::getScreenId()
273 | {
274 | return screenId;
275 | //if(getModuleId() == 0 &&
276 | }
277 |
278 | byte DabbleClass::readModuleId()
279 | {
280 | return readModuleID;
281 | }
282 | //Data Getter
283 | byte * DabbleClass::getArgumentData(byte x)
284 | {
285 | if(argumentL[x]!=0)
286 | {
287 | return arguments[x];
288 | }
289 | else return NULL;
290 | }
291 |
292 | //Convert float to array of bytes
293 | void DabbleClass::convertFloatToBytes(float data, byte * out)
294 | {
295 | FloatUnion f2bUnion;
296 | f2bUnion.number = data;
297 | out[0]=f2bUnion.floatBytes[0];
298 | out[1]=f2bUnion.floatBytes[1];
299 | out[2]=f2bUnion.floatBytes[2];
300 | out[3]=f2bUnion.floatBytes[3];
301 |
302 | }
303 |
304 | //Convert array of bytes to float
305 | float DabbleClass::convertBytesToFloat(byte *data)
306 | {
307 | FloatUnion b2fUnion;;
308 | b2fUnion.floatBytes[0] = data[0];
309 | b2fUnion.floatBytes[1] = data[1];
310 | b2fUnion.floatBytes[2] = data[2];
311 | b2fUnion.floatBytes[3] = data[3];
312 | return b2fUnion.number;
313 | }
314 |
315 | //Incomming Frames processing
316 | void DabbleClass::processInput(int data) {
317 | #ifdef DEBUG
318 | Serial.write(data);
319 | //Serial.print(" ");
320 | #endif
321 |
322 | if(data==-1){
323 | return;
324 | }
325 | if((millis() - argumentDataBytesTimeReceived) > 2000 && argumentDataBytesTimeReceived !=0 && framestart)
326 | {
327 | freeMemoryAllocated();
328 | }
329 | argumentDataBytesTimeReceived = millis();
330 | if(!framestart&&data==START_OF_FRAME)
331 | {
332 | freeMemoryAllocated();
333 | counter=0;
334 | framestart=true;
335 | arguments=0;
336 | argumentL=0;
337 | counter++;
338 | }
339 | else if(counter==3&&framestart) //data is the no of arguments
340 | {
341 | #ifdef DEBUG
342 | Serial.print("C3 ");
343 | #endif
344 | datalengthcounter=0;
345 | argumentcounter=0;
346 | argumentnumber=data;
347 | if(argumentnumber > FrameLimits[2][Module])
348 | {
349 | framestart = false;
350 | counter = 0;
351 | return;
352 | }
353 | if(argumentnumber !=0)
354 | {
355 | isArgumentsNumberMalloced=true;
356 | isArgumentLengthMalloced=true;
357 | arguments = new byte* [argumentnumber];
358 | argumentL = new byte [argumentnumber];
359 | }
360 | counter++;
361 | }
362 | else if (counter==4&&framestart) // data is the first argument length
363 | {
364 | #ifdef DEBUG
365 | Serial.print("C4 ");
366 | #endif
367 | datalengthcounter = 0;
368 | argumentsize = data; //size of each argument line
369 | if(argumentsize > FrameLimits[3][Module])
370 | {
371 | framestart = false;
372 | counter = 0;
373 | return;
374 | }
375 | if(argumentnumber !=0)
376 | {
377 |
378 | argumentL[argumentcounter] = argumentsize;
379 | arguments[argumentcounter] = new byte[argumentsize];
380 | counter++;
381 | }
382 | else
383 | {
384 | counter = 6; //move to endframe section
385 | }
386 | numberOfDataMalloced++;
387 | }
388 | else if (counter==5&&framestart)
389 | {
390 | #ifdef DEBUG
391 | Serial.print("C5 ");
392 | #endif
393 | if(argumentnumber !=0)
394 | {
395 | if(datalengthcounter < argumentsize)
396 | {
397 | arguments[argumentcounter][datalengthcounter++] = data;
398 | }
399 | if(datalengthcounter == argumentsize)
400 | {
401 | counter = 4;
402 | argumentcounter++;
403 | }
404 | if(argumentnumber == argumentcounter) //check if data stored in all lines
405 | {
406 | counter = 6;
407 | }
408 | }
409 |
410 |
411 | }
412 | else if(counter==6&&framestart)
413 | {
414 | #ifdef DEBUG
415 | Serial.print("C6 ");
416 | #endif
417 | endFrame=data;
418 | if(endFrame==END_OF_FRAME) //if the endframe is equal to zero send to Modules and free memory
419 | {
420 | framestart=false;
421 | //Serial.println("Sent to modules");
422 | sendToModules();
423 | /* if(isModuleFrameCallback && Module!=0)
424 | {
425 | enteringACallback();
426 | ModuleFrameCallback(Module,functions,argumentnumber,argumentL,arguments);
427 | exitingACallback();
428 | }*/
429 | freeMemoryAllocated();
430 | #ifdef DEBUG
431 | Serial.println();
432 | #endif
433 | }
434 | else //if endframe wasn't equal to zero make sure that the memory is free anyway
435 | {
436 | freeMemoryAllocated();
437 | }
438 | }
439 | else if(framestart){
440 |
441 | if(counter==1){
442 | Module=data;
443 | bool found = false;
444 | if(Module == Dabble_ID || isModuleFrameCallback) found = true;
445 | else
446 | {
447 | for (int i=0;igetModuleId()){
449 | found = true;
450 | /*#ifdef DEBUG
451 | Serial.print("Module: ");
452 | Serial.print(Module, HEX);
453 | Serial.print(" ");
454 | #endif*/
455 | }
456 | }
457 | }
458 | if (!found) {
459 | framestart=false;
460 | freeMemoryAllocated();
461 | return;
462 | }
463 | }
464 | else if(counter==2){
465 | functions=data;
466 | if(functions > FrameLimits[1][Module])
467 | {
468 | counter = 0;
469 | framestart=false;
470 | return;
471 | }
472 | #ifdef DEBUG
473 | Serial.print("C2 ");
474 | #endif
475 | }
476 | counter++;
477 | }
478 |
479 | }
480 |
481 | void DabbleClass::processInput()
482 | {
483 |
484 |
485 | if(esp32ble.available())
486 | {
487 | isDabbleConnected = true;
488 | while(esp32ble.available())
489 | {
490 | byte data=esp32ble.read();
491 | /*#ifdef DEBUG
492 | Serial.print(data);
493 | Serial.print(" ");
494 | #endif*/
495 | processInput(data);
496 | /*if(isSerialDataCallback)
497 | {
498 | enteringACallback();
499 | serialDataCallback(data);
500 | exitingACallback();
501 | }*/
502 | }
503 | /*#ifdef DEBUG
504 | Serial.println();
505 | #endif*/
506 | }
507 |
508 |
509 | }
510 |
511 | void DabbleClass::freeMemoryAllocated(){
512 | framestart=false;
513 | if(isArgumentsNumberMalloced)
514 | {
515 | for(int i=0;iprocessFrame();
551 | }
552 | }
553 | }
554 |
555 | void DabbleClass::processFrame(){
556 | byte functionId = getFunctionId();
557 | if(argumentnumber !=0)
558 | {
559 | readModuleID = getArgumentData(0)[0];
560 | screenId = getArgumentData(0)[1];
561 | }
562 | if(callBackForDataLogger == true)
563 | {
564 | callBackForDataLogger =false;
565 | (*dataLoggerCallBack)();
566 | }
567 | //Check the function ID
568 | if(functionId == BOARDID_REQUEST)
569 | {
570 | // uint8_t BoardId_evive[1]={0x01};
571 | uint8_t BoardId_Mega[4] = {0x02,1,5,1};
572 | uint8_t BoardId_Uno[4] = {0x03,1,5,1};
573 | uint8_t BoardId_Nano[4] = {0x04,1,5,1};
574 | uint8_t BoardId_ESP32[4] = {0x06,1,5,1};
575 | uint8_t BoardId_Other[4] = {0x05,1,5,1};
576 | #if ((defined(ARDUINO_AVR_MEGA2560)) || (defined(ARDUINO_AVR_MEGA)))
577 | sendModuleFrame(Dabble_ID,0,BOARDID_REQUEST,1,new FunctionArg(4,BoardId_Mega));
578 | #elif(defined(ARDUINO_AVR_NANO))
579 | sendModuleFrame(Dabble_ID,0,BOARDID_REQUEST,1,new FunctionArg(4,BoardId_Nano));
580 | #elif(defined(ARDUINO_AVR_UNO))
581 | sendModuleFrame(Dabble_ID,0,BOARDID_REQUEST,1,new FunctionArg(4,BoardId_Uno));
582 | #elif(ESP32)
583 | sendModuleFrame(Dabble_ID,0,BOARDID_REQUEST,1,new FunctionArg(4,BoardId_ESP32));
584 | #else
585 | sendModuleFrame(Dabble_ID,0,BOARDID_REQUEST,1,new FunctionArg(4,BoardId_Other));
586 | #endif
587 | /* #if (defined(__AVR_ATmega2560__))
588 | sendModuleFrame(Dabble_ID,0,BOARDID_REQUEST,1,new FunctionArg(4,BoardId_Mega));
589 | #elif (defined(__AVR_ATmega328P__))
590 | sendModuleFrame(Dabble_ID,0,BOARDID_REQUEST,1,new FunctionArg(4,BoardId_Uno));
591 | #else
592 | sendModuleFrame(Dabble_ID,0,BOARDID_REQUEST,1,new FunctionArg(4,BoardId_Other));
593 | #endif*/
594 | }
595 | /*else if(functionId == LIBRARY_VERSION_REQUEST)
596 | {
597 | sendModuleFrame(Dabble_ID,0,SEND_LIBRARY_VERSION,0);
598 | }
599 | else if(functionId == LIBRARY_TESTING_REQUEST)
600 | {
601 | if(!memcmp("Are you ok?",getArgumentData(0),11))
602 | {
603 | const char * responseString = "Yup, I'm feeling great!";
604 | byte testAnswer = 0;
605 | int sumOfData = 0;
606 | for(int i = 0 ; i < getArgumentLength(1) ; i++)
607 | {
608 | sumOfData+= getArgumentData(1)[i];
609 | }
610 | testAnswer = sumOfData%256;
611 | sendModuleFrame(Dabble_ID,0x00,LIBRARY_TESTING_RESPONSE,2,new FunctionArg(23,(byte *)responseString),new FunctionArg(1,&testAnswer));
612 | }
613 | }*/
614 | }
615 |
616 | //PulseWidthModulation Getter
617 | unsigned char DabbleClass::analogRead(int pin)
618 | {
619 | double period=(double)pulseIn(pin,HIGH)+(double)pulseIn(pin,LOW);;
620 | double duty=(double)pulseIn(pin,HIGH);
621 | double fraction=duty/period;
622 | unsigned char pwm_out=(unsigned char)(ceil)(fraction*255);
623 | return pwm_out;
624 | }
625 |
626 | void DabbleClass::enteringACallback()
627 | {
628 | if(!isInACallback())
629 | {
630 | inACallback=true;
631 | dontDelay = true;
632 | sendModuleFrame(Dabble_ID,0,CALLBACK_ENTERED,0);
633 | dontDelay = false;
634 | }
635 | }
636 |
637 | void DabbleClass::exitingACallback()
638 | {
639 | if(isInACallback())
640 | {
641 | inACallback=false;
642 | dontDelay = true;
643 | sendModuleFrame(Dabble_ID,0,CALLBACK_EXITED,0);
644 | dontDelay = false;
645 | }
646 | }
647 |
648 | bool DabbleClass::isInACallback()
649 | {
650 | return inACallback && !callbacksInterrupts;
651 | }
652 |
653 | bool DabbleClass::isCallbacksInterruptsSet()
654 | {
655 | return callbacksInterrupts;
656 | }
657 |
658 | void DabbleClass::disableCallbacksInterrupts()
659 | {
660 | callbacksInterrupts=false;
661 | }
662 |
663 | void DabbleClass::enableCallbacksInterrupts()
664 | {
665 | callbacksInterrupts=true;
666 | }
667 |
668 | void DabbleClass::delay(unsigned long time)
669 | {
670 | unsigned long now=millis();
671 | /*if(inACallback)
672 | {
673 | DabbleClass TempDabble;
674 | ModuleParent::setDabbleInstance(TempDabble);
675 | while((millis()<(now+time))||TempDabble.framestart)
676 | {
677 | if(TempDabble.DabbleSerial->available())
678 | TempDabble.processInput(TempDabble.DabbleSerial->read());
679 | }
680 | ModuleParent::unSetDabbleInstance();
681 | }else*/
682 | while((millis()<(now+time))||framestart)
683 | {
684 | #if (defined(ESP32))
685 | if(esp32ble.available())
686 | Dabble.processInput(esp32ble.read());
687 | #else
688 | if(DabbleSerial->available())
689 | Dabble.processInput(DabbleSerial->read());
690 | #endif
691 | }
692 | }
693 | DabbleClass Dabble;
694 | //Instantiating Object
695 | /*#if (defined(__AVR_ATmega32U4__) || \
696 | defined(ARDUINO_LINUX) || \
697 | defined(__MK20DX128__) || \
698 | defined(__MK20DX256__) || \
699 | defined(__MKL26Z64__) || \
700 | defined(_VARIANT_ARDUINO_101_X_) || \
701 | defined(_VARIANT_ARDUINO_ZERO_))
702 | void serialEvent1()
703 | #else
704 | void serialEvent3()
705 | #endif
706 | {
707 | if(!Dabble.isSoftwareSerial()) Dabble.processInput();
708 | }*/
709 |
710 | byte DabbleClass::getVerificationByte()
711 | {
712 | byte randomValue = (byte)random(0,16);
713 | byte randomValueComplement = ~(randomValue);
714 | randomValue&=0x0F;
715 | randomValue = randomValue|(randomValueComplement<<4);
716 | return randomValue;
717 | }
718 |
--------------------------------------------------------------------------------
/src/DabbleESP32.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This library is developed for Dabble app. https://thestempedia.com/product/dabble/
3 | * It includes modulewise sublibraries as per modules present in
4 | * Dabble app.
5 | * Version 1.5.1
6 | *
7 | * This library structure is derived from OneSheeld Library.
8 | *
9 | * This is licensed under GNU GPL V3 [http://www.gnu.org/licenses/gpl.txt].
10 | * Written by Dhrupal R Shah for ESP32, Agilo Research Pvt. Ltd
11 | * Created on: April 10, 2019
12 | * Updated on: 20190610
13 | * Contact: support@thestempedia.com
14 | * Copyright (c) 2018 Agilo Research Pvt. Ltd. All rights reserved.
15 | *
16 | * This program is free software: you can redistribute it and/or modify
17 | * it under the terms of the GNU General Public License as published by
18 | * the Free Software Foundation, either version 3 of the License, or
19 | * (at your option) any later version.
20 | *
21 | * This program is distributed in the hope that it will be useful,
22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 | * GNU General Public License for more details.
25 | *
26 | * You should have received a copy of the GNU General Public License
27 | * along with this program. If not, see
54 | #include "esp32BLEUtilities.h"
55 |
56 | #include "ModuleIds.h"
57 | #include "ModuleSelection.h"
58 | #include "ModuleIncludes.h"
59 | #include "ModuleParent.h"
60 | #include "ModuleInstantiation.h"
61 | //#include "InternetModule.h"
62 | //#include "HttpResponse.h"
63 | //#include "HttpRequest.h"
64 |
65 | #define ONE_SECOND 1000
66 |
67 | //Start and End of packet sent
68 | #define START_OF_FRAME 0xFF
69 | #define END_OF_FRAME 0x00
70 | //Time between sending Frames
71 | #define TIME_GAP 10UL
72 |
73 | //#define DEBUG
74 |
75 | //Output function ID's
76 | #define CHECK_CONNECTION 0x01
77 | #define BOARDID_REQUEST 0x03
78 |
79 | #define SEND_LIBRARY_VERSION 0x01
80 |
81 | #define CALLBACK_ENTERED 0x03
82 | #define CALLBACK_EXITED 0x04
83 | #define LIBRARY_TESTING_RESPONSE 0x05
84 | //Input function ID's
85 | //Checking Bluetooth connection
86 | #define CONNECTION_CHECK_FUNCTION 0x01
87 | #define DISCONNECTION_CHECK_FUNCTION 0x02
88 |
89 |
90 |
91 | //#define LIBRARY_VERSION_REQUEST 0x03
92 | //#define LIBRARY_TESTING_REQUEST 0x05
93 |
94 |
95 | //Number of Module
96 | #define MODULE_NO 18
97 | extern bool callBackForDataLogger;
98 | extern void (*dataLoggerCallBack)(void);
99 | //Class for Datalength and Data
100 | class FunctionArg
101 | {
102 | private:
103 | byte length;
104 | byte * data;
105 | bool saveData;
106 | public:
107 | FunctionArg(int l ,byte * d, bool _saveData=false)
108 | {
109 | saveData=_saveData;
110 | length=(l>0xff)?0xff:l;
111 | if(saveData)
112 | {
113 | data=(byte *)malloc(sizeof(byte)*length);
114 | memcpy(data,d,length);
115 | }
116 | else
117 | {
118 | data=d;
119 | }
120 | }
121 | byte getLength()
122 | {
123 | return length;
124 | }
125 | byte * getData()
126 | {
127 | return data;
128 | }
129 | ~FunctionArg()
130 | {
131 | if(saveData)free(data);
132 | }
133 |
134 | };
135 |
136 | union FloatUnion{
137 | float number;
138 | byte floatBytes[sizeof(float)];
139 | };
140 |
141 |
142 |
143 | class DabbleClass
144 | {
145 |
146 |
147 | public:
148 |
149 | DabbleClass();
150 | //Blocking function
151 | void waitForAppConnection();
152 | //Check connection
153 | bool isAppConnected();
154 | void setOnAppConnected(void (*)(bool));
155 | //rx,tx pins for software
156 | uint8_t pin_rx,pin_tx;
157 | //Getters
158 | byte getModuleId();
159 | byte getFunctionId();
160 | byte getArgumentNo();
161 | byte getScreenId();
162 | byte readModuleId();
163 | byte getArgumentLength(byte x);
164 | byte * getArgumentData(byte );
165 | void convertFloatToBytes(float , byte *);
166 | float convertBytesToFloat(byte * );
167 | //Processing Incomming Frames
168 | void processInput();
169 | void appWrite(byte command);
170 | void begin(std::string bleName);
171 | //Adding objects in array
172 | static void addToModulesArray(ModuleParent *);
173 | // #ifdef INTERNET_MODULE
174 | //static void addToUnSentRequestsArray(HttpRequest *);
175 | // #endif
176 | static bool isInitialized();
177 | static bool isSoftwareSerial();
178 | //Frame Sender
179 | void sendModuleFrame(byte , byte ,byte , byte , ...);
180 | void sendModuleFrame(byte , byte , byte , byte , FunctionArg ** );
181 | void setOnNewModuleFrame(void (*)(byte, byte, byte, byte *,byte **));
182 | void setOnNewSerialData(void (*)(byte));
183 | //PulseWidthModulation Getter
184 | unsigned char analogRead(int );
185 | void delay(unsigned long);
186 | bool isCallbacksInterruptsSet();
187 | void enableCallbacksInterrupts();
188 | void disableCallbacksInterrupts();
189 | byte getVerificationByte();
190 | private:
191 | //Reserve Variables
192 | bool isArgumentsNumberMalloced;
193 | bool isArgumentLengthMalloced;
194 | bool isDabbleConnected;
195 | bool isAppConnectionCallBack;
196 | bool isModuleFrameCallback;
197 | bool isSerialDataCallback;
198 | bool dontDelay;
199 | static bool isFirstFrame;
200 | bool framestart;
201 | static bool inACallback;
202 | static bool callbacksInterrupts;
203 | //Data bytes
204 | byte numberOfDataMalloced;
205 | byte Module;
206 | byte verificationByte;
207 | byte functions;
208 | byte counter;
209 | byte screenId;
210 | byte readModuleID;
211 | byte argumentcounter;
212 | byte datalengthcounter;
213 | byte argumentnumber;
214 | byte argumentsize;
215 | byte **arguments;
216 | byte *argumentL;
217 | byte endFrame;
218 | //Module Counter
219 | static byte ModulesCounter;
220 | //Requests Counter
221 | static byte requestsCounter;
222 | //Is constructor called
223 | static bool isInit;
224 | static bool isSws;
225 | //Checker variable
226 | static unsigned long lastTimeFrameSent;
227 |
228 | static unsigned long argumentDataBytesTimeReceived;
229 | //Array of pointers to Parents
230 | static ModuleParent * ModulesArray[MODULE_NO];
231 | // #ifdef INTERNET_MODULE
232 | //Array of pointers to un sent requests
233 | //static HttpRequest ** requestsArray;
234 | // #endif
235 | //Send Incomming Data to Modules
236 | void sendToModules();
237 | //void begin(long baudRate);
238 | void init();
239 | void freeMemoryAllocated();
240 | void processFrame();
241 | void (*isAppConnectedCallBack)(bool);
242 | void (*ModuleFrameCallback)(byte, byte, byte, byte *,byte **);
243 | void (*serialDataCallback)(byte);
244 | void enteringACallback();
245 | void exitingACallback();
246 | bool isInACallback();
247 | void processInput(int);
248 |
249 | friend class ModuleParent;
250 | };
251 | //Extern Object
252 | extern DabbleClass Dabble;
253 | #endif
254 |
--------------------------------------------------------------------------------
/src/DabbleInputs.cpp:
--------------------------------------------------------------------------------
1 | #define FROM_DABBLE_LIBRARY
2 | #include "DabbleESP32.h"
3 | #include "DabbleInputs.h"
4 |
5 | DabbleInputs::DabbleInputs() : ModuleParent(EVIVEINTERFACES_ID)
6 | {
7 | }
8 |
9 | uint16_t DabbleInputs::getvalue_Pot1()
10 | {
11 | return uint16_t(data_1 << 8) + uint16_t (data_2);
12 | }
13 |
14 | uint16_t DabbleInputs::getvalue_Pot2()
15 | {
16 | return uint16_t(data_3 << 8) + uint16_t (data_4);
17 | }
18 |
19 | uint8_t DabbleInputs::getStatus_SlideSwitch1()
20 | {
21 | if((data_5 & 0x04) == 0x04)
22 | {
23 | state_ss1 =2;
24 |
25 | }
26 | else if((data_5 & 0x02) == 0x02)
27 | {
28 | state_ss1 =0;
29 |
30 | }
31 | else if((data_5 & 0x01) == 0x01)
32 | {
33 | state_ss1 =1;
34 |
35 | }
36 | return state_ss1;
37 | }
38 |
39 | uint8_t DabbleInputs::getStatus_SlideSwitch2()
40 | {
41 | if((data_5 & 0x20) == 0x20)
42 | {
43 | state_ss2=2;
44 | }
45 | else if((data_5&0x10) == 0x10)
46 | {
47 | state_ss2=0;
48 | }
49 | else if((data_5&0x08) == 0x08)
50 | {
51 | state_ss2=1;
52 | }
53 | return state_ss2;
54 | }
55 |
56 | bool DabbleInputs::getStatus_TactileSwitch1()
57 | {
58 | return ((data_5 & 0x40) == 0x40);
59 | }
60 |
61 | bool DabbleInputs::getStatus_TactileSwitch2()
62 | {
63 | return ((data_5 & 0x80) == 0x80);
64 | }
65 |
66 |
67 | uint16_t DabbleInputs::getPot1Value()
68 | {
69 | return uint16_t(data_1 << 8) + uint16_t (data_2);
70 | }
71 |
72 | uint16_t DabbleInputs::getPot2Value()
73 | {
74 | return uint16_t(data_3 << 8) + uint16_t (data_4);
75 | }
76 |
77 | uint8_t DabbleInputs::getSlideSwitch1Value()
78 | {
79 | if((data_5 & 0x04) == 0x04)
80 | {
81 | state_ss1 =2;
82 |
83 | }
84 | else if((data_5 & 0x02) == 0x02)
85 | {
86 | state_ss1 =0;
87 |
88 | }
89 | else if((data_5 & 0x01) == 0x01)
90 | {
91 | state_ss1 =1;
92 |
93 | }
94 | return state_ss1;
95 | }
96 |
97 | uint8_t DabbleInputs::getSlideSwitch2Value()
98 | {
99 | if((data_5 & 0x20) == 0x20)
100 | {
101 | state_ss2=2;
102 | }
103 | else if((data_5&0x10) == 0x10)
104 | {
105 | state_ss2=0;
106 | }
107 | else if((data_5&0x08) == 0x08)
108 | {
109 | state_ss2=1;
110 | }
111 | return state_ss2;
112 | }
113 |
114 | bool DabbleInputs::getTactileSwitch1Value()
115 | {
116 | return ((data_5 & 0x40) == 0x40);
117 | }
118 |
119 | bool DabbleInputs::getTactileSwitch2Value()
120 | {
121 | return ((data_5 & 0x80) == 0x80);
122 | }
123 |
124 | bool DabbleInputs::getSlideSwitchStatus(uint8_t SS,uint8_t dir)
125 | {
126 | if(SS == 1 && dir == 2) //SS1 left
127 | {
128 | if((data_5 & 0x01)==0x01)
129 | {
130 | return 1;
131 | }
132 | else
133 | {
134 | return 0;
135 | }
136 | }
137 | else if(SS == 1 && dir == 3) //SS1 right
138 | {
139 | if((data_5&0x04) == 0x04)
140 | {
141 | return 1;
142 | }
143 | else
144 | {
145 | return 0;
146 | }
147 | }
148 | else if(SS == 1 && dir == 1) //SS1 Off
149 | {
150 | if((data_5&0x02) == 0x02)
151 | {
152 | return 1;
153 | }
154 | else
155 | {
156 | return 0;
157 | }
158 | }
159 | else if(SS == 2 && dir == 2) //SS2 left
160 | {
161 | if((data_5&0x08) == 0x08)
162 | {
163 | return 1;
164 | }
165 | else
166 | {
167 | return 0;
168 | }
169 | }
170 | else if(SS == 2 && dir == 3) //SS2 right
171 | {
172 | if((data_5&0x20) == 0x20)
173 | {
174 | return 1;
175 | }
176 | else
177 | {
178 | return 0;
179 | }
180 | }
181 | else if(SS == 2 && dir == 1) //SS2 Off
182 | {
183 | if((data_5&0x10) == 0x10)
184 | {
185 | return 1;
186 | }
187 | else
188 | {
189 | return 0;
190 | }
191 | }
192 | }
193 |
194 | bool DabbleInputs::getTactileSwitchStatus(uint8_t TS)
195 | {
196 | if(TS == 1)
197 | {
198 | if((data_5 & 0x40) == 0x40)
199 | return 1;
200 | else
201 | return 0;
202 | }
203 | else if(TS == 2)
204 | {
205 | if((data_5 & 0x80) == 0x80)
206 | return 1;
207 | else
208 | return 0;
209 | }
210 | }
211 |
212 | int DabbleInputs::getPotValue(uint8_t Pot)
213 | {
214 | if(Pot == 1)
215 | {
216 | return uint16_t(data_1 << 8) + uint16_t (data_2);
217 | }
218 | else if(Pot == 2)
219 | {
220 | return uint16_t(data_3 << 8) + uint16_t (data_4);
221 | }
222 | }
223 |
224 |
225 | void DabbleInputs::processData()
226 | {
227 | /*#ifdef DEBUG
228 | Serial.println("DabbleInputs:processData");
229 | #endif*/
230 |
231 | //Checking Function-ID
232 | byte functionId =getDabbleInstance().getFunctionId();
233 | if(functionId == Potentiometer_1)
234 | {
235 | data_1=getDabbleInstance().getArgumentData(0)[0];
236 | data_2=getDabbleInstance().getArgumentData(0)[1];
237 | }
238 | else if(functionId == Potentiometer_2)
239 | {
240 | data_3=getDabbleInstance().getArgumentData(0)[0];
241 | data_4=getDabbleInstance().getArgumentData(0)[1];
242 |
243 | }
244 | else if(functionId == Switches)
245 | {
246 | data_5=getDabbleInstance().getArgumentData(0)[0];
247 | }
248 | }
--------------------------------------------------------------------------------
/src/DabbleInputs.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef DabbleInputs_h
3 | #define DabbleInputs_h
4 |
5 | #include "ModuleParent.h"
6 |
7 | #define Potentiometer_1 0x01
8 | #define Potentiometer_2 0x02
9 | #define Switches 0x03
10 | //#define DEBUG
11 | class DabbleInputs: public ModuleParent
12 | {
13 | public:
14 | //Constructor
15 | DabbleInputs();
16 | //Checker Functions
17 | uint16_t getPot1Value();
18 | uint16_t getPot2Value();
19 |
20 | uint8_t getSlideSwitch1Value();
21 | uint8_t getSlideSwitch2Value();
22 |
23 | bool getTactileSwitch1Value();
24 | bool getTactileSwitch2Value();
25 |
26 | uint16_t getvalue_Pot1();
27 | uint16_t getvalue_Pot2();
28 |
29 | uint8_t getStatus_SlideSwitch1();
30 | uint8_t getStatus_SlideSwitch2();
31 |
32 | bool getStatus_TactileSwitch1();
33 | bool getStatus_TactileSwitch2();
34 |
35 |
36 |
37 | bool getSlideSwitchStatus(uint8_t SS,uint8_t dir); //1 2 SS1 left //2 2 SS2 left
38 | //1 3 SS1 right //2 3 SS2 right
39 | //1 1 SS1 Off //2 1 SS2 Off
40 | bool getTactileSwitchStatus(uint8_t TS); //1 TS1 2 TS2
41 |
42 | int getPotValue(uint8_t Pot);
43 |
44 |
45 | public:
46 | byte functionId;
47 |
48 | byte data_1=0;
49 | byte data_2=0;
50 | byte data_3=0;
51 | byte data_4=0;
52 | byte data_5=0;
53 | uint8_t state_ss1;
54 | uint8_t state_ss2;
55 |
56 |
57 |
58 | private:
59 |
60 |
61 | void processData();
62 | };
63 |
64 | //Extern Object
65 | extern DabbleInputs Inputs;
66 | #endif
--------------------------------------------------------------------------------
/src/DabblePrint.cpp:
--------------------------------------------------------------------------------
1 |
2 | #define FROM_DABBLE_LIBRARY
3 | #include "DabbleESP32.h"
4 | #include "DabblePrint.h"
5 |
6 |
7 |
8 |
9 | //Constructor
10 | PrintClass::PrintClass(byte shid,byte writefnid, byte printfnid)
11 | {
12 | ModuleId=shid;
13 | print_fn_id=printfnid;
14 | write_fn_id=writefnid;
15 | }
16 | //Write character
17 | void PrintClass::write(char data)
18 | {
19 | Dabble.sendModuleFrame(ModuleId,0,write_fn_id,1,new FunctionArg(1,(byte *)&data));
20 | }
21 | //Print character
22 | void PrintClass::print(char data)
23 | {
24 | Dabble.sendModuleFrame(ModuleId,0,print_fn_id,1,new FunctionArg(1,(byte *)&data));
25 | }
26 | //Print integers
27 | void PrintClass::print(int data)
28 | {
29 | char stringPointer[7];
30 | snprintf(stringPointer,7,"%d",data);
31 |
32 | Dabble.sendModuleFrame(ModuleId,0,print_fn_id,1,new FunctionArg(strlen(stringPointer),(byte *)stringPointer));
33 | }
34 | //Print unsigned integers
35 | void PrintClass::print(unsigned int data)
36 | {
37 | char stringPointer[6];
38 | snprintf(stringPointer,6,"%d",data);
39 |
40 | Dabble.sendModuleFrame(ModuleId,0,print_fn_id,1,new FunctionArg(strlen(stringPointer),(byte *)stringPointer));
41 | }
42 | //Print long integers
43 | void PrintClass::print(long data)
44 | {
45 | char stringPointer[12];
46 | snprintf(stringPointer,12,"%ld",data);
47 |
48 | Dabble.sendModuleFrame(ModuleId,0,print_fn_id,1,new FunctionArg(strlen(stringPointer),(byte *)stringPointer));
49 | }
50 | //Print unsigned long integers
51 | void PrintClass::print(unsigned long data)
52 | {
53 | char stringPointer[11];
54 | snprintf(stringPointer,11,"%lu",data);
55 |
56 | Dabble.sendModuleFrame(ModuleId,0,print_fn_id,1,new FunctionArg(strlen(stringPointer),(byte *)stringPointer));
57 | }
58 | //Print string
59 | void PrintClass::print(const char * stringData)
60 | {
61 | //Serial.println("Print String");
62 | //Check length of string
63 | int stringDataLength = strlen(stringData);
64 | #ifdef DEBUG
65 | Serial.println(stringDataLength);
66 | #endif
67 | if(!stringDataLength) return;
68 | Dabble.sendModuleFrame(ModuleId,0,print_fn_id,1,new FunctionArg(stringDataLength,(byte*)stringData));
69 | }
70 |
71 | void PrintClass::print(String stringData)
72 | {
73 | print(&stringData[0]);
74 | }
75 |
76 | //Print double
77 | //Unsupported by Intel Galileo board and Arduino Due
78 | #if !defined(ARDUINO_LINUX) && !defined(SAM3X8)
79 | void PrintClass::print(double data , int precesion)
80 | {
81 | char buffer[32]={'\0'};
82 | dtostrf(data,1,precesion,buffer);
83 |
84 | Dabble.sendModuleFrame(ModuleId,0,print_fn_id,1,new FunctionArg(strlen(buffer),(byte *) buffer));
85 | }
86 | #endif
--------------------------------------------------------------------------------
/src/DabblePrint.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ifndef PrintClass_h
4 | #define PrintClass_h
5 |
6 | //Defining decimal
7 | #define DEC 10
8 |
9 | class PrintClass
10 | {
11 | public:
12 | PrintClass(byte, byte, byte);
13 | //Write
14 | void write(char);
15 | //Printing functions
16 | void print(char);
17 | void print(int);
18 | void print(unsigned int);
19 | void print(long);
20 | void print(unsigned long);
21 | void print(const char *);
22 | void print(String );
23 | //Unsupported by Intel Galileo board and Arduino Due
24 | #if !defined(ARDUINO_LINUX) && !defined(SAM3X8)
25 | void print(double ,int = 3 );
26 | #endif
27 | private:
28 | //Reserve variables for function ID's
29 | byte print_fn_id;
30 | byte write_fn_id;
31 | //Reserve variable for the Module ID
32 | byte ModuleId;
33 | };
34 | extern PrintClass PinStatus;
35 | #endif
--------------------------------------------------------------------------------
/src/DabblePrintln.cpp:
--------------------------------------------------------------------------------
1 |
2 | #define FROM_DABBLE_LIBRARY
3 | #include "DabbleESP32.h"
4 | #include "DabblePrintln.h"
5 |
6 | //Constructor
7 | PrintlnClass::PrintlnClass(byte shid,byte writefnid, byte printfnid):PrintClass(shid,writefnid,printfnid)
8 | {
9 | }
10 | //Print newline
11 | void PrintlnClass::println()
12 | {
13 | char buffer[3];
14 | buffer[0]='\r';
15 | buffer[1]='\n';
16 | buffer[2]='\0';
17 |
18 | print(buffer);
19 | }
20 | //Print character with newline
21 | void PrintlnClass::println(char data)
22 | {
23 | char buffer[4];
24 | buffer[0]=data;
25 | buffer[1]='\r';
26 | buffer[2]='\n';
27 | buffer[3]='\0';
28 |
29 | print(buffer);
30 | }
31 | //Print integers with newline
32 | void PrintlnClass::println(int data)
33 | {
34 | char stringPointer[10];
35 | snprintf(stringPointer,9,"%d",data);
36 | strcat(stringPointer,"\r\n");
37 |
38 | print(stringPointer);
39 | #ifdef DEBUG
40 | Serial.println(data);
41 | Serial.println(stringPointer);
42 | #endif
43 | }
44 | //Print unsigned integers with newline
45 | void PrintlnClass::println(unsigned int data)
46 | {
47 | char stringPointer[9];
48 | snprintf(stringPointer,8,"%d",data);
49 | strcat(stringPointer,"\r\n");
50 |
51 | print(stringPointer);
52 |
53 | }
54 | //Print long with newline
55 | void PrintlnClass::println(long data)
56 | {
57 | char stringPointer[15];
58 | snprintf(stringPointer,14,"%ld",data);
59 | strcat(stringPointer,"\r\n");
60 |
61 | print(stringPointer);
62 | }
63 | //Print unsigned long with newline
64 | void PrintlnClass::println(unsigned long data)
65 | {
66 | char stringPointer[14];
67 | snprintf(stringPointer,13,"%lu",data);
68 | strcat(stringPointer,"\r\n");
69 |
70 | print(stringPointer);
71 | }
72 | //Print string with newline
73 | void PrintlnClass::println(const char * stringData)
74 | {
75 | char stringNewLine[strlen(stringData)+3];
76 | stringNewLine[0]='\0';
77 | strcat(stringNewLine,stringData);
78 | strcat(stringNewLine,"\r\n");
79 |
80 | print(stringNewLine);
81 | }
82 |
83 | //Support strings
84 | void PrintlnClass::println(String stringData)
85 | {
86 | println(&stringData[0]);
87 | }
88 |
89 | //Unsupported by Intel Galileo board and Arduino Due
90 | #if !defined(ARDUINO_LINUX) && !defined(SAM3X8)
91 | void PrintlnClass::println(double data, int precesion)
92 | {
93 | int i=0;
94 | char buffer[32]={'\0'};
95 | dtostrf(data,1,precesion,buffer);
96 |
97 | while(buffer[i]!='\0' && i<32)i++;
98 |
99 | if(i+2>32)return;
100 | buffer[i]='\r';
101 | buffer[i+1]='\n';
102 | buffer[i+2]='\0';
103 |
104 | print(buffer);
105 |
106 | }
107 | #endif
108 |
--------------------------------------------------------------------------------
/src/DabblePrintln.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ifndef PrintlnClass_h
4 | #define PrintlnClass_h
5 |
6 | #include "DabblePrint.h"
7 |
8 | class PrintlnClass: public PrintClass
9 | {
10 | public:
11 | PrintlnClass(byte, byte, byte);
12 | //Printing in new line
13 | void println();
14 | void println(char);
15 | void println(int);
16 | void println(unsigned int);
17 | void println(long);
18 | void println(unsigned long);
19 | void println(const char *);
20 | void println(String);
21 | //Unsupported by Intel Galileo board and Arduino Due
22 | #if !defined(ARDUINO_LINUX) && !defined(SAM3X8)
23 | void println(double , int = 3);
24 | #endif
25 | };
26 |
27 | #endif
--------------------------------------------------------------------------------
/src/DataLoggerModule.cpp:
--------------------------------------------------------------------------------
1 | #define FROM_DABBLE_LIBRARY
2 | #include "DabbleESP32.h"
3 | #include "DataLoggerModule.h"
4 | uint8_t columnNumber=0;
5 | String *tempColName = NULL;
6 | DataLoggerModule::DataLoggerModule():ModuleParent(DATALOGGER_ID)
7 | {}
8 |
9 | void DataLoggerModule::sendSettings(void(*function)(void))
10 | {
11 | callBackForDataLogger = true;
12 | dataLoggerCallBack = function;
13 | }
14 | void DataLoggerModule::createFile(String FileName)
15 | {
16 | columnNumber=0;
17 | Dabble.sendModuleFrame(DATALOGGER_ID,0,FILENAME,1,new FunctionArg(FileName.length(),(byte *)&FileName[0]));
18 | }
19 |
20 | void DataLoggerModule::createColumn(String colName)
21 | {
22 | //Process to store FileNames starts
23 | if(columnNumber != 0)
24 | {
25 | if(columnNumber != 1)
26 | delete [] tempColName;
27 | tempColName = new String[columnNumber];
28 | }
29 | for(int i=0;i>8);
183 | a[1] = byte(data);
184 | //Serial.print(a[0],BIN);
185 | //Serial.print(" ");
186 | //Serial.print(a[1],BIN);
187 | //Serial.print(" ");
188 | //Serial.println(data,BIN);
189 | Dabble.sendModuleFrame(DATALOGGER_ID,0,DATATYPE_INT,2,new FunctionArg(1,&columnFlag),new FunctionArg(sizeof(int),a));
190 | }*/
191 |
192 | /*void send(int count,...)
193 | {
194 | String tempColName = "";
195 | byte columnFlag = 0;
196 | va_list columData;
197 | va_start(colData, count);
198 | for(int i=0;i> 3)*15);
198 | uint8_t radius=value&0x07;
199 | float x_value= float(radius*(float(cos(float(angle*PI/180)))));
200 | float y_value= float(radius*(float(sin(float(angle*PI/180)))));
201 | if(b == 0)
202 | {
203 |
204 | return angle;
205 | }
206 | else if(b==1)
207 | {
208 |
209 | return radius;
210 | }
211 | else if(b==2)
212 | {
213 | return x_value;
214 | }
215 | else if(b==3)
216 | {
217 | return y_value;
218 | }
219 | }
220 |
221 |
222 | uint16_t GamePadModule::getAngle()
223 | {
224 | if(mode == 1)
225 | return ((value >> 3)*15);
226 | else
227 | return 0;
228 | }
229 |
230 | uint8_t GamePadModule::getRadius()
231 | {
232 | if(mode == 1)
233 | return (value&0x07);
234 | else
235 | return 0;
236 | }
237 |
238 | float GamePadModule::getXaxisData()
239 | {
240 | uint16_t angle=((value >> 3)*15);
241 | uint8_t radius=value&0x07;
242 | float x_value= float(radius*(float(cos(float(angle*PI/180)))));
243 | return x_value;
244 | }
245 |
246 | float GamePadModule::getYaxisData()
247 | {
248 | uint16_t angle=((value >> 3)*15);
249 | uint8_t radius=value&0x07;
250 | float y_value= float(radius*(float(sin(float(angle*PI/180)))));
251 | return y_value;
252 | }
253 |
254 | float GamePadModule::getx_axis()
255 | {
256 | uint16_t angle=((value >> 3)*15);
257 | uint8_t radius=value&0x07;
258 | float x_value= float(radius*(float(cos(float(angle*PI/180)))));
259 | return x_value;
260 | }
261 |
262 | float GamePadModule::gety_axis()
263 | {
264 | uint16_t angle=((value >> 3)*15);
265 | uint8_t radius=value&0x07;
266 | float y_value= float(radius*(float(sin(float(angle*PI/180)))));
267 | return y_value;
268 | }
--------------------------------------------------------------------------------
/src/GamePadModule.h:
--------------------------------------------------------------------------------
1 | #ifndef GamePadModule_h
2 | #define GamePadModule_h
3 |
4 | #include "ModuleParent.h"
5 |
6 | //Input Function ID
7 | #define GAMEPAD_DIGITAL 0x01
8 | #define GAMEPAD_ANALOG 0x02
9 | #define GAMEPAD_ACCL 0x03
10 | //GamePad Bit Reference
11 | //Byte 1
12 | #define START_BIT 0
13 | #define SELECT_BIT 1
14 | #define TRIANGLE_BIT 2
15 | #define CIRCLE_BIT 3
16 | #define CROSS_BIT 4
17 | #define SQUARE_BIT 5
18 |
19 | //Byte 2 in case of Digital Mode GamePad
20 | #define UP_BIT 0
21 | #define DOWN_BIT 1
22 | #define LEFT_BIT 2
23 | #define RIGHT_BIT 3
24 |
25 |
26 |
27 | //Byte 2 in case of Analog/Accelerometer Mode GamePad
28 | //XXXXXYYY = XXXXX(*15) is angle in radians, YYY is radius
29 |
30 | class GamePadModule : public ModuleParent
31 | {
32 | public:
33 | //Constructor
34 | GamePadModule();
35 | //Arduino
36 | //Checker Functions
37 | bool isStartPressed();
38 | bool isSelectPressed();
39 | bool isTrianglePressed();
40 | bool isCirclePressed();
41 | bool isCrossPressed();
42 | bool isSquarePressed();
43 | bool isUpPressed();
44 | bool isDownPressed();
45 | bool isLeftPressed();
46 | bool isRightPressed();
47 | uint16_t getAngle();
48 | uint8_t getRadius();
49 | float getXaxisData();
50 | float getYaxisData();
51 |
52 | float getx_axis();
53 | float gety_axis();
54 |
55 | //Pictoblox
56 | bool isPressed(uint8_t a);
57 | float getJoystickData(uint8_t b);
58 |
59 | //setOnChange for Users Function
60 | /* void setOnButtonChange(void (*)(unsigned char , unsigned char ,
61 | unsigned char , unsigned char ,
62 | unsigned char , unsigned char ,
63 | unsigned char , unsigned char ));
64 | */private:
65 | //Reserve Variables
66 | bool mode; //mode=0 for gamepad , mode = 1 for joystick
67 | byte value;
68 | byte value0;
69 | //bool isCallBackAssigned;
70 | //Process Input Data
71 | void processData();
72 | /*void (*buttonChangeCallBack)(unsigned char , unsigned char ,
73 | unsigned char , unsigned char ,
74 | unsigned char ,unsigned char ,
75 | unsigned char ,unsigned char );*/
76 | };
77 |
78 | //Extern Object
79 | extern GamePadModule GamePad;
80 | #endif
--------------------------------------------------------------------------------
/src/IncludedModulesDefines.h:
--------------------------------------------------------------------------------
1 | #define INCLUDE_DABBLEINPUTS_MODULE
2 | #define INCLUDE_TERMINAL_MODULE
3 | #define INCLUDE_INTERNET_MODULE
4 | #define INCLUDE_MOTORCONTROL_MODULE
5 | #define INCLUDE_GAMEPAD_MODULE
6 | #define INCLUDE_PINMONITOR_MODULE
7 | #define INCLUDE_SENSOR_MODULE
8 | #define INCLUDE_CAMERA_MODULE
9 | #define INCLUDE_LEDCONTROL_MODULE
10 | #define INCLUDE_COLORDETECTOR_MODULE
11 | #define INCLUDE_DATALOGGER_MODULE
12 | #define INCLUDE_SMS_MODULE
13 | #define INCLUDE_NOTIFICATION_MODULE
14 | #define INCLUDE_MUSIC_MODULE
15 | #define INCLUDE_ROBOTICARM_MODULE
16 | #define INCLUDE_HOMEAUTOMATION_MODULE
--------------------------------------------------------------------------------
/src/InternetModule.cpp:
--------------------------------------------------------------------------------
1 | #define FROM_DABBLE_LIBRARY
2 | #include "DabbleESP32.h"
3 | #include "InternetModule.h"
4 |
5 | //Constructor
6 | InternetModule::InternetModule():ModuleParent(INTERNET_ID)
7 | {}
8 |
9 | /*//Read from Android
10 | char InternetModule::read()
11 | {
12 | if(buffer.remain()<=0)return -1;
13 | return buffer.pop();
14 | return 0;
15 | }
16 | //Flush buffer contents
17 | void InternetModule::flush()
18 | {
19 | while(read()!=-1);
20 | }
21 | //Check Data avialable in Buffer
22 | int InternetModule::available()
23 | {
24 | return buffer.remain();
25 | }
26 | //Read bytes from Buffer
27 | int InternetModule::readBytes(char *arr, int length)
28 | {
29 | int count = 0;
30 | while (count < length) {
31 | int c = read();
32 | if (c < 0) break;
33 | *arr++ = (char)c;
34 | count++;
35 | }
36 | return count;
37 | }
38 | */
39 | //Terminal Incomming Data processing
40 | void InternetModule::processData()
41 | {
42 | byte functionID = getDabbleInstance().getFunctionId();
43 | byte dataLength = getDabbleInstance().getArgumentLength(0);
44 | byte dataLines = getDabbleInstance().getArgumentNo();
45 |
46 | /*Serial.print("In processInput");
47 | Serial.println(functionID);
48 | Serial.println(dataLength);*/
49 | if(functionID == HTTP_RESPONSE && successState == 1 )
50 | {
51 | successState = 0;
52 | //Serial.println("Response");
53 | mainString = "";
54 | int counter = 0;
55 | for(int i = 0;i< dataLines; i++)
56 | {
57 | for (int j=0; j
7 |
8 |
9 | #ifdef ESP32
10 | #define MAX_PWM_CHANNELS 8
11 | uint8_t freeChannel =0,prevPin=0,currentChannel=0;
12 | bool pinType=0; // flag to differentiate pin behaviour means whether pin will be traeted as PWM or digital
13 | #endif
14 |
15 | LedControlModule::LedControlModule(): ModuleParent(LEDCONTROL_ID)
16 | {
17 | }
18 |
19 | void LedControlModule::processData()
20 | {
21 | byte functionId =getDabbleInstance().getFunctionId();
22 |
23 | if(functionId == 0x01)
24 | {
25 | pin = getDabbleInstance().getArgumentData(0)[0];
26 | if(prevPin != pin)
27 | {
28 | if(freeChannel < MAX_PWM_CHANNELS)
29 | {
30 | #ifdef DEBUG
31 | Serial.println("Pin is treated as pwm pin");
32 | #endif
33 | /*#ifdef DEBUG
34 | Serial.print("Channels: ");
35 | Serial.print(freeChannel);
36 | Serial.print(" ");
37 | Serial.println(currentChannel);
38 | #endif*/
39 | currentChannel = freeChannel;
40 | ledcAttachChannel(pin, 12000, 8, currentChannel);
41 |
42 | // ledcAttach(pin, currentChannel); // Attach the pin to the channel
43 | // ledcSetup(currentChannel, 1000, 8); // Set the PWM frequency (1000 Hz in this example) and resolution (8 bits)
44 |
45 | freeChannel++;
46 | /*#ifdef DEBUG
47 | Serial.print("freeChannels: ");
48 | Serial.println(freeChannel);
49 | #endif*/
50 | pinType =1; // pin is a PWM type
51 | }
52 | else
53 | {
54 | #ifdef DEBUG
55 | Serial.println("Pin is treated as digital pin");
56 | #endif
57 | pinMode(pin,OUTPUT);
58 | pinType = 0; // pin is a digital type
59 | }
60 | }
61 | prevPin = pin;
62 | }
63 | else if (functionId == 0x03) //ON as per Brightness value
64 | {
65 | brightness = getDabbleInstance().getArgumentData(0)[0];
66 | #ifdef DEBUG
67 | Serial.println(brightness);
68 | #endif
69 | value = map(brightness,0,100,0,255);
70 | #ifdef DEBUG
71 | Serial.println(value);
72 | #endif
73 | }
74 | else if(functionId == 0x02) //OFF
75 | {
76 | brightness =0;
77 | value=0;
78 | }
79 |
80 | if(pinType == 1 && pin!= 0) //for PWM type pin
81 | {
82 | //Serial.println("Value Assigned");
83 | ledcWrite(currentChannel,value);
84 | }
85 | else //for digital type pin
86 | {
87 | //Serial.println("Value Assigned");
88 | if(value == 255)
89 | {
90 | digitalWrite(pin,HIGH);
91 | }
92 | else
93 | {
94 | digitalWrite(pin,LOW);
95 | }
96 | }
97 | }
98 |
99 | uint8_t LedControlModule::readBrightness()
100 | {
101 | return brightness;
102 | }
103 |
104 | bool LedControlModule::getpinState()
105 | {
106 | if(brightness>0)
107 | return 1;
108 | else
109 | return 0;
110 | }
111 |
112 | uint8_t LedControlModule::getpinNumber()
113 | {
114 | return pin;
115 | }
116 |
117 |
--------------------------------------------------------------------------------
/src/LedControlModule.h:
--------------------------------------------------------------------------------
1 | #ifndef LedControlModule_h
2 | #define LedControlModule_h
3 |
4 | #include "ModuleParent.h"
5 |
6 |
7 | class LedControlModule : public ModuleParent
8 | {
9 | public:
10 | //Constructor
11 | LedControlModule();
12 | public:
13 | uint8_t readBrightness();
14 | bool getpinState();
15 | uint8_t getpinNumber();
16 | uint8_t pin;
17 | uint8_t brightness=0;
18 | private:
19 | //Reserve Variables
20 | byte value;
21 | //bool isCallBackAssigned;
22 | //Process Input Data
23 | void processData();
24 | /*void (*buttonChangeCallBack)(unsigned char , unsigned char ,
25 | unsigned char , unsigned char ,
26 | unsigned char ,unsigned char ,
27 | unsigned char ,unsigned char );*/
28 | };
29 |
30 | //Extern Object
31 | extern LedControlModule LedControl;
32 | #endif
--------------------------------------------------------------------------------
/src/ModuleIds.h:
--------------------------------------------------------------------------------
1 | #define Dabble_ID 0x00
2 | #define GAMEPAD_ID 0x01
3 | #define TERMINAL_ID 0x02
4 | #define CONTROLS_ID 0x05
5 | #define EVIVEINTERFACES_ID 0x09
6 | //#define INTERNET_ID 0x29
7 | #define PINMONITOR_ID 0x03
8 | #define SENSORS_ID 0x04
9 | #define CAMERA_ID 0x06
10 | #define LEDCONTROL_ID 0x0A
11 | #define COLORDETECTOR_ID 0x0B
12 | #define DATALOGGER_ID 0x0C
13 | #define SMS_ID 0x0D
14 | #define NOTIFICATION_ID 0x0D
15 | #define MUSIC_ID 0x0E
16 | #define ROBOTICARM_ID 0x0F
17 | #define HOMEAUTOMATION_ID 0x10
18 | #define INTERNET_ID 0x11
19 |
20 |
--------------------------------------------------------------------------------
/src/ModuleIncludes.h:
--------------------------------------------------------------------------------
1 | #include "motorControls.h"
2 | #include "InternetModule.h"
3 | #include "DabbleInputs.h"
4 | #include "TerminalModule.h"
5 | #include "GamePadModule.h"
6 | #include "PinMonitorModule.h"
7 | #include "SensorModule.h"
8 | #include "CameraModule.h"
9 | #include "LedControlModule.h"
10 | #include "ColorDetectorModule.h"
11 | #include "DataLoggerModule.h"
12 | #include "NotifyAndSMSModule.h"
13 | #include "MusicModule.h"
14 |
--------------------------------------------------------------------------------
/src/ModuleInstantiation.h:
--------------------------------------------------------------------------------
1 |
2 | #ifdef INCLUDE_INTERNET_MODULE
3 | EXTERN InternetModule Internet;
4 | #endif
5 |
6 | #ifdef INCLUDE_TERMINAL_MODULE
7 | EXTERN TerminalModule Terminal;
8 | #endif
9 |
10 | #ifdef INCLUDE_DABBLEINPUTS_MODULE
11 | EXTERN DabbleInputs Inputs;
12 | #endif
13 |
14 | #ifdef INCLUDE_MOTORCONTROL_MODULE
15 | EXTERN motorControls Controls;
16 | #endif
17 |
18 | #ifdef INCLUDE_GAMEPAD_MODULE
19 | EXTERN GamePadModule GamePad;
20 | #endif
21 |
22 | #ifdef INCLUDE_PINMONITOR_MODULE
23 | EXTERN PinMonitorModule PinMonitor;
24 | #endif
25 |
26 | #ifdef INCLUDE_SENSOR_MODULE
27 | EXTERN SensorModule Sensor;
28 | #endif
29 |
30 | #ifdef INCLUDE_CAMERA_MODULE
31 | EXTERN CameraModule Camera;
32 | #endif
33 |
34 | #ifdef INCLUDE_LEDCONTROL_MODULE
35 | EXTERN LedControlModule LedControl;
36 | #endif
37 |
38 | #ifdef INCLUDE_COLORDETECTOR_MODULE
39 | EXTERN ColorDetectorModule ColorDetector;
40 | #endif
41 |
42 | #ifdef INCLUDE_DATALOGGER_MODULE
43 | EXTERN DataLoggerModule DataLogger;
44 | #endif
45 |
46 | #ifdef INCLUDE_SMS_MODULE
47 | EXTERN SMSModule SMS;
48 | #endif
49 |
50 | #ifdef INCLUDE_NOTIFICATION_MODULE
51 | EXTERN NotificationModule Notification;
52 | #endif
53 |
54 | #ifdef INCLUDE_MUSIC_MODULE
55 | EXTERN MusicModule Music;
56 | #endif
57 |
58 | /*#ifdef INCLUDE_ROBOTICARM_MODULE
59 | EXTERN RoboticArmModule RoboticArm;
60 | #endif
61 |
62 | #ifdef INCLUDE_HOMEAUTOMATION_MODULE
63 | EXTERN HomeAutomationModule HomeAutomation;;
64 | #endif*/
65 |
--------------------------------------------------------------------------------
/src/ModuleParent.cpp:
--------------------------------------------------------------------------------
1 |
2 | #define FROM_DABBLE_LIBRARY
3 | #include "DabbleESP32.h"
4 |
5 | DabbleClass * ModuleParent::DabbleInstance=NULL;
6 | bool ModuleParent::DabbleInstanceAvailable=false;
7 |
8 | ModuleParent::ModuleParent(byte ModuleNo)
9 | {
10 | //Serial.println("FOUND NEW MODULE");
11 | ModuleID = ModuleNo ;
12 | /*#ifdef DEBUG
13 | Serial.println(ModuleID);
14 | #endif*/
15 | isCallBackSet=false;
16 | DabbleClass::addToModulesArray(this);
17 | }
18 |
19 | void ModuleParent::select()
20 | {
21 | Dabble.sendModuleFrame(ModuleID,0x00,SELECT_MODULE,0x00);
22 | }
23 |
24 | void ModuleParent::deselect()
25 | {
26 | Dabble.sendModuleFrame(ModuleID,0x00,DESELECT_MODULE,0x00);
27 | }
28 |
29 | void ModuleParent::setOnSelected(void (*userFunction)(void))
30 | {
31 | Dabble.sendModuleFrame(ModuleID,0x00,QUERY_SELECTED,0x00);
32 | isCallBackSet=true;
33 | selectedCallBack=userFunction;
34 | }
35 |
36 | byte ModuleParent::getModuleId()
37 | {
38 | return ModuleID;
39 | }
40 |
41 | void ModuleParent::enteringACallback()
42 | {
43 | Dabble.enteringACallback();
44 | }
45 |
46 | void ModuleParent::exitingACallback()
47 | {
48 | Dabble.exitingACallback();
49 | }
50 |
51 | bool ModuleParent::isInACallback()
52 | {
53 | return Dabble.isInACallback();
54 | }
55 |
56 | void ModuleParent::setDabbleInstance(DabbleClass & instance)
57 | {
58 | DabbleInstance=&instance;
59 | DabbleInstanceAvailable=true;
60 | }
61 |
62 | void ModuleParent::unSetDabbleInstance()
63 | {
64 | DabbleInstance=NULL;
65 | DabbleInstanceAvailable=false;
66 | }
67 |
68 | DabbleClass & ModuleParent::getDabbleInstance()
69 | {
70 | if(DabbleInstanceAvailable)return *DabbleInstance;
71 | else return Dabble;
72 | }
73 |
74 | void ModuleParent::processFrame()
75 | {
76 | if(ModuleID!=getDabbleInstance().getModuleId())
77 | {
78 | return;
79 | }
80 | byte functionID = getDabbleInstance().getFunctionId();
81 |
82 | if(functionID == CHECK_SELECTED)
83 | {
84 | if(isCallBackSet && !isInACallback())
85 | {
86 | enteringACallback();
87 | (*selectedCallBack)();
88 | exitingACallback();
89 | }
90 | }
91 | else
92 | {
93 | processData();
94 | }
95 | }
--------------------------------------------------------------------------------
/src/ModuleParent.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ifndef ModuleParent_h
4 | #define ModuleParent_h
5 |
6 |
7 | /* Output functions ID. */
8 | #define QUERY_SELECTED 0xFF
9 | #define SELECT_MODULE 0xFE
10 | #define DESELECT_MODULE 0xFD
11 |
12 |
13 | /* Input functions ID. */
14 | #define CHECK_SELECTED 0xFF
15 |
16 | class DabbleClass;
17 |
18 | class ModuleParent
19 | {
20 | protected:
21 | ModuleParent(byte);
22 | virtual void processFrame(void);
23 | virtual void processData(void){};
24 | void enteringACallback();
25 | void exitingACallback();
26 | bool isInACallback();
27 | DabbleClass & getDabbleInstance();
28 | public:
29 | /* Functions will be inherited by all Modules. */
30 | void select(void);
31 | void deselect(void);
32 | void setOnSelected(void(*)(void));
33 | byte getModuleId(void);
34 | private:
35 | bool isCallBackSet;
36 | byte ModuleID;
37 | void (*selectedCallBack)(void);
38 | static DabbleClass * DabbleInstance;
39 | static bool DabbleInstanceAvailable;
40 | static void setDabbleInstance(DabbleClass &);
41 | static void unSetDabbleInstance();
42 |
43 | friend class DabbleClass;
44 | };
45 |
46 | #endif
--------------------------------------------------------------------------------
/src/ModuleSelection.h:
--------------------------------------------------------------------------------
1 | #define ANY_MODULE_DEFINED \
2 | (defined(INCLUDE_DABBLEINPUTS_MODULE) || \
3 | defined(INCLUDE_GAMEPAD_MODULE) || \
4 | defined(INCLUDE_INTERNET_MODULE) || \
5 | defined(INCLUDE_MOTORCONTROL_MODULE) || \
6 | defined (INCLUDE_PINMONITOR_MODULE) || \
7 | defined(INCLUDE_TERMINAL_MODULE) || \
8 | defined(INCLUDE_CAMERA_MODULE) || \
9 | defined(INCLUDE_COLORDETECTOR_MODULE) || \
10 | defined(INCLUDE_LEDCONTROL_MODULE) || \
11 | defined(INCLUDE_DATALOGGER_MODULE) || \
12 | defined(INCLUDE_SMS_MODULE) || \
13 | defined(INCLUDE_NOTIFICATION_MODULE) || \
14 | defined(INCLUDE_MUSIC_MODULE) || \
15 | defined(INCLUDE_SENSOR_MODULE))
16 |
17 | // defined(INCLUDE_HOMEAUTOMATION_MODULE) || \
18 | // defined(INCLUDE_ROBOTICARM_MODULE) || \
19 |
20 | #if !defined(FROM_DABBLE_LIBRARY)
21 | #if (defined(INCLUDE_ALL_MODULES) && defined(CUSTOM_SETTINGS)) || (!defined(CUSTOM_SETTINGS) && !ANY_MODULE_DEFINED)
22 | #include "IncludedModulesDefines.h"
23 | #define ALL_MODULES_INCLUDED
24 | #endif
25 | #endif
26 |
27 | #if (ANY_MODULE_DEFINED && defined(CUSTOM_SETTINGS)) || defined(ALL_MODULES_INCLUDED)
28 | #define EXTERN
29 | #else
30 | #define EXTERN extern
31 | #endif
--------------------------------------------------------------------------------
/src/MusicModule.cpp:
--------------------------------------------------------------------------------
1 | #define FROM_DABBLE_LIBRARY
2 | #include "DabbleESP32.h"
3 | #include "MusicModule.h"
4 |
5 | MusicModule::MusicModule():ModuleParent(MUSIC_ID)
6 | {}
7 |
8 | void MusicModule::play(String name){
9 | //uint8_t namelength = strlen(name);
10 | Dabble.sendModuleFrame(MUSIC_ID,0,PLAYNOW,1, new FunctionArg(name.length(), (byte *)&name[0]));
11 | }
12 |
13 | void MusicModule::addToQueue(String name){
14 | //uint8_t namelength = strlen(name);
15 | Dabble.sendModuleFrame(MUSIC_ID,0,ADDTOQUEUE,1, new FunctionArg(name.length(), (byte *)&name[0]));
16 | }
17 |
18 | void MusicModule::stop(){
19 | Dabble.sendModuleFrame(MUSIC_ID,0,STOPMUSIC,0);
20 | }
21 |
22 | void MusicModule::playMusic(uint8_t a, String key)
23 | {
24 | if(a == 1)
25 | {
26 | play(key);
27 | }
28 | if(a == 2)
29 | {
30 | addToQueue(key);
31 | }
32 | }
--------------------------------------------------------------------------------
/src/MusicModule.h:
--------------------------------------------------------------------------------
1 | #ifndef MusicModule_H_
2 | #define MusicModule_H_
3 | #include "ModuleParent.h"
4 |
5 | #define ADDTOQUEUE 0x01
6 | #define PLAYNOW 0x02
7 | #define STOPMUSIC 0x03
8 |
9 | class MusicModule:public ModuleParent
10 | {
11 | public:
12 | MusicModule();
13 | void play(String);
14 | void addToQueue(String);
15 | void stop();
16 | void playMusic(uint8_t , String);
17 | };
18 | extern MusicModule Music;
19 | #endif
--------------------------------------------------------------------------------
/src/NotifyAndSMSModule.cpp:
--------------------------------------------------------------------------------
1 | #define FROM_DABBLE_LIBRARY
2 | #include "DabbleESP32.h"
3 | #include "NotifyAndSMSModule.h"
4 |
5 | SMSModule::SMSModule():ModuleParent(SMS_ID)
6 | {}
7 |
8 | void SMSModule::sendMessage(String number, String content)
9 | {
10 | uint8_t* numberInt = NULL;
11 | numberInt = new uint8_t [number.length()];
12 | for(int i =0 ; i
5 |
6 | #define ACCELEROMETER 0x01
7 | #define GYROSCOPE 0x02
8 | #define MAGNETOMETER 0x03
9 | #define PROXIMITY 0x04
10 | #define LIGHT 0x05
11 | #define SOUND 0x06
12 | #define TEMPERATURE 0x07
13 | #define BAROMETER 0x08
14 | #define GPS 0x09
15 |
16 | class SensorModule: public ModuleParent
17 | {
18 | public:
19 | SensorModule();
20 | float getdata_Accelerometer_xaxis();
21 | float getdata_Accelerometer_yaxis();
22 | float getdata_Accelerometer_zaxis();
23 | float getdata_Gyroscope_xaxis();
24 | float getdata_Gyroscope_yaxis();
25 | float getdata_Gyroscope_zaxis();
26 | float getdata_Magnetometer_xaxis();
27 | float getdata_Magnetometer_yaxis();
28 | float getdata_Magnetometer_zaxis();
29 | float getdata_Proximity();
30 | float getdata_Light();
31 | float getdata_Sound();
32 | float getdata_Temperature();
33 | float getdata_Barometer();
34 | float getdata_GPS_longitude();
35 | float getdata_GPS_latitude();
36 | float getAccelerometerXaxis();
37 | float getAccelerometerYaxis();
38 | float getAccelerometerZaxis();
39 | float getGyroscopeXaxis();
40 | float getGyroscopeYaxis();
41 | float getGyroscopeZaxis();
42 | float getMagnetometerXaxis();
43 | float getMagnetometerYaxis();
44 | float getMagnetometerZaxis();
45 | float getProximityDistance();
46 | float getLightIntensity();
47 | float getSoundDecibels();
48 | float getTemperature();
49 | float getBarometerPressure();
50 | float getGPSlongitude();
51 | float getGPSLatitude();
52 | float getSensorData(uint8_t a);
53 |
54 | void processData();
55 | public:
56 | byte sensorvalue_x[4];
57 | byte sensorvalue_y[4];
58 | byte sensorvalue_z[4];
59 | byte sensor_data[4];
60 | byte sensor_data_1[4];
61 |
62 | float accelo_x=0;
63 | float accelo_y=0;
64 | float accelo_z=0;
65 |
66 | float gyro_x=0;
67 | float gyro_y=0;
68 | float gyro_z=0;
69 |
70 | float magneto_x=0;
71 | float magneto_y=0;
72 | float magneto_z=0;
73 |
74 | float proximity=0;
75 | float light=0;
76 | float barometer=0;
77 | float gps_longitude=0;
78 | float gps_latitude=0;
79 | float sound_level=0;
80 | float temperature=0;
81 |
82 | };
83 |
84 |
85 | extern SensorModule Sensor;
86 | #endif
--------------------------------------------------------------------------------
/src/TerminalModule.cpp:
--------------------------------------------------------------------------------
1 | #define FROM_DABBLE_LIBRARY
2 | #include "DabbleESP32.h"
3 | #include "TerminalModule.h"
4 |
5 | //String comparestring= "";
6 | String numberString= "";
7 | String stringData= "";
8 | String comparestring="";
9 | bool stringclearflag1=0;
10 | bool stringclearflag2=0;
11 | bool stringclearflag3=0;
12 |
13 | //Constructor
14 | TerminalModule::TerminalModule():PrintlnClass(TERMINAL_ID,TERMINAL_WRITE,TERMINAL_PRINT),ModuleParent(TERMINAL_ID)
15 | {}
16 |
17 | //Read from Android
18 | char TerminalModule::read()
19 | {
20 | if(buffer.remain()<=0)return -1;
21 | return buffer.pop();
22 | }
23 | //Flush buffer contents
24 | void TerminalModule::flush()
25 | {
26 | while(read()!=-1);
27 | }
28 | //Check Data avialable in Buffer
29 | int TerminalModule::available()
30 | {
31 | return buffer.remain();
32 | }
33 | //Read bytes from Buffer
34 | int TerminalModule::readBytes(char *arr, int length)
35 | {
36 | int count = 0;
37 | while (count < length) {
38 | int c = read();
39 | if (c < 0) break;
40 | *arr++ = (char)c;
41 | count++;
42 | }
43 | return count;
44 | }
45 |
46 | //Terminal Incomming Data processing
47 | void TerminalModule::processData()
48 | {
49 | byte functionID = getDabbleInstance().getFunctionId();
50 | byte dataLength = getDabbleInstance().getArgumentLength(0);
51 |
52 | if(functionID == TERMINAL_READ)
53 | {
54 |
55 | for (int j=0; j47 && numCheck.charAt(i)<58)
94 | {
95 | a=1;
96 | }
97 | }
98 | if(a==1)
99 | {
100 |
101 | numberData= numCheck.toInt();
102 | }
103 | else
104 | {
105 | numberData=-30000;
106 | }
107 | return numberData;
108 | }*/
109 |
110 | String TerminalModule::readString()
111 | {
112 | if(buffer.remain()>0)
113 | {
114 | stringclearflag1=0;
115 | stringclearflag2=0;
116 | stringclearflag3=0;
117 | //comparestring="";
118 | //numberstring="";
119 | stringData= "";
120 | while(buffer.remain()>0)
121 | {
122 | char a = buffer.pop();
123 | stringData=String(stringData+a);
124 | numberString=stringData;
125 | comparestring=stringData;
126 | //comparestring=String(comparestring+a);
127 | //numberstring=String(numberstring+a);
128 | }
129 | }
130 | if(stringclearflag1==0)
131 | {
132 | stringclearflag1 =1;
133 | return stringData;
134 | }
135 | else
136 | {
137 | stringData = "";
138 | return stringData;
139 | }
140 | }
141 |
142 | int TerminalModule::readNumber()
143 | {
144 | int numberData;
145 | bool a=0;
146 | readString();
147 | for(int i=0;i47 && numberString.charAt(i)<58)
150 | {
151 | a=1;
152 | }
153 | else
154 | {
155 | break;
156 | }
157 | }
158 | if(a==1 && stringclearflag2 == 0)
159 | {
160 | stringclearflag2=1;
161 | numberData= numberString.toInt();
162 | }
163 | else
164 | {
165 | numberData=-100;
166 | }
167 | return numberData;
168 | }
169 |
170 |
171 |
172 |
--------------------------------------------------------------------------------
/src/TerminalModule.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef TerminalModule_h
3 | #define TerminalModule_h
4 |
5 | #include "ModuleParent.h"
6 |
7 | #include "DabblePrintln.h"
8 | #include "CircularBuffer.h"
9 |
10 |
11 | //Output Function ID's
12 | #define TERMINAL_WRITE 0x02
13 | #define TERMINAL_PRINT 0x02
14 |
15 | //Input Function ID
16 | #define TERMINAL_READ 0x01
17 |
18 | class TerminalModule : public PrintlnClass, public ModuleParent
19 | {
20 | public:
21 | //Constructor
22 | TerminalModule();
23 | //Checker
24 | int available();
25 | //Getter
26 | char read();
27 | //Getter
28 | int readBytes(char *, int);
29 | //Setter
30 | void flush();
31 | String readString();
32 | bool compareString(String text);
33 | int readNumber();
34 |
35 | private:
36 | //Instatiate Object from class CircularBuffer
37 | CircularBuffer buffer;
38 | //CircularBuffer buffer1;
39 | //Process Input data
40 | void processData();
41 | };
42 | //Extern Object
43 | extern TerminalModule Terminal;
44 | #endif
--------------------------------------------------------------------------------
/src/esp32BLEUtilities.cpp:
--------------------------------------------------------------------------------
1 | #if defined(ESP32)
2 | #include "esp32BLEUtilities.h"
3 |
4 | bool BLE_status = 0;
5 | bool isDeviceConnected = false;
6 | bool prevDeviceConnected = false;
7 | uint8_t tx_Value = 0;
8 | uint8_t rxdatalength = 0;
9 | uint8_t bytesremaining = 0;
10 | uint8_t* rxdataBuffer = NULL;
11 | bool newDataReceived = 0;
12 |
13 | BLEServer *bleServer = NULL;
14 | BLECharacteristic *bleTxCharacteristic;
15 |
16 | // BLE Server Callbacks
17 | class BleServerCallbacks : public BLEServerCallbacks {
18 | void onConnect(BLEServer* bleServer) override {
19 | isDeviceConnected = true;
20 | }
21 |
22 | void onDisconnect(BLEServer* bleServer) override {
23 | isDeviceConnected = false;
24 | }
25 | };
26 |
27 | // BLE Characteristic Callbacks
28 | class BleCallbacks : public BLECharacteristicCallbacks {
29 | void onWrite(BLECharacteristic *bleCharacteristic) override {
30 | String rx_Value = bleCharacteristic->getValue(); // Use String instead of std::string
31 | if (newDataReceived == 1) {
32 | delete[] rxdataBuffer;
33 | }
34 |
35 | newDataReceived = 1;
36 | if (rx_Value.length() > 0) {
37 | rxdataBuffer = new uint8_t[rx_Value.length()];
38 | for (int i = 0; i < rx_Value.length(); i++) {
39 | rxdataBuffer[i] = rx_Value[i];
40 | #ifdef DEBUG
41 | Serial.print(rxdataBuffer[i]);
42 | Serial.print(" ");
43 | #endif
44 | }
45 | #ifdef DEBUG
46 | Serial.println();
47 | #endif
48 | rxdatalength = rx_Value.length();
49 | bytesremaining = rx_Value.length();
50 | }
51 | }
52 | };
53 |
54 | void Esp32ble::begin(String a) { // Use String as parameter type
55 | BLEDevice::init(a);
56 |
57 | // Create the BLE Server
58 | bleServer = BLEDevice::createServer();
59 | bleServer->setCallbacks(new BleServerCallbacks());
60 |
61 | // Create the BLE Service
62 | BLEService *bleService = bleServer->createService(UUID_Service);
63 |
64 | // Create a BLE Characteristic
65 | bleTxCharacteristic = bleService->createCharacteristic(
66 | UUID_Transmit,
67 | BLECharacteristic::PROPERTY_NOTIFY
68 | );
69 |
70 | bleTxCharacteristic->addDescriptor(new BLE2902());
71 |
72 | BLECharacteristic *bleRxCharacteristic = bleService->createCharacteristic(
73 | UUID_Receive,
74 | BLECharacteristic::PROPERTY_WRITE
75 | );
76 |
77 | bleRxCharacteristic->setCallbacks(new BleCallbacks());
78 |
79 | // Start the service
80 | bleService->start();
81 |
82 | // Start advertising
83 | bleServer->getAdvertising()->start();
84 |
85 | #ifdef DEBUG
86 | Serial.println("Waiting for a client connection...");
87 | #endif
88 | }
89 |
90 | void Esp32ble::write(uint8_t a) {
91 | if (isDeviceConnected) {
92 | bleTxCharacteristic->setValue(&a, 1);
93 | bleTxCharacteristic->notify();
94 | delay(10); // avoid congestion in the BLE stack
95 | }
96 |
97 | if (!isDeviceConnected && prevDeviceConnected) {
98 | delay(500);
99 | bleServer->startAdvertising();
100 | #ifdef DEBUG
101 | Serial.println("Start advertising");
102 | #endif
103 | prevDeviceConnected = isDeviceConnected;
104 | }
105 | }
106 |
107 | void Esp32ble::write(String x) { // Use String as parameter type
108 | if (isDeviceConnected) {
109 | bleTxCharacteristic->setValue(x); // Use String
110 | bleTxCharacteristic->notify();
111 | delay(10);
112 | }
113 |
114 | if (!isDeviceConnected && prevDeviceConnected) {
115 | delay(500);
116 | bleServer->startAdvertising();
117 | #ifdef DEBUG
118 | Serial.println("Start advertising");
119 | #endif
120 | prevDeviceConnected = isDeviceConnected;
121 | }
122 | }
123 |
124 | void Esp32ble::write(int a) {
125 | if (isDeviceConnected) {
126 | bleTxCharacteristic->setValue(a);
127 | bleTxCharacteristic->notify();
128 | delay(10);
129 | }
130 |
131 | if (!isDeviceConnected && prevDeviceConnected) {
132 | delay(500);
133 | bleServer->startAdvertising();
134 | #ifdef DEBUG
135 | Serial.println("Start advertising");
136 | #endif
137 | prevDeviceConnected = isDeviceConnected;
138 | }
139 | }
140 |
141 | void Esp32ble::write(float a) {
142 | if (isDeviceConnected) {
143 | bleTxCharacteristic->setValue(a);
144 | bleTxCharacteristic->notify();
145 | delay(10);
146 | }
147 |
148 | if (!isDeviceConnected && prevDeviceConnected) {
149 | delay(500);
150 | bleServer->startAdvertising();
151 | #ifdef DEBUG
152 | Serial.println("Start advertising");
153 | #endif
154 | prevDeviceConnected = isDeviceConnected;
155 | }
156 | }
157 |
158 | uint8_t Esp32ble::available() {
159 | return bytesremaining;
160 | }
161 |
162 | uint8_t Esp32ble::read() {
163 | if (bytesremaining > 0) {
164 | uint8_t a = rxdataBuffer[rxdatalength - bytesremaining];
165 | bytesremaining--;
166 | return a;
167 | } else {
168 | return 0;
169 | }
170 | }
171 |
172 | void Esp32ble::stop() {
173 | btStop();
174 | }
175 |
176 | // Define the global instance
177 | Esp32ble esp32ble;
178 |
179 | #endif
180 |
--------------------------------------------------------------------------------
/src/esp32BLEUtilities.h:
--------------------------------------------------------------------------------
1 | #if (defined(ESP32))
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #define UUID_Service "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
10 | #define UUID_Transmit "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
11 | #define UUID_Receive "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
12 |
13 |
14 |
15 | class Esp32ble
16 | {
17 | public:
18 | // void begin(std::string a);
19 | // void write(uint8_t a);
20 | // void write(std::string x);
21 | // void write(int a);
22 | // void write(float a);
23 | // uint8_t available();
24 | // uint8_t read();
25 | // void stop();
26 | void begin(String a);
27 | void write(uint8_t a);
28 | void write(String x);
29 | void write(int a);
30 | void write(float a);
31 | uint8_t available();
32 | uint8_t read();
33 | void stop();
34 | };
35 | extern bool BLE_status; //extern BLE_status
36 | extern Esp32ble esp32ble;
37 | #endif
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/src/motorControls.cpp:
--------------------------------------------------------------------------------
1 | #define FROM_DABBLE_LIBRARY
2 | #include "DabbleESP32.h"
3 | #include "motorControls.h"
4 |
5 | int motorControls::minPulseWidth = 544;
6 | int motorControls::maxPulseWidth = 2400;
7 | int motorControls::minAngle = 0;
8 | int motorControls::maxAngle = 180;
9 |
10 |
11 | motorControls::motorControls() : ModuleParent(CONTROLS_ID)
12 | {
13 |
14 | }
15 |
16 | void motorControls::processData()
17 | {
18 |
19 | // Serial.println("Controls:processData");
20 |
21 | functionId=getDabbleInstance().getFunctionId();
22 | if(functionId == 0x01 || functionId == 0x02)
23 | {
24 |
25 | byte1=getDabbleInstance().getArgumentData(0)[0];
26 | byte2=getDabbleInstance().getArgumentData(0)[1];
27 | #ifdef DEBUG
28 | Serial.print("byte1: ");
29 | Serial.print(byte1);
30 | Serial.print("byte2: ");
31 | Serial.println(byte2);
32 | #endif
33 | if(functionId == 0x01)
34 | {
35 |
36 | if(byte1 == 0xf0)
37 | {
38 | pwmMotor1=byte2;
39 | }
40 | else if(byte1 == 0xff)
41 | {
42 | pwmMotor1= -byte2;
43 | }
44 | else if(byte1 == 0x0f)
45 | {
46 | pwmMotor1= 0;
47 | }
48 | else if(byte1 == 0x00)
49 | {
50 | pwmMotor1= 0;
51 | }
52 |
53 | }
54 |
55 | if(functionId == 0x02)
56 | {
57 | if(byte1 == 0xf0)
58 | {
59 | pwmMotor2= byte2;
60 | }
61 | else if(byte1 == 0xff)
62 | {
63 | pwmMotor2= -byte2;
64 | }
65 | else if(byte1 == 0x0f)
66 | {
67 | pwmMotor2= 0;
68 | }
69 | else if(byte1 == 0x00)
70 | {
71 | pwmMotor2= 0;
72 | }
73 | }
74 | }
75 | else if(functionId == 0x03 || functionId == 0x04)
76 | {
77 | byte1=getDabbleInstance().getArgumentData(0)[0];
78 | #ifdef DEBUG
79 | Serial.print("byte1:");
80 | Serial.println(byte1);
81 | #endif
82 | if(functionId == 0x03)
83 | {
84 | angleServo1=byte1;
85 | }
86 | else if(functionId == 0x04)
87 | {
88 | angleServo2=byte1;
89 | }
90 | }
91 |
92 | }
93 |
94 | void motorControls::runMotor1(uint8_t pwm,uint8_t direction1,uint8_t direction2)
95 | {
96 | pinMode(direction1,OUTPUT);
97 | pinMode(direction2,OUTPUT);
98 | if(prevMotor1pin != pwm)
99 | { ledcAttachChannel(pwm, 100, 8, 0);
100 | // ledcAttachPin(pwm,0);
101 | // ledcSetup(0,100,8);
102 | }
103 | if(pwmMotor1 > 0)
104 | {
105 | digitalWrite(direction1,HIGH);
106 | digitalWrite(direction2,LOW);
107 | ledcWrite(0,pwmMotor1);
108 | }
109 | else if(pwmMotor1 < 0)
110 | {
111 | digitalWrite(direction1,LOW);
112 | digitalWrite(direction2,HIGH);
113 | ledcWrite(0,-pwmMotor1); //making negative pwm value positive
114 | }
115 | else
116 | {
117 | digitalWrite(direction1,LOW);
118 | digitalWrite(direction2,LOW);
119 | ledcWrite(0,0);
120 | }
121 | prevMotor1pin = pwm;
122 | }
123 |
124 | void motorControls::runMotor2(uint8_t pwm,uint8_t direction1,uint8_t direction2)
125 | {
126 | pinMode(direction1,OUTPUT);
127 | pinMode(direction2,OUTPUT);
128 | if(prevMotor2pin != pwm)
129 | { ledcAttachChannel(pwm, 100, 8, 1);
130 | // ledcAttachPin(pwm,1);
131 | // ledcSetup(1,100,8);
132 | }
133 | if(pwmMotor2 > 0)
134 | {
135 |
136 | /*#ifdef DEBUG
137 | Serial.print(direction1);
138 | Serial.print(" ");
139 | Serial.println(direction2);
140 | Serial.println("Clockwise");
141 | #endif*/
142 | digitalWrite(direction1,HIGH);
143 | digitalWrite(direction2,LOW);
144 | ledcWrite(1,pwmMotor2);
145 | }
146 | else if(pwmMotor2 < 0)
147 | {
148 | /*#ifdef DEBUG
149 | Serial.print(direction1);
150 | Serial.print(" ");
151 | Serial.println(direction2);
152 | Serial.println("Anti-Clockwise");*
153 | #endif*/
154 | digitalWrite(direction1,LOW);
155 | digitalWrite(direction2,HIGH);
156 | ledcWrite(1,-pwmMotor2); //making negative pwm value positive
157 | }
158 | else
159 | {
160 | digitalWrite(direction1,LOW);
161 | digitalWrite(direction2,LOW);
162 | ledcWrite(1,0);
163 | }
164 | prevMotor2pin = pwm;
165 | }
166 |
167 | void motorControls::runServo1(uint8_t pin) //Attach Servo1 to channel 3
168 | {
169 | if(prevServo1pin!=pin)
170 | { ledcAttachChannel(pin, 50, 16, 3);
171 | // ledcAttachPin(pin,3);
172 | // ledcSetup(3,50,16);
173 | }
174 | writeServoAngle(angleServo1,3);
175 | prevServo1pin = pin;
176 | }
177 |
178 | void motorControls::runServo2(uint8_t pin) //Attach Servo2 to channel 4
179 | {
180 | if(prevServo2pin!=pin)
181 | { ledcAttachChannel(pin, 50, 16, 4);
182 | // ledcAttachPin(pin,4);
183 | // ledcSetup(4,50,16);
184 | }
185 | writeServoAngle(angleServo2,4);
186 | prevServo2pin = pin;
187 | }
188 |
189 | int motorControls::angleTomicroseconds(int degree)
190 | {
191 | degree = constrain(degree,minAngle,maxAngle);
192 | return map(degree,minAngle,maxAngle,minPulseWidth,maxPulseWidth);
193 | }
194 |
195 | int motorControls::microsecondsToDuty(int pulse)
196 | {
197 | pulse=constrain(pulse,minPulseWidth,maxPulseWidth);
198 | return map(pulse,0,20000,0,65535);
199 | }
200 |
201 | void motorControls::writeServoAngle(int angle,uint8_t channel)
202 | {
203 | // Serial.print(angle);
204 | // Serial.print(" ");
205 | // Serial.println(channel);
206 | int _pulse = angleTomicroseconds(angle);
207 | int _duty = microsecondsToDuty(_pulse);
208 | ledcWrite(channel,_duty);
209 | }
--------------------------------------------------------------------------------
/src/motorControls.h:
--------------------------------------------------------------------------------
1 | #ifndef motorControls_h
2 | #define motorControls_h
3 |
4 | #include "ModuleParent.h"
5 |
6 |
7 |
8 |
9 | class motorControls : public ModuleParent
10 | {
11 |
12 | public:
13 |
14 | motorControls();
15 | //Pictobox and Arduino
16 | void runMotor1(uint8_t pwm,uint8_t direction1,uint8_t direction2);
17 | void runMotor2(uint8_t pwm,uint8_t direction1,uint8_t direction2);
18 | void runServo1(uint8_t pin);
19 | void runServo2(uint8_t pin);
20 |
21 | public:
22 | byte byte1;
23 | byte byte2;
24 | uint8_t angleServo1=0;
25 | uint8_t angleServo2=0;
26 | int pwmMotor1=0;
27 | int pwmMotor2=0;
28 | byte functionId;
29 |
30 |
31 |
32 | private:
33 | void processData();
34 | uint8_t prevMotor1pin = 0;
35 | uint8_t prevMotor2pin = 0;
36 | uint8_t prevServo1pin = 0;
37 | uint8_t prevServo2pin = 0;
38 | static int minPulseWidth;
39 | static int maxPulseWidth;
40 | static int minAngle;
41 | static int maxAngle;
42 | int angleTomicroseconds(int degree);
43 | int microsecondsToDuty(int pulse);
44 | void writeServoAngle(int angle,uint8_t channel);
45 | };
46 |
47 |
48 | //void runMotor1(int a);
49 | //void runMotor2(int b);
50 |
51 |
52 | extern motorControls Controls;
53 |
54 | #endif
--------------------------------------------------------------------------------