Skip to content

Commit

Permalink
Apply pre-commit on all files
Browse files Browse the repository at this point in the history
  • Loading branch information
iMicknl committed Jun 8, 2024
1 parent 35e9cf9 commit 4e212b0
Show file tree
Hide file tree
Showing 14 changed files with 343 additions and 391 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ In order to connect the control box to a Raspberry Pi and ESP32/ESP8266 chip I u
<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->

If your control panel is missing, feel free to [create an issue](https://github.com/iMicknl/LoctekMotion_IoT/issues/new) to discuss the possibilities or create a PR to add your research to this overview.
If your control panel is missing, feel free to [create an issue](https://github.com/iMicknl/LoctekMotion_IoT/issues/new) to discuss the possibilities or create a PR to add your research to this overview.

#### HS13B-1

- **Desk model**: Flexispot E7
- **Tested with control box**: CB38M2J(IB)-1
- **Source**: Printed on the PCB of the control box.

| RJ45 pin | Name | Original Cable Color | Ethernet cable color (T568B) |
| -------- | ---------- | -------------------- | ---------------------------- |
| 8 | RESET | Brown | White-Orange |
Expand All @@ -75,7 +75,7 @@ Note that RX and TX is defined like this on receiver (control panel) side. So RX
- **Desk model**: Flexispot EK5
- **Tested with control box**: CB38M2B(IB)-1
- **Source**: Printed on the PCB of the control box.

| RJ45 pin | Name | Original Cable Color | Ethernet cable color (T568B) |
| -------- | ---------- | -------------------- | ---------------------------- |
| 8 | RESET SWIM | Brown | White-Orange |
Expand All @@ -94,15 +94,15 @@ Note that RX and TX is defined like this on receiver (control panel) side. So RX
- **Desk model**: Flexispot E5B
- **Tested with control box**: CB38M2A-1
- **Source**: [nv1t/standing-desk-interceptor](https://github.com/nv1t/standing-desk-interceptor)
| RJ45 pin | Name |
| -------- | --------- |
| 8 | +5V (VDD) |
| 7 | GND |

| RJ45 pin | Name |
| -------- | --------- |
| 8 | +5V (VDD) |
| 7 | GND |
| 6 | TX |
| 5 | RX |
| 5 | RX |
| 4 | PIN 20 |
| 3 | (unknown) |
| 3 | (unknown) |
| 2 | SWIM |
| 1 | RES |

Expand All @@ -112,7 +112,7 @@ Other control panels / control boxes could be supported in the same way, but you

### Retrieve current height

Based upon the great work of [minifloat](https://www.mikrocontroller.net/topic/493524), it became clear that the control panel utilises a [7-segment display](https://en.wikipedia.org/wiki/Seven-segment_display). Fortunately, this is very common in such devices and thus there is a lot of [documentation](https://lastminuteengineers.com/seven-segment-arduino-tutorial/) on this topic.
Based upon the great work of [minifloat](https://www.mikrocontroller.net/topic/493524), it became clear that the control panel utilises a [7-segment display](https://en.wikipedia.org/wiki/Seven-segment_display). Fortunately, this is very common in such devices and thus there is a lot of [documentation](https://lastminuteengineers.com/seven-segment-arduino-tutorial/) on this topic.

The control box sends the height as 4-bit hexadecimal, which is decoded in the control panel to drive the 7-segment display. The second number on the display also supports an optional decimal point ("8 segment").

Expand Down Expand Up @@ -151,7 +151,7 @@ All bytes combined will become the command to send to the control box. See the [
While working on this project, I found out that I am not the only one with this idea. There are a few repositories on GitHub with great research which helped me kickstart this project. ❤️

- [grssmnn / ha-flexispot-standing-desk](https://github.com/grssmnn/ha-flexispot-standing-desk) - Home Assistant integration via MQTT (micropython)
- [Dude88 / loctek_IOT_box](https://github.com/Dude88/loctek_IOT_box) - Arduino code to control via Alexa and MQTT
- [Dude88 / loctek_IOT_box](https://github.com/Dude88/loctek_IOT_box) - Arduino code to control via Alexa and MQTT
- [nv1t / standing-desk-interceptor](https://github.com/nv1t/standing-desk-interceptor) - Research on intercepting commands from Flexispot desks
- [VinzSpring / LoctekReverseengineering](https://github.com/VinzSpring/LoctekReverseengineering#assumptions) - Research and Python samples

Expand Down
40 changes: 18 additions & 22 deletions archive/arduino/flexispot_e8.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@
#include <SoftwareSerial.h>

#define displayPin20 4 // D2 GPIO4
#define rxPin 12 // D5 GPIO12
#define txPin 14 // D6 GPIO14
#define rxPin 12 // D5 GPIO12
#define txPin 14 // D6 GPIO14

SoftwareSerial sSerial(rxPin, txPin); // RX, TX
byte history[2];

// Supported Commands
const byte wakeup[] = { 0x9b, 0x06, 0x02, 0x00, 0x00, 0x6c, 0xa1, 0x9d };
const byte command_up[] = { 0x9b, 0x06, 0x02, 0x01, 0x00, 0xfc, 0xa0, 0x9d };
const byte command_down[] = { 0x9b, 0x06, 0x02, 0x02, 0x00, 0x0c, 0xa0, 0x9d };
const byte command_m[] = {0x9b, 0x06, 0x02, 0x20, 0x00, 0xac, 0xb8, 0x9d };
const byte command_preset_1[] = { 0x9b, 0x06, 0x02, 0x04, 0x00, 0xac, 0xa3, 0x9d };
const byte command_preset_2[] = { 0x9b, 0x06, 0x02, 0x08, 0x00, 0xac, 0xa6, 0x9d };
const byte command_preset_3[] = { 0x9b, 0x06, 0x02, 0x10, 0x00, 0xac, 0xac, 0x9d };
const byte command_preset_4[] = { 0x9b, 0x06, 0x02, 0x00, 0x01, 0xac, 0x60, 0x9d };

const byte wakeup[] = {0x9b, 0x06, 0x02, 0x00, 0x00, 0x6c, 0xa1, 0x9d};
const byte command_up[] = {0x9b, 0x06, 0x02, 0x01, 0x00, 0xfc, 0xa0, 0x9d};
const byte command_down[] = {0x9b, 0x06, 0x02, 0x02, 0x00, 0x0c, 0xa0, 0x9d};
const byte command_m[] = {0x9b, 0x06, 0x02, 0x20, 0x00, 0xac, 0xb8, 0x9d};
const byte command_preset_1[] = {0x9b, 0x06, 0x02, 0x04,
0x00, 0xac, 0xa3, 0x9d};
const byte command_preset_2[] = {0x9b, 0x06, 0x02, 0x08,
0x00, 0xac, 0xa6, 0x9d};
const byte command_preset_3[] = {0x9b, 0x06, 0x02, 0x10,
0x00, 0xac, 0xac, 0x9d};
const byte command_preset_4[] = {0x9b, 0x06, 0x02, 0x00,
0x01, 0xac, 0x60, 0x9d};

void setup() {
Serial.begin(115200); // Debug serial
sSerial.begin(9600); // Flexispot E8
Serial.begin(115200); // Debug serial
sSerial.begin(9600); // Flexispot E8

pinMode(displayPin20, OUTPUT);
digitalWrite(displayPin20, LOW);
Expand All @@ -33,7 +36,6 @@ void setup() {
demo();
}


void demo() {

// Calls sit-preset and waits 20 seconds
Expand All @@ -49,7 +51,6 @@ void demo() {
wake();
}


void turnon() {
// Turn desk in operating mode by setting controller pin20 to HIGH
Serial.println("sending turn on command");
Expand All @@ -58,7 +59,6 @@ void turnon() {
digitalWrite(displayPin20, LOW);
}


void wake() {
turnon();

Expand All @@ -70,7 +70,6 @@ void wake() {
sSerial.enableTx(false);
}


void sit() {
turnon();

Expand All @@ -82,7 +81,6 @@ void sit() {
sSerial.enableTx(false);
}


void stand() {
turnon();

Expand All @@ -94,10 +92,8 @@ void stand() {
sSerial.enableTx(false);
}


void loop() {
while (sSerial.available())
{
while (sSerial.available()) {
unsigned long in = sSerial.read();

// Start of packet
Expand All @@ -121,4 +117,4 @@ void loop() {
Serial.print(in, HEX);
Serial.print(" ");
}
}
}
74 changes: 38 additions & 36 deletions archive/arduino/flexispot_ek5.ino
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
#include <SoftwareSerial.h>

#define displayPin20 4 // D2 GPIO4
#define rxPin 12 // D5 GPIO12
#define txPin 14 // D6 GPIO14
#define rxPin 12 // D5 GPIO12
#define txPin 14 // D6 GPIO14

SoftwareSerial sSerial(rxPin, txPin); // RX, TX
byte history[2];

// Supported Commands
unsigned long wakeup[] = { 0x9b, 0x06, 0x02, 0x00, 0x00, 0x6c, 0xa1, 0x9d };
unsigned long command_up[] = { 0x9b, 0x06, 0x02, 0x01, 0x00, 0xfc, 0xa0, 0x9d };
unsigned long command_down[] = { 0x9b, 0x06, 0x02, 0x02, 0x00, 0x0c, 0xa0, 0x9d };
unsigned long command_m[] = {0x9b, 0x06, 0x02, 0x20, 0x00, 0xac, 0xb8, 0x9d };
unsigned long command_preset_1[] = { 0x9b, 0x06, 0x02, 0x04, 0x00, 0xac, 0xa3, 0x9d };
unsigned long command_preset_2[] = { 0x9b, 0x06, 0x02, 0x08, 0x00, 0xac, 0xa6, 0x9d };
unsigned long command_preset_3[] = { 0x9b, 0x06, 0x02, 0x10, 0x00, 0xac, 0xac, 0x9d };
unsigned long command_preset_4[] = { 0x9b, 0x06, 0x02, 0x00, 0x01, 0xac, 0x60, 0x9d };

unsigned long wakeup[] = {0x9b, 0x06, 0x02, 0x00, 0x00, 0x6c, 0xa1, 0x9d};
unsigned long command_up[] = {0x9b, 0x06, 0x02, 0x01, 0x00, 0xfc, 0xa0, 0x9d};
unsigned long command_down[] = {0x9b, 0x06, 0x02, 0x02, 0x00, 0x0c, 0xa0, 0x9d};
unsigned long command_m[] = {0x9b, 0x06, 0x02, 0x20, 0x00, 0xac, 0xb8, 0x9d};
unsigned long command_preset_1[] = {0x9b, 0x06, 0x02, 0x04,
0x00, 0xac, 0xa3, 0x9d};
unsigned long command_preset_2[] = {0x9b, 0x06, 0x02, 0x08,
0x00, 0xac, 0xa6, 0x9d};
unsigned long command_preset_3[] = {0x9b, 0x06, 0x02, 0x10,
0x00, 0xac, 0xac, 0x9d};
unsigned long command_preset_4[] = {0x9b, 0x06, 0x02, 0x00,
0x01, 0xac, 0x60, 0x9d};

void setup() {
Serial.begin(115200); // Debug serial
sSerial.begin(9600); // Flexispot EK5
Serial.begin(115200); // Debug serial
sSerial.begin(9600); // Flexispot EK5

// Turn desk in operating mode by setting controller pin20 to HIGH
// This will allow us to send commands and to receive the current height
Serial.println("Turn Operation Mode on");
Expand All @@ -37,29 +40,28 @@ void setup() {
}

void loop() {
while (sSerial.available())
{
unsigned long in = sSerial.read();

// Start of packet
if(in == 0x9b) {
Serial.println();
}

// Second byte defines the message length
if(history[0] == 0x9b) {
int msg_len = (int)in;
Serial.print("(LENGTH:");
Serial.print(in);
Serial.print(")");
}
while (sSerial.available()) {
unsigned long in = sSerial.read();

// Get package length (second byte)
history[1] = history[0];
history[0] = in;
// Start of packet
if (in == 0x9b) {
Serial.println();
}

// Print hex for debug
Serial.print(in, HEX);
Serial.print(" ");
// Second byte defines the message length
if (history[0] == 0x9b) {
int msg_len = (int)in;
Serial.print("(LENGTH:");
Serial.print(in);
Serial.print(")");
}

// Get package length (second byte)
history[1] = history[0];
history[0] = in;

// Print hex for debug
Serial.print(in, HEX);
Serial.print(" ");
}
}
10 changes: 5 additions & 5 deletions archive/arduino/height_demo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#define displayPin20 4 // D2 GPIO4
#define rxPin 12 // D5 GPIO12
#define txPin 14 // D6 GPIO14
#define txPin 14 // D6 GPIO14

SoftwareSerial sSerial(rxPin, txPin); // RX, TX
int packet_pos = 0; //position in packet
Expand Down Expand Up @@ -107,11 +107,11 @@ void DecodeHeight()
if(height != h)
{
height = h;

Serial.print("Height: ");
Serial.print(height);
Serial.println();
}
}
}
int DecodeNumber(byte in)
{
Expand Down Expand Up @@ -188,7 +188,7 @@ void loop()
{
while (sSerial.available())
{
unsigned long in = sSerial.read();
unsigned long in = sSerial.read();

// Start of packet
if(in == 0x9B) //start of packet
Expand All @@ -211,6 +211,6 @@ void loop()
else if(packet_pos == 2) //position 2 = type of packet
packet_type = (int)in;
else if(packet_type == 18 && packet_pos >= 3 && packet_pos <= 5) //if packet type is height (0x12) and position is 3-5
message_height[packet_pos - 3] = in;
message_height[packet_pos - 3] = in;
}
}
14 changes: 7 additions & 7 deletions archive/esphome/Flexispot_E7_MQTT_control.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ wifi:
ssid: "${device_name} Fallback Hotspot"
password: !secret ap_fallback_password

# Enable MQTT communication. ReadOnly Variables are published immediatly
# Enable MQTT communication. ReadOnly Variables are published immediatly

mqtt:
topic_prefix: Flexispot
Expand All @@ -32,17 +32,17 @@ mqtt:
port: 1883
username: !secret mqtt_username
password: !secret mqtt_password

# OnMessage is used for MQTT control
# Only a short
# Only a short

on_message:
- topic: Flexispot/Sit/command
then:
- switch.turn_on: switch_sit
- topic: Flexispot/Stand/command
then:
- switch.turn_on: switch_stand
- switch.turn_on: switch_stand
- topic: Flexispot/Preset1/command
then:
- switch.turn_on: switch_preset1
Expand Down Expand Up @@ -183,14 +183,14 @@ cover:
- logger.log: "Executing up command"
- switch.turn_on: switch_up
- delay: 10ms

# Move desk down
close_action:
- while:
condition:
sensor.in_range:
id: desk_height
above: ${min_height}
above: ${min_height}
then:
- logger.log: "Executing down command"
- switch.turn_on: switch_down
Expand Down
Loading

0 comments on commit 4e212b0

Please sign in to comment.