Categories
Uri_ba's pit

DED Adventures – Part 3

now that we covered the basics, and we know how to run our FuelFlow, we can continue our dive into the project. DED screen was chosen as it is the closest I could get to the real thing from the selection of avaiable hardware. I chose the BuyDIsplay 2.8″ OLED Yellow-On-Black another option would be the New Haven 2.8″ OLED Yellow-On-Black they both use the same u8glib constructor and are interchangeable (different wiring is required of course).

Let’s look back at the DED in the “flightData.h” file.

 //DED Lines
    char DEDLines[5][26]; //25 usable chars
    char Invert[5][26]; //25 usable chars

in C a string is a char array ending with null character (ASCII 0)
so we actually have 5 lines of 25 chars ending with a 0 (from now it will be referred as “\0”)
DED is actually 5*24, so I don’t know why the extra \0, so we can safely only transmit the 24 bytes.

in Part 1 you saw a video with an early code, in that code I’ve sent the two arrays and drew them with the arduino, that required multiple passes on both arrays, costing many CPU cycles. I’ve decided to do the manipulation on the computer side, sending only one ANSI array. However that required a special font to be loaded onto the Arduino/Display. The font was drawn as TTF, re-positioned to correct ANSI position, and converted to the Format u8glib can use.
I’ve created the font using fontstruct and it’s available here

I ofcourse had to write the code to normlize the entire thing

        private string NormalizeLine(string Disp, string Inv)
        {
            char[] NormLine = new char[25];
            for (short j = 0; j < Disp.Length; j++)
            {
                if (Inv[j] == 2)
                {
                    if (char.IsLetter(Disp[j]))
                    {
                        NormLine[j] = char.ToLower((Disp[j]));
                    }
                    else if (Disp[j] == 1)
                    {
                        NormLine[j] = (char)192;
                    }
                    else if (Disp[j] == 2)
                    {
                        NormLine[j] = (char)170;
                    }
                    else if (Disp[j] == 3)
                    {
                        NormLine[j] = (char)223;
                    }
                    else if (Disp[j] == '~')
                    {
                        NormLine[j] = (char)252;
                    }
                    else
                    {
                        NormLine[j] = (char)(Disp[j] + 128);
                    }
                }
                else
                {
                    if (Disp[j] == 1)
                    {
                        NormLine[j] = '@';
                    }
                    else if (Disp[j] == 2)
                    {
                        NormLine[j] = '*';
                    }
                    else if (Disp[j] == 3)
                    {
                        NormLine[j] = '_';
                    }
                    else if (Disp[j] == '~')
                    {
                        NormLine[j] = '|';
                    }
                    else
                    {
                        NormLine[j] = Disp[j];
                    }
                }

            }
            return new string(NormLine);
        }

The arduino side is very simple, so I will not elaborate much

char DED[5][26] = {{ 0 }};

void  readDED() {
  for (short i = 0; i < 5; i++) {
    Serial.print("D");
    Serial.print(i);
    Serial.flush();
    Serial.readBytes(DED[i], 25);
  }
}

void drawDED() {
  /// Begin Picture loop ///
  dedDisp.firstPage();
  do {
    for (unsigned short i = 0; i < 5; i++ ) {
      dedDisp.drawStr(DED_H_CONST, i * DED_CHAR_H + DED_V_CONST, DED[i]);
    }
  } while ( dedDisp.nextPage() );
  /// End Picture loop ///
}

Combining this, with the code we saw in the previous part, gives us a DED and an animated FuelFlow. in the video you can also see the indexers modeled by 6 leds, but that code uses a different logic, and will be covered in a later post.

BTW – The code shown here is pretty old, so there is a bug in the FuelFlow code used here, the snippet in Post 2 is already corrected (one of the benefits of starting a blog late)

Enjoy! 🙂

Leave a Reply