From ef99adf6e71437c450bb336755e72f776cc09257 Mon Sep 17 00:00:00 2001 From: manuel Date: Sat, 11 Apr 2020 13:44:43 +0200 Subject: Update martin --- martin/door/src/cc1101.cpp | 7 +++++- martin/door/src/cc1101.h | 1 + martin/door/src/hcs200.cpp | 2 +- martin/door/src/main.cpp | 62 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 67 insertions(+), 5 deletions(-) diff --git a/martin/door/src/cc1101.cpp b/martin/door/src/cc1101.cpp index 86129db..0f76d38 100644 --- a/martin/door/src/cc1101.cpp +++ b/martin/door/src/cc1101.cpp @@ -317,7 +317,7 @@ bool CC1101::setISM(CC1101::ISM_FREQ ism_freq) return false; } - spi_write_burst(PATABLE_BURST, patable, 8); + setPatable(patable); // stores the new freq setting for defined ISM band spi_write_register(FREQ2, freq2); @@ -327,6 +327,11 @@ bool CC1101::setISM(CC1101::ISM_FREQ ism_freq) return true; } +void CC1101::setPatable(const uint8_t patable[8]) +{ + spi_write_burst(PATABLE_BURST, patable, 8); +} + bool CC1101::register_check() { return (spi_read_register(PKTCTRL0) == cc1101_init[PKTCTRL0] diff --git a/martin/door/src/cc1101.h b/martin/door/src/cc1101.h index 04d828e..3bb0ad9 100644 --- a/martin/door/src/cc1101.h +++ b/martin/door/src/cc1101.h @@ -21,6 +21,7 @@ class CC1101 #endif bool setup(); bool setISM(ISM_FREQ ism_freq); + void setPatable(const uint8_t patable[8]); bool register_check(); bool transmit(); void setGDO0(int value); diff --git a/martin/door/src/hcs200.cpp b/martin/door/src/hcs200.cpp index 401e670..661380a 100644 --- a/martin/door/src/hcs200.cpp +++ b/martin/door/src/hcs200.cpp @@ -165,7 +165,7 @@ void HCS200_Keycode::print(Print &stream) stream.print("\n"); } -#define PULSE_WIDTH 400 +#define PULSE_WIDTH 440 inline void HCS200_Keycode::send(bool value, std::function setOutput) { diff --git a/martin/door/src/main.cpp b/martin/door/src/main.cpp index 4491785..38146e4 100644 --- a/martin/door/src/main.cpp +++ b/martin/door/src/main.cpp @@ -54,6 +54,12 @@ void setup() http_service.send_P(200, PSTR("text/plain"), PSTR("I'm a-door-able")); }); http_service.on("/door/open", HTTP_PUT, http_door_open); + http_service.on("/door/close", HTTP_GET, []() { + http_service.send_P(200, PSTR("text/plain"), PSTR("OK")); + }); + http_service.on("/door/status", HTTP_GET, []() { + http_service.send_P(200, PSTR("text/plain"), PSTR("CLOSED")); + }); http_service.begin(); Serial.println("Started listening"); @@ -103,19 +109,67 @@ void http_door_open() http_service.send_P(500, PSTR("text/plain"), PSTR("No data from HCS200")); return; } + keycode.lowbat = false; Serial.print("Got keycode: "); keycode.print(Serial); + + if (http_service.hasArg("power")) + { + static const uint8_t patable_power_n30[8] = { 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + static const uint8_t patable_power_n20[8] = { 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + static const uint8_t patable_power_n15[8] = { 0x00, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + static const uint8_t patable_power_n10[8] = { 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + static const uint8_t patable_power_0[8] = { 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + static const uint8_t patable_power_5[8] = { 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + static const uint8_t patable_power_7[8] = { 0x00, 0xC8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + static const uint8_t patable_power_10[8] = { 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + int power = http_service.arg("power").toInt(); + if (power == -30) + radio.setPatable(patable_power_n30); + else if (power == -20) + radio.setPatable(patable_power_n20); + else if (power == -15) + radio.setPatable(patable_power_n15); + else if (power == -10) + radio.setPatable(patable_power_n10); + else if (power == 0) + radio.setPatable(patable_power_0); + else if (power == 5) + radio.setPatable(patable_power_5); + else if (power == 7) + radio.setPatable(patable_power_7); + else if (power == 10) + radio.setPatable(patable_power_10); + else + { + http_service.send_P(500, PSTR("text/plain"), PSTR("Unsupported power level")); + return; + } + } + if (!radio.transmit()) { http_service.send_P(500, PSTR("text/plain"), PSTR("Unable to enable radio transmit mode")); return; } - long count = constrain(http_service.arg("count").toInt(), 2, 10); - for (unsigned short i = 0; i < count; i++) + if (http_service.hasArg("button1")) + keycode.buttons = HCS200_Keycode::BM_S0; + else if (http_service.hasArg("button2")) + keycode.buttons = HCS200_Keycode::BM_S1; + else if (http_service.hasArg("button3")) + keycode.buttons = HCS200_Keycode::BM_S2; + else if (http_service.hasArg("button4")) + keycode.buttons = HCS200_Keycode::BM_S3; + + unsigned long count = constrain(http_service.arg("count").toInt(), 2, 400); + for (unsigned int i = 0; i < count; i++) + { keycode.send([&](int value) { radio.setGDO0(value); }); + yield(); + } (void)radio.idle(); Serial.println("Sending done"); @@ -161,11 +215,13 @@ void loop() MDNS.update(); http_service.handleClient(); +#if 0 if (Serial.available() > 0) { - (void)Serial.read(); + while (Serial.read() >= 0) {} serial_door_open(Serial); } +#endif delay(1); } -- cgit v1.2.3