Skip to content

Commit

Permalink
Merge pull request #5 from sivar2311/Version-1.0.0
Browse files Browse the repository at this point in the history
Codechanges for Version 1.0.0
  • Loading branch information
sivar2311 authored Mar 27, 2022
2 parents 66b7b79 + e33967c commit b636a2d
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 621 deletions.
2 changes: 1 addition & 1 deletion doc/ble_advertising.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
| Name: | BLE advertisement flags | length of the<br>next field | type of the<br>next field | Manufacturer<br>data |
|----------:|:-----------------------:|:---------------------------:|:-----------------------------:|:--------------------:|
| *Length*: | 3 Bytes | 1 Byte | 1 Byte | 20 Bytes |
| *Value*: | `0x02` `0x01` `0x06` | `0x15` | `0xFF`<br>(manufacturer data) | [Data](#data) |
| *Value*: | `0x02` `0x01` `0x06` | `0x15` | `0xFF`<br>(manufacturer data) | [Data](#data) |
| | **fixed** | **fixed**<br> | **fixed** | *variable* |

**Note:**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
NVSRemoteControlStorage storage;
BLERemoteControlReceiver receiver;

#define COMMAND_LED_ON 0x0001
#define COMMAND_LED_OFF 0x0002
const uint32_t COMMAND_LED_ON = 0x0001;
const uint32_t COMMAND_LED_OFF = 0x0002;

#define GPIO_LED 16
#define GPIO_SYNC_BUTTON 34
#define PRESSED HIGH
const int GPIO_LED = 16;
const int GPIO_SYNC_BUTTON = 34;

const bool PRESSED = HIGH;

const uint32_t SHARED_SYNCHRONIZATION_PIN = 123456;

void turn_on_led() {
digitalWrite(GPIO_LED, HIGH);
Expand All @@ -31,13 +34,10 @@ void handle_sync_button() {
bool sync_button = digitalRead(GPIO_SYNC_BUTTON);

if (sync_button == PRESSED) {
if (receiver.is_synchronizing()) {
receiver.stop_synchronizing();
} else {
receiver.start_synchronizing();
}
delay(150); // simple debounce
receiver.start_synchronizing(10);
}

delay(150); // simple button debounce
}

void setup_led() {
Expand All @@ -48,18 +48,19 @@ void setup_button() {
pinMode(GPIO_SYNC_BUTTON, INPUT);
}

void setup_receiver() {
void setup_storage() {
storage.begin("ble_remote");
storage.load();
}

void setup_receiver() {
receiver.on_command(handle_command);
receiver.set_sync_pin(123456);
receiver.begin(&storage);
receiver.begin(&storage, SHARED_SYNCHRONIZATION_PIN);
}

void setup() {
setup_led();
setup_button();
setup_storage();
setup_receiver();
}

Expand Down
68 changes: 0 additions & 68 deletions examples/Receiver/SingleReceiver/SingleReceiver.ino

This file was deleted.

56 changes: 32 additions & 24 deletions examples/Sender/Sender.ino
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
#include <Arduino.h>

#include <BLERemoteControlSender.h>
#include <NVSRemoteControlStorage.h>

NVSRemoteControlStorage storage;
BLERemoteControlSender sender;
BLERemoteControlSender sender;

#define GPIO_BUTTON_ON 34
#define GPIO_BUTTON_OFF 35
#define GPIO_BUTTON_SYNC 36
const int GPIO_BUTTON_ON = 34;
const int GPIO_BUTTON_OFF = 35;
const int GPIO_BUTTON_SYNC = 36;

#define PRESSED HIGH
const bool PRESSED = HIGH;

#define COMMAND_LED_ON 0x0001
#define COMMAND_LED_OFF 0x0002
const uint32_t COMMAND_LED_ON = 0x0001;
const uint32_t COMMAND_LED_OFF = 0x0002;

const uint32_t UNIQUE_REMOTE_ID = 0xBEEF;
const int SHARED_SYNCHRONIZATION_PIN = 123456;
const int SYNCHRONIZATION_TIMEOUT = 10;

void setup_storage() {
storage.begin("ble_remote");
if (!storage.load()) {
storage.add(new ble_remote_control_info_t(0x0001,true));
storage.save();
void handle_buttons() {
bool button_on = digitalRead(GPIO_BUTTON_ON);
bool button_off = digitalRead(GPIO_BUTTON_OFF);
bool button_sync = digitalRead(GPIO_BUTTON_SYNC);

if (button_on == PRESSED) sender.send_command(COMMAND_LED_ON);
if (button_off == PRESSED) sender.send_command(COMMAND_LED_OFF);
if (button_sync == PRESSED) sender.start_synchronizing(SYNCHRONIZATION_TIMEOUT);

bool a_button_was_pressed = (button_on == PRESSED || button_off == PRESSED || button_sync == PRESSED);
if (a_button_was_pressed) {
delay(150); // simple "debounce"
}
}

Expand All @@ -30,23 +39,22 @@ void setup_buttons() {
pinMode(GPIO_BUTTON_SYNC, INPUT);
}

void handle_buttons() {
bool button_on = digitalRead(GPIO_BUTTON_ON);
bool button_off = digitalRead(GPIO_BUTTON_OFF);
bool button_sync = digitalRead(GPIO_BUTTON_SYNC);

if (button_on == PRESSED) sender.send_command(COMMAND_LED_ON, storage[0]);
if (button_off == PRESSED) sender.send_command(COMMAND_LED_OFF, storage[0]);
if (button_sync == PRESSED) sender.start_sync(*(storage[0]));
void setup_storage() {
storage.begin("ble_remote");

if (button_on == PRESSED || button_off == PRESSED || button_sync == PRESSED) {
delay(150); // simple "debounce"
if (storage.exist(UNIQUE_REMOTE_ID) == false) {
storage.save(new ble_remote_control_info_t(UNIQUE_REMOTE_ID, true));
}
}

void setup_sender() {
sender.begin(UNIQUE_REMOTE_ID, &storage, SHARED_SYNCHRONIZATION_PIN);
}

void setup() {
setup_buttons();
sender.begin();
setup_storage();
setup_sender();
}

void loop() {
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"maintainer": true
}
],
"version": "0.2.1",
"version": "1.0.0",
"frameworks": "arduino",
"platforms": [
"espressif32"
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ESP32-BLE-RemoteControl
version=0.2.1
version=1.0.0
author=Sivar2311 <[email protected]>
maintainer=Sivar2311 <[email protected]>
sentence=This library allows you to send and receive simple command messages via Bluetooth Low Energy.
Expand Down
Loading

0 comments on commit b636a2d

Please sign in to comment.