Jump to content

Recommended Posts

Okay everyone thanks to @Middlefart for his main code, my wife for her expertise, helping me with this code for everyone looking for the F-16 Total Fuel gauge.  All you need to do is add your code for your motors for the FWD/AFT pointers and your backlighting for your gauge. Easy and done!

Hope this helps everyone!! This does work great on my seeeduino XIAO controller (DEFAULT_SERIAL only). Mega, nano, etc will work with IRQ_SERIAL.

 

/*
  F-16 Total Fuel Gauge
  Thanks to: Middlefart (Original code), Fusion and Fusion's Wife (software engineer)
  Code is for the 128x32 oled i2c display.
  All you have to do is add your motor pins and guage backlight pins if desired.
  Hope this helps others!
  DCS-BIOS has made things far easier for DCS than software made to drive simulator 
  components in FalconBMS. Glad to be apart of the DCS world.

  Matt "Fusion" G.
*/

//#define DCSBIOS_DEFAULT_SERIAL
#define DCSBIOS_DEFAULT_SERIAL
#include "DcsBios.h"

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "characters.h"
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
  

int AB;
float Value1;
float Value2;
float Value3;
float Total;
unsigned long time = 0;
unsigned int i = 0;


//Comment for barometric pressure
    #define ALTIMETER
    int updateInterval = 100; //the number of milliseconds between updates
    struct scrollDigit {
      int digit; //The digit that is displayed
      int y; // The vertical position of the digit
    };
    
    struct disp {
      Adafruit_SSD1306 display;
      int width;
      int numberOfDigits;
      scrollDigit digits[5];
    };
//disp oled = {Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET), 24, 5, {{0,0},{0,0},{0,0},{0,0},{0,0}}};
disp oled = {Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET), 16, 5, {{0,0},{0,0},{0,0},{0,0},{0,0}}};
void setup() {
  if(!oled.display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
    for(;;); // Don't proceed, loop forever
  }
  DcsBios::setup();

}

void UpdateDisplay()
{
  oled.display.clearDisplay();
  for (int i = 0; i < oled.numberOfDigits; i++)
  {  
    printScrollingDigit(oled.digits[i].digit, oled.width, oled.digits[i].y, i + 1, &oled);    
  }
  //Clear the area below the the numbers if we are using the small font
  if (oled.width == 16)
  {
    oled.display.fillRect(0, 30, 127, 7, BLACK);
  }
  
  oled.display.display();
}

int YPos()
{
  return ((oled.width + 9) * -1);
}
void printScrollingDigit(int digit, int width, int y, int pos, disp *oled)
{
  int x = (width * pos) - width + pos + 30;
  y +=5;
  switch (digit)
        {
      case -1: oled->display.drawBitmap(x, y, c16_0, 16, 24, 1); oled->display.drawBitmap(x, y+25, c16_1, 16, 24, 1); break;
      case 1: oled->display.drawBitmap(x, y, c16_1, 16, 24, 1); oled->display.drawBitmap(x, y+25, c16_2, 16, 24, 1); break;
      case 2: oled->display.drawBitmap(x, y, c16_2, 16, 24, 1); oled->display.drawBitmap(x, y+25, c16_3, 16, 24, 1); break;
      case 3: oled->display.drawBitmap(x, y, c16_3, 16, 24, 1); oled->display.drawBitmap(x, y+25, c16_4, 16, 24, 1); break;
      case 4: oled->display.drawBitmap(x, y, c16_4, 16, 24, 1); oled->display.drawBitmap(x, y+25, c16_5, 16, 24, 1); break;
      case 5: oled->display.drawBitmap(x, y, c16_5, 16, 24, 1); oled->display.drawBitmap(x, y+25, c16_6, 16, 24, 1); break;
      case 6: oled->display.drawBitmap(x, y, c16_6, 16, 24, 1); oled->display.drawBitmap(x, y+25, c16_7, 16, 24, 1); break;
      case 7: oled->display.drawBitmap(x, y, c16_7, 16, 24, 1); oled->display.drawBitmap(x, y+25, c16_8, 16, 24, 1); break;
      case 8: oled->display.drawBitmap(x, y, c16_8, 16, 24, 1); oled->display.drawBitmap(x, y+25, c16_9, 16, 24, 1); break;
      case 9: oled->display.drawBitmap(x, y, c16_9, 16, 24, 1); oled->display.drawBitmap(x, y+25, c16_0, 16, 24, 1); break;
      default: 
        if (pos < 3) {
          oled->display.drawBitmap(x, y, c16_0, 16, 24, 1); oled->display.drawBitmap(x, y+25, c16_1, 16, 24, 1); 
        } else {
          oled->display.drawBitmap(x, y, c16_0, 16, 24, 1); oled->display.drawBitmap(x, y+25, c16_0, 16, 24, 1);   
        }
        break;
    }
}
void onFueltotalizer10kChange(unsigned int newValue)
  {
    unsigned int mappedValue = newValue / 6553;
    unsigned int y = map(newValue, mappedValue * 6553, mappedValue * 6553 + 6553, 0, YPos());

    if (mappedValue == 0)
    {
      mappedValue = -1;
    }
    #ifdef TEST
      Serial.println(mappedValue);
    #endif
    oled.digits[0].digit = mappedValue;
    oled.digits[0].y = y;
  }
  
  void onFueltotalizer1kChange(unsigned int newValue)
  {
    unsigned int mappedValue = newValue / 6553;
    unsigned int y = map(newValue, mappedValue * 6553, mappedValue * 6553 + 6553, 0, YPos());
  
    oled.digits[1].digit = mappedValue;
    oled.digits[1].y = y;
  }
  
  void onFueltotalizer100Change(unsigned int newValue)
  {
    unsigned int mappedValue = newValue / 6553;
    unsigned int y = map(newValue, mappedValue * 6553, mappedValue * 6553 + 6553, 0, YPos());
  
    oled.digits[2].digit = mappedValue;
    oled.digits[2].y = y;

    oled.digits[3].digit = 0;
    oled.digits[3].y = y;

    oled.digits[4].digit = 0;
    oled.digits[4].y = y;
  }
DcsBios::IntegerBuffer fueltotalizer10kBuffer(0x44e4, 0xffff, 0, onFueltotalizer10kChange);
DcsBios::IntegerBuffer fueltotalizer1kBuffer(0x44e6, 0xffff, 0, onFueltotalizer1kChange);
DcsBios::IntegerBuffer fueltotalizer100Buffer(0x44e8, 0xffff, 0, onFueltotalizer100Change);

 




void loop() {
DcsBios::loop();

  time = millis();

  if (time % updateInterval == 0)
  {
    UpdateDisplay();
  }
  
}

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...