-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
106 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
esp32-heart-pair-handler-device-client/blemodeupdatercallbacks.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef MODE_UPDATER_H | ||
#define MODE_UPDATER_H | ||
|
||
#include <BLEDevice.h> | ||
#include <BLEUtils.h> | ||
#include <BLEServer.h> | ||
#include <Arduino.h> | ||
|
||
class BLEModeUpdaterCallbacks: public BLECharacteristicCallbacks { | ||
private: | ||
uint8_t* mode_ref; | ||
uint8_t tmp[1]; | ||
public: | ||
BLEModeUpdaterCallbacks(uint8_t* val_ref) { | ||
mode_ref = val_ref; | ||
} | ||
|
||
void onRead(BLECharacteristic* pCharacteristic) { | ||
pCharacteristic->setValue(tmp, 1); | ||
} | ||
|
||
void onWrite(BLECharacteristic* pCharacteristic) { | ||
*mode_ref = *(pCharacteristic->getData()); | ||
pCharacteristic->setValue(tmp, 1); | ||
} | ||
}; | ||
|
||
BLECharacteristic * create_mode_characteristic(BLEService *pService, std::string uuid, uint8_t* opmode) { | ||
BLECharacteristic *pCharacteristic = pService->createCharacteristic( | ||
uuid, | ||
BLECharacteristic::PROPERTY_READ | | ||
BLECharacteristic::PROPERTY_WRITE | ||
); | ||
uint8_t tmp[1]; | ||
tmp[0] = *opmode; | ||
pCharacteristic->setValue(tmp, 1); | ||
pCharacteristic->setCallbacks(new BLEModeUpdaterCallbacks(opmode)); | ||
return pCharacteristic; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef MODE_H | ||
#define MODE_H | ||
|
||
#define NORMAL_MODE 0 | ||
#define LAMP_MODE 1 | ||
#define LAMP_MODE_NO_INDICATORS 2 | ||
#define CONFIGURE_MODE 3 | ||
#define PROM_MODE 4 | ||
#define OFF_MODE 5 | ||
|
||
uint8_t opmode = NORMAL_MODE; | ||
|
||
|
||
#endif |