Skip to content

Commit da84a48

Browse files
Rocketctpennam
authored andcommitted
added support for relay
1 parent 442d193 commit da84a48

File tree

3 files changed

+1241
-1192
lines changed

3 files changed

+1241
-1192
lines changed

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)