The Code Repository for the REV0 Steering Wheel.
Dependencies: CANBuffer KS0108_fork mbed-rtos mbed CAN Addresses
Fork of REVO_Updated_Steering by
Screens.h@45:aea289639d6b, 2015-05-15 (annotated)
- Committer:
- jayf
- Date:
- Fri May 15 04:14:09 2015 +0000
- Revision:
- 45:aea289639d6b
- Parent:
- 40:92f08fdc32df
More changes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tmccurbin | 36:8544a8900884 | 1 | #include "KS0108.h" |
tmccurbin | 36:8544a8900884 | 2 | #include "Buffers.h" |
tmccurbin | 36:8544a8900884 | 3 | |
tmccurbin | 36:8544a8900884 | 4 | // Macro for printing to screen; Where y is the start poition of the text, and y2 is the start position of the variable |
tmccurbin | 36:8544a8900884 | 5 | #define PUT2SCREEN(string, var, unit, x, y, y2) display.PutString(x, y, string); display.PutString(x, y2, var); display.PutString(x,y2+15,unit); |
tmccurbin | 36:8544a8900884 | 6 | #define HOME_SCREEN 0 |
tmccurbin | 36:8544a8900884 | 7 | #define BATTERY_SCREEN 1 |
tmccurbin | 36:8544a8900884 | 8 | #define MOTOR_SCREEN 2 |
tmccurbin | 36:8544a8900884 | 9 | #define SYS_MGMT_SCREEN 3 |
tmccurbin | 36:8544a8900884 | 10 | #define CHARGE_SCREEN 4 |
tmccurbin | 36:8544a8900884 | 11 | #define FAULT_SCREEN 5 |
tmccurbin | 36:8544a8900884 | 12 | |
tmccurbin | 36:8544a8900884 | 13 | |
jayf | 45:aea289639d6b | 14 | char display_string_buffer[30]; |
jayf | 45:aea289639d6b | 15 | char* formatPercentage(int CANID){ |
jayf | 45:aea289639d6b | 16 | return float_to_string(CANID); |
jayf | 45:aea289639d6b | 17 | } |
jayf | 45:aea289639d6b | 18 | char* wheel_speed(int CANID){ |
jayf | 45:aea289639d6b | 19 | float average_rpm =*((float*)message_data[CANID])+*((float*)(message_data[CANID]+4)) |
jayf | 45:aea289639d6b | 20 | //assuming nominal tire diameter of 19.25in |
jayf | 45:aea289639d6b | 21 | sprintf(display_string_buffer,"%2.2f",average_rpm*1.09375); |
jayf | 45:aea289639d6b | 22 | return display_string_buffer; |
jayf | 45:aea289639d6b | 23 | } |
jayf | 45:aea289639d6b | 24 | char* CtoF(int CANID){ |
jayf | 45:aea289639d6b | 25 | sprintf(display_string_buffer,"3.2f", 32+9*((float*)message_data[CANID])/5; |
jayf | 45:aea289639d6b | 26 | return display_string_buffer; |
jayf | 45:aea289639d6b | 27 | } |
jayf | 45:aea289639d6b | 28 | char* CtoF(int CANID,int index){ |
jayf | 45:aea289639d6b | 29 | sprintf(display_string_buffer,"3.2f", 32+9*((float*)message_data[CANID]+index)/5; |
jayf | 45:aea289639d6b | 30 | return display_string_buffer; |
jayf | 45:aea289639d6b | 31 | } |
jayf | 45:aea289639d6b | 32 | char* float_to_string(int CANID){ |
jayf | 45:aea289639d6b | 33 | sprintf(display_string_buffer,"%3.2f",message_data[CANID]); |
jayf | 45:aea289639d6b | 34 | return display_string_buffer; |
jayf | 45:aea289639d6b | 35 | } |
jayf | 45:aea289639d6b | 36 | char* float_to_string(int CANID,int index){ |
jayf | 45:aea289639d6b | 37 | sprintf(display_string_buffer,"%3.2f",*((float*)(message_data[CANID]+index))); |
jayf | 45:aea289639d6b | 38 | return display_string_buffer; |
jayf | 45:aea289639d6b | 39 | } |
tmccurbin | 36:8544a8900884 | 40 | // Initialize Variables |
tmccurbin | 36:8544a8900884 | 41 | int CurrScreen = HOME_SCREEN; |
tmccurbin | 36:8544a8900884 | 42 | int PrevScreen = !CurrScreen; |
tmccurbin | 36:8544a8900884 | 43 | |
tmccurbin | 36:8544a8900884 | 44 | // Defines the pins for the dsiplay. These are hardwired. |
tmccurbin | 36:8544a8900884 | 45 | KS0108 display(p26, p21, p22, p23, p25, p24, p8, p7, p6, p5, p13, p14, p12, p11); |
tmccurbin | 36:8544a8900884 | 46 | void DisplayHomeScreen() |
tmccurbin | 36:8544a8900884 | 47 | { |
tmccurbin | 36:8544a8900884 | 48 | display.ClearScreen(); |
tmccurbin | 36:8544a8900884 | 49 | display.PutString(0, 54, "Home"); |
tmccurbin | 36:8544a8900884 | 50 | |
tmccurbin | 36:8544a8900884 | 51 | //Info line 1: Battery Life & Vehicle Speed |
jayf | 45:aea289639d6b | 52 | PUT2SCREEN("BatLife:", formatPercentage(0x30B), "%", 1, 0, 39);//SOC_TX_ID |
jayf | 45:aea289639d6b | 53 | PUT2SCREEN(",", formatPercentage(0x513), "%", 1, 59, 62);//SYS_GLV_SOC_ID |
jayf | 45:aea289639d6b | 54 | PUT2SCREEN("Spd:", wheel_speed(0x222), "mph", 1, 89,108);//PCM_FRPM_ID |
tmccurbin | 36:8544a8900884 | 55 | |
tmccurbin | 36:8544a8900884 | 56 | //Info line 2: Average Battery Temp & Peak Battery Temp |
jayf | 45:aea289639d6b | 57 | PUT2SCREEN("AvgBatT:", CtoF(0x319), "F", 3, 0, 39);//TEMP_MMA_TX_ID_BASE2 |
jayf | 45:aea289639d6b | 58 | PUT2SCREEN("PkBatT:", CtoF(0x318), "F", 3, 69,103);//TEMP_MMA_TX_ID_BASE |
tmccurbin | 36:8544a8900884 | 59 | |
tmccurbin | 36:8544a8900884 | 60 | //Info line 3: Left Motor Temp & Right Motor Temp |
jayf | 45:aea289639d6b | 61 | PUT2SCREEN("LMtTmp:", CtoF(0x212), "F", 5, 0, 34);//MOC_MOTEMP_ID |
jayf | 45:aea289639d6b | 62 | PUT2SCREEN("RMtTmp:", CtoF(0x212,4), "F", 5, 69,103);//MOC_MOTEMP_ID bytes 4-7 |
tmccurbin | 36:8544a8900884 | 63 | |
tmccurbin | 36:8544a8900884 | 64 | //Fault line |
tmccurbin | 36:8544a8900884 | 65 | display.PutString(7, 14, "Reserved for faults"); |
tmccurbin | 36:8544a8900884 | 66 | } |
tmccurbin | 36:8544a8900884 | 67 | |
tmccurbin | 36:8544a8900884 | 68 | void DisplayBatteryScreen() |
tmccurbin | 36:8544a8900884 | 69 | { |
tmccurbin | 36:8544a8900884 | 70 | display.ClearScreen(); |
tmccurbin | 36:8544a8900884 | 71 | display.PutString(0, 34, "Main Battery"); |
tmccurbin | 36:8544a8900884 | 72 | |
tmccurbin | 36:8544a8900884 | 73 | //Info line 1: Battery Voltage, Power & Current |
jayf | 45:aea289639d6b | 74 | PUT2SCREEN("V:", float_to_string(0x308), "V", 1, 0, 10);//VOLTAGE_TX_ID |
jayf | 45:aea289639d6b | 75 | PUT2SCREEN("P:", float_to_string(0x314), "W", 1, 45, 55);//POWER_TX_ID |
jayf | 45:aea289639d6b | 76 | PUT2SCREEN("I:", float_to_string(0x306), "A", 1, 90,100);//CURRENT_TX_ID |
tmccurbin | 36:8544a8900884 | 77 | |
tmccurbin | 36:8544a8900884 | 78 | //Info line 2: High, Low, & Average Cell Voltage |
jayf | 45:aea289639d6b | 79 | PUT2SCREEN("Vmx:", VmaxBuffer, "V", 3, 0, 20);//CELLV_MMA_TX_ID_BASE 4-7 |
jayf | 45:aea289639d6b | 80 | PUT2SCREEN("Vmn:", VminBuffer, "", 3, 47, 67);//CELLV_MMA_TX_ID_BASE 0-3 |
jayf | 45:aea289639d6b | 81 | PUT2SCREEN("Vav:", VavgBuffer, "", 3, 88,108);//CELLV_MMA_TX_ID_BASE2 |
tmccurbin | 36:8544a8900884 | 82 | |
tmccurbin | 36:8544a8900884 | 83 | //Info line 3: High, Low, & Average Cell Temp |
jayf | 45:aea289639d6b | 84 | PUT2SCREEN("Tmx:", MaxBatTBuffer, "F", 5, 0, 20);//TEMP_MMA_TX_ID_BASE 4-7 |
jayf | 45:aea289639d6b | 85 | PUT2SCREEN("Tmn:", MinBatTBuffer, "", 5, 47, 67);//TEMP_MMA_TX_ID_BASE 0-3 |
jayf | 45:aea289639d6b | 86 | PUT2SCREEN("Tav:", AvgBatTBuffer, "", 5, 88,108);//TEMP_MMA_TX_ID_BASE2 |
tmccurbin | 36:8544a8900884 | 87 | |
tmccurbin | 36:8544a8900884 | 88 | //Info line 4: Highest Board Temp |
jayf | 45:aea289639d6b | 89 | PUT2SCREEN("HighBoardTemp:", BoardTempBuffer, "F", 7, 17, 87);//BOARDTEMP_TX_ID |
tmccurbin | 36:8544a8900884 | 90 | } |
tmccurbin | 36:8544a8900884 | 91 | |
tmccurbin | 36:8544a8900884 | 92 | void DisplayMotorScreen() |
tmccurbin | 36:8544a8900884 | 93 | { |
tmccurbin | 36:8544a8900884 | 94 | display.ClearScreen(); |
tmccurbin | 36:8544a8900884 | 95 | display.PutString(0, 52, "Motor"); |
tmccurbin | 36:8544a8900884 | 96 | |
tmccurbin | 36:8544a8900884 | 97 | //Info line 1: Left Motor Temp & Right Motor Temp |
tmccurbin | 36:8544a8900884 | 98 | PUT2SCREEN("LMtTmp:", LMtrTmpBuffer, "F", 1, 0, 34); |
tmccurbin | 36:8544a8900884 | 99 | PUT2SCREEN("RMtTmp:", RMtrTmpBuffer, "F", 1, 64, 98); |
tmccurbin | 36:8544a8900884 | 100 | |
tmccurbin | 36:8544a8900884 | 101 | //Info line 2: Left & Right Air Temp |
tmccurbin | 36:8544a8900884 | 102 | PUT2SCREEN("LAirTp:", LAirTmpBuffer, "F", 2, 0, 34); |
tmccurbin | 36:8544a8900884 | 103 | PUT2SCREEN("RairTp:", RAirTmpBuffer, "F", 2, 64, 98); |
tmccurbin | 36:8544a8900884 | 104 | |
tmccurbin | 36:8544a8900884 | 105 | //Info line 3: Left & Right IGBT Temp |
tmccurbin | 36:8544a8900884 | 106 | PUT2SCREEN("LIGBTp:", LIGBTmpBuffer, "F", 3, 0, 34); |
tmccurbin | 36:8544a8900884 | 107 | PUT2SCREEN("RIGBTp:", RIGBTmpBuffer, "F", 3, 64, 98); |
tmccurbin | 36:8544a8900884 | 108 | |
tmccurbin | 36:8544a8900884 | 109 | //Info line 4: Left & Right Motor RPM |
tmccurbin | 36:8544a8900884 | 110 | PUT2SCREEN("Rpm-L:", Rpm_LBuffer, "", 5, 0, 30); |
tmccurbin | 36:8544a8900884 | 111 | PUT2SCREEN("Rpm-R:", Rpm_RBuffer, "", 5, 77,107); |
tmccurbin | 36:8544a8900884 | 112 | |
tmccurbin | 36:8544a8900884 | 113 | //Info line 5: Torque Request (Throttle) |
tmccurbin | 36:8544a8900884 | 114 | PUT2SCREEN("Torque Request:", TRequestBufferL, "%", 7, 0, 75); |
tmccurbin | 36:8544a8900884 | 115 | PUT2SCREEN(",", TRequestBufferR, "%", 7, 95, 98); |
tmccurbin | 36:8544a8900884 | 116 | } |
tmccurbin | 36:8544a8900884 | 117 | |
tmccurbin | 36:8544a8900884 | 118 | void DisplaySysMgmtScreen() |
tmccurbin | 36:8544a8900884 | 119 | { |
tmccurbin | 36:8544a8900884 | 120 | display.ClearScreen(); |
tmccurbin | 36:8544a8900884 | 121 | display.PutString(0, 22, "System Management"); |
tmccurbin | 36:8544a8900884 | 122 | |
tmccurbin | 36:8544a8900884 | 123 | //Info line 1: Small Battery Current & Shutdown Switch State |
tmccurbin | 36:8544a8900884 | 124 | PUT2SCREEN("I_GLV:", SmallBatCurrentBuffer,"A", 1, 0, 30); |
tmccurbin | 36:8544a8900884 | 125 | PUT2SCREEN("ShtdSwtch:", ShtdSwtchBuffer, "", 1, 58,108); |
tmccurbin | 36:8544a8900884 | 126 | |
tmccurbin | 36:8544a8900884 | 127 | //Info line 2: Fan Duty Cycle |
tmccurbin | 36:8544a8900884 | 128 | PUT2SCREEN("Fan-1:", Fan1Buffer, "", 3, 0, 30); |
tmccurbin | 36:8544a8900884 | 129 | PUT2SCREEN("Fan-2:", Fan2Buffer, "", 3, 77,107); |
tmccurbin | 36:8544a8900884 | 130 | |
tmccurbin | 36:8544a8900884 | 131 | //Info line 3: Pump Duty Cycle |
tmccurbin | 36:8544a8900884 | 132 | PUT2SCREEN("Pump1:", Pump1Buffer, "", 5, 0, 30); |
tmccurbin | 36:8544a8900884 | 133 | PUT2SCREEN("Pump2:", Pump2Buffer, "", 5, 77,107); |
tmccurbin | 36:8544a8900884 | 134 | |
tmccurbin | 36:8544a8900884 | 135 | //Info line 4: DCDC & IMD Status |
tmccurbin | 36:8544a8900884 | 136 | PUT2SCREEN("DCDC :", DCDCBuffer, "", 7, 0, 30); |
tmccurbin | 40:92f08fdc32df | 137 | PUT2SCREEN(" IMD :", IMDRBuffer, "", 7, 52,82); |
tmccurbin | 36:8544a8900884 | 138 | } |
tmccurbin | 36:8544a8900884 | 139 | |
tmccurbin | 36:8544a8900884 | 140 | void DisplayFaultScreen() |
tmccurbin | 36:8544a8900884 | 141 | { |
tmccurbin | 36:8544a8900884 | 142 | display.ClearScreen(); |
tmccurbin | 36:8544a8900884 | 143 | display.PutString(0, 49, "Faults"); |
tmccurbin | 36:8544a8900884 | 144 | |
tmccurbin | 36:8544a8900884 | 145 | //Info line 1: Battery Voltage, Power & Current |
tmccurbin | 36:8544a8900884 | 146 | PUT2SCREEN("", Fault1Buffer, "", 1, 0, 0); |
tmccurbin | 36:8544a8900884 | 147 | PUT2SCREEN("", Fault1Buffer, "", 2, 0, 0); |
tmccurbin | 36:8544a8900884 | 148 | PUT2SCREEN("", Fault1Buffer, "", 3, 0, 0); |
tmccurbin | 36:8544a8900884 | 149 | PUT2SCREEN("", Fault1Buffer, "", 4, 0, 0); |
tmccurbin | 36:8544a8900884 | 150 | PUT2SCREEN("", Fault1Buffer, "", 5, 0, 0); |
tmccurbin | 36:8544a8900884 | 151 | PUT2SCREEN("", Fault1Buffer, "", 6, 0, 0); |
tmccurbin | 36:8544a8900884 | 152 | PUT2SCREEN("", Fault1Buffer, "", 7, 0, 0); |
tmccurbin | 36:8544a8900884 | 153 | } |
tmccurbin | 36:8544a8900884 | 154 | |
tmccurbin | 36:8544a8900884 | 155 | void DisplayChargeScreen() |
tmccurbin | 36:8544a8900884 | 156 | { |
tmccurbin | 36:8544a8900884 | 157 | display.ClearScreen(); |
tmccurbin | 36:8544a8900884 | 158 | display.PutString(0, 44, "CHARGING"); |
tmccurbin | 36:8544a8900884 | 159 | |
tmccurbin | 36:8544a8900884 | 160 | // Battery Voltage, Charge Current, & Source Voltage |
tmccurbin | 36:8544a8900884 | 161 | PUT2SCREEN("Battery Voltage :", BigBatVoltBuffer, "V", 1, 9, 94); |
tmccurbin | 36:8544a8900884 | 162 | PUT2SCREEN("Charging Current:", ChargeCurrBuffer, "V", 3, 9, 94); |
tmccurbin | 36:8544a8900884 | 163 | PUT2SCREEN("Source Voltage :", SourceVBuffer, "F", 5, 12, 92); |
tmccurbin | 36:8544a8900884 | 164 | } |
tmccurbin | 36:8544a8900884 | 165 | |
tmccurbin | 36:8544a8900884 | 166 | void ToggleScreen() |
tmccurbin | 36:8544a8900884 | 167 | { |
tmccurbin | 36:8544a8900884 | 168 | CurrScreen = (CurrScreen+1) %5; |
tmccurbin | 36:8544a8900884 | 169 | } |
tmccurbin | 36:8544a8900884 | 170 | |
tmccurbin | 36:8544a8900884 | 171 | void DisplayCurrScreen(void const *args) |
tmccurbin | 36:8544a8900884 | 172 | { |
tmccurbin | 36:8544a8900884 | 173 | while(1) { |
tmccurbin | 36:8544a8900884 | 174 | if(PrevScreen != CurrScreen) { |
tmccurbin | 36:8544a8900884 | 175 | switch(CurrScreen) { |
tmccurbin | 36:8544a8900884 | 176 | case 0: |
tmccurbin | 36:8544a8900884 | 177 | DisplayHomeScreen(); |
tmccurbin | 36:8544a8900884 | 178 | break; |
tmccurbin | 36:8544a8900884 | 179 | case 1: |
tmccurbin | 36:8544a8900884 | 180 | DisplayBatteryScreen(); |
tmccurbin | 36:8544a8900884 | 181 | break; |
tmccurbin | 36:8544a8900884 | 182 | case 2: |
tmccurbin | 36:8544a8900884 | 183 | DisplayMotorScreen(); |
tmccurbin | 36:8544a8900884 | 184 | break; |
tmccurbin | 36:8544a8900884 | 185 | case 3: |
tmccurbin | 36:8544a8900884 | 186 | DisplaySysMgmtScreen(); |
tmccurbin | 36:8544a8900884 | 187 | break; |
tmccurbin | 36:8544a8900884 | 188 | case 4: |
tmccurbin | 36:8544a8900884 | 189 | DisplayChargeScreen(); |
tmccurbin | 36:8544a8900884 | 190 | break; |
tmccurbin | 36:8544a8900884 | 191 | case 5: |
tmccurbin | 36:8544a8900884 | 192 | DisplayFaultScreen(); |
tmccurbin | 36:8544a8900884 | 193 | break; |
tmccurbin | 36:8544a8900884 | 194 | default: |
tmccurbin | 36:8544a8900884 | 195 | break; |
tmccurbin | 36:8544a8900884 | 196 | } |
tmccurbin | 36:8544a8900884 | 197 | PrevScreen = CurrScreen; |
tmccurbin | 36:8544a8900884 | 198 | } |
tmccurbin | 36:8544a8900884 | 199 | } |
tmccurbin | 36:8544a8900884 | 200 | |
tmccurbin | 36:8544a8900884 | 201 | } |