separate display control from knobs

This commit is contained in:
2024-02-01 23:55:25 +01:00
parent 40bdd23478
commit e15547ce65
3 changed files with 127 additions and 44 deletions

View File

@ -1,5 +1,3 @@
#include <U8g2lib.h>
#include <MCP23017.h>
#include <ArduinoMqttClient.h>
#include <Ethernet.h>
@ -30,7 +28,6 @@ MqttClient mqttClient(client);
byte lastRotInput_1A;
MCP23017 mcp1 = MCP23017(ROT_ADDR_1, 100);
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // High speed I2C
void setup() {
// put your setup code here, to run once:
@ -49,7 +46,7 @@ void setup() {
// print your local IP address:
Serial.println(Ethernet.localIP());
mqttClient.setUsernamePassword(MQTT_USER, MQTT_PASS);
mqttClient.setUsernamePassword(MQTT_USER2, MQTT_PASS);
if (!mqttClient.connect(broker, port)) {
Serial.print("MQTT connection failed! Error code = ");
@ -75,15 +72,6 @@ void setup() {
mcp1.setPortPullUp(0b00000000, ROT_PORT_A);
lastRotInput_1A = mcp1.getPort(ROT_PORT_A);
u8g2.begin();
mqttClient.beginMessage("/xplane/meta/rref");
mqttClient.print("001 010 sim/cockpit/autopilot/heading_mag");
mqttClient.endMessage();
mqttClient.beginMessage("/xplane/meta/rref");
mqttClient.print("002 010 sim/cockpit/autopilot/airspeed");
mqttClient.endMessage();
}
bool isBitDown(byte input, byte reference) {
@ -149,37 +137,6 @@ void loop() {
}
void onMqttMessage(int messageSize) {
if (mqttClient.messageTopic() == "/xplane/rref/1") {
char buf[3] = "";
char c = '\0';
for (int i = 0; i < 3 && mqttClient.available() && c != '.'; i++) {
c = (char)mqttClient.read();
if (c != '.') {
buf[i] = c;
}
}
if (buf[1] == '\0') {
buf[1] = buf[0];
buf[0] = '0';
}
if (buf[2] == '\0') {
buf[2] = buf[1];
buf[1] = buf[0];
buf[0] = '0';
}
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_fub11_tf);
u8g2.drawStr(0, 11, "HDG");
u8g2.setFont(u8g2_font_fub42_tn);
u8g2.drawStr(10, 63, buf);
u8g2.sendBuffer();
}
// TODO: speed display
// // we received a message, print out the topic and contents
// Serial.println("Received a message with topic '");
// Serial.print(mqttClient.messageTopic());