demo new haven display

Dependencies:   LCD Menu ButtonCtrl TimeManagement EventLog AddressMap emic2

ESCM 2000 Control and Display application provides interface for the LPC1768 processor boards with the ECSM 2000 system.

This application implements SW interface : - RX 485 Receive from physical system - RX 485 Interface to send toECOM / ESCM board - CAN Interface to send to ECOM / ESCM board - 4x40 LCD with menu controls - RTC configuration -EMIC2 Sound Card - GPIO Extender to push buttons etc

Revision:
3:ecaf9963341b
Parent:
1:a16e53a9e991
Child:
5:65f21c0b6b79
--- a/main.cpp	Mon Jun 17 15:16:59 2019 +0000
+++ b/main.cpp	Thu Jul 25 00:45:01 2019 +0000
@@ -1,50 +1,311 @@
 #include "mbed.h"
+#include "rtos.h"
+
 #include "LCD.h"
 
+#include "ButtonController.h"
+
+#include "ESCMControlApp.h"
+
+#include "Menu.h"
+#include "EditTimeMenu.h"
+#include "DisplayCodesMenu.h"
+
+//#include "EditDateMenu.h"
+//#include "EditAddressMenu.h"
+//#include "DisplayFaultAddressMenu.h"
+
+#include "Navigator.h"
+#include "Selection.h"
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+
+Thread gpioThread (osPriorityHigh, 2000);
+
+Thread ioThread (osPriorityHigh, 2000);
+
+Thread soundThread(osPriorityLow, 2000);
+
+Thread displayThread(osPriorityNormal, 2000);
+
+
+//EventQueue messageQueue(32 * EVENTS_EVENT_SIZE);
+
+typedef struct {
+   int    event; 
+   char    msg[40];
+} event_t;
+
+
+
+CircularBuffer<event_t, 64> event_queue;
+CircularBuffer<event_t, 64> playback_queue;
+
 
 Serial pc(USBTX, USBRX); // tx, rx
 
-LCD   MyLCD;
+LCD   lcd;
+
+
+
+Menu                    rootMenu   ("root menu"); 
+EditTimeMenu            editTime   ("Edit Time");
+//EditDateMenu            editDate   ("Edit Date");
+//EditAddressMenu         editAdress ("Edit Addresses");
+
+DisplayCodesMenu showEvents ("Display Events" );
+
+    
+Navigator navigator(&rootMenu,  &lcd); 
+
+
+Menu * currentMenu = &showEvents;
+
+ButtonController controller(&navigator);
+
+
+ESCMControlApp escmController;
+
+void toggleLed1(void* obj)
+{
+        led1 = !led1;
+}
+void toggleLed2(void* obj)
+{
+        led2 = !led2;
+}
+void toggleLed3(void* obj)
+{
+        led3 = !led3;
+}
+void toggleLed4()
+{
+        led4 = !led4;
+}
+/***********************************************************************
+* Thread to read GPIO and handle events
+***********************************************************************/
+
+void ReadGPIOExtender(void const *name)
+{
+    uint8_t code = 0;
+    
+    pc.printf("Starting %s task\n", name );
+    
+    led4 = !led4;
+    
+    while (true) {
+        
+        controller.update();
+        
+        code = controller.currentValue & 0x1F; // filter code(s)
+        
+        if (code)
+        {
+            event_t e;
+            e.event = code;
+            
+            if (!event_queue.full()){
+                pc.printf("<%02x>\n",e.event);
+                event_queue.push(e);
+            }
+                
+        }
+        
+        led4 = !led4;        
+        Thread::wait(10);
+    }
+    
+    
+}
+
+/***********************************************************************
+* Thread to read GPIO and handle events
+***********************************************************************/
+
+void ESCMController_Update(void const *name)
+{
+    
+    pc.printf("Starting %s task\n", name ); 
+    
+    
+    while(1) {
+                
+        escmController.update();
+                
+        Thread::wait(1000);
+    }
+}
+
+
+/***********************************************************************
+* Update LCD Display Thread
+***********************************************************************/
+
+void UpdateDisplay(void const *name)
+{
+    
+    pc.printf("Starting %s task\n", name ); 
+    
+    lcd.init();
+    lcd.locate(0,0);
+    lcd.cls();
+    
+    lcd.writeLine (0, "Initializing System..");
+    
+    event_t ex;// = (event_t*)(event_queue.alloc()); 
+    int event =0;
+    
+    currentMenu->update_needed = 1;
+    
+    while (true) {
+        
+ #if 1       
+        
+         while (!event_queue.empty()) {
+                event_queue.pop(ex);
+                
+                switch(ex.event)
+                {
+                    case 0x01://up
+                        currentMenu->pressUp();
+                        break;
+                        
+                    case 0x02://down
+                        currentMenu->pressDown();
+                        break;
+                        
+                    case 0x04://clear
+                        currentMenu->pressClear();
+                        break;
+                        
+                    case 0x08://mode
+                        currentMenu->pressMode();
+                        break;
+                        
+                    case 0x10://set
+                        currentMenu->pressSet();
+                        break;
+                    default:
+                        break;
+                }
+        }     
+        
+        currentMenu->lcd = &lcd;
+        currentMenu->display(&lcd);
+#endif     
+        
+        led3 = !led3;        
+        
+        Thread::wait(50);
+        
+    }
+}
+
+/***********************************************************************
+* Play sounds
+* TODO: should have its own queue.
+***********************************************************************/
+
+void PlaySound(void const *name)
+{
+    char msg[40];
+    
+    event_t e;
+        
+    pc.printf("Starting %s task\n", name ); 
+            
+    while (true) {
+        
+            while (!playback_queue.empty()) {
+                playback_queue.pop(e);         
+                                
+                sprintf(msg, "Unit %d is open\r",e.event); 
+                speaker.speakf("S");//Speak command starts with "S"
+                speaker.speakf(msg);  // Send the desired string to convert to speech
+                speaker.speakf("\r"); //marks end of speak command
+                speaker.ready(); //ready waits for speech to finish from last command with a ":" response
+                led2 = !led2;
+            }
+            Thread::wait(2000);
+    }
+}
+
+/***********************************************************************
+* Main Loop
+***********************************************************************/
 
 int main() {
-        
+    
+    led1=1;
+    led1=!led1;
+
     pc.printf("\n\r");
     pc.printf("=====================================\n\r");
     pc.printf("= LCD TEST                          =\n\r");
     pc.printf("=====================================\n\r");
 
-    MyLCD.init();
-    //MyLCD.display("Initializing System...");
-    
-    MyLCD.locate(1,1);
-    MyLCD.write("Initializing System.......Hello World!");
+    escmController.init();
+    escmController.tx485Message(0);
+    led1=!led1;
+
+    #if 0
+    Menu ledMenu1("Events menu"); 
+    Menu ledMenu2("Address menu"); 
+    Menu ledMenu3("Set Time"); 
+    Menu ledMenu4("Set Date"); 
     
-    pc.printf("=====================================\n\r");
-    pc.printf("= Launch                            =\n\r");
-    pc.printf("=====================================\n\r");
-   // myLcd.clear(1,1);
-   // MyLCD.writeCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZ..............",0,0);
-    //wait_ms(5);
-    //MyLCD.writeCharacters("----------------------------------------",1,0);
-    //wait_ms(5);
-    //MyLCD.write("Hello World!!!!");
-    //wait_ms(5);
-    //MyLCD.writeCharacters("----------------------------------------",3,0);
-    //wait_ms(5);
+    //Add any selections 
+    ledMenu1.add(Selection(&toggleLed1, 0, NULL, "Toggle LED1")); 
+    ledMenu1.add(Selection(&toggleLed2, 0, NULL, "Toggle LED2"));
+    ledMenu1.add(Selection(&toggleLed3, 0, NULL, "Toggle LED3"));
+    ledMenu1.add(Selection(&toggleLed4, 0, NULL, "Toggle LED4"));
+    ledMenu1.add(Selection(NULL, 0, &rootMenu, "Go back")); 
+       
+    //add a selection to go back up in the menu hierarchy. 
+    // Do this by letting the child menu point to the previous menu 
+    
+    ledMenu2.add(Selection(&toggleLed4, 0, NULL, "Current Address Code"));
+    ledMenu2.add(Selection(NULL, 0, &rootMenu, "Go back")); 
+    
+    ledMenu3.add(Selection(&toggleLed4, 0, NULL, "Current Time"));
+    ledMenu3.add(Selection(NULL, 0, &rootMenu, "Go back")); 
+    
+    ledMenu4.add(Selection(&toggleLed4, 0, NULL, "Current Date"));
+    ledMenu4.add(Selection(NULL, 0, &rootMenu, "Go back")); 
+    
+    #endif
     
     
-    MyLCD.writeCommand((char)0x80,1,0); //address 0 position (=0,=0)
-    MyLCD.writeData   ((char)0x55,1,0); //x
+    //add submenus to the root (as selections with child parameters set to the submenus) 
+//    rootMenu.add(Selection(NULL, 0, &showEvents, "View Events"));
+//   rootMenu.add(Selection(NULL, 1, &editAdress, "Modify Addresses"));
+    rootMenu.add(Selection(NULL, 2, &editTime,   "Set Time"));
+//    rootMenu.add(Selection(NULL, 3, &editDate,   "Set Date"));
+     
+    led1=!led1;
+    
+    ioThread.start (callback(ESCMController_Update , (void *)"io"));
     
-    //int i=0;
+    gpioThread.start (callback(ReadGPIOExtender , (void *)"gpio"));
+    
+    soundThread.start(callback(PlaySound, (void *)"audio"));
+    
+    displayThread.start (callback(UpdateDisplay, (void *)"display"));  
+    
+    escmController.say("Welcome");
+             
+    uint32_t frameCount = 0;
+        
     while(1) {
-        wait_ms(5);
-        //MyLCD.writeCommand(0x80,1,0); //Turn on display; no cursor 
-        //MyLCD.writeData   (0x55,1,0); //Turn on display; no cursor 
-        //MyLCD.locate(0,1);
-        //MyLCD.writeCharacter('X',0,i++);
-        //if(i>MyLCD.columns())
-        //    i=i;
+        wait_ms(500);           
+        frameCount++;
+        led1=!led1;
+        
     }
 }