Skip to content

Commit

Permalink
Added events and buttonpresses now as int and bool
Browse files Browse the repository at this point in the history
  • Loading branch information
J2thatsme committed Jan 9, 2025
1 parent 6621831 commit 1fe1611
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 21 deletions.
70 changes: 62 additions & 8 deletions types/oxon/oxobutton2/default.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,108 @@
"title": "Default",
"properties": {
"button1": {
"title": "Button 1",
"type": "boolean",
"description": "Button 1 got pressed if true",
"hideFromKpis": true
},
"button2": {
"title": "Button 2",
"type": "boolean",
"description": "Button 2 got pressed if true",
"hideFromKpis": true
},
"button3": {
"title": "Button 3",
"type": "boolean",
"description": "Button 3 got pressed if true",
"hideFromKpis": true
},
"button4": {
"title": "Button 4",
"type": "boolean",
"description": "Button 4 got pressed if true",
"hideFromKpis": true
},
"periodicUplink": {
"title": "Periodic uplink",
"type": "boolean",
"description": "It is a periodic uplink if true",
"hideFromKpis": true
},
"heartbeatEvent": {
"title": "Heartbeat event",
"type": "boolean",
"description": "It is a heartbeat event if true",
"hideFromKpis": true
},
"temperatureEvent": {
"title": "Temperature event",
"type": "boolean",
"description": "It is a temperature event if true",
"hideFromKpis": true
},
"humidityEvent": {
"title": "Humidity event",
"type": "boolean",
"description": "It is a humidity event if true",
"hideFromKpis": true
},
"ambientLightEvent": {
"title": "Light event",
"type": "boolean",
"description": "It is a light event if true",
"hideFromKpis": true
},
"button1Count": {
"title": "Button 1",
"type": "integer",
"description": "Button 1 got pressed if the number is 1",
"hideFromKpis": true
},
"button2": {
"button2Count": {
"title": "Button 2",
"type": "integer",
"description": "Button 2 got pressed if the number is 1",
"hideFromKpis": true
},
"button3": {
"button3Count": {
"title": "Button 3",
"type": "integer",
"description": "Button 3 got pressed if the number is 1",
"hideFromKpis": true
},
"button4": {
"button4Count": {
"title": "Button 4",
"type": "integer",
"description": "Button 4 got pressed if the number is 1",
"hideFromKpis": true
},
"periodicUplink": {
"periodicUplinkCount": {
"title": "Periodic uplink",
"type": "integer",
"description": "It is a periodic uplink if the number is 1",
"hideFromKpis": true
},
"heartbeatEvent": {
"heartbeatEventCount": {
"title": "Heartbeat event",
"type": "integer",
"description": "It is a heartbeat event if the number is 1",
"hideFromKpis": true
},
"temperatureEvent": {
"temperatureEventCount": {
"title": "Temperature event",
"type": "integer",
"description": "It is a temperature event if the number is 1",
"hideFromKpis": true
},
"humidityEvent": {
"humidityEventCount": {
"title": "Humidity event",
"type": "integer",
"description": "It is a humidity event if the number is 1",
"hideFromKpis": true
},
"ambientLightEvent": {
"ambientLightEventCount": {
"title": "Light event",
"type": "integer",
"description": "It is a light event if the number is 1",
Expand Down
18 changes: 9 additions & 9 deletions types/oxon/oxobutton2/uplink.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ function consume(event) {
const reason1 = Bits.bitsToUnsigned(bits.substr(8, 8));
const reason2 = Bits.bitsToUnsigned(bits.substr(16, 8));

if (reason1 & 0x01) { data.button1 = 1; }
if (reason1 & 0x02) { data.button2 = 1; }
if (reason1 & 0x04) { data.button3 = 1; }
if (reason1 & 0x08) { data.button4 = 1; }
if (reason1 & 0x10) { data.heartbeatEvent = 1; }
if (reason2 & 0x01) { data.periodicUplink = 1; }
if (reason2 & 0x02) { data.temperatureEvent = 1; }
if (reason2 & 0x04) { data.humidityEvent = 1; }
if (reason2 & 0x08) { data.ambientLightEvent = 1; }
if (reason1 & 0x01) { data.button1Count = 1; data.button1 = true; }
if (reason1 & 0x02) { data.button2Count = 1; data.button2 = true; }
if (reason1 & 0x04) { data.button3Count = 1; data.button3 = true; }
if (reason1 & 0x08) { data.button4Count = 1; data.button4 = true; }
if (reason1 & 0x10) { data.heartbeatEventCount = 1; data.heartbeatEvent = true; }
if (reason2 & 0x01) { data.periodicUplinkCount = 1; data.periodicUplink = true; }
if (reason2 & 0x02) { data.temperatureEventCount = 1; data.temperatureEvent = true; }
if (reason2 & 0x04) { data.humidityEventCount = 1; data.humidityEvent = true; }
if (reason2 & 0x08) { data.ambientLightEventCount = 1; data.ambientLightEvent = true; }

const appMode = Bits.bitsToUnsigned(bits.substr(24, 8));
switch (appMode) {
Expand Down
18 changes: 14 additions & 4 deletions types/oxon/oxobutton2/uplink.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,27 @@ describe("Oxon Oxobutton 2 Uplink", () => {
assert.typeOf(value.data, "object");

assert.equal(value.topic, "default");
assert.equal(value.data.button1, 0);
assert.equal(value.data.button2, 0);
assert.equal(value.data.button3, 0);
assert.equal(value.data.button4, 0);
assert.equal(value.data.button1Count, 0);
assert.equal(value.data.button2Count, 0);
assert.equal(value.data.button3Count, 0);
assert.equal(value.data.button4Count, 0);

assert.equal(value.data.button1, false);
assert.equal(value.data.button2, false);
assert.equal(value.data.button3, false);
assert.equal(value.data.button4, false);

assert.equal(value.data.periodicUplink, 0);
assert.equal(value.data.temperatureEvent, 1);
assert.equal(value.data.ambientLightEvent, 0);
assert.equal(value.data.heartbeatEvent, 0);
assert.equal(value.data.humidityEvent, 0);

assert.equal(value.data.periodicUplink, false);
assert.equal(value.data.temperatureEvent, true);
assert.equal(value.data.ambientLightEvent, false);
assert.equal(value.data.heartbeatEvent, false);
assert.equal(value.data.humidityEvent, false);

assert.equal(value.data.light, 0);
assert.equal(value.data.humidity, 42.72);
Expand Down

0 comments on commit 1fe1611

Please sign in to comment.