-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
CC1101.ino
48 lines (39 loc) · 1.01 KB
/
CC1101.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <EEPROM.h>
#include <EEPROMRollingCodeStorage.h>
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <SomfyRemote.h>
#define EMITTER_GPIO 2
#define EEPROM_ADDRESS 0
#define REMOTE 0x5184c8
#define CC1101_FREQUENCY 433.42
EEPROMRollingCodeStorage rollingCodeStorage(EEPROM_ADDRESS);
SomfyRemote somfyRemote(EMITTER_GPIO, REMOTE, &rollingCodeStorage);
void setup() {
Serial.begin(115200);
somfyRemote.setup();
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.setMHZ(CC1101_FREQUENCY);
#if defined(ESP32)
if (!EEPROM.begin(4)) {
Serial.println("failed to initialise EEPROM");
delay(1000);
}
#elif defined(ESP8266)
EEPROM.begin(4);
#endif
}
void sendCC1101Command(Command command) {
ELECHOUSE_cc1101.SetTx();
somfyRemote.sendCommand(command);
ELECHOUSE_cc1101.setSidle();
}
void loop() {
if (Serial.available() > 0) {
const String string = Serial.readStringUntil('\n');
const Command command = getSomfyCommand(string);
sendCC1101Command(command);
#ifdef DEBUG
Serial.println("finished sending");
#endif
}
}