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: mbed MCP23017 mbed-rtos WattBob_TextLCD
Revision 8:09b78bc5551f, committed 2018-03-27
- Comitter:
- Steaar
- Date:
- Tue Mar 27 15:11:02 2018 +0000
- Parent:
- 7:84c2156e1ace
- Child:
- 9:c3c90e137cfb
- Commit message:
- All working, tasks need tidied. Empty mail queue
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Mar 27 14:11:17 2018 +0000
+++ b/main.cpp Tue Mar 27 15:11:02 2018 +0000
@@ -42,14 +42,14 @@
Thread sp;
Thread task1;
-Thread task2;
+Thread task246;
Thread task3;
-Thread task4;
-Thread task5;
-Thread task6;
+//Thread task4;
+Thread task59;
+//Thread task6;
Thread task7;
Thread task8;
-Thread task9;
+//Thread task9;
Thread task10;
Thread indi;
Semaphore ac(1);
@@ -85,7 +85,28 @@
Thread::wait(50);
}
}
-void ignition() // 2. Read engine on/off show LED 2
+void LCD() // 6. display odometer and speed 2
+{
+ lcd->locate(0,0);
+ lcd->printf("KM:%0.1f",distance);
+ lcd->locate(1,0);
+ lcd->printf("KM/H:%.1f",aveSpeed);
+ lcd->locate(0,8);
+ //ac.wait();
+ lcd->printf("sp:%0.1f",kmph);
+ //lcd->locate(1,8);
+ //ac.release();
+ //lcd->printf("b:%d",engine.read());
+}
+void braking() // 4. Brake indicated by LED 2
+{
+ if ( br > 0) {
+ brakeLights = 1;
+ } else {
+ brakeLights = 0;
+ }
+}
+void t246() // 2. Read engine on/off show LED 2
{
while (1) {
if (engine.read() > 0) {
@@ -93,6 +114,9 @@
} else {
engLight = 0;
}
+ LCD();
+ braking();
+
Thread::wait(500);
}
}
@@ -107,84 +131,6 @@
Thread::wait(200);
}
}
-void braking() // 4. Brake indicated by LED 2
-{
- while (1) {
- if ( br > 0) {
- brakeLights = 1;
- } else {
- brakeLights = 0;
- }
-
- Thread::wait(500);
- }
-}
-void greatScott() // 5. if speed > 88 LED on 1
-{
- while (1) {
- if (kmph > 141.6) { // 141.6 km = 88 miles
- fluxCapacitor = 1;
- } else {
- fluxCapacitor = 0;
- }
-
- Thread::wait(1000);
- }
-}
-void LCD() // 6. display odometer and speed 2
-{
- while (1) {
-
- lcd->locate(0,0);
- lcd->printf("KM:%0.1f",distance);
- lcd->locate(1,0);
- lcd->printf("KM/H:%.1f",aveSpeed);
- lcd->locate(0,8);
- //ac.wait();
- lcd->printf("sp:%0.1f",kmph);
- //lcd->locate(1,8);
- //ac.release();
- //lcd->printf("b:%d",engine.read());
-
- Thread::wait(500);
- }
-}
-void send_thread (void) // 7. Send speed, acc, brake to MAILq 0.2
-{
- uint32_t i = 0;
- while (true) {
- i++; // fake data update
- mail_t *mail = mail_box.alloc();
- mail->m_speed = speed;
- mail->m_acc = acc;
- mail->m_br = br;
- mail->counter = i;
- mail_box.put(mail);
-
- osEvent evt = mail_box.get();
- if (evt.status == osEventMail) {
- mail_t *mail = (mail_t*)evt.value.p;
- printf("\nSpeed: %.1f \n\r" , mail->m_speed);
- printf("Acceleration: %.2f \n\r" , mail->m_acc);
- printf("Braking: %.1f \n\r", mail->m_br);
-
- mail_box.free(mail);
- }
- Thread::wait(5000);
- }
-}
-void toSerial() // 8. MAIL q to serial PC 0.05
-{
- while (1) {
- osEvent evt = mail_box.get();
- mail_t *mail = (mail_t*)evt.value.p;
- pc.printf("\nSpeed: %.2f \n\r", mail->m_speed);
- pc.printf("Acceleration: %.2f \n\r", mail->m_acc);
- pc.printf("Braking: %.2f \n\r", mail->m_br);
-
- Thread::wait(20000);
- }
-}
void lights() // 9. set side lights 1
{
while (1) {
@@ -197,6 +143,47 @@
Thread::wait(1000);
}
}
+void t59() // 5. if speed > 88 LED on 1
+{
+ while (1) {
+ if (kmph > 141.6) { // 141.6 km = 88 miles
+ fluxCapacitor = 1;
+ } else {
+ fluxCapacitor = 0;
+ }
+ lights();
+
+ Thread::wait(1000);
+ }
+}
+void send_thread (void) // 7. Send speed, acc, brake to MAILq 0.2
+{
+ while (true) {
+ mail_t *mail = mail_box.alloc();
+ mail->m_speed = kmph;
+ mail->m_acc = acc;
+ mail->m_br = br;
+ mail_box.put(mail);
+
+ Thread::wait(5000);
+ }
+}
+void toSerial() // 8. MAIL q to serial PC 0.05
+{
+ while (1) {
+ osEvent evt = mail_box.get();
+ mail_t *mail = (mail_t*)evt.value.p;
+ pc.printf("\nSpeed: %.2f \n\r", mail->m_speed);
+ pc.printf("Acceleration: %.2f \n\r", mail->m_acc);
+ pc.printf("Braking: %.2f \n\r", mail->m_br);
+ //pc.printf("\r\nSpeed: %.2f ", kmph);
+ //pc.printf(", Acceleration: %.2f", acc);
+ //pc.printf(", Braking: %.2f", br);
+
+ Thread::wait(20000);
+ }
+}
+
void indicators() // 10. check indicators 0.5
{
while (1) {
@@ -252,14 +239,14 @@
sp.start(getSpeed); //20 y
task1.start(acceleration); //10 y
- task2.start(ignition); //2 .setPriority(); y
+ task246.start(t246); //2 .setPriority(); y 4, 6
task3.start(speedo); //5 y
- task4.start(braking); //2 y
- task5.start(greatScott); //1 y
- task6.start(LCD); //2 y
-// task7.start(callback(send_thread)); //0.2
-// task8.start(toSerial); //0.05
- task9.start(lights); //1 y
+ //task4.start(braking); //2 y
+ task59.start(t59); //1 y 9
+ //task6.start(LCD); //2 y
+ task7.start(callback(send_thread)); //0.2
+ task8.start(toSerial); //0.05
+ //task9.start(lights); //1 y
task10.start(indicators); //0.5 y
indi.start(indicate); // 1-2 y