U8g2 in combination with DCS-BIOS and translation the info send by DCS-BIOS #1458
Unanswered
eaglewen2020
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
below my Arduino script to show the DED-info of the DCS-F16 via DCS-BIOS. It's working fine already meaning that the information of the DED-display of the Sim is shown on the display.
My problem is that some special characters like the degree sign (char(167)) is sent by DCS-BIOS as a little o. So the array includes "o" instead of the degree symbol. The degree sign is used for instance to show the heading of the airplane like 045° which is of course better then 045o.
My thougt was to iterate over the array and check for an "o", if this is the case I"m translating this to char(176).
The problem is that when I do this the line isn't shown anymore on the display, the line to show seems to be empty after translation or is of the wrong data type.
When I use a small script to print it to Serial.write the degree symbol is printed (see code below).
The script below is the working one...my different tests have comments and the result of it. I only have done the translation for the first line (function onDedLine1Change), the rest will follow if the translation is working.
`#include <Arduino.h>
#include <U8g2lib.h>
#define DCSBIOS_DEFAULT_SERIAL
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#include "DcsBios.h"
//declare display interface
U8G2_SSD1322_NHD_256X64_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=/ 52, / data=/ 51, / cs=/ 53, / dc=/ 9, / reset=*/ 8);
//char DEDLine1[25]; //Tried it also with a buffered array instead of char*, no luck
String DEDLine1String="tt"; //when Arduin is restarted the display shows "tt"..as soon as DEDLine1 is refreshed the tt is gone so the function onDedLine1Change is called
char* DEDLine1;
char* DEDLine2;
char* DEDLine3;
char* DEDLine4;
char* DEDLine5;
long previousMillis = 0;
long interval = 1000; //refresh display each second
void onDedLine1Change(char newValue1[25]) {
DEDLine1String="";
/* //This isn't working in combination with u8g2.drawStr(20,10,DEDLine1String.c_str()) in the loop section
for (byte i = 0; i < sizeof(newValue1) - 1; i++) {
switch (newValue1[i]) {
case 'o':
DEDLine1String+=char(167);
break;
case 'a':
DEDLine1String+=char(181);
break;
default:
DEDLine1String+=String(newValue1[i]);
}
}*/
DEDLine1=newValue1; //This is working but doesn't include the translation
//DEDLine1String="123456789012345678901234"; is working when I use it in combination with u8g2.drawStr(20,10,DEDLine1String.c_str()) in the loop section
}
DcsBios::StringBuffer<25> dedLine1Buffer(0x44fc, onDedLine1Change);
void onDedLine2Change(char newValue2[25]) {
DEDLine2=newValue2;
}
DcsBios::StringBuffer<25> dedLine2Buffer(0x4516, onDedLine2Change);
void onDedLine3Change(char newValue3[25]) {
DEDLine3=newValue3;
}
DcsBios::StringBuffer<25> dedLine3Buffer(0x4530, onDedLine3Change);
void onDedLine4Change(char newValue4[25]) {
DEDLine4=newValue4;
}
DcsBios::StringBuffer<25> dedLine4Buffer(0x454a, onDedLine4Change);
void onDedLine5Change(char newValue5[25]) {
DEDLine5=newValue5;
}
DcsBios::StringBuffer<25> dedLine5Buffer(0x4564, onDedLine5Change);
void setup() {
u8g2.begin();
u8g2.setFont(u8g2_font_7x14B_tf);
DcsBios::setup();
}
void loop() {
DcsBios::loop();
unsigned long currentMillis = millis();//time elapsed
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
u8g2.clearBuffer();
}
}
`
The small script I used for testing the concept of the translations is like this:
`char myStr[] = "this is a 31oC test";
void setup() {
Serial.begin(9600);
}
void loop() {
for (byte i = 0; i < sizeof(myStr) - 1; i++) {
switch (myStr[i]) {
case 'o':
myStr[i]=char(176);
break;
case 'i':
myStr[i]=char(33);
break;
}
Serial.write(myStr[i]);
}
Serial.println();
delay(5000);
}`
Result is th!s !s a 31ºC test
I hope someone can help me with this.
Thanks in advance
Werner
Beta Was this translation helpful? Give feedback.
All reactions