mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-10-31 13:52:15 +01:00
PR B of SHADE_BEHAVIOUR_PLAN.md. What a shade does with frames, commands, group commands and radio events moves unchanged from SomfyShade into ShadeBehaviour, which builds natively and is pinned by test_shadebehaviour. ShadeBehaviour reads ShadeSettings and RemoteSettings, gets the time on every input, and holds the motion state that other files now read through state(). It sends through MotorLink and reports through ShadeEvents (changes, commands, save wanted, sensor flags) as things happen. SomfyShade wraps it: its MotorLink is SomfyRemote::sendCommandAfter, which now leaves the sender out of the echo and radio hold because the module hears its own frame. lastFrame stays shared with the send path. ConfigFile writes through restore() and clearTilt(), SomfyShadeOps through setPosition(). The pinning tests label where the copies of a rule disagree "today:", for the reconcile phase. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
76 lines
2.1 KiB
C
76 lines
2.1 KiB
C
#ifndef SOMFY_FRAME_H
|
|
#define SOMFY_FRAME_H
|
|
#include <Arduino.h>
|
|
|
|
// The RTS frame codec and command names. Kept free of the radio, storage and
|
|
// network so it can be unit tested on the PC (pio test -e native).
|
|
enum class radio_proto : byte { // Ordinal byte 0-255
|
|
RTS = 0x00,
|
|
RTW = 0x01,
|
|
RTV = 0x02,
|
|
GP_Relay = 0x08,
|
|
GP_Remote = 0x09
|
|
};
|
|
enum class somfy_commands : byte {
|
|
Unknown0 = 0x0,
|
|
My = 0x1,
|
|
Up = 0x2,
|
|
MyUp = 0x3,
|
|
Down = 0x4,
|
|
MyDown = 0x5,
|
|
UpDown = 0x6,
|
|
MyUpDown = 0x7,
|
|
Prog = 0x8,
|
|
SunFlag = 0x9,
|
|
Flag = 0xA,
|
|
StepDown = 0xB,
|
|
Toggle = 0xC,
|
|
UnknownD = 0xD,
|
|
Sensor = 0xE,
|
|
RTWProto = 0xF, // RTW Protocol
|
|
// Command extensions for 80 bit frames
|
|
StepUp = 0x8B,
|
|
Favorite = 0xC1,
|
|
Stop = 0xF1
|
|
};
|
|
String translateSomfyCommand(const somfy_commands cmd);
|
|
somfy_commands translateSomfyCommand(const String& string);
|
|
// The command with up and down swapped, for motors wired the other way round.
|
|
somfy_commands flipCommand(somfy_commands cmd);
|
|
// The command that turns the sun flag on (SunFlag) or off (Flag).
|
|
somfy_commands sunFlagCommand(bool on);
|
|
// Whether cmd can set a shade moving.
|
|
bool startsMovement(somfy_commands cmd);
|
|
|
|
struct somfy_rx_t;
|
|
struct somfy_frame_t {
|
|
bool valid = false;
|
|
bool processed = false;
|
|
bool synonym = false;
|
|
radio_proto proto = radio_proto::RTS;
|
|
int rssi = 0;
|
|
byte lqi = 0x0;
|
|
somfy_commands cmd;
|
|
uint32_t remoteAddress = 0;
|
|
uint16_t rollingCode = 0;
|
|
uint8_t encKey = 0xA7;
|
|
uint8_t checksum = 0;
|
|
uint8_t hwsync = 0;
|
|
uint8_t repeats = 0;
|
|
uint32_t await = 0;
|
|
uint8_t bitLength = 56;
|
|
uint16_t pulseCount = 0;
|
|
uint8_t stepSize = 0;
|
|
uint8_t rawCmd = 0;
|
|
void print();
|
|
void encode80BitFrame(byte *frame, uint8_t repeat);
|
|
byte calc80Checksum(byte b0, byte b1, byte b2);
|
|
byte encode80Byte7(byte start, uint8_t repeat);
|
|
void encodeFrame(byte *frame);
|
|
void decodeFrame(byte* frame);
|
|
void decodeFrame(somfy_rx_t *rx);
|
|
bool isRepeat(somfy_frame_t &f);
|
|
bool isSynonym(somfy_frame_t &f);
|
|
void copy(somfy_frame_t &f);
|
|
};
|
|
#endif
|