Skip to content

Commit

Permalink
coding style update for BLE
Browse files Browse the repository at this point in the history
  • Loading branch information
M-ichae-l committed Feb 1, 2023
1 parent a664e0d commit 545c333
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void setup() {
battChar.setCCCDCallback(notifCB);

battService.addCharacteristic(battChar);

BLE.init();
BLE.configAdvert()->setAdvData(advdata);
BLE.configAdvert()->setScanRspData(scandata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,51 @@ BLEAdvertData advdata;

// We need to define a HID gamepad report descriptor to replace the default keyboard and mouse descriptor
uint8_t hid_gamepad_report_descriptor[] = {
TUD_HID_REPORT_DESC_GAMEPAD ( HID_REPORT_ID(1) )
TUD_HID_REPORT_DESC_GAMEPAD(HID_REPORT_ID(1))
};

void setup() {
Serial.begin(115200);
advdata.addFlags();
advdata.addCompleteName("AMEBA_BLE_HID");
advdata.addAppearance(GAP_GATT_APPEARANCE_GAMEPAD);
advdata.addCompleteServices(BLEUUID(HID_SERVICE_UUID));
Serial.begin(115200);
advdata.addFlags();
advdata.addCompleteName("AMEBA_BLE_HID");
advdata.addAppearance(GAP_GATT_APPEARANCE_GAMEPAD);
advdata.addCompleteServices(BLEUUID(HID_SERVICE_UUID));

BLEHIDDev.init();
// Replace the default HID report descriptor, and provide the HID gamepad report descriptor with the corresponding report ID
BLEHIDDev.setReportMap(hid_gamepad_report_descriptor, sizeof(hid_gamepad_report_descriptor));
padDev.setReportID(1);
BLEHIDDev.init();
// Replace the default HID report descriptor, and provide the HID gamepad report descriptor with the corresponding report ID
BLEHIDDev.setReportMap(hid_gamepad_report_descriptor, sizeof(hid_gamepad_report_descriptor));
padDev.setReportID(1);

BLE.init();
BLE.configAdvert()->setAdvData(advdata);
BLE.setDeviceName("AMEBA_BLE_HID");
BLE.setDeviceAppearance(GAP_GATT_APPEARANCE_GAMEPAD);
BLE.configSecurity()->setPairable(true);
BLE.configSecurity()->setAuthFlags(GAP_AUTHEN_BIT_BONDING_FLAG);
BLE.configServer(3);
BLE.addService(BLEHIDDev.hidService());
BLE.addService(BLEHIDDev.battService());
BLE.addService(BLEHIDDev.devInfoService());
BLE.init();
BLE.configAdvert()->setAdvData(advdata);
BLE.setDeviceName("AMEBA_BLE_HID");
BLE.setDeviceAppearance(GAP_GATT_APPEARANCE_GAMEPAD);
BLE.configSecurity()->setPairable(true);
BLE.configSecurity()->setAuthFlags(GAP_AUTHEN_BIT_BONDING_FLAG);
BLE.configServer(3);
BLE.addService(BLEHIDDev.hidService());
BLE.addService(BLEHIDDev.battService());
BLE.addService(BLEHIDDev.devInfoService());

pinMode(ENABLE_PIN, INPUT);
pinMode(ENABLE_PIN, INPUT);

BLE.beginPeripheral();
BLE.beginPeripheral();
}

void loop() {
if (BLE.connected() && digitalRead(ENABLE_PIN)) {
Serial.println("Moving joysticks and pressing buttons");
// Press buttons 5 and 16. Move all axes to max. Set DPAD (hat 1) to down right
padDev.gamepadReport( (GAMEPAD_BUTTON_4 | GAMEPAD_BUTTON_15) , GAMEPAD_HAT_DOWN_RIGHT, 32767, 32767, 32767, 32767, 32767, 32767);
delay(1000);
// Release button 5. Move all axes to min. Set DPAD (hat 1) to centred
padDev.gamepadReport( (GAMEPAD_BUTTON_15), GAMEPAD_HAT_CENTERED, -32767, -32767, -32767, -32767, -32767, -32767);
delay(1000);
// Release all buttons and set all axes to centered
padDev.buttonReleaseAll();
padDev.setAxes(0, 0, 0, 0, 0, 0);
delay(1000);
} else {
delay(500);
}
}
if (BLE.connected() && digitalRead(ENABLE_PIN)) {
Serial.println("Moving joysticks and pressing buttons");
// Press buttons 5 and 16. Move all axes to max. Set DPAD (hat 1) to down right
padDev.gamepadReport( (GAMEPAD_BUTTON_4 | GAMEPAD_BUTTON_15) , GAMEPAD_HAT_DOWN_RIGHT, 32767, 32767, 32767, 32767, 32767, 32767);
delay(1000);
// Release button 5. Move all axes to min. Set DPAD (hat 1) to centred
padDev.gamepadReport( (GAMEPAD_BUTTON_15), GAMEPAD_HAT_CENTERED, -32767, -32767, -32767, -32767, -32767, -32767);
delay(1000);
// Release all buttons and set all axes to centered
padDev.buttonReleaseAll();
padDev.setAxes(0, 0, 0, 0, 0, 0);
delay(1000);
} else {
delay(500);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,45 @@ BLEAdvertData advdata;
#define ENABLE_PIN 8

void setup() {
Serial.begin(115200);
advdata.addFlags();
advdata.addCompleteName("AMEBA_BLE_HID");
advdata.addAppearance(GAP_GATT_APPEARANCE_HUMAN_INTERFACE_DEVICE);
advdata.addCompleteServices(BLEUUID(HID_SERVICE_UUID));

BLEHIDDev.init();

BLE.init();
BLE.configAdvert()->setAdvData(advdata);
BLE.setDeviceName("AMEBA_BLE_HID");
BLE.setDeviceAppearance(GAP_GATT_APPEARANCE_HUMAN_INTERFACE_DEVICE);
BLE.configSecurity()->setPairable(true);
BLE.configSecurity()->setAuthFlags(GAP_AUTHEN_BIT_BONDING_FLAG);
BLE.configServer(3);
BLE.addService(BLEHIDDev.hidService());
BLE.addService(BLEHIDDev.battService());
BLE.addService(BLEHIDDev.devInfoService());

pinMode(ENABLE_PIN, INPUT);

BLE.beginPeripheral();
Serial.begin(115200);
advdata.addFlags();
advdata.addCompleteName("AMEBA_BLE_HID");
advdata.addAppearance(GAP_GATT_APPEARANCE_HUMAN_INTERFACE_DEVICE);
advdata.addCompleteServices(BLEUUID(HID_SERVICE_UUID));

BLEHIDDev.init();

BLE.init();
BLE.configAdvert()->setAdvData(advdata);
BLE.setDeviceName("AMEBA_BLE_HID");
BLE.setDeviceAppearance(GAP_GATT_APPEARANCE_HUMAN_INTERFACE_DEVICE);
BLE.configSecurity()->setPairable(true);
BLE.configSecurity()->setAuthFlags(GAP_AUTHEN_BIT_BONDING_FLAG);
BLE.configServer(3);
BLE.addService(BLEHIDDev.hidService());
BLE.addService(BLEHIDDev.battService());
BLE.addService(BLEHIDDev.devInfoService());

pinMode(ENABLE_PIN, INPUT);

BLE.beginPeripheral();
}

void loop() {
if (BLE.connected() && digitalRead(ENABLE_PIN)) {
Serial.println("Sending keystrokes");
keyboardDev.keyReleaseAll();
delay(500);
keyboardDev.keySequence("Hello World !");
delay(1000);
keyboardDev.keyPress(HID_KEY_BACKSPACE);
delay(2000);
keyboardDev.keyReleaseAll();
delay(500);
keyboardDev.consumerPress(HID_USAGE_CONSUMER_MUTE);
delay(500);
if (BLE.connected() && digitalRead(ENABLE_PIN)) {
Serial.println("Sending keystrokes");
keyboardDev.keyReleaseAll();
delay(500);
keyboardDev.keySequence("Hello World !");
delay(1000);
keyboardDev.keyPress(HID_KEY_BACKSPACE);
delay(2000);
keyboardDev.keyReleaseAll();
delay(500);
keyboardDev.consumerPress(HID_USAGE_CONSUMER_MUTE);
delay(500);
keyboardDev.consumerRelease();
} else {
delay(500);
}
}
} else {
delay(500);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,58 +14,58 @@ BLEAdvertData advdata;
#define ENABLE_PIN 8

void setup() {
Serial.begin(115200);
advdata.addFlags();
advdata.addCompleteName("AMEBA_BLE_HID");
advdata.addAppearance(GAP_GATT_APPEARANCE_HUMAN_INTERFACE_DEVICE);
advdata.addCompleteServices(BLEUUID(HID_SERVICE_UUID));
Serial.begin(115200);
advdata.addFlags();
advdata.addCompleteName("AMEBA_BLE_HID");
advdata.addAppearance(GAP_GATT_APPEARANCE_HUMAN_INTERFACE_DEVICE);
advdata.addCompleteServices(BLEUUID(HID_SERVICE_UUID));

BLEHIDDev.init();
BLEHIDDev.init();

BLE.init();
BLE.configAdvert()->setAdvData(advdata);
BLE.setDeviceName("AMEBA_BLE_HID");
BLE.setDeviceAppearance(GAP_GATT_APPEARANCE_HUMAN_INTERFACE_DEVICE);
BLE.configSecurity()->setPairable(true);
BLE.configSecurity()->setAuthFlags(GAP_AUTHEN_BIT_BONDING_FLAG);
BLE.configServer(3);
BLE.addService(BLEHIDDev.hidService());
BLE.addService(BLEHIDDev.battService());
BLE.addService(BLEHIDDev.devInfoService());
BLE.init();
BLE.configAdvert()->setAdvData(advdata);
BLE.setDeviceName("AMEBA_BLE_HID");
BLE.setDeviceAppearance(GAP_GATT_APPEARANCE_HUMAN_INTERFACE_DEVICE);
BLE.configSecurity()->setPairable(true);
BLE.configSecurity()->setAuthFlags(GAP_AUTHEN_BIT_BONDING_FLAG);
BLE.configServer(3);
BLE.addService(BLEHIDDev.hidService());
BLE.addService(BLEHIDDev.battService());
BLE.addService(BLEHIDDev.devInfoService());

pinMode(ENABLE_PIN, INPUT);
pinMode(ENABLE_PIN, INPUT);

BLE.beginPeripheral();
BLE.beginPeripheral();
}

void loop() {
if (BLE.connected() && digitalRead(ENABLE_PIN)) {
Serial.println("Moving mouse");
// Move cursor in a square
mouseDev.mouseMove(0, 50);
delay(500);
// Right click
mouseDev.mousePress(MOUSE_BUTTON_RIGHT);
delay(100);
mouseDev.mouseRelease(MOUSE_BUTTON_RIGHT);
delay(100);
mouseDev.mouseMove(-50, 0);
delay(500);
mouseDev.mouseMove(0, -50);
delay(500);
// Left click
mouseDev.mousePress(MOUSE_BUTTON_LEFT);
delay(100);
mouseDev.mouseRelease(MOUSE_BUTTON_LEFT);
delay(100);
mouseDev.mouseMove(50, 0);
delay(500);
// Scroll up and down
mouseDev.mouseScroll(5);
delay(500);
mouseDev.mouseScroll(-5);
delay(500);
} else {
delay(500);
}
}
if (BLE.connected() && digitalRead(ENABLE_PIN)) {
Serial.println("Moving mouse");
// Move cursor in a square
mouseDev.mouseMove(0, 50);
delay(500);
// Right click
mouseDev.mousePress(MOUSE_BUTTON_RIGHT);
delay(100);
mouseDev.mouseRelease(MOUSE_BUTTON_RIGHT);
delay(100);
mouseDev.mouseMove(-50, 0);
delay(500);
mouseDev.mouseMove(0, -50);
delay(500);
// Left click
mouseDev.mousePress(MOUSE_BUTTON_LEFT);
delay(100);
mouseDev.mouseRelease(MOUSE_BUTTON_LEFT);
delay(100);
mouseDev.mouseMove(50, 0);
delay(500);
// Scroll up and down
mouseDev.mouseScroll(5);
delay(500);
mouseDev.mouseScroll(-5);
delay(500);
} else {
delay(500);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void scanFunction(T_LE_CB_DATA* p_data) {
Serial.print("Scan Data ");
Serial.println(++dataCount);
BLE.configScan()->printScanInfo(p_data);
BLE.configConnection()->disconnect();

foundDevice.parseScanInfo(p_data);
if (foundDevice.hasName()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ void setup() {
BLE.configAdvert()->updateAdvertParams();
delay(100);
BLE.configAdvert()->startAdv();

}

void loop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void writeCB (BLECharacteristic* chr, uint8_t connID) {
uint8_t command[datalen];
chr->getData(command, datalen);
if (command[1] == 'C') {
// print hax
// print hex
printf("Color command R = %x G = %x B = %x \n", command[2], command[3], command[4]);
// print decimal
//printf("Color command R = %d G = %d B = %d \n", command[2], command[3], command[4]);
Expand Down
9 changes: 0 additions & 9 deletions Arduino_package/hardware/libraries/BLE/src/BLEAddr.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
#include "BLEAddr.h"

#ifdef __cplusplus
extern "C" {
#endif


#ifdef __cplusplus
}
#endif

static uint8_t ctoi(char c) {
if((c >= 'A') && (c <= 'F')) {
return (c - 'A' + 0x0A);
Expand Down
9 changes: 0 additions & 9 deletions Arduino_package/hardware/libraries/BLE/src/BLEAddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@

#include <Arduino.h>

#ifdef __cplusplus
extern "C" {
#endif


#ifdef __cplusplus
}
#endif

class BLEAddr {
public:
BLEAddr();
Expand Down
2 changes: 1 addition & 1 deletion Arduino_package/hardware/libraries/BLE/src/BLEConnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BLEConnect {

void setScanInterval(uint16_t scanInt_ms);
void setScanWindow(uint16_t scanWindow_ms);

void setConnInterval(uint16_t min_ms, uint16_t max_ms);
void setConnLatency(uint16_t latency);
void setConnTimeout(uint16_t timeout_ms);
Expand Down

0 comments on commit 545c333

Please sign in to comment.