fix; wip for prefs

This commit is contained in:
Alban 2024-04-04 18:58:37 +02:00
parent e1f2ca1de1
commit 573a531ef1
4 changed files with 78 additions and 30 deletions

File diff suppressed because one or more lines are too long

View File

@ -28,7 +28,7 @@ class Schedule {
// Load from binary data
var view = new DataView(buffer);
for (var i = 0; i < 24; i++) {
this.schedule[i] = view.getUint16(i * 2, true);
this.schedule[i] = view.getUint16(i * 2);
}
};
@ -102,8 +102,7 @@ class Schedule {
var buffer = new ArrayBuffer(24 * 2);
var view = new DataView(buffer);
for (var i = 0; i < 24; i++) {
view.setUint8( i*2 , (this.schedule[i] & 65280) >> 8, true);
view.setUint8( i*2 + 1, this.schedule[i] & 255 , true);
view.setUint16( i*2, this.schedule[i]);
}
return buffer;
};

View File

@ -37,7 +37,7 @@ def binary_stream_to_ints(binary_data):
integers = []
# Every 32-bit integer is represented by 2 bytes
for i in range(0, len(binary_data), 2):
integers.append(int.from_bytes(binary_data[i:i + 2]) & 0b111111111111) # Extract 32-bit value
integers.append(int.from_bytes(binary_data[i:i + 2], byteorder='big') & 0b111111111111) # Extract 32-bit value
return integers
@ -53,7 +53,7 @@ def get_schedule(plug_id):
# Ensure integer is in 12-bit range
integer &= 0b111111111111
# Convert to bytes and append
yield integer.to_bytes(2) # 2 bytes per integer
yield integer.to_bytes(2, byteorder='big') # 2 bytes per integer
# Return as a binary stream
return Response(ints_to_binary_stream(schedule), status=200, content_type='application/octet-stream')

View File

@ -1,3 +1,4 @@
#include <sys/_stdint.h>
#define A00 0b000000000000
#define A60 0b111111111111
@ -13,7 +14,7 @@
// one hour is represented by 1 unsigned int
// each bit of the hour represent one BI_MINUTE.
// the output of the scheduler is ON if one bit is set, OFF otherwise.
unsigned int scheduler_1_default[24] = {
uint16_t scheduler_1_default[24] = {
EVERY_2_INV,
EVERY_2,
EVERY_2_INV,
@ -39,7 +40,7 @@ unsigned int scheduler_1_default[24] = {
EVERY_2_INV,
EVERY_2,
};
unsigned int scheduler_default_deactivate[24] = {
uint16_t scheduler_default_deactivate[24] = {
A00,
A00,
A00,
@ -65,7 +66,7 @@ unsigned int scheduler_default_deactivate[24] = {
A00,
A00,
};
unsigned int scheduler_2_default[24] = {
uint16_t scheduler_2_default[24] = {
EVERY_2,
EVERY_2_INV,
EVERY_2,