Penn Electric Racing / Mbed 2 deprecated SystemManagement

Dependencies:   mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP

Fork of SystemManagement by Martin Deng

Revision:
20:3dfa7e9461a0
Parent:
19:3a817d2cef11
Child:
22:fc802e7715f8
Child:
29:f148490b5f65
--- a/SerialDiagnostics/SerialDiagnostics.cpp	Sat Oct 25 16:48:09 2014 +0000
+++ b/SerialDiagnostics/SerialDiagnostics.cpp	Fri Nov 07 01:26:13 2014 +0000
@@ -16,6 +16,7 @@
 }
 
 void SerialDiagnostics::thread_serialOut(void const* args){
+    
     const int max_charsPerLine = 81;                 // Max chars per line
     const int max_lines = 30;                        // Max lines that the layout prints out
     pc.printf("\033[2J");                            // Clear the screen to get rid of reset message
@@ -32,6 +33,56 @@
         padCenter(line, max_charsPerLine-2, " Penn Electric Racing - REV0 System Management Module Serial Dashboard ", '-'); ADD_LINE
         padCenter(line, max_charsPerLine-2, "-", '-'); ADD_LINE     // Generate a line full of 80 -'s 
         
+        
+    // Polling Switches -----------------------------------------------------------------------------------------------//
+    
+        padCenter(line, max_charsPerLine-2, " ", ' '); ADD_LINE     // Generate blank line 
+        padCenter(line, max_charsPerLine-2, " Poll Switches ", '*'); ADD_LINE
+        
+        char binary_out[12];
+        uint16_t poll = pollSwitch.poll();
+        
+        for(int i = 0; i < 10; i++){
+            binary_out[i] = (poll & 0x1) ? '1' : '0';
+            poll = poll >> 1;
+        }
+        binary_out[11] = '\0';
+        
+        sprintf(temp, "Switch Bits: %s", binary_out); ADD_SPRINTF_LINE
+        
+    // Reading IMD status and resistance -------------------------------------------------------------------------------//
+    
+        padCenter(line, max_charsPerLine-2, " ", ' '); ADD_LINE     // Generate blank line 
+        padCenter(line, max_charsPerLine-2, " IMD ", '*'); ADD_LINE
+        
+        char status = imd.status();
+        
+        switch(status){
+        case OFF:
+            sprintf(temp, "IMD Status: OFF"); ADD_SPRINTF_LINE break;
+        case NORMAL:
+            sprintf(temp, "IMD Status: NORMAL"); ADD_SPRINTF_LINE break;
+        case UNDERVOLT:
+            sprintf(temp, "IMD Status: UNDERVOLT"); ADD_SPRINTF_LINE break;
+        case SPEEDSTART:
+            sprintf(temp, "IMD Status: SPEEDSTART"); ADD_SPRINTF_LINE break;
+        case ERROR:
+            sprintf(temp, "IMD Status: ERROR"); ADD_SPRINTF_LINE break;
+        case GROUNDERR:
+            sprintf(temp, "IMD Status: GROUNDERR"); ADD_SPRINTF_LINE break;
+        case INVALID:
+            sprintf(temp, "IMD Status: INVALID"); ADD_SPRINTF_LINE break;
+        default:
+            sprintf(temp, "IMD Status: UNKNOWN STATUS ERROR"); ADD_SPRINTF_LINE break;
+        }
+        
+    // Reading Coulomb Counter
+        
+        padCenter(line, max_charsPerLine-2, " ", ' '); ADD_LINE     // Generate blank line 
+        padCenter(line, max_charsPerLine-2, " CoulombCounter ", '*'); ADD_LINE
+        
+        sprintf(temp, "Current: %f ampHours: %f Capacity: %f SOC: %f", coulombCounter.current(), coulombCounter.ampHours(), coulombCounter.capacity(), coulombCounter.SOC()); ADD_SPRINTF_LINE
+        
         // Write it all at once to output tx buffer
         for (int i = 0; i < strlen(buff); i++) {
             pc.putc(buff[i]);   
@@ -40,3 +91,13 @@
         Thread::wait(100);
     }
 }
+
+/*
+    Testing Notes
+    
+    Oct 25
+    Tested PollSwitch:
+        
+        Wasn't able to access pins p1_x, but tried out pollswitch with pins p0_x
+        Logic seems to work
+*/
\ No newline at end of file