Skip to content

Commit

Permalink
Implemented voltage display
Browse files Browse the repository at this point in the history
  • Loading branch information
flyandi committed Aug 4, 2015
1 parent d510224 commit e8a2b9f
Show file tree
Hide file tree
Showing 21 changed files with 128 additions and 59 deletions.
Binary file modified 3d/box/micro-bitsyosd.skp
Binary file not shown.
Binary file modified 3d/box/micro-bitsyosd~.skp
Binary file not shown.
18 changes: 17 additions & 1 deletion bitsyosd/bitsyosd.ino
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ void Update() {

// Update the GPS Information
UpdateGPS();

// Update Values
UpdateValues();

// Update the Display
UpdateDisplay();
Expand Down Expand Up @@ -305,7 +308,20 @@ void UpdateDisplay() {

// Permanent GPS Display
DrawStatus(LAYOUT_GPS_X, LAYOUT_GPS_Y, true, SYMBOL_GPS);
DrawOneSmallValue(LAYOUT_GPS_X + 1, LAYOUT_GPS_Y, gpsdata.Satellites > 9 ? 9 : gpsdata.Satellites);
DrawOneSmallValue(LAYOUT_GPS_X + 1, LAYOUT_GPS_Y, gpsdata.Satellites > 9 ? 9 : gpsdata.Satellites);

// Permanent Voltage Display
#ifdef SHOW_VOLTAGE

if(SHOW_VOLTAGE == 1 || SHOW_VOLTAGE == 3) {
DrawBattery(LAYOUT_BATTERY1_X, LAYOUT_BATTERY1_Y, runtime.voltage1, TYPE_BATTERY1);
}

if(SHOW_VOLTAGE == 2 || SHOW_VOLTAGE == 3) {
DrawBattery(LAYOUT_BATTERY2_X, LAYOUT_BATTERY2_Y, runtime.voltage2, TYPE_BATTERY2);
}

#endif

// Check GPS Status
if(gpsdata.Status >= GPS_ACCURACY && gpsdata.Satellites >= GPS_REQUIRED_SAT) {
Expand Down
47 changes: 37 additions & 10 deletions bitsyosd/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ tweak to your likening.
* Uncomment one of the options below. If you want to test the OSD without GPS, use the SIM parser.
*/

#define GPS_PARSER_NEMA
//#define GPS_PARSER_NEMA
//#define GPS_PARSER_DJI
//#define GPS_PARSER_UBLOX
//#define GPS_PARSER_SIM
#define GPS_PARSER_SIM


/**
Expand Down Expand Up @@ -167,6 +167,9 @@ tweak to your likening.
* Enables to display the battery voltage. Only supported on the Micro MinimOSD Hardware.
* Don't forget to set the proper Voltage divider.
*
* NOTE: You need to define the Voltage Divider and Battery type for each type you want to display.
* Otherwise it won't compile.
*
* 0 = Off (Default)
* 1 = Bat1 (Only shows Battery 1)
* 2 = Bat2 (Only shows Battery 2)
Expand All @@ -175,20 +178,45 @@ tweak to your likening.

//#define SHOW_VOLTAGE 0


/**
* (Voltage Divider)
*
* If you enable the voltage display, you need to set the voltage divider to see proper
* Battery voltages on your screen.
*
* 2s =
* 1 = Bat1 (Only shows Battery 1)
* 2 = Bat2 (Only shows Battery 2)
* 3 = All (Shows both Batteries)
* 2s = 0
* 3s = 1
* 4s = 2
*/

//#define VOLTAGE_DIVIDER_BATTERY1 0
//#define VOLTAGE_DIVIDER_BATTERY2 0
#define VOLTAGE_DIVIDER_BATTERY1 10
#define VOLTAGE_DIVIDER_BATTERY2 10


/**
* (Battery Types)
*
* For accurate display, please specify the type of Battery used on each port.
*
* 1s = 0 - Probably never been used
* 2s = 1
* 3s = 2
* 4s = 3 - Maximum supported by the Hardware
*/

#define TYPE_BATTERY1 2
#define TYPE_BATTERY2 2

/**
* (Configuration for LiPo)
*
* Specify the min and max voltage of a cell
*
*/

#define CELL_MAX_VOLTAGE 4.2
#define CELL_MIN_VOLTAGE 3.6


/**
Expand All @@ -203,6 +231,5 @@ tweak to your likening.
//#define SHOW_RSSI 0


#endif /* _CONF_ */


#endif /* _CONF_ */
27 changes: 14 additions & 13 deletions bitsyosd/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,14 @@
#define SYMBOL_TIMEFLY 0x7e
#define SYMBOL_LAT 0x6e
#define SYMBOL_LON 0x6f
#define SYMBOL_RSSI 0x86

/**
* (Layout)
*
* This defines the positions of the different values displayed on the OSD
*/

#define LAYOUT_BATTERY_X 24
#define LAYOUT_BATTERY_Y 1

#define LAYOUT_SPEED_X 3
#define LAYOUT_SPEED_Y 6

Expand Down Expand Up @@ -133,6 +131,12 @@
#define LAYOUT_PROGRESS_X 12
#define LAYOUT_PROGRESS_Y 5

#define LAYOUT_BATTERY1_X 2
#define LAYOUT_BATTERY1_Y 1

#define LAYOUT_BATTERY2_X 2
#define LAYOUT_BATTERY2_Y 2

/**
* (Control)
*
Expand Down Expand Up @@ -160,7 +164,7 @@
#define GPS_MEASURE_PERIOD 95 // Period for meassuring distance
#define GPS_MEASURE_FLYTIME 3 // Minimum value for meassuring flight
#define GPS_TIMEOUT 4000 // timeout for lost GPS
#define BOOTTIME 10000
#define BOOTTIME 5000

/**
* (LED)
Expand All @@ -173,8 +177,8 @@
* (Voltage, Current and RSSI)
*/

#define VOLTAGE_PIN_BATTERY1 A0
#define VOLTAGE_PIN_BATTERY2 A2
#define VOLTAGE_PIN_BATTERY1 A2
#define VOLTAGE_PIN_BATTERY2 A0
#define CURRENT_PIN A1
#define RSSI_PIN A3

Expand Down Expand Up @@ -223,18 +227,15 @@ struct OSD_RUNTIME_VALUES {
long flytimelast;

// RSSI
int16_t rssi;
int16_t rssiADC;
int16_t rssiMin;
int16_t rssiMax;
int16_t rssi_Int;
float rssi;

// Voltage
uint16_t voltage1;
uint16_t voltage2;
float voltage1;
float voltage2;
};


#endif /* _CONST_ */



1 change: 1 addition & 0 deletions bitsyosd/gps.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ typedef struct GPS_DATA {

#endif /* GPS */


1 change: 1 addition & 0 deletions bitsyosd/gps_dji.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,4 @@ struct DJIPacket {


#endif /* GOS_H */

1 change: 1 addition & 0 deletions bitsyosd/gps_dji.ino
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,4 @@ GPS_DATA gps_values() {
#endif /* GPS_PARSER_DJI */



1 change: 1 addition & 0 deletions bitsyosd/gps_nema.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ static uint32_t NEMA_lastframe_time = 0;


#endif /* GPS_PARSER */

1 change: 1 addition & 0 deletions bitsyosd/gps_nema.ino
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,4 @@ bool NEMA_parse(char c) {
}

#endif /* GPS_PARSER */

1 change: 1 addition & 0 deletions bitsyosd/gps_sim.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ Great for development!
#define GPS_P_H

#endif

1 change: 1 addition & 0 deletions bitsyosd/gps_sim.ino
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ GPS_DATA gps_values() {


#endif

24 changes: 13 additions & 11 deletions bitsyosd/helpers.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ void unplugSlaves() {
* (ReadVoltage)
*/

uint16_t ReadVoltage(int pin, int divider) {
float ReadVoltage(int pin, int divider) {

static uint16_t i = 0;
static uint32_t raw[8];
uint16_t voltageRaw = 0;
static uint16_t i = 0;
static uint32_t raw[8];
uint16_t voltageRaw = 0;

// read raw voltage from pin
raw[(i++)%8] = analogRead(pin);
// read raw voltage from pin
raw[(i++)%8] = analogRead(pin);

// process
for (uint16_t i=0;i<8;i++)
voltageRaw += voltageRawArray[i];
// process
for (uint16_t i=0;i<8;i++)
voltageRaw += raw[i];

// return voltage
return float(voltageRaw) * divider / 1023;
// return voltage
float voltage = float(voltageRaw) * divider / 1023;

return voltage;
}
1 change: 1 addition & 0 deletions bitsyosd/max7456.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,4 @@ void OSD::flush(void){
}



1 change: 1 addition & 0 deletions bitsyosd/max7456.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,4 @@ class OSD: public BetterStream
#endif



1 change: 1 addition & 0 deletions bitsyosd/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ byte GetUnitSpeedSymbol(float unit, boolean panel = false);
#endif /* _OSD_ */



53 changes: 30 additions & 23 deletions bitsyosd/osd.ino
Original file line number Diff line number Diff line change
Expand Up @@ -198,29 +198,35 @@ void DrawNumber(int x, int y, int v, int d, int mi, int ma, int font) {
}

/* (DrawBattery) Draws the Battery Status */
void DrawBattery(int p) {
// some sanity check
p = p>99?99:(p<0?0:p);
// get symbol
int symbol = SYMBOL_BATTERY_0;
if(p > 80) {
symbol = SYMBOL_BATTERY_100;
} else if (p > 50) {
symbol = SYMBOL_BATTERY_60;
} else if (p > 20) {
symbol = SYMBOL_BATTERY_30;
}
// draw panel
osd.setPanel(LAYOUT_BATTERY_X, LAYOUT_BATTERY_Y);
osd.openPanel();
// write percentage
osd.write(FONT_LARGE + (p/10));
osd.write(FONT_LARGE + (p%10));
osd.write(0x4c);
// write symbol
osd.write(symbol);
osd.closePanel();

void DrawBattery(int x, int y, float voltage, int type) {

// calculate voltage
int maxVoltage = (type + 1) * CELL_MAX_VOLTAGE,
minVoltage = (type + 1) * CELL_MIN_VOLTAGE;

// calculate percentage
int p = 100 - (((maxVoltage - voltage) * 100) / (maxVoltage - minVoltage));

// sanity check
p = p > 100 ? 100 : (p < 0 ? 0 : p);

// set symbol
int symbol = SYMBOL_BATTERY_0;

if(p > 90) {
symbol = SYMBOL_BATTERY_100;
} else if (p > 60) {
symbol = SYMBOL_BATTERY_60;
} else if (p > 30) {
symbol = SYMBOL_BATTERY_30;
}

// draw text
osd.setPanel(x, y);
osd.openPanel();
osd.write(symbol);
osd.writefloat(voltage, 1);
osd.closePanel();
}


Expand Down Expand Up @@ -342,3 +348,4 @@ int vma(int v, int a) {
return VIDEO_MODE == 0 ? v + a : v;
}


1 change: 1 addition & 0 deletions bitsyosd/spi.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ byte SPI::transfer(byte value, byte period)

SPI Spi = SPI();


1 change: 1 addition & 0 deletions bitsyosd/spi.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ extern SPI Spi;

#endif


4 changes: 4 additions & 0 deletions font/12.6
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
12.6 4.2 100% 0.0
12.4 0.2
11.7 0.9
10.2 3.4 0% 2.4
2 changes: 1 addition & 1 deletion font/fonttest.mdm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MAX7456
NTSC
Z:\code\fpv\bitsyosd\font\bitsyosd-font.mcm
Z:\code\air\bitsyosd\font\bitsyosd-font.mcm
0
0
0
Expand Down

0 comments on commit e8a2b9f

Please sign in to comment.