Skip to content

Commit ee25464

Browse files
RF driver (receiver RF directly with SYN590R or similar)
* test * T * T * W * Update RCSwitch.cpp * t * w * Update RCSwitch.h * Update RCSwitch.cpp * w * ww * Update RCSwitch.cpp * t * ttt * test * dbg * Update RCSwitch.cpp * Update RCSwitch.cpp * ww * Update drv_rc.cpp * c * Update RCSwitch.h * make * fix * Update drv_rc.cpp * wwww * wwwwwwwwwww * Update drv_rc.cpp * fix * dsfsdsd * IOR_RCRecv * Update RCSwitch.cpp * test * ffffffffffffx * sds * try * fx * tttttttt * fixes * fx * hold * hide debug vars
1 parent cf0bcf2 commit ee25464

File tree

27 files changed

+2169
-0
lines changed

27 files changed

+2169
-0
lines changed

platforms/obk_main.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ OBKM_SRC += $(OBK_SRCS)i2c/drv_i2c_mcp23017.c
171171
OBKM_SRC += $(OBK_SRCS)i2c/drv_i2c_tc74.c
172172

173173
OBKM_SRC_CXX += $(OBK_SRCS)driver/drv_ir.cpp
174+
OBKM_SRC_CXX += $(OBK_SRCS)driver/drv_rc.cpp
174175
OBKM_SRC_CXX += $(OBK_SRCS)driver/drv_ir_new.cpp
176+
OBKM_SRC_CXX += $(OBK_SRCS)libraries/rc-switch/src/RCSwitch.cpp
175177
OBKM_SRC_CXX += $(OBK_SRCS)libraries/IRremoteESP8266/src/IRac.cpp
176178
OBKM_SRC_CXX += $(OBK_SRCS)libraries/IRremoteESP8266/src/IRproto.cpp
177179
OBKM_SRC_CXX += $(OBK_SRCS)libraries/IRremoteESP8266/src/IRrecv.cpp

src/cmnds/cmd_eventHandlers.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ int EVENT_ParseEventName(const char *s) {
234234
return CMD_EVENT_ON_HTTP;
235235
if (!stricmp(s, "OnDiscovery"))
236236
return CMD_EVENT_ON_DISCOVERY;
237+
if (!stricmp(s, "RC"))
238+
return CMD_EVENT_RC;
237239
if (isdigit((unsigned char)*s)) {
238240
return atoi(s);
239241
}

src/cmnds/cmd_public.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ enum EventCode {
172172

173173
CMD_EVENT_ON_DISCOVERY,
174174

175+
CMD_EVENT_RC,
176+
175177
// must be lower than 256
176178
CMD_EVENT_MAX_TYPES
177179
};

src/driver/drv_main.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "drv_bl_shared.h"
66
#include "drv_cse7766.h"
77
#include "drv_ir.h"
8+
#include "drv_rc.h"
89
#include "drv_local.h"
910
#include "drv_ntp.h"
1011
#include "drv_deviceclock.h"
@@ -757,6 +758,22 @@ static driver_t g_drivers[] = {
757758
false, // loaded
758759
},
759760
#endif
761+
#if ENABLE_DRIVER_RC
762+
//drvdetail:{"name":"RC",
763+
//drvdetail:"title":"TODO",
764+
//drvdetail:"descr":"",
765+
//drvdetail:"requires":""}
766+
{ "RC", // Driver Name
767+
DRV_RC_Init, // Init
768+
NULL, // onEverySecond
769+
RC_AppendInformationToHTTPIndexPage, // appendInformationToHTTPIndexPage
770+
DRV_RC_RunFrame, // runQuickTick
771+
NULL, // stopFunction
772+
NULL, // onChannelChanged
773+
NULL, // onHassDiscovery
774+
false, // loaded
775+
},
776+
#endif
760777
#if ENABLE_DRIVER_IR2
761778
//drvdetail:{"name":"IR2",
762779
//drvdetail:"title":"TODO",

src/driver/drv_rc.cpp

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+

src/driver/drv_rc.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef __DRV_RC_H__
2+
#define __DRV_RC_H__
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
void DRV_RC_Init();
9+
void DRV_RC_RunFrame();
10+
void RC_AppendInformationToHTTPIndexPage(http_request_t *request, int bPreState);
11+
12+
#ifdef __cplusplus
13+
}
14+
15+
#endif
16+
#endif
17+

src/httpserver/new_http.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ const char* htmlPinRoleNames[] = {
558558
"StripState",
559559
"StripState_n",
560560
"HLW_8112_SCSN",
561+
"RCRecv",
562+
"RCRecv_nPup",
561563
"error",
562564
"error",
563565
"error",

src/libraries/rc-switch/.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Mac stuff
2+
.DS_Store
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
9+
# Compiled Dynamic libraries
10+
*.so
11+
*.dylib
12+
13+
# Compiled Static libraries
14+
*.lai
15+
*.la
16+
*.a
17+

src/libraries/rc-switch/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
**Modified Tasmota Fork of RC-SWITCH by @sui77 and @1technophile**
2+
3+
## Info
4+
5+
This will most likely work with all popular low cost power outlet sockets.
6+
7+
All you need is a 315/433MHz AM transmitter and one
8+
or more devices with one of the supported chipsets:
9+
10+
- SC5262 / SC5272
11+
- HX2262 / HX2272
12+
- PT2262 / PT2272
13+
- EV1527 / RT1527 / FP1527 / HS1527
14+
- Intertechno outlets
15+
- HT6P20X
16+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Example for receiving
3+
4+
https://github.com/sui77/rc-switch/
5+
6+
If you want to visualize a telegram copy the raw data and
7+
paste it into http://test.sui.li/oszi/
8+
*/
9+
10+
#include <RCSwitch.h>
11+
12+
RCSwitch mySwitch = RCSwitch();
13+
14+
void setup() {
15+
Serial.begin(9600);
16+
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
17+
}
18+
19+
void loop() {
20+
if (mySwitch.available()) {
21+
output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
22+
mySwitch.resetAvailable();
23+
}
24+
}

0 commit comments

Comments
 (0)