first relyable
This commit is contained in:
parent
7ccdac4f3e
commit
6a3feb9835
|
@ -12,5 +12,6 @@
|
||||||
platform = espressif32
|
platform = espressif32
|
||||||
board = odroid_esp32
|
board = odroid_esp32
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
upload_speed = 460800
|
||||||
lib_deps =
|
lib_deps =
|
||||||
ESP32 BLE Arduino
|
ESP32 BLE Arduino
|
85
src/main.cpp
85
src/main.cpp
|
@ -39,24 +39,32 @@ uint8_t txValue = 0;
|
||||||
|
|
||||||
#define BUTTON_A_PIN 32
|
#define BUTTON_A_PIN 32
|
||||||
#define BUTTON_B_PIN 33
|
#define BUTTON_B_PIN 33
|
||||||
|
#define BUTTON_MENU 13
|
||||||
|
#define BUTTON_SELECT 27
|
||||||
|
#define BUTTON_VOLUME 0
|
||||||
|
#define BUTTON_START 39
|
||||||
|
#define BUTTON_JOY_Y 35
|
||||||
|
#define BUTTON_JOY_X 34
|
||||||
|
|
||||||
uint8_t params[] = { 0x66, 0x11, 0x20, 0x00, 0x64, 0x30, 0x3C, 0x2A, 0x14, 0xD9, 0x00, 0x32, 0x00, 0x64, 0x00, 0x2D, 0x00, 0xCC, 0x10, 0x64, 0x32, 0xFC, 0x53, 0x98, 0x08, 0x64, 0x00, 0x41, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x78 };
|
#define BUTTNO_PAUSE 100
|
||||||
|
|
||||||
|
uint8_t params[] = { 0x66, 0x11, 0x20, 0x09, 0x64, 0x30, 0x3C, 0x2A, 0x14, 0xD9, 0x00, 0x32, 0x00, 0x64, 0x00, 0x2D, 0x00, 0xCC, 0x10, 0x64, 0x32, 0xFC, 0x53, 0x98, 0x08, 0x64, 0x00, 0x41, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x78 };
|
||||||
byte params_request[] = { 0x66, 0x11, 0x00, 0x77 };
|
byte params_request[] = { 0x66, 0x11, 0x00, 0x77 };
|
||||||
bool send_params = false;
|
bool send_params = false;
|
||||||
|
|
||||||
// uint8_t status[] = { 0x66, 0x41, 0x05, 0x32, 0x32, 0x00, 0x00, 0x02 , 0x02};
|
uint8_t status[] = { 0x66, 0x41, 0x05, 0x05, 0x00, 0x00, 0xFF, 0x01, 0x00 };
|
||||||
uint8_t status[] = { 0x66, 0x41, 0x05, 0x05, 0x00, 0xFF, 0xFF, 0x00, 0xAF, 0xFC };
|
|
||||||
byte status_request[] = { 0x66, 0x41, 0x02 };
|
byte status_request[] = { 0x66, 0x41, 0x02 };
|
||||||
bool send_status = false;
|
bool send_status = false;
|
||||||
|
|
||||||
|
int btn_pressed = millis();
|
||||||
|
|
||||||
void write_status_checksum() {
|
void write_status_checksum() {
|
||||||
int suma = 0;
|
int suma = 0;
|
||||||
for (int i = 0; i < sizeof(status) - 1; i++) {
|
for (int i = 0; i < sizeof(status) - 1; i++) {
|
||||||
suma += status[i];
|
suma += status[i];
|
||||||
}
|
}
|
||||||
int tmp_suma = (suma / 256) * 256;
|
int tmp_suma = (suma / 256) * 256;
|
||||||
status[8] = suma - tmp_suma;
|
status[sizeof(status) - 1] = suma - tmp_suma;
|
||||||
status[8] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyServerCallbacks: public BLEServerCallbacks {
|
class MyServerCallbacks: public BLEServerCallbacks {
|
||||||
|
@ -96,12 +104,12 @@ class MyCallbacks: public BLECharacteristicCallbacks {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
pinMode(BUTTON_A_PIN, INPUT_PULLUP);
|
pinMode(BUTTON_A_PIN, INPUT_PULLUP);
|
||||||
pinMode(BUTTON_B_PIN, INPUT_PULLUP);
|
pinMode(BUTTON_B_PIN, INPUT_PULLUP);
|
||||||
|
pinMode(BUTTON_START, INPUT_PULLUP);
|
||||||
|
|
||||||
// Create the BLE Device
|
// Create the BLE Device
|
||||||
BLEDevice::init("RAYVOLT DUMMY");
|
BLEDevice::init("RAYVOLT DUMMY");
|
||||||
|
@ -138,46 +146,79 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (!digitalRead(BUTTON_A_PIN)) {
|
if ( (!digitalRead(BUTTON_A_PIN)) && (millis() - btn_pressed > BUTTNO_PAUSE) ) {
|
||||||
Serial.println("Button A");
|
if ( status[7] == 0x00 ) {
|
||||||
if (status[3] == 0xFF) {
|
status[7] = 0x01;
|
||||||
|
}
|
||||||
|
else if ( status[7] == 0x01 ) {
|
||||||
|
status[7] = 0x02;
|
||||||
|
}
|
||||||
|
else if ( status[7] == 0x02 ) {
|
||||||
|
status[7] = 0x04;
|
||||||
|
}
|
||||||
|
else if ( status[7] == 0x04 ) {
|
||||||
|
status[7] = 0x08;
|
||||||
|
}
|
||||||
|
else if ( status[7] == 0x08 ) {
|
||||||
|
status[7] = 0x00;
|
||||||
|
}
|
||||||
|
btn_pressed = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( (!digitalRead(BUTTON_B_PIN)) && (millis() - btn_pressed > BUTTNO_PAUSE) ) {
|
||||||
|
if ( status[5] == 0xFF ) {
|
||||||
|
status[5] = 0x00;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
status[5] += 1;
|
||||||
|
}
|
||||||
|
Serial.print("RMP1: ");
|
||||||
|
Serial.print(status[5]);
|
||||||
|
Serial.println("");
|
||||||
|
btn_pressed = millis();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( (!digitalRead(BUTTON_START)) && (millis() - btn_pressed > BUTTNO_PAUSE) ) {
|
||||||
|
Serial.println("Start pressed");
|
||||||
|
if ( status[3] == 0x05 ) {
|
||||||
status[3] = 0x00;
|
status[3] = 0x00;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
status[3] += 1;
|
status[3] += 1;
|
||||||
}
|
}
|
||||||
|
btn_pressed = millis();
|
||||||
}
|
}
|
||||||
if (!digitalRead(BUTTON_B_PIN)) {
|
|
||||||
Serial.println("Button B");
|
|
||||||
if (status[3] == 0x00) {
|
|
||||||
status[3] = 0xFF;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
status[3] -= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (deviceConnected) {
|
if (deviceConnected) {
|
||||||
if (send_params) {
|
if (send_params) {
|
||||||
Serial.print("sending: ");
|
Serial.println("sending params");
|
||||||
|
Serial.print(sizeof(params), DEC);
|
||||||
|
/*
|
||||||
for (int i = 0; i < sizeof(params); i++) {
|
for (int i = 0; i < sizeof(params); i++) {
|
||||||
Serial.print(params[i], HEX);
|
Serial.print(params[i], HEX);
|
||||||
|
Serial.print(" ");
|
||||||
pRTxCharacteristic->setValue(¶ms[i], 1);
|
pRTxCharacteristic->setValue(¶ms[i], 1);
|
||||||
pRTxCharacteristic->notify();
|
pRTxCharacteristic->notify();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
pRTxCharacteristic->setValue(params, sizeof(params));
|
||||||
|
pRTxCharacteristic->notify();
|
||||||
send_params = false;
|
send_params = false;
|
||||||
Serial.println("");
|
|
||||||
}
|
}
|
||||||
else if (send_status) {
|
else if (send_status) {
|
||||||
write_status_checksum();
|
write_status_checksum();
|
||||||
Serial.print("sending: ");
|
Serial.println("sending status");
|
||||||
|
/*
|
||||||
for (int i = 0; i < sizeof(status); i++) {
|
for (int i = 0; i < sizeof(status); i++) {
|
||||||
Serial.print(status[i], HEX);
|
Serial.print(status[i], HEX);
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
pRTxCharacteristic->setValue(&status[i], 1);
|
pRTxCharacteristic->setValue(&status[i], 1);
|
||||||
pRTxCharacteristic->notify();
|
pRTxCharacteristic->notify();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
pRTxCharacteristic->setValue(status, sizeof(status));
|
||||||
|
pRTxCharacteristic->notify();
|
||||||
send_status = false;
|
send_status = false;
|
||||||
Serial.println("");
|
|
||||||
}
|
}
|
||||||
delay(10); // bluetooth stack will go into congestion, if too many packets are sent
|
delay(10); // bluetooth stack will go into congestion, if too many packets are sent
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue