Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of FBRDash by
Diff: main.cpp
- Revision:
- 2:825f572902c6
- Parent:
- 1:b3907b8d9f65
- Child:
- 3:cb334e1d31c6
diff -r b3907b8d9f65 -r 825f572902c6 main.cpp
--- a/main.cpp Mon Jun 25 21:01:02 2012 +0000
+++ b/main.cpp Mon Jun 25 21:20:22 2012 +0000
@@ -8,29 +8,44 @@
#include "LEDS.h"
#include "bigchar.h"
+//Refresh interval for LCD
#define LCD_REFRESH_TIME 150000
+
+//Refresh interval for rev LEDs
#define REV_REFRESH_TIME 50000
+//Warning lights
DigitalOut warn[] = { (p20), (p19), (p27), (p18) };
+
+//mBED LEDs
DigitalOut debug[] = { (LED1), (LED2), (LED3) };
+//Heartbeat LED
DigitalOut heartbeat(LED4);
+//Rev LEDS
PwmOut leds[] = { (p24), (p25), (p26), (p23), (p22), (p21) };
+//LCD
TextLCD lcd(p5, p6, p7, p8, p9, p10, p11);
+//Tickers for refreshing
Ticker lcdRefreshTicker;
Ticker revRefreshTicker;
+
+//Used to animate LEDs for testing
Ticker increment;
+//Main car state structure
State car;
+//Classes for various parts of the firmware
Menu dashMenu(&lcd, p13, p14, p15); //*LCD, OK, Left, Right
PCComms pc(&car);
Gears gearButtons(p17, p16, p12, &car.gear, &pc); //Up, Neutral, Down, *Current Gear
LEDS revs(leds);
+//Refresh the rev LEDs and warning LEDs
void revRefresh()
{
revs.refresh(car.rpm);
@@ -41,8 +56,10 @@
}
}
+//Refresh the LCD
void lcdRefresh()
{
+ //If menu off screen, display HUD
if(dashMenu.display == false)
{
lcd.locate(0, 0);
@@ -52,25 +69,31 @@
write_bigchar(&lcd, 13, car.gear);
}
+ //Otherwise show menu
else
{
dashMenu.refresh();
}
+ //Blink heartbeat
heartbeat = !heartbeat;
}
+
+//Used to animate LEDs for testing
/*void doIncrement()
{
if(car.rpm < LIMIT && car.gear > 0)
car.rpm++;
}*/
+//Startup animation
void selfTest()
{
lcd.printf(" FBR 2012");
- for(int i = 0; i < LEDS::NUM_LEDS; i++)
+ //Light up LEDs
+ for(int i = 0; i < LEDS::NUM_LEDS; i++)
{
leds[i] = true;
if(i < 4)
@@ -78,6 +101,7 @@
wait(0.04);
}
+ //Turn off LEDs
for(int i = LEDS::NUM_LEDS - 1; i >= 0; i--)
{
leds[i] = false;
@@ -90,12 +114,12 @@
}
int main()
-{
+{
+ //Initialise state
car.rpm = 5000;
car.gear = 0;
car.speed = 150;
- car.coolant_temp = 21.5;
-
+ car.coolant_temp = 21.5;
car.throttle_pos = 1;
car.manifold_pres = 2;
car.air_temp = 3;
@@ -106,23 +130,27 @@
car.oil_pres = 11;
car.warnings = 12;
+ //Set up menu
dashMenu.addItem<float>("Coolant Temp ", "%12.1f\xDF\x43", &car.coolant_temp); // \xDF\x43 -> �C . Need code for C as otherwise it gets taken as hex digit.
dashMenu.addItem<unsigned char>("Air Temp ", "%12d\xDF\x43", &car.air_temp);
dashMenu.addItem<unsigned char>("Throttle Pos ", "%13d\xDF", &car.throttle_pos);
dashMenu.addItem<unsigned char>("Manifold Pres ", "%10d psi", &car.manifold_pres);
- dashMenu.addItem<unsigned char>("Lambda ", "%14d", &car.lambda);
-
+ dashMenu.addItem<unsigned char>("Lambda ", "%14d", &car.lambda);
dashMenu.addItem<unsigned char>("Oil Temp ", "%12d\xDF\x43", &car.oil_temp);
dashMenu.addItem<unsigned char>("Oil Pressure ", "%10d psi", &car.oil_pres);
+ //Set up characters on LCS
setup_bigchar(&lcd);
-
+
+ //Do bootup animation
selfTest();
+ //Start refresh tickers
lcdRefreshTicker.attach_us(&lcdRefresh, LCD_REFRESH_TIME);
revRefreshTicker.attach_us(&revRefresh, REV_REFRESH_TIME);
//increment.attach(&doIncrement, 0.0005);
+ //Infinite loop - program is interrupt driven
while(true)
{
__WFI();
