Skip to content

Instantly share code, notes, and snippets.

@simkim
Last active January 29, 2024 21:20
Show Gist options
  • Save simkim/9f383eb82bff9e3ba227ecbdacccbf06 to your computer and use it in GitHub Desktop.
Save simkim/9f383eb82bff9e3ba227ecbdacccbf06 to your computer and use it in GitHub Desktop.

Revisions

  1. simkim revised this gist Jan 29, 2024. 1 changed file with 14 additions and 14 deletions.
    28 changes: 14 additions & 14 deletions cc1101_somfy_arduino_remote.ino
    Original file line number Diff line number Diff line change
    @@ -50,36 +50,36 @@ class CLICommand {
    const SomfyRemote somfyRemote(EMITTER_GPIO, remoteAddr, &rollingCodeStorage);

    ELECHOUSE_cc1101.SetTx();
    somfyRemote.sendCommand(scommand);
    ELECHOUSE_cc1101.setSidle();
    somfyRemote.sendCommand(scommand);
    ELECHOUSE_cc1101.setSidle();
    }
    };


    void setup() {
    Serial.begin(115200);
    Serial.begin(115200);

    pinMode(EMITTER_GPIO, OUTPUT);
    digitalWrite(EMITTER_GPIO, LOW);
    pinMode(EMITTER_GPIO, OUTPUT);
    digitalWrite(EMITTER_GPIO, LOW);

    ELECHOUSE_cc1101.Init();
    ELECHOUSE_cc1101.setMHZ(CC1101_FREQUENCY);
    ELECHOUSE_cc1101.Init();
    ELECHOUSE_cc1101.setMHZ(CC1101_FREQUENCY);

    #if defined(ESP32)
    if (!EEPROM.begin(4)) {
    Serial.println("failed to initialise EEPROM");
    delay(1000);
    }
    if (!EEPROM.begin(4)) {
    Serial.println("failed to initialise EEPROM");
    delay(1000);
    }
    #elif defined(ESP8266)
    EEPROM.begin(4);
    EEPROM.begin(4);
    #endif
    }

    void loop() {
    CLICommand cli;
    CLICommand cli;
    if (Serial.available() > 0) {
    cli.readLine();
    cli.debug();
    cli.send();
    }
    }
    }
  2. simkim created this gist Jan 29, 2024.
    85 changes: 85 additions & 0 deletions cc1101_somfy_arduino_remote.ino
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,85 @@
    #include <EEPROM.h>
    #include <EEPROMRollingCodeStorage.h>
    #include <ELECHOUSE_CC1101_SRC_DRV.h>
    #include <SomfyRemote.h>

    #define EMITTER_GPIO 2
    #define EEPROM_ADDRESS 0
    #define CC1101_FREQUENCY 433.42


    class CLICommand {
    String command;
    uint32_t remoteAddr;
    int eeprom_slot;

    public:

    void readLine() {
    const String line = Serial.readStringUntil('\n');
    int wordPtr = line.indexOf(" ");
    const String remoteString = line.substring(0, wordPtr);
    remoteAddr = remoteString.toInt();
    line.remove(0, wordPtr+1);

    wordPtr = line.indexOf(" ");
    const String indexString = line.substring(0, wordPtr);
    eeprom_slot = indexString.toInt();
    line.remove(0, wordPtr+1);

    wordPtr = line.indexOf("\n");
    command = line.substring(0, wordPtr-1);
    }

    void debug() {
    Serial.print("command ");
    Serial.print(command);
    Serial.print(" to ");
    Serial.println(remoteAddr);
    Serial.print(" index ");
    Serial.print(eeprom_slot);
    Serial.print(" code ");
    uint16_t code;
    EEPROM.get(eeprom_slot*2, code);
    Serial.println(code);
    }

    void send() {
    const Command scommand = getSomfyCommand(command);
    EEPROMRollingCodeStorage rollingCodeStorage(eeprom_slot*2);
    const SomfyRemote somfyRemote(EMITTER_GPIO, remoteAddr, &rollingCodeStorage);

    ELECHOUSE_cc1101.SetTx();
    somfyRemote.sendCommand(scommand);
    ELECHOUSE_cc1101.setSidle();
    }
    };


    void setup() {
    Serial.begin(115200);

    pinMode(EMITTER_GPIO, OUTPUT);
    digitalWrite(EMITTER_GPIO, LOW);

    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 loop() {
    CLICommand cli;
    if (Serial.available() > 0) {
    cli.readLine();
    cli.debug();
    cli.send();
    }
    }