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.
Dependencies: PinDetect TextLCD mbed
Fork of FBRDash by
Diff: main.cpp
- Revision:
- 1:b3907b8d9f65
- Parent:
- 0:1f422ed56e0f
- Child:
- 2:825f572902c6
--- a/main.cpp Thu Nov 03 20:38:12 2011 +0000
+++ b/main.cpp Mon Jun 25 21:01:02 2012 +0000
@@ -1,80 +1,130 @@
#include "mbed.h"
#include "TextLCD.h"
+#include "PinDetect.h"
+#include "Menu.h"
+#include "Comms.h"
+#include "PCComms.h"
+#include "Gears.h"
+#include "LEDS.h"
+#include "bigchar.h"
-#define NUM_LEDS 6
-PwmOut leds[] = { (p26), (p25), (p24), (p23), (p22), (p21) };
+#define LCD_REFRESH_TIME 150000
+#define REV_REFRESH_TIME 50000
+
+DigitalOut warn[] = { (p20), (p19), (p27), (p18) };
+DigitalOut debug[] = { (LED1), (LED2), (LED3) };
-TextLCD lcd(p10, p11, p12, p17, p18, p19, p20);
+DigitalOut heartbeat(LED4);
+
+PwmOut leds[] = { (p24), (p25), (p26), (p23), (p22), (p21) };
+
+TextLCD lcd(p5, p6, p7, p8, p9, p10, p11);
-InterruptIn shiftDown(p5);
-InterruptIn shiftUp(p6);
-InterruptIn shiftNeutral(p7);
+Ticker lcdRefreshTicker;
+Ticker revRefreshTicker;
+Ticker increment;
+
+State car;
-volatile float increment = 0;
+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);
-void up()
+void revRefresh()
{
- increment += 0.01;
+ revs.refresh(car.rpm);
+
+ for(int i = 0; i < 4; i++)
+ {
+ warn[i] = car.warnings & (1 << i);
+ }
}
-void down()
+void lcdRefresh()
{
- increment -= 0.01;
-}
-
-void neutral()
-{
- increment = 0;
+ if(dashMenu.display == false)
+ {
+ lcd.locate(0, 0);
+ lcd.printf("R:%-11.0d", car.rpm);
+ lcd.locate(0, 1);
+ lcd.printf("S:%-3d T:%-5.0f", car.speed, car.coolant_temp);
+
+ write_bigchar(&lcd, 13, car.gear);
+ }
+ else
+ {
+ dashMenu.refresh();
+ }
+
+ heartbeat = !heartbeat;
}
-int main() {
- float i;
+/*void doIncrement()
+{
+ if(car.rpm < LIMIT && car.gear > 0)
+ car.rpm++;
+}*/
- shiftUp.rise(&up);
- shiftDown.rise(&down);
- shiftNeutral.rise(&neutral);
-
- leds[0].period(0.0001);
+void selfTest()
+{
+ lcd.printf(" FBR 2012");
- lcd.locate(0, 1);
- lcd.printf("Neutral");
+ for(int i = 0; i < LEDS::NUM_LEDS; i++)
+ {
+ leds[i] = true;
+ if(i < 4)
+ warn[i] = true;
+ wait(0.04);
+ }
- while(1) {
- if(increment >= 0)
- i = 0;
- else
- i = 6.0;
+ for(int i = LEDS::NUM_LEDS - 1; i >= 0; i--)
+ {
+ leds[i] = false;
+ if(i < 4)
+ warn[i] = false;
+ wait(0.04);
+ }
- for(; i <= 6 && i >= 0; i += increment)
- {
- for(int j = 0; j < NUM_LEDS; j++)
- {
- if(j < (int)i)
- {
- leds[j] = 1.0;
- }
- else if(j >= (int)i + 1)
- {
- leds[j] = 0;
- }
- else
- {
- leds[j] = i - ((int)i);
- }
- }
-
- lcd.locate(0, 0);
- lcd.printf("%4.2f %4.2f", i, increment);
-
- lcd.locate(0, 1);
- if(increment < 0)
- lcd.printf("Down ");
- else if(increment > 0)
- lcd.printf("Up ");
- else
- lcd.printf("Neutral");
-
- wait_ms(10);
- }
+ lcd.cls();
+}
+
+int main()
+{
+ car.rpm = 5000;
+ car.gear = 0;
+ car.speed = 150;
+ car.coolant_temp = 21.5;
+
+ car.throttle_pos = 1;
+ car.manifold_pres = 2;
+ car.air_temp = 3;
+ car.lambda = 5;
+ car.accel_x = 7;
+ car.accel_y = 8;
+ car.oil_temp = 10;
+ car.oil_pres = 11;
+ car.warnings = 12;
+
+ 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>("Oil Temp ", "%12d\xDF\x43", &car.oil_temp);
+ dashMenu.addItem<unsigned char>("Oil Pressure ", "%10d psi", &car.oil_pres);
+
+ setup_bigchar(&lcd);
+
+ selfTest();
+
+ lcdRefreshTicker.attach_us(&lcdRefresh, LCD_REFRESH_TIME);
+ revRefreshTicker.attach_us(&revRefresh, REV_REFRESH_TIME);
+ //increment.attach(&doIncrement, 0.0005);
+
+ while(true)
+ {
+ __WFI();
}
-}
+}
\ No newline at end of file
