Skip to content

Commit 2560386

Browse files
Rocketctfacchinm
authored andcommitted
added support for opto relay
1 parent 755dc04 commit 2560386

File tree

4 files changed

+1266
-1192
lines changed

4 files changed

+1266
-1192
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <Modulino.h>
2+
3+
ModulinoRelay relay;
4+
5+
void setup() {
6+
Serial.begin(115200);
7+
Modulino.begin();
8+
relay.begin();
9+
10+
}
11+
void loop() {
12+
relay.on();
13+
if(relay.getStatus())
14+
{
15+
Serial.println("Relay state ON!");
16+
}
17+
delay(1000);
18+
relay.off();
19+
if(!(relay.getStatus()))
20+
{
21+
Serial.println("Relay state OFF!");
22+
}
23+
Serial.println();
24+
delay(1000);
25+
}

examples/Utilities/AddressChanger/AddressChanger.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ String pinstrapToName(uint8_t pinstrap) {
232232
return "Joystick";
233233
case 0x7C:
234234
return "Buttons";
235+
case 0x28:
236+
return "Opto Relay";
235237
case 0x76:
236238
case 0x74:
237239
return "Encoder";

src/Modulino.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,4 +639,51 @@ class ModulinoDistance : public Module {
639639
_distance_api* api = nullptr;
640640
};
641641

642+
class ModulinoRelay : public Module {
643+
public:
644+
ModulinoRelay(uint8_t address = 0xFF)
645+
: Module(address, "RELAY") {}
646+
bool update() {
647+
uint8_t buf[3];
648+
auto res = read((uint8_t*)buf, 3);
649+
auto ret = res && (buf[0] != last_status[0] || buf[1] != last_status[1] || buf[2] != last_status[2]);
650+
last_status[0] = buf[0];
651+
last_status[1] = buf[1];
652+
last_status[2] = buf[2];
653+
return ret;
654+
}
655+
void on() {
656+
uint8_t buf[3];
657+
buf[0] = 1;
658+
buf[1] = 0;
659+
buf[2] = 0;
660+
write((uint8_t*)buf, 3);
661+
return;
662+
}
663+
void off() {
664+
uint8_t buf[3];
665+
buf[0] = 0;
666+
buf[1] = 0;
667+
buf[2] = 0;
668+
write((uint8_t*)buf, 3);
669+
return;
670+
}
671+
bool getStatus() {
672+
update();
673+
return last_status[0];
674+
}
675+
virtual uint8_t discover() {
676+
for (unsigned int i = 0; i < sizeof(match)/sizeof(match[0]); i++) {
677+
if (scan(match[i])) {
678+
return match[i];
679+
}
680+
}
681+
return 0xFF;
682+
}
683+
private:
684+
bool last_status[3];
685+
protected:
686+
uint8_t match[1] = { 0x28 }; // same as fw main.c
687+
};
688+
642689
#endif

0 commit comments

Comments
 (0)