|
| 1 | + |
| 2 | +#include "../obk_config.h" |
| 3 | + |
| 4 | +#if ENABLE_DRIVER_RC |
| 5 | + |
| 6 | +extern "C" { |
| 7 | + // these cause error: conflicting declaration of 'int bk_wlan_mcu_suppress_and_sleep(unsigned int)' with 'C' linkage |
| 8 | +#include "../new_common.h" |
| 9 | +#include "../httpserver/new_http.h" |
| 10 | +#include "../logging/logging.h" |
| 11 | +#include "../new_pins.h" |
| 12 | +#include "../new_cfg.h" |
| 13 | +#include "../cmnds/cmd_public.h" |
| 14 | + |
| 15 | +} |
| 16 | + |
| 17 | +#include "drv_rc.h" |
| 18 | +#include "../libraries/rc-switch/src/RCSwitch.h" |
| 19 | + |
| 20 | +RCSwitch mySwitch = RCSwitch(); |
| 21 | +void DRV_RC_Init() { |
| 22 | + // allow user to change them |
| 23 | + int pin = -1; |
| 24 | + bool pup = true; |
| 25 | + pin = PIN_FindPinIndexForRole(IOR_RCRecv, pin); |
| 26 | + if (pin == -1) |
| 27 | + { |
| 28 | + pin = PIN_FindPinIndexForRole(IOR_RCRecv_nPup, pin); |
| 29 | + if (pin >= 0) |
| 30 | + pup = false; |
| 31 | + } |
| 32 | + ADDLOG_INFO(LOG_FEATURE_IR, "DRV_RC_Init: passing pin %i\n", pin); |
| 33 | + mySwitch.enableReceive(pin, pup); // Receiver on interrupt 0 => that is pin #2 |
| 34 | +} |
| 35 | +//extern long g_micros; |
| 36 | +//extern int rc_triggers; |
| 37 | +//extern int g_rcpin; |
| 38 | +//extern int rc_checkedProtocols; |
| 39 | +//extern int rc_singleRepeats; |
| 40 | +//extern int rc_repeats; |
| 41 | +static int rc_totalDecoded = 0; |
| 42 | + |
| 43 | +void RC_AppendInformationToHTTPIndexPage(http_request_t *request, int bPreState) { |
| 44 | + |
| 45 | + if (bPreState) { |
| 46 | + } |
| 47 | + else { |
| 48 | + hprintf255(request, "<h3>RC signals decoded: %i</h3>", rc_totalDecoded); |
| 49 | + //hprintf255(request, "<h3>Triggers: %i</h3>", (int)rc_triggers); |
| 50 | + //hprintf255(request, "<h3>Micros: %i</h3>", (int)g_micros); |
| 51 | + //hprintf255(request, "<h3>g_rcpin: %i</h3>", (int)g_rcpin); |
| 52 | + //hprintf255(request, "<h3>rc_checkedProtocols: %i</h3>", (int)rc_checkedProtocols); |
| 53 | + //hprintf255(request, "<h3>rc_singleRepeats: %i</h3>", (int)rc_singleRepeats); |
| 54 | + //hprintf255(request, "<h3>rc_repeats: %i</h3>", (int)rc_repeats); |
| 55 | + } |
| 56 | +} |
| 57 | +unsigned long rc_prev = 0; |
| 58 | +int loopsUntilClear = 0; |
| 59 | +void DRV_RC_RunFrame() { |
| 60 | + if (loopsUntilClear) { |
| 61 | + loopsUntilClear--; |
| 62 | + if (loopsUntilClear <= 0) { |
| 63 | + rc_prev = 0; |
| 64 | + ADDLOG_INFO(LOG_FEATURE_IR, "Clearing hold timer\n"); |
| 65 | + } |
| 66 | + } |
| 67 | + if (mySwitch.available()) { |
| 68 | + rc_totalDecoded++; |
| 69 | + |
| 70 | + unsigned long rc_now = mySwitch.getReceivedValue(); |
| 71 | + int bHold = 0; |
| 72 | + if (rc_now != rc_prev) { |
| 73 | + rc_prev = rc_now; |
| 74 | + } |
| 75 | + else { |
| 76 | + bHold = 1; |
| 77 | + } |
| 78 | + loopsUntilClear = 15; |
| 79 | + // TODO 64 bit |
| 80 | + // generic |
| 81 | + // addEventHandler RC 1234 toggleChannel 5 123 |
| 82 | + // on first receive |
| 83 | + // addEventHandler2 RC 1234 0 toggleChannel 5 123 |
| 84 | + // on hold |
| 85 | + // addEventHandler2 RC 1234 1 toggleChannel 5 123 |
| 86 | + ADDLOG_INFO(LOG_FEATURE_IR, "Received %lu / %u bit protocol %u, hold %i\n", |
| 87 | + rc_now, |
| 88 | + mySwitch.getReceivedBitlength(), |
| 89 | + mySwitch.getReceivedProtocol(), |
| 90 | + bHold); |
| 91 | + EventHandlers_FireEvent2(CMD_EVENT_RC, mySwitch.getReceivedValue(), bHold); |
| 92 | + |
| 93 | + |
| 94 | + mySwitch.resetAvailable(); |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | + |
| 99 | +#endif |
| 100 | + |
| 101 | + |
0 commit comments