send rref data to salve and display

This commit is contained in:
2025-05-17 19:57:15 +02:00
parent d8fe68679a
commit 107297f162
3 changed files with 124 additions and 73 deletions

View File

@ -20,7 +20,7 @@
#define VALUE_BUFFER 30
#define SKIP_ROTARY_INPUTS 50
#define SKIP_ROTARY_INPUTS 40
#define INTERNAL_STATE_UNKNOWN 0
#define INTERNAL_STATE_INITIALIZED 1
@ -160,6 +160,26 @@ void i2cReceive(int bytes) {
for (int i = 0; i < 3 && Wire.available(); i++) {
name2[i] = Wire.read();
}
} else if (data == DATA_BYTE) {
// next byte will be trigger bit
byte triggerBit = Wire.read();
// next byte will be length of data
byte dataLength = Wire.read();
// next byte(s) will be the data itself
char dataBytes[dataLength];
for (int i = 0; i < dataLength && Wire.available(); i++) {
dataBytes[i] = Wire.read();
}
if (triggerBit & TRIGGER_BIT_1) {
updateDisplay1(dataBytes, dataLength);
} else if (triggerBit & TRIGGER_BIT_2) {
updateDisplay2(dataBytes, dataLength);
} else {
Serial.println("Unknown trigger bit");
}
} else {
// not yet implemented?
Serial.println("Received unknown");
@ -177,6 +197,35 @@ void displayTestScreen(Adafruit_SSD1306 display) {
display.display();
}
void updateDisplay1(char *data, byte len) {
updateDisplay(&display1, name1, data, len);
}
void updateDisplay2(char *data, byte len) {
updateDisplay(&display2, name2, data, len);
}
void updateDisplay(Adafruit_SSD1306 *display, char *name, char *data, byte len) {
display->clearDisplay();
display->setTextColor(SSD1306_WHITE); // Draw white text
display->cp437(true); // Use full 256 char 'Code Page 437' font
display->setTextSize(1); // Normal 1:1 pixel scale
display->setCursor(0, 8); // Start at top-left corner
display->setFont(NULL);
display->write(name[0]);
display->write(name[1]);
display->write(name[2]);
display->setTextSize(2); // Normal 1:1 pixel scale
display->setCursor(0, 56); // Start at top-left corner
display->setFont(&FreeMonoBold18pt7b);
for (byte i = 0; i < len; i++) {
display->write(data[i]);
}
display->display();
}
uint8_t address = I2C_ADDRESS_START;
void setup() {
// https://support.arduino.cc/hc/en-us/articles/4839084114460-If-your-board-runs-the-sketch-twice
@ -219,46 +268,11 @@ void setup() {
displayTestScreen(display2);
// make sure, test screen is at least displayed 2 seconds
delay(2000);
updateDisplay1("---", 3);
updateDisplay2("---", 3);
}
void loop() {
display1.clearDisplay();
display1.setTextColor(SSD1306_WHITE); // Draw white text
display1.cp437(true); // Use full 256 char 'Code Page 437' font
display1.setTextSize(1); // Normal 1:1 pixel scale
display1.setCursor(0, 8); // Start at top-left corner
display1.setFont(NULL);
display1.write(name1[0]);
display1.write(name1[1]);
display1.write(name1[2]);
display1.setTextSize(2); // Normal 1:1 pixel scale
display1.setCursor(0, 56); // Start at top-left corner
display1.setFont(&FreeMonoBold18pt7b);
display1.write('8');
display1.write('9');
display1.write('0');
display1.display();
display2.clearDisplay();
display2.setTextColor(SSD1306_WHITE); // Draw white text
display2.cp437(true); // Use full 256 char 'Code Page 437' font
display2.setTextSize(1); // Normal 1:1 pixel scale
display2.setCursor(0, 8); // Start at top-left corner
display2.setFont(NULL);
display2.write(name2[0]);
display2.write(name2[1]);
display2.write(name2[2]);
display2.setTextSize(2); // Normal 1:1 pixel scale
display2.setCursor(0, 56); // Start at top-left corner
display2.setFont(&FreeMonoBold18pt7b);
display2.write('1');
display2.write('2');
display2.write('3');
display2.display();
delay(1000);
}