Skip to content

Commit

Permalink
Work on 80-bit protocol
Browse files Browse the repository at this point in the history
* Fixes issue #11 TX Power is now persisted to NVS
* Increase timing for tilt motors from 7 to 15 beats. #1
* Add time to frame log.
* Allow RX and TX pins to be shared and multiplexed
  • Loading branch information
rstrouse committed Mar 29, 2023
1 parent ab7cdba commit 5f5ac9f
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 20 deletions.
2 changes: 1 addition & 1 deletion ConfigSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef configsettings_h
#define configsettings_h

#define FW_VERSION "v1.4.3"
#define FW_VERSION "v1.4.4"
enum DeviceStatus {
DS_OK = 0,
DS_ERROR = 1,
Expand Down
14 changes: 12 additions & 2 deletions Somfy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ uint8_t rxmode = 0; // Indicates whether the radio is in receive mode. Just to
#endif

#define SETMY_REPEATS 15
#define TILT_REPEATS 7
#define TILT_REPEATS 15

int sort_asc(const void *cmp1, const void *cmp2) {
int a = *((uint8_t *)cmp1);
Expand Down Expand Up @@ -137,12 +137,14 @@ void somfy_frame_t::decodeFrame(byte* frame) {
case somfy_commands::Prog:
case somfy_commands::SunFlag:
case somfy_commands::Flag:
case somfy_commands::StepUp:
case somfy_commands::UnknownC:
case somfy_commands::UnknownD:
case somfy_commands::UnknownE:
case somfy_commands::UnknownF:
break;
case somfy_commands::StepUp:
case somfy_commands::StepDown:
// These must be 80 bit commands
break;
default:
this->valid = false;
Expand Down Expand Up @@ -1812,8 +1814,11 @@ void Transceiver::emitFrame(somfy_frame_t *frame, somfy_rx_t *rx) {
evt.appendMessage(buf);
snprintf(buf, sizeof(buf), "\"bits\":%d,", rx->bit_length);
evt.appendMessage(buf);
snprintf(buf, sizeof(buf), "\"valid\":%s,", frame->valid ? "true" : "false");
evt.appendMessage(buf);
snprintf(buf, sizeof(buf), "\"sync\":%d,\"pulses\":[", frame->hwsync);
evt.appendMessage(buf);

if(rx) {
for(uint16_t i = 0; i < rx->pulseCount; i++) {
snprintf(buf, sizeof(buf), "%s%d", i != 0 ? "," : "", rx->pulses[i]);
Expand Down Expand Up @@ -1969,6 +1974,7 @@ void transceiver_config_t::save() {
pref.putFloat("rxBandwidth", this->rxBandwidth); // float
pref.putBool("enabled", this->enabled);
pref.putBool("radioInit", true);
pref.putChar("txPower", this->txPower);

/*
pref.putBool("internalCCMode", this->internalCCMode);
Expand Down Expand Up @@ -2061,6 +2067,10 @@ void transceiver_config_t::apply() {
if(!radioInit) return;
Serial.print("Applying radio settings ");
Serial.printf("Setting Data Pins RX:%u TX:%u\n", this->RXPin, this->TXPin);
//if(this->TXPin != this->RXPin)
// pinMode(this->TXPin, OUTPUT);
//pinMode(this->RXPin, INPUT);
// Essentially these call only preform the two functions above.
if(this->TXPin == this->RXPin)
ELECHOUSE_cc1101.setGDO0(this->TXPin); // This pin may be shared.
else
Expand Down
Binary file modified SomfyController.ino.esp32.bin
Binary file not shown.
Binary file modified SomfyController.littlefs.bin
Binary file not shown.
10 changes: 8 additions & 2 deletions Web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,10 @@ void Web::begin() {
server.send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"Shade not found to pair\"}"));
}
else {
shade->sendCommand(somfy_commands::Prog, 7);
if(shade->bitLength == 56)
shade->sendCommand(somfy_commands::Prog, 7);
else
shade->sendCommand(somfy_commands::Prog, 1);
shade->paired = true;
shade->save();
DynamicJsonDocument doc(512);
Expand Down Expand Up @@ -951,7 +954,10 @@ void Web::begin() {
server.send(500, _encoding_json, F("{\"status\":\"ERROR\",\"desc\":\"Shade not found to unpair\"}"));
}
else {
shade->sendCommand(somfy_commands::Prog, 7);
if(shade->bitLength == 56)
shade->sendCommand(somfy_commands::Prog, 7);
else
shade->sendCommand(somfy_commands::Prog, 1);
shade->paired = false;
shade->save();
DynamicJsonDocument doc(512);
Expand Down
2 changes: 1 addition & 1 deletion data/appversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.3
1.4.4
8 changes: 4 additions & 4 deletions data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<link rel="stylesheet" href="main.css?v=1.4.3" type="text/css" />
<link rel="stylesheet" href="icons.css?v=1.4.3" type="text/css" />
<link rel="stylesheet" href="main.css?v=1.4.4" type="text/css" />
<link rel="stylesheet" href="icons.css?v=1.4.4" type="text/css" />
<link rel="icon" type="image/png" href="favicon.png" />
<script type="text/javascript" src="index.js?v=1.4.3"></script>
<script type="text/javascript" src="index.js?v=1.4.4"></script>
</head>
<body>
<div id="divContainer" class="container" style="user-select:none;position:relative;border-radius:27px;">
Expand Down Expand Up @@ -426,7 +426,7 @@ <h1 style="text-align: center;"><img src="icon.png" style="width:50px;float:left
<div id="divFrameLog" class="frame-log" style="display:none;">
<h1 style="text-align: center;padding:10px;"><span>Frame Logs</span><span class="button-outline" onclick="document.getElementById('divFrameLog').style.display = 'none';" style="float:right;font-size:1.25rem;display:inline-block;vertical-align:middle;width:38px;height:38px;position:relative;padding-top:4px;"><span style="vertical-align:middle;clear:both;text-align:center;display:inline-block;"><i id="icoConfig" class="icss-x" style=""></i></span></span></h1>
<hr style="margin:0px;" />
<div class="frame-header"><span>Key</span><span>Address</span><span>Command</span><span>Code</span><span>RSSI</span><span>Bits</span></div>
<div class="frame-header"><span>Key</span><span>Address</span><span>Command</span><span>Code</span><span>RSSI</span><span>Bits</span><span style="text-align:center;width:77px;">Time</span></div>
<div id="divFrames" class="frame-list"></div>
<div class="button-container" style="text-align:center">
<button type="button" class="btnCopyFrame" style="display:inline-block;width:44%;" onclick="somfy.framesToClipboard();">Copy</button>
Expand Down
38 changes: 29 additions & 9 deletions data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ document.oncontextmenu = (event) => {
event.preventDefault(); event.stopPropagation(); return false;
}
}

Date.prototype.toJSON = function () {
let tz = this.getTimezoneOffset();
let sign = tz > 0 ? '-' : '+';
let tzHrs = Math.floor(Math.abs(tz) / 60).fmt('00');
let tzMin = (Math.abs(tz) % 60).fmt('00');
return `${this.getFullYear()}-${(this.getMonth() + 1).fmt('00')}-${this.getDate().fmt('00')}T${this.getHours().fmt('00')}:${this.getMinutes().fmt('00')}:${this.getSeconds().fmt('00')}.${this.getMilliseconds().fmt('000')}${sign}${tzHrs}${tzMin}`;
};
Number.prototype.round = function (dec) { return Number(Math.round(this + 'e' + dec) + 'e-' + dec); };
Number.prototype.fmt = function (format, empty) {
if (isNaN(this)) return empty || '';
Expand Down Expand Up @@ -81,7 +87,7 @@ Number.prototype.fmt = function (format, empty) {
}
if (fw.length > rw.length) {
var pstart = fw.indexOf('0');
if (pstart > 0) {
if (pstart >= 0) {
var plen = fw.length - pstart;
var pos = fw.length - rw.length - 1;
while (rw.length < plen) {
Expand Down Expand Up @@ -372,7 +378,7 @@ async function reopenSocket() {
await initSockets();
}
class General {
appVersion = 'v1.4.3';
appVersion = 'v1.4.4';
reloadApp = false;
async init() {
this.setAppVersion();
Expand Down Expand Up @@ -987,9 +993,14 @@ class Somfy {
return false;
}
if (sval === val) {
errorMessage(document.getElementById('fsSomfySettings'), `The ${name.replace('Pin', '')} pin is duplicated by the ${s.replace('Pin', '')}. All pin definitions must be unique`);
valid = false;
return false;
if ((name === 'TXPin' && s === 'RXPin') ||
(name === 'RXPin' && s === 'TXPin'))
continue; // The RX and TX pins can share the same value. In this instance the radio will only use GDO0.
else {
errorMessage(document.getElementById('fsSomfySettings'), `The ${name.replace('Pin', '')} pin is duplicated by the ${s.replace('Pin', '')}. All pin definitions must be unique`);
valid = false;
return false;
}
}
}
}
Expand Down Expand Up @@ -1300,11 +1311,22 @@ class Somfy {
let frames = document.getElementById('divFrames');
let row = document.createElement('div');
row.classList.add('frame-row');
let html = `<span>${frame.encKey}</span><span>${frame.address}</span><span>${frame.command}</span><span>${frame.rcode}</span><span>${frame.rssi}dBm</span><span>${frame.bits}</span><div class="frame-pulses">`;
row.setAttribute('data-valid', frame.valid);
// The socket is not sending the current date so we will snag the current receive date from
// the browser.
let fnFmtDate = (dt) => {
return `${(dt.getMonth() + 1).fmt('00')}/${dt.getDate().fmt('00')} ${dt.getHours().fmt('00')}:${dt.getMinutes().fmt('00')}:${dt.getSeconds().fmt('00')}.${dt.getMilliseconds().fmt('000')}`;
}
let fnFmtTime = (dt) => {
return `${dt.getHours().fmt('00')}:${dt.getMinutes().fmt('00')}:${dt.getSeconds().fmt('00')}.${dt.getMilliseconds().fmt('000')}`;
}
frame.time = new Date();
let html = `<span>${frame.encKey}</span><span>${frame.address}</span><span>${frame.command}</span><span>${frame.rcode}</span><span>${frame.rssi}dBm</span><span>${frame.bits}</span><span>${fnFmtTime(frame.time)}</span><div class="frame-pulses">`;
for (let i = 0; i < frame.pulses.length; i++) {
if (i !== 0) html += ',';
html += `${frame.pulses[i]}`;
}
html += '</div>'
row.innerHTML = html;
frames.prepend(row);
this.frames.push(frame);
Expand Down Expand Up @@ -1732,7 +1754,6 @@ class Somfy {
putJSON('/tiltCommand', { shadeId: shadeId, target: parseInt(command, 10) }, (err, shade) => {
});
};

linkRemote(shadeId) {
let div = document.createElement('div');
let html = `<div id="divLinking" class="instructions" data-type="link-remote" data-shadeid="${shadeId}">`;
Expand Down Expand Up @@ -1785,7 +1806,6 @@ class Somfy {
somfy.sendTiltCommand(shadeId, el.value);
}
}

openSetPosition(shadeId) {
console.log('Opening Shade Positioner');
if (typeof shadeId === 'undefined') {
Expand Down
12 changes: 11 additions & 1 deletion data/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ div.frame-header > span {
}
div.frame-row > span {
text-align:right;
text-decoration:inherit;
}
div.frame-row > span:nth-child(1),
div.frame-header > span:nth-child(1) {
Expand All @@ -728,9 +729,14 @@ div.frame-header > span {
}
div.frame-row > span:nth-child(6),
div.frame-header > span:nth-child(6) {
width: 47px;
width: 27px;
text-align:center;
}
div.frame-row > span:nth-child(7),
div.frame-header > span:nth-child(7) {
text-align: right;
white-space:nowrap;
}

div.frame-list > div:nth-child(2n+1) {
background: beige;
Expand All @@ -740,6 +746,10 @@ div.frame-row {
width:100%;
background:white;
}
div.frame-row[data-valid="false"] {
text-decoration:line-through;
color:red;
}
div.frame-pulses {
width:100%;
padding-left:7px;
Expand Down

0 comments on commit 5f5ac9f

Please sign in to comment.