summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--martin/door/src/cc1101.cpp7
-rw-r--r--martin/door/src/cc1101.h1
-rw-r--r--martin/door/src/hcs200.cpp2
-rw-r--r--martin/door/src/main.cpp62
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)
317 return false; 317 return false;
318 } 318 }
319 319
320 spi_write_burst(PATABLE_BURST, patable, 8); 320 setPatable(patable);
321 321
322 // stores the new freq setting for defined ISM band 322 // stores the new freq setting for defined ISM band
323 spi_write_register(FREQ2, freq2); 323 spi_write_register(FREQ2, freq2);
@@ -327,6 +327,11 @@ bool CC1101::setISM(CC1101::ISM_FREQ ism_freq)
327 return true; 327 return true;
328} 328}
329 329
330void CC1101::setPatable(const uint8_t patable[8])
331{
332 spi_write_burst(PATABLE_BURST, patable, 8);
333}
334
330bool CC1101::register_check() 335bool CC1101::register_check()
331{ 336{
332 return (spi_read_register(PKTCTRL0) == cc1101_init[PKTCTRL0] 337 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
21#endif 21#endif
22 bool setup(); 22 bool setup();
23 bool setISM(ISM_FREQ ism_freq); 23 bool setISM(ISM_FREQ ism_freq);
24 void setPatable(const uint8_t patable[8]);
24 bool register_check(); 25 bool register_check();
25 bool transmit(); 26 bool transmit();
26 void setGDO0(int value); 27 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)
165 stream.print("\n"); 165 stream.print("\n");
166} 166}
167 167
168#define PULSE_WIDTH 400 168#define PULSE_WIDTH 440
169 169
170inline void HCS200_Keycode::send(bool value, std::function<void(int)> setOutput) 170inline void HCS200_Keycode::send(bool value, std::function<void(int)> setOutput)
171{ 171{
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()
54 http_service.send_P(200, PSTR("text/plain"), PSTR("I'm a-door-able")); 54 http_service.send_P(200, PSTR("text/plain"), PSTR("I'm a-door-able"));
55 }); 55 });
56 http_service.on("/door/open", HTTP_PUT, http_door_open); 56 http_service.on("/door/open", HTTP_PUT, http_door_open);
57 http_service.on("/door/close", HTTP_GET, []() {
58 http_service.send_P(200, PSTR("text/plain"), PSTR("OK"));
59 });
60 http_service.on("/door/status", HTTP_GET, []() {
61 http_service.send_P(200, PSTR("text/plain"), PSTR("CLOSED"));
62 });
57 http_service.begin(); 63 http_service.begin();
58 64
59 Serial.println("Started listening"); 65 Serial.println("Started listening");
@@ -103,19 +109,67 @@ void http_door_open()
103 http_service.send_P(500, PSTR("text/plain"), PSTR("No data from HCS200")); 109 http_service.send_P(500, PSTR("text/plain"), PSTR("No data from HCS200"));
104 return; 110 return;
105 } 111 }
112 keycode.lowbat = false;
106 113
107 Serial.print("Got keycode: "); 114 Serial.print("Got keycode: ");
108 keycode.print(Serial); 115 keycode.print(Serial);
109 116
117
118 if (http_service.hasArg("power"))
119 {
120 static const uint8_t patable_power_n30[8] = { 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
121 static const uint8_t patable_power_n20[8] = { 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
122 static const uint8_t patable_power_n15[8] = { 0x00, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
123 static const uint8_t patable_power_n10[8] = { 0x00, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
124 static const uint8_t patable_power_0[8] = { 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
125 static const uint8_t patable_power_5[8] = { 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
126 static const uint8_t patable_power_7[8] = { 0x00, 0xC8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
127 static const uint8_t patable_power_10[8] = { 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
128 int power = http_service.arg("power").toInt();
129 if (power == -30)
130 radio.setPatable(patable_power_n30);
131 else if (power == -20)
132 radio.setPatable(patable_power_n20);
133 else if (power == -15)
134 radio.setPatable(patable_power_n15);
135 else if (power == -10)
136 radio.setPatable(patable_power_n10);
137 else if (power == 0)
138 radio.setPatable(patable_power_0);
139 else if (power == 5)
140 radio.setPatable(patable_power_5);
141 else if (power == 7)
142 radio.setPatable(patable_power_7);
143 else if (power == 10)
144 radio.setPatable(patable_power_10);
145 else
146 {
147 http_service.send_P(500, PSTR("text/plain"), PSTR("Unsupported power level"));
148 return;
149 }
150 }
151
110 if (!radio.transmit()) 152 if (!radio.transmit())
111 { 153 {
112 http_service.send_P(500, PSTR("text/plain"), PSTR("Unable to enable radio transmit mode")); 154 http_service.send_P(500, PSTR("text/plain"), PSTR("Unable to enable radio transmit mode"));
113 return; 155 return;
114 } 156 }
115 157
116 long count = constrain(http_service.arg("count").toInt(), 2, 10); 158 if (http_service.hasArg("button1"))
117 for (unsigned short i = 0; i < count; i++) 159 keycode.buttons = HCS200_Keycode::BM_S0;
160 else if (http_service.hasArg("button2"))
161 keycode.buttons = HCS200_Keycode::BM_S1;
162 else if (http_service.hasArg("button3"))
163 keycode.buttons = HCS200_Keycode::BM_S2;
164 else if (http_service.hasArg("button4"))
165 keycode.buttons = HCS200_Keycode::BM_S3;
166
167 unsigned long count = constrain(http_service.arg("count").toInt(), 2, 400);
168 for (unsigned int i = 0; i < count; i++)
169 {
118 keycode.send([&](int value) { radio.setGDO0(value); }); 170 keycode.send([&](int value) { radio.setGDO0(value); });
171 yield();
172 }
119 173
120 (void)radio.idle(); 174 (void)radio.idle();
121 Serial.println("Sending done"); 175 Serial.println("Sending done");
@@ -161,11 +215,13 @@ void loop()
161 MDNS.update(); 215 MDNS.update();
162 http_service.handleClient(); 216 http_service.handleClient();
163 217
218#if 0
164 if (Serial.available() > 0) 219 if (Serial.available() > 0)
165 { 220 {
166 (void)Serial.read(); 221 while (Serial.read() >= 0) {}
167 serial_door_open(Serial); 222 serial_door_open(Serial);
168 } 223 }
224#endif
169 225
170 delay(1); 226 delay(1);
171} 227}