Skip to content
Snippets Groups Projects
Commit 363b3bc2 authored by Denis Bobrovskiy's avatar Denis Bobrovskiy
Browse files

Modified the code so ble data only sent when a game is running in app

parent d0fc2dcc
Branches CrocsDevice
No related tags found
No related merge requests found
.pio/build/ .pio/build/
.vscode/ .vscode/
platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
; upload_port =
...@@ -180,8 +180,10 @@ void _robADXL375_dancingDecode() // Decodes and sends the d ...@@ -180,8 +180,10 @@ void _robADXL375_dancingDecode() // Decodes and sends the d
} }
//SEND BLUETOOTH DATA FOR DANCE DIRECTION //SEND BLUETOOTH DATA FOR DANCE DIRECTION
if(gameToggle==true){
crocDirectionChar->setValue(&sendDirection,1); crocDirectionChar->setValue(&sendDirection,1);
crocDirectionChar->notify(); crocDirectionChar->notify();
}
} }
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
BLECharacteristic *jumpCounterChar; BLECharacteristic *jumpCounterChar;
BLECharacteristic *crocDirectionChar; BLECharacteristic *crocDirectionChar;
BLECharacteristic *dancingGameToggle;
bool gameToggle = 0;
void _denisBluetooth_setup() void _denisBluetooth_setup()
{ {
...@@ -30,10 +33,18 @@ void _denisBluetooth_setup() ...@@ -30,10 +33,18 @@ void _denisBluetooth_setup()
BLECharacteristic::PROPERTY_NOTIFY | BLECharacteristic::PROPERTY_NOTIFY |
BLECharacteristic::PROPERTY_INDICATE BLECharacteristic::PROPERTY_INDICATE
); );
dancingGameToggle = mainService->createCharacteristic(
CROC_DANCING_GAME_TOGGLE_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE |
BLECharacteristic::PROPERTY_NOTIFY |
BLECharacteristic::PROPERTY_INDICATE
);
jumpCounterChar->addDescriptor(new BLE2902()); jumpCounterChar->addDescriptor(new BLE2902());
crocDirectionChar->addDescriptor(new BLE2902()); crocDirectionChar->addDescriptor(new BLE2902());
dancingGameToggle->addDescriptor(new BLE2902());
mainService->start(); mainService->start();
...@@ -50,3 +61,20 @@ void _denisBluetooth_setup() ...@@ -50,3 +61,20 @@ void _denisBluetooth_setup()
Serial.println("GATT server set up"); Serial.println("GATT server set up");
#endif #endif
} }
void gameToggleThread(void *parameter){
Serial.println("Started game toggle thread");
for(;;){
Serial.println("Loopin game toggle tjread");
uint8_t *data;
data = dancingGameToggle->getData();
if(*data==1){
gameToggle = true;
}else{
gameToggle = false;
}
Serial.println(*data);
Serial.println(gameToggle);
delay(200);
}
}
...@@ -18,9 +18,14 @@ ...@@ -18,9 +18,14 @@
#define CROC_JUMP_DETECTOR_UUID "f4c00485-1f79-4ce7-90ed-5e4740adc8c2" #define CROC_JUMP_DETECTOR_UUID "f4c00485-1f79-4ce7-90ed-5e4740adc8c2"
#define CROC_DIRECTION_DETECTOR_UUID "cff7b61a-66fc-407b-b02c-7887c20d9382" #define CROC_DIRECTION_DETECTOR_UUID "cff7b61a-66fc-407b-b02c-7887c20d9382"
#define CROC_DANCING_GAME_TOGGLE_UUID "64016a6d-987d-4c7c-8ead-5a818c1a4bf9"
void _denisBluetooth_setup(); void _denisBluetooth_setup();
extern BLECharacteristic *jumpCounterChar; extern BLECharacteristic *jumpCounterChar;
extern BLECharacteristic *crocDirectionChar; extern BLECharacteristic *crocDirectionChar;
extern BLECharacteristic *dancingGameToggle;
void gameToggleThread(void *parameter);
extern bool gameToggle;
#endif /* DENISBLUETOOTH_HPP */ #endif /* DENISBLUETOOTH_HPP */
#include "DancingCrocs.hpp" #include "DancingCrocs.hpp"
#include "DenisBluetooth.hpp" #include "DenisBluetooth.hpp"
SemaphoreHandle_t gameToggleMux;
void setup() void setup()
{ {
Serial.begin(115200); // Initiate serial communication for printing the results on the Serial monitor Serial.begin(115200); // Initiate serial communication for printing the results on the Serial monitor
Serial.println("Running setup"); Serial.println("Running setup");
Serial.println("Running setup");
// gameToggleMux = xSemaphoreCreateMutex();
Wire.begin(); // Initiate the Wire library Wire.begin(); // Initiate the Wire library
_denisBluetooth_setup(); _denisBluetooth_setup();
_robADXL375_setup(); TaskHandle_t gameToggleThreadHandle;
xTaskCreatePinnedToCore(
gameToggleThread, /* Function to implement the task */
"Game toggle thread", /* Name of the task */
10000, /* Stack size in words */
NULL, /* Task input parameter */
0, /* Priority of the task */
&gameToggleThreadHandle, /* Task handle. */
0); /* Core where the task should run */
//_robADXL375_setup();
} }
void loop() void loop()
{ {
_robADXL375_reading(); //_robADXL375_reading();
// Serial.println("Running main loop"); Serial.println("Running main loop");
// uint8_t value = 12; uint8_t value = 12;
// uint8_t value2 = 15; uint8_t value2 = 15;
// crocDirectionChar->setValue(&value,1); if(gameToggle){
// crocDirectionChar->notify(); crocDirectionChar->setValue(&value,1);
// jumpCounterChar->setValue(&value2,1); crocDirectionChar->notify();
// jumpCounterChar->notify(); jumpCounterChar->setValue(&value2,1);
// delay(1000); jumpCounterChar->notify();
}
delay(1000);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment