![](/media/cache/profiles/0df840aed5f513a02964d0c27bc4f277.jpg.50x50_q85.jpg)
Dual CANbus monitor and instrumentation cluster. Presently tuned for the Nissan Leaf EV.
Dependencies: SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2_ILI9341 mbed
Fork of CANary_corrupt by
After adding the LPC1768 platform, import as a program and do not select the "update to latest revision" box
User Guide
Eagle Schematic and Board design
/media/uploads/TickTock/canaryr6.zip
For LCD Rev 1.01:
For VCD Rev 2.00:
Parts List
Assembly
1) LCD Displays
I found ribbon cable is a nice way to organize the wires to the displays. There are two versions of the display and each must be wired differently. The original project used HW REV. 1.01. For that version, you'll need 12 conductors and I connected them in the following order:
1 | LED+ |
2 | LED- |
3 | RST |
4 | SDI |
5 | WR/SCLK |
6 | CS |
7 | X+ |
8 | X- |
9 | Y+ |
10 | Y- |
11 | VDD |
12 | GND |
If, instead, you have HW REV 2.0, you will need 13 conductors with the following order:
1 | LED+ |
2 | LED- |
3 | RST |
4 | SDI |
5 | RS (SCLK) |
6 | WR (DC) |
7 | CS |
8 | X+ |
9 | X- |
10 | Y+ |
11 | Y- |
12 | VDD |
13 | GND |
First I connected all the GND connections (2 GND & IM0, IM1, IM3 for REV1.01 or 2 GND, RD, & IM0 for REV2.00). Do not connect the bottom GND until you have the ribbon cable connected. After making all the ribbon cable connections (connecting the GND of the ribbon cable to the bottom GND pad), solder the GND bar from the previous step to the back of the bottom GND connection. Finally, make a connection from the back side 3.3V pin to IM2 for REV1.01 or to IM1,IM2,&IM3 for REV2.00. Take a break and repeat for the second display.
Examples of REV1.01 boards:
Examples of REV2.00:
Once the two displays are complete combine all wires except CS0, CS1, X+, X-, Y+, and Y-. Connect X- of the left display to X+ of the right. Similarly connect Y- of the left display to Y+ of the right. Insulate any exposed wires.
2) PCB
Refer to the schematics to place all the components on the board. If you plan to install into the CANary 3D enclosure, DO NOT install the battery holder or the socket for the mbed and, instead, connect two wires to the VB and GND pads nearby. You will have to install the battery holder against the back wall to avoid interfering with the right-hand display and the mbed will have to be directly soldered. I have not found a socket with a low enough profile to fit in the space provided (depth of enclosure is limited by the space behind the center console). Also, I recommend keeping as much lead as possible on the Zener diode (bending it as shown to clear the back wall). Although it is operating well within parameters, the Zener gets quite hot during extended operation and the leads help dissipate the heat and keep it away from the PCB and other components.Update: Several Zeners have failed resulting in damage to some users boards so I recommend using a DC-DC converter instead to bring the 12V down to 7V.
Once the PCB is populated, solder the LCDs to the PCB. CS0 connects to the right display and CS1 connects to the left.
Update:
The Zener diodes tended to fail after a few months so I am recommending removing them and replacing with a DC-DC converter. This will run cooler and waste less energy, too. To install, remove the left display panel to gain access to the Zener. From there, the Zener can be removed and it's pads used to connect to the DC-DC converter. I recommend setting the output voltage on the bench before installing since the trim pot is tricky to reach once installed. Set it to 7V. The input can be connected to the left pad previously occupied by the zener and the output can connect to the right. GND(-) can be connected to the bottom right pad on the 2x6 header below the flex cable connector. Make sure the GND wire lies flat so it doesn't interfere with the connection of the flex cable.
Once soldered in place, the DC-DC converter can easily be mounted to the back wall with double sided tape above the battery holder.
3) Testing
1) | First step is to buzz out all connections from the LCDs to the pins in the main board |
2) | Next check the touch screen connections. On the main board, place an Ohm meter across X+ and X-. You should read 700 Ohms. Repeat for Y+ and Y-. Then test the resistance from X+ to Y+. With nothing touching the screens, it should read >100K Ohms and <1K when touching either screen. |
3) | When all connections are checked, solder in the mbed. Download and install the touch2 program http://mbed.org/users/TickTock/code/touch2/ to test the basic operation of the mbed and touch screens. |
tips: | |
Touch screen is sensitive - excess flux on X+,X-,Y+,Y- connection on mbed can result in flakey operation | |
If touch is not working, double-check the LCD0_CS and LCD1_CS are not swapped. LCD0_CS must connect to the CS of the LCD that has X- & Y- connected to the mbed. LCD1_CS must connect to the CS of the LCD that has X+ & Y+ connected to the mbed. | |
4) | Once touch2 works, it is time to connect to the OBD connector. I highly recommend double checking all connections from the OBD to the PCB with the cable in place before connecting to the Leaf. Buzz out all the pins in the OBS to make sure none are shorting to each other, Check that the 12V goes to the Zener (and nothing else) and the switched 12V to the resistor divider (and nothing else). Test the ground connection properly connects to ground and nothing else. |
5) | Once you are confident there are no shorts or wrong connections from the OBD connector, take a deep breath and plug it into your leaf. Touch2 program should come up and function. Unplug and install the latest CANary firmware. If you have the REV2.00 LCD boards, you will need to edit the precompile.h file in the TOUCH_TFTx2_w9341 library and set USE_ILI9341 to 1. Test all features before installing into the enclosure (gids, cellpair, menu system, logging) since installing and removing from the enclosure is a PITA. |
4) Enclosure
The 3D printer leaves a lot of powder behind - I used a strong spray of water to get it out of all the cracks. The enclosure comes with a rather rough finish. I recommend convincing yourself you like it, then simply lightly sand then paint before assembly. Sanding is very difficult - the nylon is very nicely fused and doesn't want to sand. I tried sandblasting and that didn't work either. I had some limited success with filler and then sanding, but only on the outside - it is too difficult to sand the face.
5) Final Assembly
Make sure you are well rested with lots of patience before attempting assembly. It is a puzzle figuring out how to get both displays and the PCB in place. Enclosure was too expensive for me to keep iterating to optimize for assembly. I ended up snipping the thin display posts shorter and using various tools to push the displays into place. Also, some USB connectors are taller than others. If you have one of the taller ones, you will have to deflect the back wall a bit while inserting the PCB (being careful not to bend the housing) to get it to it's opening in the back wall. Do use a screw in the provided post to secure the PCB as USB insertion will otherwise dislodge it.
I added an additional safety line which wraps around the center post to prevent the enclosure from becoming a projectile in the event of an accident.
Installed:
displayModes.cpp@189:f566191877e4, 2014-05-18 (annotated)
- Committer:
- TickTock
- Date:
- Sun May 18 13:15:14 2014 +0000
- Revision:
- 189:f566191877e4
- Parent:
- 184:5ca7b78297fe
- Child:
- 187:af5ba64c0afe
cleanup library names
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TickTock | 13:62e0f7f39ff5 | 1 | //displayModes.cpp |
TickTock | 37:fea2c1d52c5f | 2 | #include "displayModes.h" |
TickTock | 13:62e0f7f39ff5 | 3 | |
TickTock | 25:ddf0ec209f03 | 4 | char sTemp1[40]; |
TickTock | 24:6cf76ed8c432 | 5 | char sTemp2[16]; |
TickTock | 13:62e0f7f39ff5 | 6 | |
TickTock | 42:4533b13b297d | 7 | void mainDisplay (bool force, bool showButtons){ |
TickTock | 124:0d622967b764 | 8 | unsigned short gids, SOC_x10, packV_x2, tireP; |
TickTock | 165:4daa921730dd | 9 | float dte,total_kW; |
TickTock | 150:ef46ce63345c | 10 | unsigned char aTemp; |
TickTock | 148:6e3b9135fad2 | 11 | static unsigned short lgids=0, lSOC=0, lpackV_x2=0, ltireP=0; |
TickTock | 148:6e3b9135fad2 | 12 | static unsigned char laTemp=0; |
TickTock | 165:4daa921730dd | 13 | static float lmaxTemp=0, lkW=0, laccV=0, lmpkWh=0, useable_kWh=0; |
TickTock | 131:0d926c080a65 | 14 | |
TickTock | 13:62e0f7f39ff5 | 15 | CANMessage msg; |
TickTock | 13:62e0f7f39ff5 | 16 | |
TickTock | 13:62e0f7f39ff5 | 17 | msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids |
TickTock | 13:62e0f7f39ff5 | 18 | gids = (msg.data[0]<<2)+(msg.data[1]>>6); |
TickTock | 13:62e0f7f39ff5 | 19 | msg = lastMsg[indexLastMsg[0x55b]]; //Get SOC |
TickTock | 122:138a40892a4c | 20 | SOC_x10 = (msg.data[0]<<2)+(msg.data[1]>>6); |
TickTock | 13:62e0f7f39ff5 | 21 | msg = lastMsg[indexLastMsg[0x1db]]; //Get pack volts |
TickTock | 119:0e2b641e98a2 | 22 | packV_x2 = (msg.data[2]<<2)+(msg.data[3]>>6); |
TickTock | 150:ef46ce63345c | 23 | msg = lastMsg[indexLastMsg[0x54c]]; //Get ambient |
TickTock | 150:ef46ce63345c | 24 | aTemp = msg.data[6]-56; |
TickTock | 124:0d622967b764 | 25 | msg = lastMsg[indexLastMsg[0x385]]; //Get tire pressure |
TickTock | 124:0d622967b764 | 26 | tireP = msg.data[2]+msg.data[3]+msg.data[4]+msg.data[5]; |
TickTock | 118:02010b18efdc | 27 | |
TickTock | 13:62e0f7f39ff5 | 28 | tt.background(Navy); |
TickTock | 38:155ec32c5e91 | 29 | tt.set_font((unsigned char*) Arial28x28); |
TickTock | 13:62e0f7f39ff5 | 30 | if(force) tt.cls(); |
TickTock | 48:d1ce92104a1f | 31 | if(skin==ttSkin){ |
TickTock | 165:4daa921730dd | 32 | if(force||gids!=lgids){ |
TickTock | 166:ec3951ba9701 | 33 | tt.locate(10,4); |
TickTock | 136:41a204105511 | 34 | tt.foreground(White); |
TickTock | 165:4daa921730dd | 35 | printf("%dgids \n",gids); |
TickTock | 170:7ee98e3611bc | 36 | useable_kWh = (float)(gids-5)*kWperGid; |
TickTock | 136:41a204105511 | 37 | if (useable_kWh<0){ |
TickTock | 136:41a204105511 | 38 | useable_kWh=0; |
TickTock | 136:41a204105511 | 39 | } |
TickTock | 184:5ca7b78297fe | 40 | if(debugMode){ |
TickTock | 184:5ca7b78297fe | 41 | tt.locate(165,4); |
TickTock | 184:5ca7b78297fe | 42 | if (useable_kWh<9.95){ |
TickTock | 184:5ca7b78297fe | 43 | printf("%3.2f %3.2f\n",useable_kWh,(wh[gids]-400)/1000); //LAJ temp |
TickTock | 184:5ca7b78297fe | 44 | } else { |
TickTock | 184:5ca7b78297fe | 45 | printf("%3.1f %3.1f\n",useable_kWh,(wh[gids]-400)/1000); //LAJ temp |
TickTock | 184:5ca7b78297fe | 46 | } |
TickTock | 184:5ca7b78297fe | 47 | }else{ |
TickTock | 184:5ca7b78297fe | 48 | tt.locate(181,4); |
TickTock | 184:5ca7b78297fe | 49 | if (useable_kWh<9.95){ |
TickTock | 184:5ca7b78297fe | 50 | printf("%3.2fkWh\n",useable_kWh); |
TickTock | 184:5ca7b78297fe | 51 | } else { |
TickTock | 184:5ca7b78297fe | 52 | printf("%3.1fkWh\n",useable_kWh); |
TickTock | 184:5ca7b78297fe | 53 | } |
TickTock | 165:4daa921730dd | 54 | } |
TickTock | 165:4daa921730dd | 55 | } |
TickTock | 165:4daa921730dd | 56 | if(force||SOC_x10!=lSOC){ |
TickTock | 166:ec3951ba9701 | 57 | tt.locate(10,34);//216,10 |
TickTock | 165:4daa921730dd | 58 | tt.foreground(LightGrey); |
TickTock | 166:ec3951ba9701 | 59 | printf("%2.1f%s\n",(float)SOC_x10/10,"%"); |
TickTock | 165:4daa921730dd | 60 | lSOC=SOC_x10; |
TickTock | 165:4daa921730dd | 61 | } |
TickTock | 165:4daa921730dd | 62 | total_kW=kW[0]+CCkW; |
TickTock | 165:4daa921730dd | 63 | if(force||total_kW!=lkW){ |
TickTock | 165:4daa921730dd | 64 | tt.foreground(Yellow); |
TickTock | 168:9227024c4e3a | 65 | if(total_kW<=-9.95){ //Right justify |
TickTock | 168:9227024c4e3a | 66 | tt.locate(186,34); |
TickTock | 168:9227024c4e3a | 67 | printf("%3.1fkW\n",total_kW); |
TickTock | 165:4daa921730dd | 68 | } else if (total_kW<0){ |
TickTock | 168:9227024c4e3a | 69 | tt.locate(186,34); |
TickTock | 168:9227024c4e3a | 70 | printf("%3.2fkW\n",total_kW); |
TickTock | 168:9227024c4e3a | 71 | } else if (total_kW<9.95){ |
TickTock | 168:9227024c4e3a | 72 | tt.locate(180,34); |
TickTock | 168:9227024c4e3a | 73 | printf(" %3.2fkW\n",total_kW); |
TickTock | 165:4daa921730dd | 74 | } else { |
TickTock | 168:9227024c4e3a | 75 | tt.locate(180,34); |
TickTock | 168:9227024c4e3a | 76 | printf(" %3.1fkW\n",total_kW); |
TickTock | 165:4daa921730dd | 77 | } |
TickTock | 165:4daa921730dd | 78 | lkW=total_kW; |
TickTock | 165:4daa921730dd | 79 | if(CCon){ |
TickTock | 165:4daa921730dd | 80 | tt.set_font((unsigned char*) Arial12x12); |
TickTock | 169:84d790ac18a2 | 81 | tt.locate(228,64); |
TickTock | 169:84d790ac18a2 | 82 | tt.foreground(GreenYellow); |
TickTock | 169:84d790ac18a2 | 83 | printf(" -%3.2fkW\n",CCkW); |
TickTock | 165:4daa921730dd | 84 | tt.set_font((unsigned char*) Arial28x28); |
TickTock | 165:4daa921730dd | 85 | } |
TickTock | 165:4daa921730dd | 86 | } |
TickTock | 165:4daa921730dd | 87 | if(force||gids!=lgids||mpkWh[dtePeriod]!=lmpkWh){ |
TickTock | 132:08748a67280a | 88 | // Display DTE |
TickTock | 167:58d4edf403d4 | 89 | // worst-case DTE |
TickTock | 167:58d4edf403d4 | 90 | // Compute DTE based on worst saved trip efficiency (without climate control) and adding the impact |
TickTock | 167:58d4edf403d4 | 91 | // of the current climate control power relative to the last 10 minutes of driving |
TickTock | 177:6fda79c2fda1 | 92 | if(maxTripEff>0){// Skip if no data available |
TickTock | 177:6fda79c2fda1 | 93 | dte=convertDistance((minTripEff-mpkWh_noCC+mpkWh[dtePeriod])*useable_kWh); //LM - add metric conversion |
TickTock | 177:6fda79c2fda1 | 94 | tt.foreground(Green); |
TickTock | 177:6fda79c2fda1 | 95 | tt.locate(10,84); |
TickTock | 177:6fda79c2fda1 | 96 | if(dte>=9.5){ |
TickTock | 177:6fda79c2fda1 | 97 | printf("%2.0f \n",dte); |
TickTock | 177:6fda79c2fda1 | 98 | }else{ |
TickTock | 177:6fda79c2fda1 | 99 | printf("%2.1f \n",dte); |
TickTock | 177:6fda79c2fda1 | 100 | } |
TickTock | 136:41a204105511 | 101 | } |
TickTock | 163:3b6fab958773 | 102 | // 10-minute DTE |
TickTock | 48:d1ce92104a1f | 103 | tt.set_font((unsigned char*) SCProSB31x55); |
TickTock | 136:41a204105511 | 104 | tt.foreground(Yellow); |
TickTock | 163:3b6fab958773 | 105 | dte=convertDistance(mpkWh[dtePeriod]*useable_kWh); //LM - add metric conversion |
TickTock | 136:41a204105511 | 106 | if(dte>199){ |
TickTock | 136:41a204105511 | 107 | dte=199; |
TickTock | 136:41a204105511 | 108 | } |
TickTock | 136:41a204105511 | 109 | // " "=0x10, "."=0x15, #=0x1D |
TickTock | 139:ac227b203ef2 | 110 | if(dte>=99.5){ |
TickTock | 165:4daa921730dd | 111 | tt.locate(70,85); |
TickTock | 163:3b6fab958773 | 112 | printf(" %3.0f\n",dte); |
TickTock | 139:ac227b203ef2 | 113 | }else if(dte>=9.5){ |
TickTock | 165:4daa921730dd | 114 | tt.locate(84,85); |
TickTock | 163:3b6fab958773 | 115 | printf(" %2.0f\n",dte); |
TickTock | 136:41a204105511 | 116 | }else{ |
TickTock | 165:4daa921730dd | 117 | tt.locate(79,85); |
TickTock | 163:3b6fab958773 | 118 | printf(" %2.1f\n",dte); |
TickTock | 136:41a204105511 | 119 | } |
TickTock | 136:41a204105511 | 120 | tt.set_font((unsigned char*) Arial28x28); |
TickTock | 165:4daa921730dd | 121 | tt.locate(185,106); |
TickTock | 163:3b6fab958773 | 122 | printf("%s\n",distanceUnit()); |
TickTock | 136:41a204105511 | 123 | |
TickTock | 163:3b6fab958773 | 124 | // No Climate Control DTE |
TickTock | 163:3b6fab958773 | 125 | tt.set_font((unsigned char*) Arial24x23); |
TickTock | 164:46ed06263b0e | 126 | if(CCon) { |
TickTock | 165:4daa921730dd | 127 | dte=convertDistance((mpkWh_noCC-mpkWh[dtePeriod])*useable_kWh); //LM - add metric conversion |
TickTock | 164:46ed06263b0e | 128 | if(dte>199){ |
TickTock | 164:46ed06263b0e | 129 | dte=199; |
TickTock | 164:46ed06263b0e | 130 | } |
TickTock | 169:84d790ac18a2 | 131 | tt.foreground(GreenYellow); |
TickTock | 169:84d790ac18a2 | 132 | if(dte>=9.5){ |
TickTock | 169:84d790ac18a2 | 133 | tt.locate(130,134); |
TickTock | 169:84d790ac18a2 | 134 | printf("+%2.0f \n",dte); |
TickTock | 164:46ed06263b0e | 135 | }else{ |
TickTock | 169:84d790ac18a2 | 136 | tt.locate(130,134); |
TickTock | 169:84d790ac18a2 | 137 | printf("+%2.1f \n",dte); |
TickTock | 169:84d790ac18a2 | 138 | } |
TickTock | 169:84d790ac18a2 | 139 | |
TickTock | 167:58d4edf403d4 | 140 | lmaxTemp=0; //force battery termperature refresh (sometimes overlaps) |
TickTock | 163:3b6fab958773 | 141 | } |
TickTock | 163:3b6fab958773 | 142 | // best-case DTE |
TickTock | 163:3b6fab958773 | 143 | tt.set_font((unsigned char*) Arial28x28); |
TickTock | 167:58d4edf403d4 | 144 | // Compute DTE based on best saved trip efficiency (without climate control) and adding the impact |
TickTock | 167:58d4edf403d4 | 145 | // of the current climate control power relative to the last 10 minutes of driving |
TickTock | 177:6fda79c2fda1 | 146 | if(maxTripEff>0){// Skip if no data available |
TickTock | 177:6fda79c2fda1 | 147 | dte=convertDistance((maxTripEff-mpkWh_noCC+mpkWh[dtePeriod])*useable_kWh); //LM - add metric conversion |
TickTock | 177:6fda79c2fda1 | 148 | tt.foreground(Orange); |
TickTock | 177:6fda79c2fda1 | 149 | if(dte>=99.5){ |
TickTock | 177:6fda79c2fda1 | 150 | tt.locate(255,84); |
TickTock | 177:6fda79c2fda1 | 151 | printf("%3.0f \n",dte); |
TickTock | 177:6fda79c2fda1 | 152 | }else if(dte>=9.5){ |
TickTock | 177:6fda79c2fda1 | 153 | tt.locate(270,84); |
TickTock | 177:6fda79c2fda1 | 154 | printf("%2.0f \n",dte); |
TickTock | 177:6fda79c2fda1 | 155 | }else{ |
TickTock | 177:6fda79c2fda1 | 156 | tt.locate(265,84); |
TickTock | 177:6fda79c2fda1 | 157 | printf("%2.1f \n",dte); |
TickTock | 177:6fda79c2fda1 | 158 | } |
TickTock | 136:41a204105511 | 159 | } |
TickTock | 50:83d5864c64a0 | 160 | lmpkWh=mpkWh[dtePeriod]; |
TickTock | 165:4daa921730dd | 161 | } //!(force||gids!=lgids||mpkWh[dtePeriod]!=lmpkWh) |
TickTock | 165:4daa921730dd | 162 | lgids=gids; |
TickTock | 136:41a204105511 | 163 | if(force||packV_x2!=lpackV_x2){ |
TickTock | 136:41a204105511 | 164 | tt.locate(210,176); |
TickTock | 136:41a204105511 | 165 | tt.foreground(Yellow); |
TickTock | 136:41a204105511 | 166 | printf("%4.1fV\n",(float)packV_x2/2); |
TickTock | 136:41a204105511 | 167 | lpackV_x2=packV_x2; |
TickTock | 136:41a204105511 | 168 | ltireP=0;//Force tire pressure redraw, too |
TickTock | 136:41a204105511 | 169 | } |
TickTock | 150:ef46ce63345c | 170 | if(force||aTemp!=laTemp){ |
TickTock | 138:a2f5af85ed0d | 171 | tt.foreground(Cyan); |
TickTock | 166:ec3951ba9701 | 172 | tt.locate(10,146); |
TickTock | 150:ef46ce63345c | 173 | printf("%2.0f%s\n",convertF(aTemp),temperatureUnit()); |
TickTock | 150:ef46ce63345c | 174 | laTemp=aTemp; |
TickTock | 148:6e3b9135fad2 | 175 | } |
TickTock | 136:41a204105511 | 176 | if(force||maxTemp!=lmaxTemp){ |
TickTock | 136:41a204105511 | 177 | tt.foreground(Cyan); |
TickTock | 138:a2f5af85ed0d | 178 | tt.locate(210,146); |
TickTock | 168:9227024c4e3a | 179 | if (convertC(maxTemp)<99.5){ |
TickTock | 148:6e3b9135fad2 | 180 | printf(" %3.1f%s\n",convertC(maxTemp),temperatureUnit()); |
TickTock | 136:41a204105511 | 181 | }else{ |
TickTock | 148:6e3b9135fad2 | 182 | printf("%4.1f%s\n",convertC(maxTemp),temperatureUnit()); |
TickTock | 136:41a204105511 | 183 | } |
TickTock | 136:41a204105511 | 184 | lmaxTemp=maxTemp; |
TickTock | 136:41a204105511 | 185 | } |
TickTock | 136:41a204105511 | 186 | if(force||accV!=laccV){ |
TickTock | 166:ec3951ba9701 | 187 | tt.locate(10,176); |
TickTock | 136:41a204105511 | 188 | tt.foreground(Yellow); |
TickTock | 148:6e3b9135fad2 | 189 | printf("%3.1fV \n",accV); |
TickTock | 136:41a204105511 | 190 | laccV=accV; |
TickTock | 136:41a204105511 | 191 | } |
TickTock | 131:0d926c080a65 | 192 | if(force||tireP!=ltireP){ |
TickTock | 134:ad243e4f1a17 | 193 | if(msg.data[2]<minTirePressure){ |
TickTock | 134:ad243e4f1a17 | 194 | tt.foreground(Orange); // Hi-light if any are low (<35psi) |
TickTock | 134:ad243e4f1a17 | 195 | }else{ |
TickTock | 134:ad243e4f1a17 | 196 | tt.foreground(LightGrey); |
TickTock | 134:ad243e4f1a17 | 197 | } |
TickTock | 131:0d926c080a65 | 198 | if(msg.data[6]&0x80){ |
TickTock | 134:ad243e4f1a17 | 199 | if(msg.data[2]<minTirePressure){ |
TickTock | 134:ad243e4f1a17 | 200 | tt.foreground(Orange); // Hi-light if any are low (<35psi) |
TickTock | 134:ad243e4f1a17 | 201 | }else{ |
TickTock | 134:ad243e4f1a17 | 202 | tt.foreground(LightGrey); |
TickTock | 134:ad243e4f1a17 | 203 | } |
TickTock | 131:0d926c080a65 | 204 | tt.locate(10,206); |
TickTock | 131:0d926c080a65 | 205 | printf("%3.1f\n",(float)msg.data[2]/4); |
TickTock | 131:0d926c080a65 | 206 | } |
TickTock | 131:0d926c080a65 | 207 | if(msg.data[6]&0x40){ |
TickTock | 134:ad243e4f1a17 | 208 | if(msg.data[3]<minTirePressure){ |
TickTock | 134:ad243e4f1a17 | 209 | tt.foreground(Orange); // Hi-light if any are low (<35psi) |
TickTock | 134:ad243e4f1a17 | 210 | }else{ |
TickTock | 134:ad243e4f1a17 | 211 | tt.foreground(LightGrey); |
TickTock | 134:ad243e4f1a17 | 212 | } |
TickTock | 131:0d926c080a65 | 213 | tt.locate(90,206); |
TickTock | 131:0d926c080a65 | 214 | printf("%3.1f\n",(float)msg.data[3]/4); |
TickTock | 131:0d926c080a65 | 215 | } |
TickTock | 131:0d926c080a65 | 216 | if(msg.data[6]&0x20){ |
TickTock | 134:ad243e4f1a17 | 217 | if(msg.data[4]<minTirePressure){ |
TickTock | 134:ad243e4f1a17 | 218 | tt.foreground(Orange); // Hi-light if any are low (<35psi) |
TickTock | 134:ad243e4f1a17 | 219 | }else{ |
TickTock | 134:ad243e4f1a17 | 220 | tt.foreground(LightGrey); |
TickTock | 134:ad243e4f1a17 | 221 | } |
TickTock | 131:0d926c080a65 | 222 | tt.locate(170,206); |
TickTock | 131:0d926c080a65 | 223 | printf("%3.1f\n",(float)msg.data[4]/4); |
TickTock | 131:0d926c080a65 | 224 | } |
TickTock | 131:0d926c080a65 | 225 | if(msg.data[6]&0x10){ |
TickTock | 134:ad243e4f1a17 | 226 | if(msg.data[5]<minTirePressure){ |
TickTock | 134:ad243e4f1a17 | 227 | tt.foreground(Orange); // Hi-light if any are low (<35psi) |
TickTock | 134:ad243e4f1a17 | 228 | }else{ |
TickTock | 134:ad243e4f1a17 | 229 | tt.foreground(LightGrey); |
TickTock | 134:ad243e4f1a17 | 230 | } |
TickTock | 131:0d926c080a65 | 231 | tt.locate(250,206); |
TickTock | 131:0d926c080a65 | 232 | printf("%3.1f\n",(float)msg.data[5]/4); |
TickTock | 131:0d926c080a65 | 233 | } |
TickTock | 131:0d926c080a65 | 234 | ltireP=tireP; |
TickTock | 102:fd19f777a0b4 | 235 | } |
TickTock | 48:d1ce92104a1f | 236 | }else {//if(skin==ggSkin){ |
TickTock | 48:d1ce92104a1f | 237 | if(force||gids!=lgids){ |
TickTock | 48:d1ce92104a1f | 238 | tt.locate(10,10); |
TickTock | 48:d1ce92104a1f | 239 | printf("%4d GIDs \n",gids); |
TickTock | 48:d1ce92104a1f | 240 | |
TickTock | 48:d1ce92104a1f | 241 | tt.locate(40,40); // gg - add GIDs Percent of 281 |
TickTock | 48:d1ce92104a1f | 242 | printf("%4.1f%s \n", (float)gids*0.355872, "% ") ; |
TickTock | 48:d1ce92104a1f | 243 | tt.locate(20,70); |
TickTock | 170:7ee98e3611bc | 244 | printf("%4.1f kwh \n",(float)gids*kWperGid); // gg - closer to usable |
TickTock | 48:d1ce92104a1f | 245 | |
TickTock | 48:d1ce92104a1f | 246 | tt.set_font((unsigned char*) SCProSB31x55); |
TickTock | 48:d1ce92104a1f | 247 | tt.foreground(Green); |
TickTock | 48:d1ce92104a1f | 248 | //tt.locate(60,96); |
TickTock | 48:d1ce92104a1f | 249 | tt.locate(60,116); // gg - move down a little |
leafman | 98:9f8bab96edff | 250 | printf("%4.1f %s \n",convertDistance((float)(gids-5)*0.31),distanceUnit()); // Approx for now - LM added metric |
TickTock | 48:d1ce92104a1f | 251 | lgids=gids; |
TickTock | 48:d1ce92104a1f | 252 | tt.foreground(Yellow); |
TickTock | 48:d1ce92104a1f | 253 | tt.set_font((unsigned char*) Arial28x28); |
TickTock | 48:d1ce92104a1f | 254 | } |
TickTock | 48:d1ce92104a1f | 255 | |
TickTock | 122:138a40892a4c | 256 | if(force||SOC_x10!=lSOC){ |
TickTock | 48:d1ce92104a1f | 257 | tt.locate(200,10); |
TickTock | 122:138a40892a4c | 258 | printf("%4.1f%s\n",(float)SOC_x10/10,"% "); |
TickTock | 122:138a40892a4c | 259 | lSOC=SOC_x10; |
TickTock | 48:d1ce92104a1f | 260 | } |
TickTock | 119:0e2b641e98a2 | 261 | if(force||packV_x2!=lpackV_x2){ |
TickTock | 48:d1ce92104a1f | 262 | tt.locate(200,200); |
TickTock | 119:0e2b641e98a2 | 263 | printf("%4.1fV \n",(float)packV_x2/2); |
TickTock | 119:0e2b641e98a2 | 264 | lpackV_x2=packV_x2; |
TickTock | 48:d1ce92104a1f | 265 | } |
TickTock | 48:d1ce92104a1f | 266 | if(force||accV!=laccV){ |
TickTock | 48:d1ce92104a1f | 267 | tt.locate(20,200); |
TickTock | 48:d1ce92104a1f | 268 | printf("%3.1fV \n",accV); |
TickTock | 48:d1ce92104a1f | 269 | laccV=accV; |
TickTock | 48:d1ce92104a1f | 270 | } |
TickTock | 161:71ac85d11f03 | 271 | total_kW=kW[0]+CCkW; |
TickTock | 161:71ac85d11f03 | 272 | if(force||total_kW!=lkW){ |
TickTock | 48:d1ce92104a1f | 273 | tt.locate(160,40); // gg - move left to keep from wrap |
TickTock | 161:71ac85d11f03 | 274 | printf("%3.2fkw \n",total_kW); // use small w to save space |
TickTock | 161:71ac85d11f03 | 275 | lkW=total_kW; |
TickTock | 48:d1ce92104a1f | 276 | } |
TickTock | 35:5acbd8a64a89 | 277 | } |
TickTock | 108:29b5a760adc2 | 278 | if(led4){ |
TickTock | 106:f016912a03db | 279 | tt.fillcircle(310,10,6,Red); |
TickTock | 106:f016912a03db | 280 | }else{ |
TickTock | 106:f016912a03db | 281 | tt.fillcircle(310,10,6,Navy); |
TickTock | 106:f016912a03db | 282 | } |
TickTock | 13:62e0f7f39ff5 | 283 | } |
TickTock | 13:62e0f7f39ff5 | 284 | |
TickTock | 42:4533b13b297d | 285 | void printLast (bool force, bool showButtons){ |
TickTock | 13:62e0f7f39ff5 | 286 | CANMessage msg; |
TickTock | 13:62e0f7f39ff5 | 287 | tt.locate(0,6); |
TickTock | 13:62e0f7f39ff5 | 288 | tt.foreground(Red); |
TickTock | 13:62e0f7f39ff5 | 289 | tt.background(Yellow); |
TickTock | 13:62e0f7f39ff5 | 290 | if(force) tt.cls(); // Just clear screen if forced - always update display |
TickTock | 13:62e0f7f39ff5 | 291 | tt.set_font((unsigned char*) Arial12x12_prop); // select the font |
TickTock | 13:62e0f7f39ff5 | 292 | for(int i=0; i<19; i++){ |
TickTock | 13:62e0f7f39ff5 | 293 | msg = lastMsg[i+indexOffset]; |
TickTock | 13:62e0f7f39ff5 | 294 | printf("%03x : %02x %02x %02x %02x %02x %02x %02x %02x \n",msg.id,msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7]); |
TickTock | 13:62e0f7f39ff5 | 295 | } |
TickTock | 122:138a40892a4c | 296 | if(showButtons){ |
garygid | 54:6ce808d0995e | 297 | showButton(0,0," <up>","",4,4); |
garygid | 54:6ce808d0995e | 298 | showButton(2,0,"<down>","",4,4); |
TickTock | 25:ddf0ec209f03 | 299 | } |
TickTock | 13:62e0f7f39ff5 | 300 | } |
TickTock | 13:62e0f7f39ff5 | 301 | |
TickTock | 42:4533b13b297d | 302 | void printChanged (bool force, bool showButtons){ |
TickTock | 13:62e0f7f39ff5 | 303 | CANMessage msg; |
TickTock | 13:62e0f7f39ff5 | 304 | unsigned char i,j; |
TickTock | 13:62e0f7f39ff5 | 305 | tt.locate(0,6); |
TickTock | 13:62e0f7f39ff5 | 306 | tt.foreground(Red); |
TickTock | 13:62e0f7f39ff5 | 307 | tt.background(Yellow); |
TickTock | 13:62e0f7f39ff5 | 308 | if(force) tt.cls(); // Just clear screen if forced - always update display |
TickTock | 13:62e0f7f39ff5 | 309 | tt.set_font((unsigned char*) Arial12x12_prop); // select the font |
TickTock | 13:62e0f7f39ff5 | 310 | i=0; |
TickTock | 13:62e0f7f39ff5 | 311 | j=indexOffset; |
TickTock | 13:62e0f7f39ff5 | 312 | do{ |
TickTock | 13:62e0f7f39ff5 | 313 | j=j<99?j+1:j; |
TickTock | 13:62e0f7f39ff5 | 314 | if(msgChanged[j]>0){ |
TickTock | 13:62e0f7f39ff5 | 315 | msg = lastMsg[j]; |
TickTock | 13:62e0f7f39ff5 | 316 | printf("%03x : %02x %02x %02x %02x %02x %02x %02x %02x \n",msg.id,msg.data[0],msg.data[1],msg.data[2],msg.data[3],msg.data[4],msg.data[5],msg.data[6],msg.data[7]); |
TickTock | 13:62e0f7f39ff5 | 317 | i++; |
TickTock | 13:62e0f7f39ff5 | 318 | }// if changed |
TickTock | 13:62e0f7f39ff5 | 319 | }while(i<19&&j<99); |
TickTock | 122:138a40892a4c | 320 | if(showButtons){ |
garygid | 54:6ce808d0995e | 321 | showButton(0,0," <up>","",4,4); |
garygid | 54:6ce808d0995e | 322 | showButton(2,0," <down>","",4,4); |
garygid | 54:6ce808d0995e | 323 | showButton(1,0," Reset","Baseline",4,4); |
TickTock | 40:0e6e71a7323f | 324 | } |
TickTock | 13:62e0f7f39ff5 | 325 | } |
TickTock | 13:62e0f7f39ff5 | 326 | |
TickTock | 42:4533b13b297d | 327 | void printLog (bool force, bool showButtons){ |
TickTock | 118:02010b18efdc | 328 | static unsigned char lastldl = 0; |
TickTock | 118:02010b18efdc | 329 | unsigned char ldl=displayLoc; |
TickTock | 118:02010b18efdc | 330 | if(force||ldl!=lastldl){ //only update if changed |
TickTock | 13:62e0f7f39ff5 | 331 | tt.foreground(Amber); |
TickTock | 13:62e0f7f39ff5 | 332 | tt.background(Black); |
TickTock | 13:62e0f7f39ff5 | 333 | tt.cls(); |
TickTock | 13:62e0f7f39ff5 | 334 | tt.locate(0,6); |
TickTock | 13:62e0f7f39ff5 | 335 | tt.set_font((unsigned char*) Arial12x12); |
TickTock | 13:62e0f7f39ff5 | 336 | for(int i=0; i<19; i++){ |
TickTock | 118:02010b18efdc | 337 | printf("%s",displayLog[ldl]); |
TickTock | 118:02010b18efdc | 338 | ldl=ldl>17?0:ldl+1; |
TickTock | 13:62e0f7f39ff5 | 339 | } |
TickTock | 13:62e0f7f39ff5 | 340 | } |
TickTock | 118:02010b18efdc | 341 | lastldl=ldl; |
TickTock | 13:62e0f7f39ff5 | 342 | } |
TickTock | 13:62e0f7f39ff5 | 343 | |
TickTock | 168:9227024c4e3a | 344 | void tripDisplay (bool force, bool showButtons, bool inclCC){ |
TickTock | 168:9227024c4e3a | 345 | static int lkWh=0; |
TickTock | 168:9227024c4e3a | 346 | float mpkWh_f, kWh_f; |
TickTock | 118:02010b18efdc | 347 | tt.background(White); |
TickTock | 118:02010b18efdc | 348 | if(force){ |
TickTock | 118:02010b18efdc | 349 | tt.cls(); |
TickTock | 118:02010b18efdc | 350 | } |
TickTock | 168:9227024c4e3a | 351 | if(force||(lkWh!=(int)(kWh_trip[0]*100))){ //only update if changed |
TickTock | 118:02010b18efdc | 352 | tt.foreground(Navy); |
TickTock | 118:02010b18efdc | 353 | tt.set_font((unsigned char*) Arial28x28); |
TickTock | 118:02010b18efdc | 354 | tt.locate(6,210); |
TickTock | 169:84d790ac18a2 | 355 | printf("kWh : %s : Eff\n",distanceUnit()); |
TickTock | 169:84d790ac18a2 | 356 | tt.set_font((unsigned char*) Arial12x12); |
TickTock | 169:84d790ac18a2 | 357 | tt.locate(260,220); |
TickTock | 168:9227024c4e3a | 358 | if(inclCC){ |
TickTock | 169:84d790ac18a2 | 359 | printf(" (+CC)\n"); |
TickTock | 168:9227024c4e3a | 360 | } else { |
TickTock | 169:84d790ac18a2 | 361 | printf("(noCC)\n"); |
TickTock | 168:9227024c4e3a | 362 | } |
TickTock | 169:84d790ac18a2 | 363 | tt.set_font((unsigned char*) Arial28x28); |
TickTock | 118:02010b18efdc | 364 | for(int i=0; i<3; i++){ |
TickTock | 168:9227024c4e3a | 365 | kWh_f = kWh_trip[i]; |
TickTock | 168:9227024c4e3a | 366 | if(inclCC){ |
TickTock | 168:9227024c4e3a | 367 | kWh_f += CCkWh_trip[i]; |
TickTock | 168:9227024c4e3a | 368 | } |
TickTock | 168:9227024c4e3a | 369 | if(kWh_f>0.01){ |
TickTock | 168:9227024c4e3a | 370 | mpkWh_f = convertDistance(miles_trip[i])/kWh_f; |
TickTock | 152:a4d66901785d | 371 | } else { |
TickTock | 168:9227024c4e3a | 372 | mpkWh_f = 0; |
TickTock | 152:a4d66901785d | 373 | } |
TickTock | 118:02010b18efdc | 374 | tt.locate(6,20+i*60); |
TickTock | 168:9227024c4e3a | 375 | printf("%3.2f : %3.1f : %2.1f \n",kWh_f,convertDistance(miles_trip[i]),mpkWh_f); |
TickTock | 118:02010b18efdc | 376 | } |
TickTock | 151:3047ebb3c9a8 | 377 | tt.foreground(Navy); |
TickTock | 151:3047ebb3c9a8 | 378 | tt.set_font((unsigned char*) Arial12x12); |
TickTock | 151:3047ebb3c9a8 | 379 | tt.locate(274,18); |
TickTock | 151:3047ebb3c9a8 | 380 | printf("per\n"); |
TickTock | 151:3047ebb3c9a8 | 381 | tt.locate(274,33); |
TickTock | 151:3047ebb3c9a8 | 382 | printf("trip\n"); |
TickTock | 151:3047ebb3c9a8 | 383 | tt.locate(274,78); |
TickTock | 151:3047ebb3c9a8 | 384 | printf("per\n"); |
TickTock | 151:3047ebb3c9a8 | 385 | tt.locate(265,93); |
TickTock | 151:3047ebb3c9a8 | 386 | printf("charge\n"); |
TickTock | 151:3047ebb3c9a8 | 387 | tt.locate(265,145); |
TickTock | 151:3047ebb3c9a8 | 388 | printf("custom\n"); |
TickTock | 168:9227024c4e3a | 389 | lkWh=(int)(kWh_trip[0]*100); |
TickTock | 122:138a40892a4c | 390 | } |
TickTock | 122:138a40892a4c | 391 | if(showButtons){ |
TickTock | 177:6fda79c2fda1 | 392 | showButton(3,1," Cancel"," Day",4,4); |
TickTock | 177:6fda79c2fda1 | 393 | showButton(3,2," Reset","Custom",4,4); |
TickTock | 118:02010b18efdc | 394 | } |
TickTock | 118:02010b18efdc | 395 | } |
TickTock | 118:02010b18efdc | 396 | |
TickTock | 118:02010b18efdc | 397 | void healthDisplay (bool force, bool showButtons){ |
TickTock | 131:0d926c080a65 | 398 | unsigned short gids, SOC_x10, SOH_x2; |
TickTock | 118:02010b18efdc | 399 | static unsigned short lgids=0, lSOC=0, lSOH=0; |
TickTock | 124:0d622967b764 | 400 | static float lmaxTemp=0, lresr=0, lunlV=0; |
TickTock | 118:02010b18efdc | 401 | static unsigned long lAh=0; |
TickTock | 13:62e0f7f39ff5 | 402 | CANMessage msg; |
TickTock | 13:62e0f7f39ff5 | 403 | |
TickTock | 13:62e0f7f39ff5 | 404 | msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids |
TickTock | 13:62e0f7f39ff5 | 405 | gids = (msg.data[0]<<2)+(msg.data[1]>>6); |
TickTock | 13:62e0f7f39ff5 | 406 | msg = lastMsg[indexLastMsg[0x55b]]; //Get SOC |
TickTock | 122:138a40892a4c | 407 | SOC_x10 = (msg.data[0]<<2)+(msg.data[1]>>6); |
TickTock | 131:0d926c080a65 | 408 | msg = lastMsg[indexLastMsg[0x5b3]]; //Get SOH |
TickTock | 131:0d926c080a65 | 409 | SOH_x2 = msg.data[1]; |
TickTock | 13:62e0f7f39ff5 | 410 | |
TickTock | 118:02010b18efdc | 411 | tt.background(Blue); |
TickTock | 38:155ec32c5e91 | 412 | tt.foreground(Yellow); |
TickTock | 38:155ec32c5e91 | 413 | tt.set_font((unsigned char*) Arial28x28); |
TickTock | 13:62e0f7f39ff5 | 414 | if(force) tt.cls(); |
TickTock | 121:553faf139a20 | 415 | |
TickTock | 121:553faf139a20 | 416 | /*if(force||tock){ // for esr debug |
TickTock | 121:553faf139a20 | 417 | tt.locate(10,10); |
TickTock | 121:553faf139a20 | 418 | printf("%d %d amps\n",Imax,Imin); |
TickTock | 121:553faf139a20 | 419 | tt.locate(10,40); |
TickTock | 121:553faf139a20 | 420 | printf(" %4.1f %4.1f\n",incRmax/2,incRmin/2); |
TickTock | 121:553faf139a20 | 421 | tt.locate(10,70); |
TickTock | 121:553faf139a20 | 422 | printf(" %4.1f %4.1f\n",redRmax/2,redRmin/2); |
TickTock | 121:553faf139a20 | 423 | tt.locate(10,100); |
TickTock | 121:553faf139a20 | 424 | printf(" %4.1f %4.1f\n",curRmax/2,curRmin/2); |
TickTock | 121:553faf139a20 | 425 | //tt.locate(10,130); |
TickTock | 121:553faf139a20 | 426 | curRmin=1000; |
TickTock | 121:553faf139a20 | 427 | curRmax=0; |
TickTock | 121:553faf139a20 | 428 | incRmin=1000; |
TickTock | 121:553faf139a20 | 429 | incRmax=0; |
TickTock | 121:553faf139a20 | 430 | redRmin=1000; |
TickTock | 121:553faf139a20 | 431 | redRmax=0; |
TickTock | 121:553faf139a20 | 432 | Imax=-1000; |
TickTock | 121:553faf139a20 | 433 | Imin=1000; |
TickTock | 121:553faf139a20 | 434 | }*/ |
TickTock | 118:02010b18efdc | 435 | if(force||gids!=lgids){ |
TickTock | 118:02010b18efdc | 436 | tt.locate(10,10); |
TickTock | 177:6fda79c2fda1 | 437 | if(dailyGids>5){ // Wh/gid, too |
TickTock | 177:6fda79c2fda1 | 438 | printf("%d gids (%0.0f)\n",gids,1000*(kWh_trip[3]+CCkWh_trip[3])/dailyGids); |
TickTock | 170:7ee98e3611bc | 439 | }else{ |
TickTock | 175:0357b4159b40 | 440 | printf("%d gids \n",gids); |
TickTock | 170:7ee98e3611bc | 441 | } |
TickTock | 119:0e2b641e98a2 | 442 | lgids=gids; |
TickTock | 118:02010b18efdc | 443 | } |
TickTock | 122:138a40892a4c | 444 | if(force||SOC_x10!=lSOC){ |
TickTock | 119:0e2b641e98a2 | 445 | tt.locate(10,40); |
TickTock | 175:0357b4159b40 | 446 | printf("%4.1f%s SOC \n",(float)SOC_x10/10,"%"); |
TickTock | 122:138a40892a4c | 447 | lSOC=SOC_x10; |
TickTock | 118:02010b18efdc | 448 | } |
TickTock | 143:88b5155622a5 | 449 | if(force||SOH2_x100!=lSOH){ |
TickTock | 118:02010b18efdc | 450 | tt.locate(10,70); |
TickTock | 175:0357b4159b40 | 451 | printf("%d%s SOH, %3.1f Hx \n",SOH_x2/2,"%",(float)SOH2_x100/100); |
TickTock | 143:88b5155622a5 | 452 | lSOH=SOH2_x100; |
TickTock | 118:02010b18efdc | 453 | } |
TickTock | 118:02010b18efdc | 454 | if(force||Ah_x10000!=lAh){ |
TickTock | 118:02010b18efdc | 455 | tt.locate(10,100); |
TickTock | 175:0357b4159b40 | 456 | printf("%4.2f Ah cap \n",(float)Ah_x10000/10000); |
TickTock | 118:02010b18efdc | 457 | lAh=Ah_x10000; |
TickTock | 118:02010b18efdc | 458 | } |
TickTock | 124:0d622967b764 | 459 | if(force||maxTemp!=lmaxTemp){ |
TickTock | 124:0d622967b764 | 460 | tt.locate(10,130); |
TickTock | 175:0357b4159b40 | 461 | printf("%4.1f %s (max) \n",convertC(maxTemp),temperatureUnit()); |
TickTock | 124:0d622967b764 | 462 | lmaxTemp=maxTemp; |
TickTock | 124:0d622967b764 | 463 | } |
TickTock | 123:a8c0042df617 | 464 | if(force||unloadedV_x2!=lunlV){ |
TickTock | 124:0d622967b764 | 465 | tt.locate(10,160); |
TickTock | 175:0357b4159b40 | 466 | printf("%4.1f V \n",unloadedV_x2/2); |
TickTock | 119:0e2b641e98a2 | 467 | lunlV=unloadedV_x2; |
TickTock | 118:02010b18efdc | 468 | } |
TickTock | 118:02010b18efdc | 469 | if(force||Resr!=lresr){ |
TickTock | 124:0d622967b764 | 470 | tt.locate(10,190); |
TickTock | 175:0357b4159b40 | 471 | printf("%3.0f mOhms \n",Resr*1000); |
TickTock | 118:02010b18efdc | 472 | lresr=Resr; |
TickTock | 35:5acbd8a64a89 | 473 | } |
TickTock | 13:62e0f7f39ff5 | 474 | } |
TickTock | 13:62e0f7f39ff5 | 475 | |
TickTock | 42:4533b13b297d | 476 | void braking (bool force, bool showButtons, bool prdata=false){ |
TickTock | 28:f24ac05645d9 | 477 | unsigned long targetBraking, regenBraking; |
TickTock | 170:7ee98e3611bc | 478 | //static unsigned long maxTarget = 1000, maxRegen = 1000, tardivreg_x1000 = 1000; |
TickTock | 170:7ee98e3611bc | 479 | static unsigned long maxRegen = 1000, tardivreg_x1000 = 1000; |
TickTock | 28:f24ac05645d9 | 480 | unsigned long temp; |
TickTock | 28:f24ac05645d9 | 481 | static unsigned char lastPressure[4] = {200,200,200,200}; |
TickTock | 28:f24ac05645d9 | 482 | unsigned char i,r,t; |
TickTock | 37:fea2c1d52c5f | 483 | static unsigned char lr=0, lt=0; |
TickTock | 37:fea2c1d52c5f | 484 | signed short steering; |
TickTock | 37:fea2c1d52c5f | 485 | unsigned short s; |
TickTock | 37:fea2c1d52c5f | 486 | static unsigned short ls; |
TickTock | 37:fea2c1d52c5f | 487 | unsigned char throttle; |
TickTock | 37:fea2c1d52c5f | 488 | static unsigned char lthrottle; |
TickTock | 48:d1ce92104a1f | 489 | short steerOutBounds = 0 ; |
TickTock | 28:f24ac05645d9 | 490 | CANMessage msg; |
TickTock | 28:f24ac05645d9 | 491 | |
TickTock | 48:d1ce92104a1f | 492 | //--------------- |
TickTock | 37:fea2c1d52c5f | 493 | msg = lastMsg[indexLastMsg[0x180]]; //Get Throttle position |
TickTock | 37:fea2c1d52c5f | 494 | throttle = msg.data[5]; |
TickTock | 48:d1ce92104a1f | 495 | |
TickTock | 48:d1ce92104a1f | 496 | // ---- steering ---- |
TickTock | 37:fea2c1d52c5f | 497 | msg = lastMsg[indexLastMsg[0x002]]; //Get Steering angle |
TickTock | 37:fea2c1d52c5f | 498 | steering = (msg.data[1]<<8)+msg.data[0]; |
TickTock | 48:d1ce92104a1f | 499 | |
TickTock | 48:d1ce92104a1f | 500 | if(skin==ttSkin){ |
TickTock | 66:b7476ce7a59e | 501 | s= (unsigned short) ((steering/10)+155)%310; // this modulo wraps display |
TickTock | 48:d1ce92104a1f | 502 | }else{// if(skin==ggSkin){ |
TickTock | 48:d1ce92104a1f | 503 | // do not go off screen left or right. gg - steering |
TickTock | 48:d1ce92104a1f | 504 | short ss = (short) ((steering/15)+160); // less gain 10 -> 15 |
TickTock | 48:d1ce92104a1f | 505 | if(ss<0) { ss=0; steerOutBounds = 1; } |
TickTock | 48:d1ce92104a1f | 506 | if(ss>310) { ss=310; steerOutBounds = 1; } |
TickTock | 48:d1ce92104a1f | 507 | s = (unsigned short) ss; |
TickTock | 48:d1ce92104a1f | 508 | } |
TickTock | 48:d1ce92104a1f | 509 | |
TickTock | 48:d1ce92104a1f | 510 | //-------------- |
TickTock | 28:f24ac05645d9 | 511 | msg = lastMsg[indexLastMsg[0x1ca]]; //Get brake pressure |
TickTock | 28:f24ac05645d9 | 512 | tt.background(Navy); |
TickTock | 28:f24ac05645d9 | 513 | if (force) { |
TickTock | 28:f24ac05645d9 | 514 | tt.cls(); |
TickTock | 28:f24ac05645d9 | 515 | tt.rect(0,111,170,239,White); |
TickTock | 28:f24ac05645d9 | 516 | tt.line(0,207,170,207,White); |
TickTock | 28:f24ac05645d9 | 517 | tt.line(0,175,170,175,White); |
TickTock | 28:f24ac05645d9 | 518 | tt.line(0,143,170,143,White); |
TickTock | 28:f24ac05645d9 | 519 | lastPressure[0] = 200; |
TickTock | 28:f24ac05645d9 | 520 | lastPressure[1] = 200; |
TickTock | 28:f24ac05645d9 | 521 | lastPressure[2] = 200; |
TickTock | 28:f24ac05645d9 | 522 | lastPressure[3] = 200; |
TickTock | 28:f24ac05645d9 | 523 | } |
TickTock | 48:d1ce92104a1f | 524 | |
TickTock | 48:d1ce92104a1f | 525 | // display the steering position small square |
TickTock | 37:fea2c1d52c5f | 526 | if (s!=ls){ |
TickTock | 48:d1ce92104a1f | 527 | // steering position has moved |
TickTock | 48:d1ce92104a1f | 528 | //tt.fillrect(ls,5,ls+9,14, Navy); // blank old position |
TickTock | 48:d1ce92104a1f | 529 | |
TickTock | 48:d1ce92104a1f | 530 | //---- gg - steering red |
TickTock | 48:d1ce92104a1f | 531 | // box is blanked by top of Braking bar, so move up 5 |
TickTock | 48:d1ce92104a1f | 532 | tt.fillrect(ls,0,ls+9,9, Navy); // blank old position |
TickTock | 48:d1ce92104a1f | 533 | if( steerOutBounds != 0 ) // draw out-of-bounds as a red box |
TickTock | 48:d1ce92104a1f | 534 | tt.fillrect(s,0,s+9,9, Red); // draw out-of-bounds position |
TickTock | 48:d1ce92104a1f | 535 | else |
TickTock | 48:d1ce92104a1f | 536 | tt.fillrect(s,0,s+9,9, White); // draw new in-bounds position |
TickTock | 48:d1ce92104a1f | 537 | |
TickTock | 48:d1ce92104a1f | 538 | //---- |
TickTock | 37:fea2c1d52c5f | 539 | //tt.foreground(Yellow); |
TickTock | 37:fea2c1d52c5f | 540 | //tt.set_font((unsigned char*) Arial28x28); |
TickTock | 37:fea2c1d52c5f | 541 | //tt.locate(10,40); |
TickTock | 37:fea2c1d52c5f | 542 | //printf("%d %d \n",s,ls); |
TickTock | 37:fea2c1d52c5f | 543 | ls=s; |
TickTock | 37:fea2c1d52c5f | 544 | } |
TickTock | 48:d1ce92104a1f | 545 | |
TickTock | 37:fea2c1d52c5f | 546 | if (throttle!=lthrottle){ |
TickTock | 37:fea2c1d52c5f | 547 | if (throttle>239) throttle=239; |
TickTock | 37:fea2c1d52c5f | 548 | if(throttle<lthrottle){ |
TickTock | 37:fea2c1d52c5f | 549 | tt.fillrect(280,239-lthrottle,310,239-throttle,Navy); |
TickTock | 37:fea2c1d52c5f | 550 | }else{ |
TickTock | 37:fea2c1d52c5f | 551 | tt.fillrect(280,239-throttle,310,239,Yellow); |
TickTock | 37:fea2c1d52c5f | 552 | } |
TickTock | 37:fea2c1d52c5f | 553 | lthrottle=throttle; |
TickTock | 37:fea2c1d52c5f | 554 | } |
TickTock | 37:fea2c1d52c5f | 555 | |
TickTock | 28:f24ac05645d9 | 556 | // plot bar graph for each wheel pressure |
TickTock | 28:f24ac05645d9 | 557 | for (i=0; i<4; i++){ |
TickTock | 28:f24ac05645d9 | 558 | if (msg.data[i]<239) { |
TickTock | 28:f24ac05645d9 | 559 | if (msg.data[i]>lastPressure[i]){ |
TickTock | 28:f24ac05645d9 | 560 | tt.fillrect(10+40*i,239-msg.data[i],40+40*i,239,Red); |
TickTock | 28:f24ac05645d9 | 561 | } else if (msg.data[i]<lastPressure[i]) { |
TickTock | 28:f24ac05645d9 | 562 | tt.fillrect(10+40*i,238-lastPressure[i],40+40*i,238-msg.data[i],Navy); |
TickTock | 28:f24ac05645d9 | 563 | } |
TickTock | 28:f24ac05645d9 | 564 | lastPressure[i]=msg.data[i]; |
TickTock | 28:f24ac05645d9 | 565 | } |
TickTock | 28:f24ac05645d9 | 566 | } |
TickTock | 28:f24ac05645d9 | 567 | |
TickTock | 156:4e5d30535cf9 | 568 | msg = lastMsg[indexLastMsg[0x1cb]]; |
TickTock | 156:4e5d30535cf9 | 569 | targetBraking = (msg.data[2]<<3)+(msg.data[3]>>5); //Get target total braking force |
TickTock | 156:4e5d30535cf9 | 570 | //regenBraking = (msg.data[0]<<3)+(msg.data[1]>>5); //Get target regen portion |
TickTock | 156:4e5d30535cf9 | 571 | msg = lastMsg[indexLastMsg[0x1d5]]; //Get regen portion - seems to be actual regen versus target regen |
TickTock | 73:62ee8eae3a84 | 572 | regenBraking = (msg.data[0]<<3)+(msg.data[1]>>5); |
TickTock | 73:62ee8eae3a84 | 573 | |
TickTock | 73:62ee8eae3a84 | 574 | if (targetBraking<2045){ |
TickTock | 73:62ee8eae3a84 | 575 | if ((targetBraking>50)&&(regenBraking>50)){ |
TickTock | 73:62ee8eae3a84 | 576 | temp = targetBraking; |
TickTock | 73:62ee8eae3a84 | 577 | temp *= 1000; |
TickTock | 73:62ee8eae3a84 | 578 | temp /= regenBraking; |
TickTock | 73:62ee8eae3a84 | 579 | if (temp<tardivreg_x1000) tardivreg_x1000=temp; |
TickTock | 73:62ee8eae3a84 | 580 | } |
TickTock | 73:62ee8eae3a84 | 581 | if (targetBraking>maxTarget) maxTarget=targetBraking; |
TickTock | 73:62ee8eae3a84 | 582 | if (regenBraking>maxRegen) maxRegen=regenBraking; |
TickTock | 73:62ee8eae3a84 | 583 | temp = targetBraking; |
TickTock | 73:62ee8eae3a84 | 584 | temp *=200; |
TickTock | 73:62ee8eae3a84 | 585 | temp /= maxTarget; |
TickTock | 73:62ee8eae3a84 | 586 | t = (char) temp; |
TickTock | 73:62ee8eae3a84 | 587 | if (t>200) t=200; |
TickTock | 73:62ee8eae3a84 | 588 | temp = regenBraking; |
TickTock | 73:62ee8eae3a84 | 589 | temp *= tardivreg_x1000; |
TickTock | 73:62ee8eae3a84 | 590 | temp /= maxTarget; |
TickTock | 73:62ee8eae3a84 | 591 | temp /= 5; // 1000/200=5 |
TickTock | 73:62ee8eae3a84 | 592 | r = (char) temp; |
TickTock | 73:62ee8eae3a84 | 593 | if (r>200) r=200; |
TickTock | 73:62ee8eae3a84 | 594 | if(lr!=r&&prdata){ |
TickTock | 73:62ee8eae3a84 | 595 | tt.foreground(Yellow); |
TickTock | 73:62ee8eae3a84 | 596 | tt.set_font((unsigned char*) Arial28x28); |
TickTock | 73:62ee8eae3a84 | 597 | tt.locate(100,40); |
TickTock | 73:62ee8eae3a84 | 598 | printf("%d %d \n",regenBraking,maxRegen); |
TickTock | 73:62ee8eae3a84 | 599 | tt.locate(100,70); |
TickTock | 73:62ee8eae3a84 | 600 | printf("%3.1f (%3.1f%s) \n",(float)tardivreg_x1000/10,(float)regenBraking*tardivreg_x1000/targetBraking/10,"%"); |
TickTock | 73:62ee8eae3a84 | 601 | } |
TickTock | 73:62ee8eae3a84 | 602 | if(lt!=t&&prdata){ |
TickTock | 73:62ee8eae3a84 | 603 | tt.foreground(Yellow); |
TickTock | 73:62ee8eae3a84 | 604 | tt.set_font((unsigned char*) Arial28x28); |
TickTock | 73:62ee8eae3a84 | 605 | tt.locate(100,10); |
TickTock | 73:62ee8eae3a84 | 606 | printf("%d %d \n",targetBraking,maxTarget); |
TickTock | 73:62ee8eae3a84 | 607 | } |
TickTock | 73:62ee8eae3a84 | 608 | if (r>t) t=r; //Should never happen |
TickTock | 73:62ee8eae3a84 | 609 | if((lr!=r||lt!=t)&&!prdata){ |
TickTock | 73:62ee8eae3a84 | 610 | tt.fillrect(190,10,260,239-t,Navy); |
TickTock | 73:62ee8eae3a84 | 611 | tt.fillrect(190,239-t,260,239-r,Red); |
TickTock | 73:62ee8eae3a84 | 612 | tt.fillrect(190,239-r,260,239,Green); |
TickTock | 73:62ee8eae3a84 | 613 | } |
TickTock | 73:62ee8eae3a84 | 614 | lt=t; |
TickTock | 73:62ee8eae3a84 | 615 | lr=r; |
TickTock | 28:f24ac05645d9 | 616 | } |
TickTock | 28:f24ac05645d9 | 617 | } |
TickTock | 28:f24ac05645d9 | 618 | |
TickTock | 42:4533b13b297d | 619 | void cpData(bool force, bool showButtons){ |
TickTock | 36:dbd39c315258 | 620 | short unsigned max, min, jv, i, bd; |
TickTock | 36:dbd39c315258 | 621 | unsigned avg; |
TickTock | 97:a25940fd7b5b | 622 | static char step=0; // counter to allow incremental update |
TickTock | 36:dbd39c315258 | 623 | if(force){ |
TickTock | 36:dbd39c315258 | 624 | tt.foreground(White); |
TickTock | 36:dbd39c315258 | 625 | tt.background(Navy); |
TickTock | 36:dbd39c315258 | 626 | tt.set_font((unsigned char*) Arial12x12_prop); // select the font |
TickTock | 36:dbd39c315258 | 627 | max=0; |
TickTock | 36:dbd39c315258 | 628 | min=9999; |
TickTock | 36:dbd39c315258 | 629 | avg=0; |
TickTock | 36:dbd39c315258 | 630 | for(i=0; i<96; i++){ |
TickTock | 124:0d622967b764 | 631 | bd=(battData[BatDataBaseG2*7+i*2+3]<<8)+battData[BatDataBaseG2*7+i*2+4]; |
TickTock | 36:dbd39c315258 | 632 | avg+=bd; |
TickTock | 36:dbd39c315258 | 633 | if(bd>max) max=bd; |
TickTock | 36:dbd39c315258 | 634 | if(bd<min) min=bd; |
TickTock | 36:dbd39c315258 | 635 | } |
TickTock | 36:dbd39c315258 | 636 | avg /= 96; |
TickTock | 36:dbd39c315258 | 637 | if(min<3713) { |
TickTock | 36:dbd39c315258 | 638 | jv=avg-(max-avg)*1.5; |
TickTock | 36:dbd39c315258 | 639 | } else { // Only compute judgement value if min cellpair meets <= 3712mV requirement |
TickTock | 36:dbd39c315258 | 640 | jv=0; |
TickTock | 36:dbd39c315258 | 641 | } |
TickTock | 99:c05abf8e1cdc | 642 | |
TickTock | 107:e9be732c1ad4 | 643 | char* sTemperatureUnit = temperatureUnit(); |
TickTock | 97:a25940fd7b5b | 644 | switch(step){ |
TickTock | 97:a25940fd7b5b | 645 | case 0: |
TickTock | 97:a25940fd7b5b | 646 | tt.cls(); |
TickTock | 97:a25940fd7b5b | 647 | showCP=true; |
TickTock | 97:a25940fd7b5b | 648 | break; |
TickTock | 97:a25940fd7b5b | 649 | case 1: |
TickTock | 97:a25940fd7b5b | 650 | tt.locate(0,6); |
TickTock | 99:c05abf8e1cdc | 651 | printf(" MAX MIN AVG CVLI T1 T2 T3 T4\n %04d %04d %04d %04d %2.0f%s %2.0f%s %2.0f%s %2.0f%s\n\n", |
TickTock | 148:6e3b9135fad2 | 652 | max,min,avg,jv, convertC(battData[BatDataBaseG4*7+5]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+8]),sTemperatureUnit, |
TickTock | 148:6e3b9135fad2 | 653 | convertC(battData[BatDataBaseG4*7+11]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+14]),sTemperatureUnit); |
TickTock | 97:a25940fd7b5b | 654 | tt.rect(8+0*41,16,40+0*41,28,Green); |
TickTock | 97:a25940fd7b5b | 655 | tt.rect(8+1*41,16,40+1*41,28,Yellow); |
TickTock | 97:a25940fd7b5b | 656 | //tt.rect(8+2*41,16,40+2*41,28,White); |
TickTock | 97:a25940fd7b5b | 657 | tt.rect(8+3*41,16,40+3*41,28,Red); |
TickTock | 97:a25940fd7b5b | 658 | break; |
TickTock | 97:a25940fd7b5b | 659 | default: |
TickTock | 97:a25940fd7b5b | 660 | tt.locate(0,36+(step-2)*48); |
TickTock | 97:a25940fd7b5b | 661 | for(i=(step-2)*4; i<(step-1)*4; i++){ |
TickTock | 97:a25940fd7b5b | 662 | printf("%02d-%02d : %04d %04d %04d %04d %04d %04d\n", |
TickTock | 97:a25940fd7b5b | 663 | i*6+1,i*6+6, |
TickTock | 124:0d622967b764 | 664 | (battData[BatDataBaseG2*7+i*12+3]<<8)+battData[BatDataBaseG2*7+i*12+4],(battData[BatDataBaseG2*7+i*12+5]<<8)+battData[BatDataBaseG2*7+i*12+6], |
TickTock | 124:0d622967b764 | 665 | (battData[BatDataBaseG2*7+i*12+7]<<8)+battData[BatDataBaseG2*7+i*12+8],(battData[BatDataBaseG2*7+i*12+9]<<8)+battData[BatDataBaseG2*7+i*12+10], |
TickTock | 124:0d622967b764 | 666 | (battData[BatDataBaseG2*7+i*12+11]<<8)+battData[BatDataBaseG2*7+i*12+12],(battData[BatDataBaseG2*7+i*12+13]<<8)+battData[BatDataBaseG2*7+i*12+14]); |
TickTock | 97:a25940fd7b5b | 667 | } |
TickTock | 97:a25940fd7b5b | 668 | for(i=(step-2)*24; i<(step-1)*24; i++){ |
TickTock | 124:0d622967b764 | 669 | bd=(battData[BatDataBaseG2*7+i*2+3]<<8)+battData[BatDataBaseG2*7+i*2+4]; |
TickTock | 97:a25940fd7b5b | 670 | if(bd>0){ |
TickTock | 97:a25940fd7b5b | 671 | if(bd==max) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,Green); |
TickTock | 97:a25940fd7b5b | 672 | //if(bd==avg) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,White); |
TickTock | 97:a25940fd7b5b | 673 | if(bd==min) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,Yellow); |
TickTock | 97:a25940fd7b5b | 674 | if(bd<jv) tt.rect(58+(i%6)*41,34+(int)(i/6)*12,90+(i%6)*41,46+(int)(i/6)*12,Red); |
TickTock | 97:a25940fd7b5b | 675 | } |
TickTock | 97:a25940fd7b5b | 676 | } |
TickTock | 36:dbd39c315258 | 677 | } |
TickTock | 97:a25940fd7b5b | 678 | step=step<5?step+1:0; |
TickTock | 97:a25940fd7b5b | 679 | if(step==0){ |
TickTock | 97:a25940fd7b5b | 680 | showCP=false; |
TickTock | 36:dbd39c315258 | 681 | } |
TickTock | 36:dbd39c315258 | 682 | } |
TickTock | 122:138a40892a4c | 683 | if(showButtons){ |
garygid | 54:6ce808d0995e | 684 | showButton(1,0,"Request","CP Data",4,4); |
TickTock | 44:6262a9fd1e56 | 685 | } |
TickTock | 44:6262a9fd1e56 | 686 | } |
TickTock | 44:6262a9fd1e56 | 687 | |
TickTock | 44:6262a9fd1e56 | 688 | //---------------- |
garygid | 67:2022fce701d0 | 689 | // gg - index |
garygid | 67:2022fce701d0 | 690 | void showIndex(bool force, bool showButtons){ |
garygid | 67:2022fce701d0 | 691 | |
garygid | 67:2022fce701d0 | 692 | if(force){ |
garygid | 67:2022fce701d0 | 693 | tt.foreground(White); |
garygid | 67:2022fce701d0 | 694 | tt.background(Navy); |
garygid | 67:2022fce701d0 | 695 | //tt.set_font((unsigned char*) Arial12x12_prop); // select the font |
garygid | 67:2022fce701d0 | 696 | |
garygid | 67:2022fce701d0 | 697 | tt.cls(); |
garygid | 67:2022fce701d0 | 698 | |
garygid | 67:2022fce701d0 | 699 | // add the buttons to GoTo to other screens |
garygid | 67:2022fce701d0 | 700 | |
TickTock | 151:3047ebb3c9a8 | 701 | // top row |
garygid | 67:2022fce701d0 | 702 | showButton(0,0," GoTo"," Main",4,4); |
garygid | 67:2022fce701d0 | 703 | showButton(1,0," GoTo"," Brake",4,4); |
garygid | 67:2022fce701d0 | 704 | showButton(2,0," GoTo"," EFF",4,4); |
TickTock | 122:138a40892a4c | 705 | showButton(3,0," GoTo","Health",4,4); |
garygid | 67:2022fce701d0 | 706 | // middle row |
garygid | 67:2022fce701d0 | 707 | showButton(0,1," GoTo","CP Data",4,4); |
garygid | 67:2022fce701d0 | 708 | showButton(1,1," GoTo","CP Hist",4,4); |
garygid | 67:2022fce701d0 | 709 | showButton(2,1," GoTo","CP Bars",4,4); |
leafman | 98:9f8bab96edff | 710 | showButton(3,1," GoTo"," Config",4,4); |
leafman | 98:9f8bab96edff | 711 | // bottom (not Nav) row |
TickTock | 157:1a100a5ed06f | 712 | showButton(0,2," GoTo","Playback",4,4); |
TickTock | 131:0d926c080a65 | 713 | //showButton(1,2," GoTo","Set Time",4,4); |
leafman | 98:9f8bab96edff | 714 | showButton(2,2," GoTo"," Log",4,4); |
TickTock | 108:29b5a760adc2 | 715 | showButton(3,2," GoTo"," Trip",4,4); |
garygid | 67:2022fce701d0 | 716 | |
garygid | 67:2022fce701d0 | 717 | showCP=false; |
garygid | 67:2022fce701d0 | 718 | } |
garygid | 67:2022fce701d0 | 719 | |
garygid | 67:2022fce701d0 | 720 | if(sMode==1&&showButtons){ |
garygid | 67:2022fce701d0 | 721 | tt.foreground(Yellow); |
garygid | 67:2022fce701d0 | 722 | tt.background(DarkCyan); |
garygid | 67:2022fce701d0 | 723 | tt.set_font((unsigned char*) Arial12x12); |
garygid | 67:2022fce701d0 | 724 | |
garygid | 67:2022fce701d0 | 725 | // do nothing here? |
garygid | 67:2022fce701d0 | 726 | } |
garygid | 67:2022fce701d0 | 727 | } |
garygid | 67:2022fce701d0 | 728 | |
garygid | 67:2022fce701d0 | 729 | //---------------- |
TickTock | 48:d1ce92104a1f | 730 | // gg - cpbars |
TickTock | 48:d1ce92104a1f | 731 | void cpBarPlot(bool force, bool showButtons){ |
TickTock | 48:d1ce92104a1f | 732 | short unsigned max, min, jv, i, bd; |
TickTock | 48:d1ce92104a1f | 733 | unsigned avg; |
TickTock | 48:d1ce92104a1f | 734 | short unsigned nBar[96] ; // bar height over min |
TickTock | 48:d1ce92104a1f | 735 | |
TickTock | 48:d1ce92104a1f | 736 | if(force){ |
TickTock | 48:d1ce92104a1f | 737 | tt.foreground(White); |
TickTock | 48:d1ce92104a1f | 738 | tt.background(Navy); |
TickTock | 48:d1ce92104a1f | 739 | tt.set_font((unsigned char*) Arial12x12_prop); // select the font |
TickTock | 48:d1ce92104a1f | 740 | max=0; |
TickTock | 48:d1ce92104a1f | 741 | min=9999; |
TickTock | 48:d1ce92104a1f | 742 | avg=0; |
TickTock | 48:d1ce92104a1f | 743 | |
TickTock | 48:d1ce92104a1f | 744 | // calc each cell-pair voltage, find max and min |
TickTock | 48:d1ce92104a1f | 745 | for(i=0; i<96; i++){ |
TickTock | 124:0d622967b764 | 746 | bd=(battData[BatDataBaseG2*7+i*2+3]<<8)+battData[BatDataBaseG2*7+i*2+4]; |
TickTock | 48:d1ce92104a1f | 747 | nBar[i] = bd; // init to bar height |
TickTock | 48:d1ce92104a1f | 748 | avg+=bd; |
TickTock | 48:d1ce92104a1f | 749 | if(bd>max) max=bd; |
TickTock | 48:d1ce92104a1f | 750 | if(bd<min) min=bd; |
TickTock | 48:d1ce92104a1f | 751 | } |
TickTock | 48:d1ce92104a1f | 752 | avg /= 96; |
TickTock | 48:d1ce92104a1f | 753 | |
TickTock | 48:d1ce92104a1f | 754 | if(min<3713) { |
TickTock | 48:d1ce92104a1f | 755 | jv=avg-(max-avg)*1.5; |
TickTock | 48:d1ce92104a1f | 756 | } else { // Only compute judgement value if min cellpair meets <= 3712mV requirement |
TickTock | 48:d1ce92104a1f | 757 | jv=0; |
TickTock | 48:d1ce92104a1f | 758 | } |
TickTock | 48:d1ce92104a1f | 759 | |
TickTock | 48:d1ce92104a1f | 760 | //------------------ |
TickTock | 48:d1ce92104a1f | 761 | tt.cls(); |
TickTock | 48:d1ce92104a1f | 762 | |
TickTock | 48:d1ce92104a1f | 763 | // show as vertical bar plot |
TickTock | 48:d1ce92104a1f | 764 | int xWinMin = 26; |
TickTock | 48:d1ce92104a1f | 765 | int xWinMax = 316; |
TickTock | 48:d1ce92104a1f | 766 | int yWinMin = 50; |
TickTock | 48:d1ce92104a1f | 767 | int yWinMax = 150; |
TickTock | 48:d1ce92104a1f | 768 | // draw the Bar Graph Frame, 2 pixels wide |
TickTock | 48:d1ce92104a1f | 769 | tt.rect( xWinMin-1,yWinMin-1, xWinMax+1,yWinMax+1,Red); |
TickTock | 48:d1ce92104a1f | 770 | tt.rect( xWinMin-2,yWinMin-2, xWinMax+2,yWinMax+2,Green); |
TickTock | 48:d1ce92104a1f | 771 | |
TickTock | 48:d1ce92104a1f | 772 | // bar heights |
TickTock | 48:d1ce92104a1f | 773 | int height = yWinMax - yWinMin ; |
TickTock | 48:d1ce92104a1f | 774 | int iBarValMax = max - min ; // zero to N |
TickTock | 48:d1ce92104a1f | 775 | |
TickTock | 48:d1ce92104a1f | 776 | //---------------- |
TickTock | 48:d1ce92104a1f | 777 | if( iBarValMax == 0 ) { |
TickTock | 48:d1ce92104a1f | 778 | // for testing |
TickTock | 48:d1ce92104a1f | 779 | min = 3501 ; |
TickTock | 48:d1ce92104a1f | 780 | //max = min + 95*2 ; // for tall values |
TickTock | 48:d1ce92104a1f | 781 | max = min + 95/4 ; // for small values |
TickTock | 48:d1ce92104a1f | 782 | avg = ( max + min ) / 2; |
TickTock | 48:d1ce92104a1f | 783 | iBarValMax = max - min ; // zero to N |
TickTock | 48:d1ce92104a1f | 784 | for(int i=0; i<96; i++) { |
TickTock | 48:d1ce92104a1f | 785 | //nBar[i] = i*2 + min ; // test tall values |
TickTock | 48:d1ce92104a1f | 786 | nBar[i] = i/4 + min ; // test small values |
TickTock | 48:d1ce92104a1f | 787 | } |
TickTock | 48:d1ce92104a1f | 788 | } |
TickTock | 48:d1ce92104a1f | 789 | //--------------- |
TickTock | 48:d1ce92104a1f | 790 | float nBarScale = float(height) / iBarValMax ; |
TickTock | 48:d1ce92104a1f | 791 | if( nBarScale < 0.1 ) nBarScale = 0.1 ; |
TickTock | 48:d1ce92104a1f | 792 | |
TickTock | 48:d1ce92104a1f | 793 | // do the Bar-height scaling |
TickTock | 48:d1ce92104a1f | 794 | for(int i=0; i<96; i++){ |
TickTock | 48:d1ce92104a1f | 795 | nBar[i] -= min ; // now, 0 to N = iBinValMax |
TickTock | 48:d1ce92104a1f | 796 | nBar[i] *= nBarScale ; // scale, as needed |
TickTock | 48:d1ce92104a1f | 797 | } |
TickTock | 48:d1ce92104a1f | 798 | |
TickTock | 161:71ac85d11f03 | 799 | // label the Y axis |
TickTock | 138:a2f5af85ed0d | 800 | tt.locate( 2, yWinMin-14 ); printf("%04d = (%d) mv range.\n", max , max - min ); |
TickTock | 138:a2f5af85ed0d | 801 | tt.locate( 2, yWinMax+5); printf("%04d\n", min ); |
TickTock | 161:71ac85d11f03 | 802 | |
TickTock | 124:0d622967b764 | 803 | // BatDataBaseG4 * 7 = 280 |
TickTock | 48:d1ce92104a1f | 804 | tt.locate( 0, yWinMax+40 ); |
TickTock | 108:29b5a760adc2 | 805 | char* sTemperatureUnit = temperatureUnit(); |
TickTock | 138:a2f5af85ed0d | 806 | printf(" MAX MIN AVG CVLI T1 T2 T3 T4\n %04d %04d %04d %04d %2.0f%s %2.0f%s %2.0f%s %2.0f%s\n", |
TickTock | 148:6e3b9135fad2 | 807 | max,min,avg,jv, convertC(battData[BatDataBaseG4*7+5]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+8]),sTemperatureUnit, |
TickTock | 148:6e3b9135fad2 | 808 | convertC(battData[BatDataBaseG4*7+11]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+14]),sTemperatureUnit); |
TickTock | 108:29b5a760adc2 | 809 | //printf(" MAX MIN AVG CVLI T1 T2 T3 T4\n %04d %04d %04d %04d %02dC %02dC %02dC %02dC\n\n", |
TickTock | 124:0d622967b764 | 810 | // max,min,avg,jv, battData[BatDataBaseG4*7+5],battData[BatDataBaseG4*7+8], battData[BatDataBaseG4*7+11],battData[BatDataBaseG4*7+14]); |
TickTock | 48:d1ce92104a1f | 811 | |
TickTock | 48:d1ce92104a1f | 812 | |
TickTock | 48:d1ce92104a1f | 813 | //--------------- |
TickTock | 48:d1ce92104a1f | 814 | // show the bars |
TickTock | 48:d1ce92104a1f | 815 | int nBarWidth = 2 ; |
TickTock | 48:d1ce92104a1f | 816 | int nBarSpace = 1 ; // 1 for testing |
TickTock | 48:d1ce92104a1f | 817 | |
TickTock | 48:d1ce92104a1f | 818 | int xPos = xWinMin + 2 ; // start one from the left |
TickTock | 48:d1ce92104a1f | 819 | |
TickTock | 48:d1ce92104a1f | 820 | for( int i=0; i<96; i++) { |
TickTock | 48:d1ce92104a1f | 821 | height = nBar[i] ; |
TickTock | 48:d1ce92104a1f | 822 | if( height > 100 ) height = 100 ; // clip tops |
TickTock | 48:d1ce92104a1f | 823 | |
TickTock | 48:d1ce92104a1f | 824 | // draw the bar, is always inside x-window |
TickTock | 121:553faf139a20 | 825 | if (shunt[i]){ |
TickTock | 121:553faf139a20 | 826 | tt.fillrect( xPos,yWinMax-height, xPos+nBarWidth-1,yWinMax, Red); |
TickTock | 121:553faf139a20 | 827 | } else { |
TickTock | 121:553faf139a20 | 828 | tt.fillrect( xPos,yWinMax-height, xPos+nBarWidth-1,yWinMax, Green); |
TickTock | 121:553faf139a20 | 829 | } |
TickTock | 48:d1ce92104a1f | 830 | // tic mark the y axis each 5 |
TickTock | 48:d1ce92104a1f | 831 | if(i%5 == 4){ |
TickTock | 48:d1ce92104a1f | 832 | tt.line( xPos,yWinMax+2, xPos,yWinMax+5, White); // a white tick mark |
TickTock | 48:d1ce92104a1f | 833 | tt.line( xPos+1,yWinMax+2, xPos+1,yWinMax+5, White); // a white tick mark, to widen |
TickTock | 48:d1ce92104a1f | 834 | //tt.rect( xPos,yWinMax+2, xPos+1,yWinMax+5, White); // a white 2-wide tick mark is SLOW |
TickTock | 48:d1ce92104a1f | 835 | } |
TickTock | 48:d1ce92104a1f | 836 | // label the y axis each 10 |
TickTock | 48:d1ce92104a1f | 837 | if(i%10 == 9){ |
TickTock | 48:d1ce92104a1f | 838 | tt.locate( xPos-6, yWinMax+8 ); |
TickTock | 48:d1ce92104a1f | 839 | printf("%02d\n", i+1 ); |
TickTock | 48:d1ce92104a1f | 840 | } |
TickTock | 48:d1ce92104a1f | 841 | |
TickTock | 48:d1ce92104a1f | 842 | // step to the next bar position |
TickTock | 48:d1ce92104a1f | 843 | xPos += nBarWidth + nBarSpace ; |
TickTock | 48:d1ce92104a1f | 844 | } |
TickTock | 48:d1ce92104a1f | 845 | |
TickTock | 48:d1ce92104a1f | 846 | showCP=false; |
TickTock | 48:d1ce92104a1f | 847 | } |
TickTock | 48:d1ce92104a1f | 848 | |
TickTock | 48:d1ce92104a1f | 849 | // handle the button |
TickTock | 48:d1ce92104a1f | 850 | if(sMode==1&&showButtons){ |
garygid | 54:6ce808d0995e | 851 | showButton(1,0,"Request","CP Data",4,4); |
TickTock | 48:d1ce92104a1f | 852 | } |
TickTock | 48:d1ce92104a1f | 853 | } |
TickTock | 48:d1ce92104a1f | 854 | |
TickTock | 48:d1ce92104a1f | 855 | //---------------- |
TickTock | 44:6262a9fd1e56 | 856 | // gg - hist |
TickTock | 47:9cc7d876dd6d | 857 | void cpHistogram(bool force, bool showButtons){ |
TickTock | 44:6262a9fd1e56 | 858 | short unsigned max, min, jv, i, bd; |
TickTock | 44:6262a9fd1e56 | 859 | unsigned avg; |
TickTock | 44:6262a9fd1e56 | 860 | if(force){ |
TickTock | 44:6262a9fd1e56 | 861 | tt.foreground(White); |
TickTock | 44:6262a9fd1e56 | 862 | tt.background(Navy); |
TickTock | 44:6262a9fd1e56 | 863 | tt.set_font((unsigned char*) Arial12x12_prop); // select the font |
TickTock | 44:6262a9fd1e56 | 864 | max=0; |
TickTock | 44:6262a9fd1e56 | 865 | min=9999; |
TickTock | 44:6262a9fd1e56 | 866 | avg=0; |
TickTock | 44:6262a9fd1e56 | 867 | for(i=0; i<96; i++){ |
TickTock | 124:0d622967b764 | 868 | bd=(battData[BatDataBaseG2*7+i*2+3]<<8)+battData[BatDataBaseG2*7+i*2+4]; |
TickTock | 44:6262a9fd1e56 | 869 | avg+=bd; |
TickTock | 44:6262a9fd1e56 | 870 | if(bd>max) max=bd; |
TickTock | 44:6262a9fd1e56 | 871 | if(bd<min) min=bd; |
TickTock | 44:6262a9fd1e56 | 872 | } |
TickTock | 44:6262a9fd1e56 | 873 | avg /= 96; |
TickTock | 44:6262a9fd1e56 | 874 | if(min<3713) { |
TickTock | 44:6262a9fd1e56 | 875 | jv=avg-(max-avg)*1.5; |
TickTock | 44:6262a9fd1e56 | 876 | } else { // Only compute judgement value if min cellpair meets <= 3712mV requirement |
TickTock | 44:6262a9fd1e56 | 877 | jv=0; |
TickTock | 44:6262a9fd1e56 | 878 | } |
TickTock | 44:6262a9fd1e56 | 879 | //------------------ |
TickTock | 44:6262a9fd1e56 | 880 | tt.cls(); |
TickTock | 44:6262a9fd1e56 | 881 | |
TickTock | 44:6262a9fd1e56 | 882 | // show as histogram |
TickTock | 44:6262a9fd1e56 | 883 | int xWinMin = 20; |
TickTock | 44:6262a9fd1e56 | 884 | int xWinMax = 300; |
TickTock | 44:6262a9fd1e56 | 885 | int yWinMin = 50; |
TickTock | 44:6262a9fd1e56 | 886 | int yWinMax = 150; |
TickTock | 161:71ac85d11f03 | 887 | |
TickTock | 44:6262a9fd1e56 | 888 | // binning |
TickTock | 44:6262a9fd1e56 | 889 | short nBin[301] ; // bins to count Min values in nBin[0], etc. |
TickTock | 161:71ac85d11f03 | 890 | int height; |
TickTock | 44:6262a9fd1e56 | 891 | int iBinValMax = max - min ; // zero to N |
TickTock | 175:0357b4159b40 | 892 | int iBinIndxMax = (xWinMax-xWinMin)/2; // Maximum number of bars |
TickTock | 44:6262a9fd1e56 | 893 | if( iBinValMax > iBinIndxMax ) iBinValMax = iBinIndxMax ; |
TickTock | 44:6262a9fd1e56 | 894 | |
TickTock | 44:6262a9fd1e56 | 895 | // clean the bins |
TickTock | 44:6262a9fd1e56 | 896 | for(int i=0; i<=iBinIndxMax; i++) { |
TickTock | 44:6262a9fd1e56 | 897 | nBin[i] = 0; |
TickTock | 44:6262a9fd1e56 | 898 | } |
TickTock | 44:6262a9fd1e56 | 899 | |
TickTock | 44:6262a9fd1e56 | 900 | // do the bin counting |
TickTock | 44:6262a9fd1e56 | 901 | for(int i=0; i<96; i++){ |
TickTock | 124:0d622967b764 | 902 | bd=(battData[BatDataBaseG2*7+i*2+3]<<8)+battData[BatDataBaseG2*7+i*2+4] - min ; |
TickTock | 44:6262a9fd1e56 | 903 | if( bd > iBinValMax ) bd = iBinValMax ; |
TickTock | 161:71ac85d11f03 | 904 | nBin[bd]++ ; |
TickTock | 44:6262a9fd1e56 | 905 | } |
TickTock | 162:c6545fc0164a | 906 | |
TickTock | 162:c6545fc0164a | 907 | //---------------- |
TickTock | 162:c6545fc0164a | 908 | if( iBinValMax == 0 ) { // dummy data if no real data |
TickTock | 162:c6545fc0164a | 909 | min = 10 ; |
TickTock | 162:c6545fc0164a | 910 | max = 50 ; |
TickTock | 162:c6545fc0164a | 911 | avg = ( max + min ) / 2; |
TickTock | 162:c6545fc0164a | 912 | iBinValMax = max - min ; |
TickTock | 162:c6545fc0164a | 913 | for(int i=0; i<=(iBinValMax/2); i++) { |
TickTock | 162:c6545fc0164a | 914 | nBin[i] = i ; |
TickTock | 162:c6545fc0164a | 915 | nBin[iBinValMax-i] = i ; |
TickTock | 162:c6545fc0164a | 916 | } |
TickTock | 162:c6545fc0164a | 917 | } |
TickTock | 161:71ac85d11f03 | 918 | |
TickTock | 161:71ac85d11f03 | 919 | // label the Y axis |
TickTock | 161:71ac85d11f03 | 920 | tt.locate( 0, yWinMin ); printf("25\n"); |
TickTock | 161:71ac85d11f03 | 921 | tt.locate( 0, yWinMax-6 ); printf("0\n"); |
TickTock | 161:71ac85d11f03 | 922 | tt.locate( xWinMin-12, yWinMax+6 ); printf("%04d\n", min); |
TickTock | 161:71ac85d11f03 | 923 | tt.locate( xWinMax-18, yWinMax+6 ); printf("%04d\n", max); |
TickTock | 161:71ac85d11f03 | 924 | // draw the Histogram Frame, 2 pixels wide |
TickTock | 175:0357b4159b40 | 925 | tt.rect( xWinMin-1,yWinMin-1, xWinMax+0,yWinMax+0,Red); |
TickTock | 175:0357b4159b40 | 926 | tt.rect( xWinMin-2,yWinMin-2, xWinMax+1,yWinMax+1,Green); |
TickTock | 48:d1ce92104a1f | 927 | tt.locate( 0, yWinMax+40 ); |
TickTock | 108:29b5a760adc2 | 928 | char* sTemperatureUnit = temperatureUnit(); |
TickTock | 108:29b5a760adc2 | 929 | printf(" MAX MIN AVG CVLI T1 T2 T3 T4\n %04d %04d %04d %04d %2.0f%s %2.0f%s %2.0f%s %2.0f%s\n\n", |
TickTock | 148:6e3b9135fad2 | 930 | max,min,avg,jv, convertC(battData[BatDataBaseG4*7+5]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+8]),sTemperatureUnit, |
TickTock | 148:6e3b9135fad2 | 931 | convertC(battData[BatDataBaseG4*7+11]),sTemperatureUnit,convertC(battData[BatDataBaseG4*7+14]),sTemperatureUnit); |
TickTock | 161:71ac85d11f03 | 932 | |
TickTock | 44:6262a9fd1e56 | 933 | //--------------- |
TickTock | 44:6262a9fd1e56 | 934 | // show the bars |
TickTock | 175:0357b4159b40 | 935 | int nBarWidth = (xWinMax-xWinMin)/(iBinValMax+1)-1; |
TickTock | 175:0357b4159b40 | 936 | if (nBarWidth < 1) nBarWidth = 1; |
TickTock | 161:71ac85d11f03 | 937 | int nBarSpace = 1 ; |
TickTock | 44:6262a9fd1e56 | 938 | |
TickTock | 175:0357b4159b40 | 939 | int xPos = (xWinMin + xWinMax)/2; |
TickTock | 175:0357b4159b40 | 940 | xPos -= ((iBinValMax+1)*(nBarWidth+nBarSpace))/2 ; |
TickTock | 161:71ac85d11f03 | 941 | |
TickTock | 44:6262a9fd1e56 | 942 | for( int i=0; i<=iBinValMax; i++) { |
TickTock | 44:6262a9fd1e56 | 943 | height = 4 * nBin[i] ; |
TickTock | 44:6262a9fd1e56 | 944 | if( height > 100 ) height = 100 ; // clip tops |
TickTock | 44:6262a9fd1e56 | 945 | |
TickTock | 44:6262a9fd1e56 | 946 | // if inside the window, draw the bar |
TickTock | 44:6262a9fd1e56 | 947 | if( ( xPos + nBarWidth < xWinMax ) && ( xPos > xWinMin ) ) |
TickTock | 44:6262a9fd1e56 | 948 | tt.fillrect( xPos,yWinMax-height, xPos+nBarWidth-1,yWinMax, Green); |
TickTock | 44:6262a9fd1e56 | 949 | |
TickTock | 44:6262a9fd1e56 | 950 | // step to the next bar position |
TickTock | 44:6262a9fd1e56 | 951 | xPos += nBarWidth + nBarSpace ; |
TickTock | 44:6262a9fd1e56 | 952 | } |
TickTock | 44:6262a9fd1e56 | 953 | |
TickTock | 44:6262a9fd1e56 | 954 | showCP=false; |
TickTock | 44:6262a9fd1e56 | 955 | } |
TickTock | 44:6262a9fd1e56 | 956 | |
TickTock | 44:6262a9fd1e56 | 957 | // handle the button |
TickTock | 47:9cc7d876dd6d | 958 | if(sMode==1&&showButtons){ |
garygid | 54:6ce808d0995e | 959 | showButton(1,0,"Request","CP Data",4,4); |
TickTock | 162:c6545fc0164a | 960 | } |
TickTock | 36:dbd39c315258 | 961 | } |
TickTock | 36:dbd39c315258 | 962 | |
TickTock | 48:d1ce92104a1f | 963 | //--------------- |
leafman | 98:9f8bab96edff | 964 | void config(bool force, bool showButtons){ |
TickTock | 36:dbd39c315258 | 965 | if (force) { |
TickTock | 36:dbd39c315258 | 966 | tt.background(Black); |
TickTock | 36:dbd39c315258 | 967 | tt.cls(); |
TickTock | 36:dbd39c315258 | 968 | } |
garygid | 65:821fc79cd7fe | 969 | //-------- top row -------- |
TickTock | 161:71ac85d11f03 | 970 | showButton(1,0," Reset","CANary",4,4); |
TickTock | 131:0d926c080a65 | 971 | showButton(2,0," Save"," Config",4,4); |
TickTock | 158:059abeb44ba1 | 972 | |
TickTock | 48:d1ce92104a1f | 973 | //------- second row ----- |
TickTock | 108:29b5a760adc2 | 974 | if (logEn&&usbEn) { |
garygid | 54:6ce808d0995e | 975 | sprintf(sTemp1,"Disable"); |
TickTock | 36:dbd39c315258 | 976 | } else { |
garygid | 54:6ce808d0995e | 977 | sprintf(sTemp1,"Enable"); |
TickTock | 36:dbd39c315258 | 978 | } |
garygid | 54:6ce808d0995e | 979 | showButton(0,1,sTemp1,"Logging",4,4); |
TickTock | 48:d1ce92104a1f | 980 | |
TickTock | 36:dbd39c315258 | 981 | if (repeatPoll) { |
garygid | 54:6ce808d0995e | 982 | sprintf(sTemp1,"Disable"); |
TickTock | 36:dbd39c315258 | 983 | } else { |
garygid | 54:6ce808d0995e | 984 | sprintf(sTemp1,"Enable"); |
TickTock | 36:dbd39c315258 | 985 | } |
garygid | 54:6ce808d0995e | 986 | showButton(1,1,sTemp1,"Auto CP",4,4); |
TickTock | 48:d1ce92104a1f | 987 | |
TickTock | 48:d1ce92104a1f | 988 | // add Enable/Disable Batt Log gg - yesBattLog |
TickTock | 48:d1ce92104a1f | 989 | if (yesBattLog) { |
garygid | 54:6ce808d0995e | 990 | sprintf(sTemp1,"Disable"); |
TickTock | 48:d1ce92104a1f | 991 | } else { |
garygid | 54:6ce808d0995e | 992 | sprintf(sTemp1,"Enable"); |
TickTock | 48:d1ce92104a1f | 993 | } |
garygid | 54:6ce808d0995e | 994 | showButton(2,1,sTemp1,"Batt Log",4,4); |
TickTock | 157:1a100a5ed06f | 995 | |
TickTock | 158:059abeb44ba1 | 996 | //------- third row ----- |
TickTock | 157:1a100a5ed06f | 997 | if(brakeMon) |
TickTock | 157:1a100a5ed06f | 998 | showButton(0,2,"Disable","BrkMon",4,4); |
TickTock | 157:1a100a5ed06f | 999 | else |
TickTock | 157:1a100a5ed06f | 1000 | showButton(0,2," Enable"," BrkMon",4,4); |
TickTock | 157:1a100a5ed06f | 1001 | |
TickTock | 157:1a100a5ed06f | 1002 | if(regenMon) |
TickTock | 157:1a100a5ed06f | 1003 | showButton(1,2,"Disable","RegMon",4,4); |
TickTock | 157:1a100a5ed06f | 1004 | else |
TickTock | 157:1a100a5ed06f | 1005 | showButton(1,2," Enable"," RegMon",4,4); |
TickTock | 159:577e9d015693 | 1006 | |
TickTock | 159:577e9d015693 | 1007 | if(heaterMon) |
TickTock | 159:577e9d015693 | 1008 | showButton(2,2,"Disable","HeatMon",4,4); |
TickTock | 159:577e9d015693 | 1009 | else |
TickTock | 159:577e9d015693 | 1010 | showButton(2,2," Enable","HeatMon",4,4); |
TickTock | 159:577e9d015693 | 1011 | |
TickTock | 157:1a100a5ed06f | 1012 | } |
TickTock | 157:1a100a5ed06f | 1013 | |
TickTock | 157:1a100a5ed06f | 1014 | void config2(bool force, bool showButtons){ |
TickTock | 157:1a100a5ed06f | 1015 | if (force) { |
TickTock | 157:1a100a5ed06f | 1016 | tt.background(Black); |
TickTock | 157:1a100a5ed06f | 1017 | tt.cls(); |
TickTock | 157:1a100a5ed06f | 1018 | } |
TickTock | 157:1a100a5ed06f | 1019 | //-------- top row -------- |
TickTock | 157:1a100a5ed06f | 1020 | showButton(0,0,"Calibrate"," Touch",4,4); // gg - 4x4 |
TickTock | 161:71ac85d11f03 | 1021 | showButton(1,0," Reset","Max/Min",4,4); |
TickTock | 169:84d790ac18a2 | 1022 | if (showHealth) { |
TickTock | 169:84d790ac18a2 | 1023 | sprintf(sTemp1," Hide"); |
TickTock | 169:84d790ac18a2 | 1024 | } else { |
TickTock | 169:84d790ac18a2 | 1025 | sprintf(sTemp1," Show"); |
TickTock | 169:84d790ac18a2 | 1026 | } |
TickTock | 169:84d790ac18a2 | 1027 | showButton(2,0,sTemp1," Health",4,4); |
TickTock | 169:84d790ac18a2 | 1028 | |
TickTock | 157:1a100a5ed06f | 1029 | // a button to step to the next skin |
TickTock | 157:1a100a5ed06f | 1030 | unsigned int nextSkin = skin + 1 ; |
TickTock | 157:1a100a5ed06f | 1031 | if( nextSkin > maxSkin ) nextSkin = 0 ; |
TickTock | 157:1a100a5ed06f | 1032 | |
TickTock | 157:1a100a5ed06f | 1033 | if( nextSkin == ttSkin ) sprintf(sTemp1,"Skin TT"); |
TickTock | 157:1a100a5ed06f | 1034 | else if( nextSkin == ggSkin ) sprintf(sTemp1,"Skin GG"); |
TickTock | 157:1a100a5ed06f | 1035 | else sprintf(sTemp1,"Skin %d",nextSkin); |
TickTock | 157:1a100a5ed06f | 1036 | |
TickTock | 157:1a100a5ed06f | 1037 | showButton(3,0," Use",sTemp1,4,4); |
TickTock | 157:1a100a5ed06f | 1038 | |
TickTock | 157:1a100a5ed06f | 1039 | //------- second row ----- |
TickTock | 157:1a100a5ed06f | 1040 | // add Enable/Disable Debug - debugMode |
garygid | 87:46ac3f2519d6 | 1041 | if (debugMode) { |
TickTock | 131:0d926c080a65 | 1042 | sprintf(sTemp1," Disable"); |
garygid | 87:46ac3f2519d6 | 1043 | } else { |
TickTock | 131:0d926c080a65 | 1044 | sprintf(sTemp1," Enable"); |
garygid | 87:46ac3f2519d6 | 1045 | } |
garygid | 87:46ac3f2519d6 | 1046 | showButton(3,1,sTemp1," Debug",4,4); |
TickTock | 157:1a100a5ed06f | 1047 | |
TickTock | 158:059abeb44ba1 | 1048 | //------- third row ----- |
TickTock | 158:059abeb44ba1 | 1049 | if (autoSync) { |
TickTock | 158:059abeb44ba1 | 1050 | sprintf(sTemp1," Disable"); |
TickTock | 158:059abeb44ba1 | 1051 | } else { |
TickTock | 158:059abeb44ba1 | 1052 | sprintf(sTemp1," Enable"); |
TickTock | 158:059abeb44ba1 | 1053 | } |
TickTock | 158:059abeb44ba1 | 1054 | showButton(0,2,sTemp1," tSync",4,4); |
TickTock | 131:0d926c080a65 | 1055 | showButton(1,2," Set"," Time",4,4); |
TickTock | 169:84d790ac18a2 | 1056 | showButton(2,2," Update"," Config",4,4); |
TickTock | 169:84d790ac18a2 | 1057 | showButton(3,2," Update","Firmware",4,4); |
TickTock | 36:dbd39c315258 | 1058 | } |
TickTock | 36:dbd39c315258 | 1059 | |
TickTock | 42:4533b13b297d | 1060 | void pbScreen(bool force, bool showButtons){ |
TickTock | 36:dbd39c315258 | 1061 | if (force) { |
TickTock | 36:dbd39c315258 | 1062 | tt.background(Black); |
TickTock | 36:dbd39c315258 | 1063 | tt.cls(); |
TickTock | 36:dbd39c315258 | 1064 | } |
TickTock | 36:dbd39c315258 | 1065 | if(playbackOpen){ |
garygid | 54:6ce808d0995e | 1066 | showButton(0,0,"Slower"," <--",4,4); |
garygid | 54:6ce808d0995e | 1067 | |
TickTock | 36:dbd39c315258 | 1068 | if(playbackEn){ |
garygid | 54:6ce808d0995e | 1069 | sprintf(sTemp1,"Pause"); |
TickTock | 36:dbd39c315258 | 1070 | }else{ |
garygid | 54:6ce808d0995e | 1071 | sprintf(sTemp1," Run"); |
TickTock | 36:dbd39c315258 | 1072 | } |
garygid | 54:6ce808d0995e | 1073 | sprintf(sTemp2,"%4.3f ",playbackInt); |
garygid | 54:6ce808d0995e | 1074 | showButton(1,0,sTemp1,sTemp2,4,4); |
garygid | 54:6ce808d0995e | 1075 | |
garygid | 54:6ce808d0995e | 1076 | showButton(2,0,"Faster"," -->",4,4); |
TickTock | 36:dbd39c315258 | 1077 | } |
TickTock | 36:dbd39c315258 | 1078 | if(playbackOpen){ |
TickTock | 36:dbd39c315258 | 1079 | sprintf(sTemp1," Stop"); |
TickTock | 36:dbd39c315258 | 1080 | }else{ |
garygid | 54:6ce808d0995e | 1081 | sprintf(sTemp1,"Start"); |
TickTock | 36:dbd39c315258 | 1082 | } |
garygid | 54:6ce808d0995e | 1083 | showButton(1,1,sTemp1,"Playback",4,4); |
TickTock | 36:dbd39c315258 | 1084 | } |
TickTock | 36:dbd39c315258 | 1085 | |
TickTock | 42:4533b13b297d | 1086 | void showDateTime(bool force, bool showButtons){ |
TickTock | 152:a4d66901785d | 1087 | CANMessage msg; |
TickTock | 36:dbd39c315258 | 1088 | struct tm t; // pointer to a static tm structure |
TickTock | 36:dbd39c315258 | 1089 | time_t seconds ; |
TickTock | 36:dbd39c315258 | 1090 | tt.foreground(Yellow); |
TickTock | 44:6262a9fd1e56 | 1091 | tt.background(Black); |
TickTock | 152:a4d66901785d | 1092 | if (force||tock) { |
TickTock | 36:dbd39c315258 | 1093 | tt.cls(); |
TickTock | 36:dbd39c315258 | 1094 | tt.locate(10,10); |
TickTock | 43:e7f6f80590e3 | 1095 | tt.set_font((unsigned char*) Arial12x12); |
TickTock | 152:a4d66901785d | 1096 | if(accOn){ |
TickTock | 152:a4d66901785d | 1097 | seconds = time(NULL); |
TickTock | 153:e94cfe3c339c | 1098 | t = *localtime(&seconds); |
TickTock | 153:e94cfe3c339c | 1099 | |
TickTock | 153:e94cfe3c339c | 1100 | if(modelYear<2013){ |
TickTock | 153:e94cfe3c339c | 1101 | msg = lastMsg[indexLastMsg[0x5fa]]; |
TickTock | 153:e94cfe3c339c | 1102 | t.tm_mon = (msg.data[5]>>4)-1; |
TickTock | 153:e94cfe3c339c | 1103 | t.tm_mday = msg.data[2]>>3; |
TickTock | 153:e94cfe3c339c | 1104 | // Have not figured out where the year is on MY2011 |
TickTock | 153:e94cfe3c339c | 1105 | msg = lastMsg[indexLastMsg[0x5fc]]; |
TickTock | 153:e94cfe3c339c | 1106 | t.tm_hour = msg.data[0]>>3; |
TickTock | 153:e94cfe3c339c | 1107 | t.tm_min = (msg.data[1]<<4&0x30)+(msg.data[2]>>4); |
TickTock | 153:e94cfe3c339c | 1108 | t.tm_sec = msg.data[1]>>2; |
TickTock | 153:e94cfe3c339c | 1109 | }else{ |
TickTock | 153:e94cfe3c339c | 1110 | // Have not figured out where Year, Month, or Day is for MY2013 |
TickTock | 153:e94cfe3c339c | 1111 | msg = lastMsg[indexLastMsg[0x5f9]]; |
TickTock | 153:e94cfe3c339c | 1112 | t.tm_hour = msg.data[5]>>3; |
TickTock | 153:e94cfe3c339c | 1113 | t.tm_min = msg.data[4]; |
TickTock | 153:e94cfe3c339c | 1114 | msg = lastMsg[indexLastMsg[0x509]]; |
TickTock | 153:e94cfe3c339c | 1115 | t.tm_sec = msg.data[2]>>2; |
TickTock | 153:e94cfe3c339c | 1116 | } |
TickTock | 153:e94cfe3c339c | 1117 | |
TickTock | 152:a4d66901785d | 1118 | strftime(sTemp1, 32, "%a %m/%d/%Y %X \n", &t); |
TickTock | 152:a4d66901785d | 1119 | printf("Leaf: %s",sTemp1); |
TickTock | 152:a4d66901785d | 1120 | } |
TickTock | 152:a4d66901785d | 1121 | seconds = time(NULL); |
TickTock | 152:a4d66901785d | 1122 | t = *localtime(&seconds); |
TickTock | 36:dbd39c315258 | 1123 | strftime(sTemp1, 32, "%a %m/%d/%Y %X \n", &t); |
TickTock | 152:a4d66901785d | 1124 | tt.locate(10,24); |
TickTock | 152:a4d66901785d | 1125 | printf("CANary: %s",sTemp1); |
TickTock | 122:138a40892a4c | 1126 | if(showButtons){ |
TickTock | 36:dbd39c315258 | 1127 | switch(dtMode){ |
TickTock | 36:dbd39c315258 | 1128 | case 0: |
TickTock | 36:dbd39c315258 | 1129 | sprintf(sTemp1,"Year"); |
TickTock | 36:dbd39c315258 | 1130 | break; |
TickTock | 36:dbd39c315258 | 1131 | case 1: |
TickTock | 36:dbd39c315258 | 1132 | sprintf(sTemp1,"Month"); |
TickTock | 36:dbd39c315258 | 1133 | break; |
TickTock | 36:dbd39c315258 | 1134 | case 2: |
TickTock | 36:dbd39c315258 | 1135 | sprintf(sTemp1,"Day"); |
TickTock | 36:dbd39c315258 | 1136 | break; |
TickTock | 36:dbd39c315258 | 1137 | case 3: |
TickTock | 36:dbd39c315258 | 1138 | sprintf(sTemp1,"Hour"); |
TickTock | 36:dbd39c315258 | 1139 | break; |
TickTock | 36:dbd39c315258 | 1140 | case 4: |
TickTock | 36:dbd39c315258 | 1141 | sprintf(sTemp1,"Minute"); |
TickTock | 36:dbd39c315258 | 1142 | break; |
TickTock | 36:dbd39c315258 | 1143 | case 5: |
TickTock | 36:dbd39c315258 | 1144 | sprintf(sTemp1,"Second"); |
TickTock | 36:dbd39c315258 | 1145 | break; |
TickTock | 36:dbd39c315258 | 1146 | default: |
TickTock | 36:dbd39c315258 | 1147 | break; |
TickTock | 36:dbd39c315258 | 1148 | } |
TickTock | 66:b7476ce7a59e | 1149 | showButton(0,1,sTemp1,"",4,4); |
TickTock | 152:a4d66901785d | 1150 | showButton(1,1," Up","",4,4); |
TickTock | 152:a4d66901785d | 1151 | showButton(2,1," Down","",4,4); |
TickTock | 152:a4d66901785d | 1152 | if(accOn){ |
TickTock | 152:a4d66901785d | 1153 | showButton(3,1," Sync","w/ car",4,4); |
TickTock | 152:a4d66901785d | 1154 | } |
TickTock | 152:a4d66901785d | 1155 | if(autoSync){ |
TickTock | 152:a4d66901785d | 1156 | showButton(3,2,"disable"," auto",4,4); |
TickTock | 152:a4d66901785d | 1157 | }else{ |
TickTock | 152:a4d66901785d | 1158 | showButton(3,2,"enable"," auto",4,4); |
TickTock | 152:a4d66901785d | 1159 | } |
TickTock | 36:dbd39c315258 | 1160 | } |
TickTock | 36:dbd39c315258 | 1161 | } |
TickTock | 36:dbd39c315258 | 1162 | } |
TickTock | 36:dbd39c315258 | 1163 | |
TickTock | 50:83d5864c64a0 | 1164 | void dteDisplay(bool force, bool showButtons, bool showMiles){ |
TickTock | 66:b7476ce7a59e | 1165 | unsigned short i,x,y,lx,ly,gids,radius,color,r,t; |
TickTock | 170:7ee98e3611bc | 1166 | unsigned char toVal,availableRegen=0; |
TickTock | 50:83d5864c64a0 | 1167 | static unsigned short lgids=0; |
TickTock | 50:83d5864c64a0 | 1168 | static unsigned char leff[39]={0}; |
TickTock | 50:83d5864c64a0 | 1169 | CANMessage msg; |
TickTock | 171:355e284f5201 | 1170 | unsigned long targetBraking, regenBraking, motorSpeed, motorAmps, frictionBraking; |
TickTock | 170:7ee98e3611bc | 1171 | static unsigned char lr=0, lt=0, lar=0; |
TickTock | 50:83d5864c64a0 | 1172 | |
TickTock | 50:83d5864c64a0 | 1173 | msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids |
TickTock | 50:83d5864c64a0 | 1174 | gids = (msg.data[0]<<2)+(msg.data[1]>>6); |
TickTock | 50:83d5864c64a0 | 1175 | if(gids==0){ |
TickTock | 83:52b1f330a62d | 1176 | gids=281; // Display new, fully charged capacity until real data obtained |
TickTock | 50:83d5864c64a0 | 1177 | } |
TickTock | 50:83d5864c64a0 | 1178 | |
TickTock | 37:fea2c1d52c5f | 1179 | tt.background(Navy); |
TickTock | 49:a3d2c5bb3cfa | 1180 | tt.foreground(Yellow); |
TickTock | 52:d5385fbf4ea1 | 1181 | if(force){ |
TickTock | 97:a25940fd7b5b | 1182 | tt.set_font((unsigned char*) Arial12x12); |
TickTock | 52:d5385fbf4ea1 | 1183 | tt.cls(); |
TickTock | 49:a3d2c5bb3cfa | 1184 | x=50+0*6; |
TickTock | 52:d5385fbf4ea1 | 1185 | tt.locate(x-10,226); |
TickTock | 49:a3d2c5bb3cfa | 1186 | printf("sec\n"); |
TickTock | 50:83d5864c64a0 | 1187 | tt.line(x,10,x,220,DarkGrey); |
TickTock | 49:a3d2c5bb3cfa | 1188 | x=50+9*6; |
TickTock | 52:d5385fbf4ea1 | 1189 | tt.locate(x-10,226); |
TickTock | 49:a3d2c5bb3cfa | 1190 | printf("min\n"); |
TickTock | 50:83d5864c64a0 | 1191 | tt.line(x,10,x,220,DarkGrey); |
TickTock | 49:a3d2c5bb3cfa | 1192 | x=50+18*6; |
TickTock | 52:d5385fbf4ea1 | 1193 | tt.locate(x-10,226); |
TickTock | 49:a3d2c5bb3cfa | 1194 | printf("hour\n"); |
TickTock | 83:52b1f330a62d | 1195 | tt.line(x,10,x,220,DarkGrey); |
TickTock | 49:a3d2c5bb3cfa | 1196 | x=50+25*6; |
TickTock | 52:d5385fbf4ea1 | 1197 | tt.locate(x-10,226); |
TickTock | 49:a3d2c5bb3cfa | 1198 | printf("day\n"); |
TickTock | 50:83d5864c64a0 | 1199 | tt.line(x,10,x,220,DarkGrey); |
TickTock | 49:a3d2c5bb3cfa | 1200 | x=50+32*6; |
TickTock | 52:d5385fbf4ea1 | 1201 | tt.locate(x-10,226); |
TickTock | 49:a3d2c5bb3cfa | 1202 | printf("mon\n"); |
TickTock | 50:83d5864c64a0 | 1203 | tt.line(x,10,x,220,DarkGrey); |
TickTock | 49:a3d2c5bb3cfa | 1204 | x=50+38*6; |
TickTock | 170:7ee98e3611bc | 1205 | lar=0; |
TickTock | 179:e4094e55f079 | 1206 | } |
TickTock | 162:c6545fc0164a | 1207 | toVal=33; |
TickTock | 83:52b1f330a62d | 1208 | if(force||lgids!=gids){ // update Y axis when kWh changes |
TickTock | 97:a25940fd7b5b | 1209 | tt.set_font((unsigned char*) Arial24x23); |
TickTock | 131:0d926c080a65 | 1210 | for(i=2;i<7;i++){ |
TickTock | 131:0d926c080a65 | 1211 | y=200-(i-2)*40; |
TickTock | 97:a25940fd7b5b | 1212 | tt.locate(0,y-8); |
TickTock | 83:52b1f330a62d | 1213 | if (showMiles){ |
leafman | 98:9f8bab96edff | 1214 | printf("%3.0f\n",convertDistance(i*((float)(gids-5)*.075))); // LM - Added metric support |
TickTock | 83:52b1f330a62d | 1215 | }else{ |
TickTock | 83:52b1f330a62d | 1216 | printf("%d.0\n",i); |
TickTock | 50:83d5864c64a0 | 1217 | } |
TickTock | 97:a25940fd7b5b | 1218 | tt.line(48,y,toVal*6+56,y,DarkGrey); |
TickTock | 83:52b1f330a62d | 1219 | } |
TickTock | 50:83d5864c64a0 | 1220 | lgids=gids; |
TickTock | 50:83d5864c64a0 | 1221 | } |
TickTock | 121:553faf139a20 | 1222 | if(tock||force){ |
TickTock | 131:0d926c080a65 | 1223 | for(i=2;i<7;i++){ |
TickTock | 131:0d926c080a65 | 1224 | y=200-(i-2)*40; |
TickTock | 83:52b1f330a62d | 1225 | tt.line(40,y,158,y,DarkGrey); |
TickTock | 50:83d5864c64a0 | 1226 | } |
TickTock | 50:83d5864c64a0 | 1227 | |
TickTock | 50:83d5864c64a0 | 1228 | x=50+0*6; |
TickTock | 50:83d5864c64a0 | 1229 | tt.line(x,10,x,220,DarkGrey); |
TickTock | 50:83d5864c64a0 | 1230 | x=50+9*6; |
TickTock | 50:83d5864c64a0 | 1231 | tt.line(x,10,x,220,DarkGrey); |
TickTock | 50:83d5864c64a0 | 1232 | x=50+18*6; |
TickTock | 50:83d5864c64a0 | 1233 | tt.line(x,10,x,220,DarkGrey); |
TickTock | 83:52b1f330a62d | 1234 | //x=50+25*6; |
TickTock | 83:52b1f330a62d | 1235 | //tt.line(x,60,x,220,DarkGrey); |
TickTock | 83:52b1f330a62d | 1236 | //x=50+32*6; |
TickTock | 83:52b1f330a62d | 1237 | //tt.line(x,60,x,220,DarkGrey); |
TickTock | 66:b7476ce7a59e | 1238 | //x=50+38*6; |
TickTock | 66:b7476ce7a59e | 1239 | //tt.line(x,60,x,220,DarkGrey); |
TickTock | 50:83d5864c64a0 | 1240 | tt.set_font((unsigned char*) SCProSB31x55); |
TickTock | 164:46ed06263b0e | 1241 | tt.foreground(Yellow); |
TickTock | 50:83d5864c64a0 | 1242 | if (showMiles){ |
TickTock | 93:c2402e8cd0e2 | 1243 | float miles = mpkWh[dtePeriod]*((float)(gids-5)*.075); |
leafman | 98:9f8bab96edff | 1244 | miles = convertDistance(miles); // LM - Metric support |
TickTock | 93:c2402e8cd0e2 | 1245 | // Right justify |
TickTock | 94:c3a14b3975d6 | 1246 | if (miles>99.9){ //space=18; num=31; . = 23 |
TickTock | 163:3b6fab958773 | 1247 | tt.locate(161,1); |
TickTock | 94:c3a14b3975d6 | 1248 | printf("%4.1f\n",miles); |
TickTock | 93:c2402e8cd0e2 | 1249 | } else if (miles>9.9){ |
TickTock | 163:3b6fab958773 | 1250 | tt.locate(156,1); |
TickTock | 94:c3a14b3975d6 | 1251 | printf(" %3.1f\n",miles); |
TickTock | 93:c2402e8cd0e2 | 1252 | } else { |
TickTock | 163:3b6fab958773 | 1253 | tt.locate(151,1); |
TickTock | 94:c3a14b3975d6 | 1254 | printf(" %2.1f\n",miles); |
TickTock | 93:c2402e8cd0e2 | 1255 | } |
TickTock | 164:46ed06263b0e | 1256 | if(CCon) { |
TickTock | 169:84d790ac18a2 | 1257 | tt.foreground(GreenYellow); |
TickTock | 164:46ed06263b0e | 1258 | tt.set_font((unsigned char*) Arial24x23); |
TickTock | 165:4daa921730dd | 1259 | miles = (mpkWh_noCC-mpkWh[dtePeriod])*((float)(gids-5)*.075); |
TickTock | 164:46ed06263b0e | 1260 | miles = convertDistance(miles); // LM - Metric support |
TickTock | 164:46ed06263b0e | 1261 | // Right justify |
TickTock | 165:4daa921730dd | 1262 | if (miles>9.9){ |
TickTock | 165:4daa921730dd | 1263 | tt.locate(190,52); |
TickTock | 165:4daa921730dd | 1264 | printf(" +%3.1f \n",miles); |
TickTock | 165:4daa921730dd | 1265 | } else { |
TickTock | 164:46ed06263b0e | 1266 | tt.locate(182,52); |
TickTock | 165:4daa921730dd | 1267 | printf(" +%2.1f \n",miles); |
TickTock | 164:46ed06263b0e | 1268 | } |
TickTock | 162:c6545fc0164a | 1269 | } |
TickTock | 50:83d5864c64a0 | 1270 | } else { |
TickTock | 163:3b6fab958773 | 1271 | tt.locate(200,1); |
TickTock | 66:b7476ce7a59e | 1272 | printf("%3.1f \n",mpkWh[dtePeriod]); |
TickTock | 164:46ed06263b0e | 1273 | if(CCon) { |
TickTock | 169:84d790ac18a2 | 1274 | tt.foreground(GreenYellow); |
TickTock | 164:46ed06263b0e | 1275 | tt.set_font((unsigned char*) Arial24x23); |
TickTock | 165:4daa921730dd | 1276 | tt.locate(190,52); |
TickTock | 165:4daa921730dd | 1277 | printf(" +%2.1f \n",(mpkWh_noCC-mpkWh[dtePeriod])); |
TickTock | 164:46ed06263b0e | 1278 | } |
TickTock | 50:83d5864c64a0 | 1279 | } |
TickTock | 49:a3d2c5bb3cfa | 1280 | lx=50; |
TickTock | 97:a25940fd7b5b | 1281 | ly=mpkWh[0]*40; |
TickTock | 50:83d5864c64a0 | 1282 | if(dtePeriod==0){ |
TickTock | 52:d5385fbf4ea1 | 1283 | radius=6; |
TickTock | 79:68f0dd8d1f19 | 1284 | color=Yellow; |
TickTock | 50:83d5864c64a0 | 1285 | }else{ |
TickTock | 50:83d5864c64a0 | 1286 | radius=2; |
TickTock | 50:83d5864c64a0 | 1287 | color=Green; |
TickTock | 50:83d5864c64a0 | 1288 | } |
TickTock | 131:0d926c080a65 | 1289 | if(ly<60){ |
TickTock | 97:a25940fd7b5b | 1290 | ly=220; |
TickTock | 97:a25940fd7b5b | 1291 | color=Red; |
TickTock | 131:0d926c080a65 | 1292 | }else if(ly<280) { |
TickTock | 131:0d926c080a65 | 1293 | ly=280-ly; |
TickTock | 97:a25940fd7b5b | 1294 | }else{ |
TickTock | 97:a25940fd7b5b | 1295 | ly=0; |
TickTock | 97:a25940fd7b5b | 1296 | } |
TickTock | 50:83d5864c64a0 | 1297 | tt.fillcircle(lx,leff[0],radius,Navy); |
TickTock | 50:83d5864c64a0 | 1298 | tt.fillcircle(lx,ly,radius,color); |
TickTock | 49:a3d2c5bb3cfa | 1299 | |
TickTock | 79:68f0dd8d1f19 | 1300 | for(i=1;i<toVal;i++){ |
TickTock | 49:a3d2c5bb3cfa | 1301 | x=50+i*6; |
TickTock | 97:a25940fd7b5b | 1302 | y=mpkWh[i]*40; |
TickTock | 50:83d5864c64a0 | 1303 | if(i==dtePeriod){ |
TickTock | 79:68f0dd8d1f19 | 1304 | radius=6; |
TickTock | 79:68f0dd8d1f19 | 1305 | color=Yellow; |
TickTock | 50:83d5864c64a0 | 1306 | }else{ |
TickTock | 50:83d5864c64a0 | 1307 | radius=2; |
TickTock | 50:83d5864c64a0 | 1308 | color=Green; |
TickTock | 50:83d5864c64a0 | 1309 | } |
TickTock | 131:0d926c080a65 | 1310 | if(y<60){ |
TickTock | 97:a25940fd7b5b | 1311 | y=220; |
TickTock | 97:a25940fd7b5b | 1312 | color=Red; |
TickTock | 131:0d926c080a65 | 1313 | }else if(y<280) { |
TickTock | 131:0d926c080a65 | 1314 | y=280-y; |
TickTock | 97:a25940fd7b5b | 1315 | }else{ |
TickTock | 97:a25940fd7b5b | 1316 | y=0; |
TickTock | 97:a25940fd7b5b | 1317 | } |
TickTock | 50:83d5864c64a0 | 1318 | tt.fillcircle(x,leff[i],radius,Navy); |
TickTock | 50:83d5864c64a0 | 1319 | tt.line(x-6,leff[i-1],x,leff[i],Navy); |
TickTock | 50:83d5864c64a0 | 1320 | leff[i-1]=ly; |
TickTock | 52:d5385fbf4ea1 | 1321 | if(y>0){ |
TickTock | 52:d5385fbf4ea1 | 1322 | tt.fillcircle(x,y,radius,color); |
TickTock | 52:d5385fbf4ea1 | 1323 | } |
TickTock | 49:a3d2c5bb3cfa | 1324 | tt.line(lx,ly,x,y,White); |
TickTock | 49:a3d2c5bb3cfa | 1325 | lx=x; |
TickTock | 49:a3d2c5bb3cfa | 1326 | ly=y; |
TickTock | 49:a3d2c5bb3cfa | 1327 | } |
TickTock | 50:83d5864c64a0 | 1328 | leff[i-1]=y; |
TickTock | 37:fea2c1d52c5f | 1329 | } |
TickTock | 66:b7476ce7a59e | 1330 | |
TickTock | 171:355e284f5201 | 1331 | // Plot Braking friction/regen bar graph |
TickTock | 171:355e284f5201 | 1332 | msg = lastMsg[indexLastMsg[0x176]]; //Get RPMs |
TickTock | 171:355e284f5201 | 1333 | motorSpeed = (msg.data[2]<<8)+msg.data[3]; |
TickTock | 170:7ee98e3611bc | 1334 | msg = lastMsg[indexLastMsg[0x260]]; //Get available regen |
TickTock | 171:355e284f5201 | 1335 | availableRegen = msg.data[1]*4; |
TickTock | 171:355e284f5201 | 1336 | msg = lastMsg[indexLastMsg[0x1cb]]; //Get target total braking |
TickTock | 171:355e284f5201 | 1337 | targetBraking = (msg.data[2]<<3)+(msg.data[3]>>5); |
TickTock | 171:355e284f5201 | 1338 | msg = lastMsg[indexLastMsg[0x292]]; //Get friction braking |
TickTock | 171:355e284f5201 | 1339 | frictionBraking = msg.data[6]; |
TickTock | 171:355e284f5201 | 1340 | msg = lastMsg[indexLastMsg[0x180]]; //Get motor amps |
TickTock | 171:355e284f5201 | 1341 | motorAmps = (msg.data[2]<<4)+(msg.data[3]>>4); |
TickTock | 171:355e284f5201 | 1342 | if(motorAmps>0x7ff){ // invert and chop positive current |
TickTock | 171:355e284f5201 | 1343 | motorAmps=0x1000-motorAmps; |
TickTock | 171:355e284f5201 | 1344 | }else{ |
TickTock | 171:355e284f5201 | 1345 | motorAmps=0; |
TickTock | 171:355e284f5201 | 1346 | } |
TickTock | 170:7ee98e3611bc | 1347 | |
TickTock | 171:355e284f5201 | 1348 | targetBraking *= motorSpeed; |
TickTock | 171:355e284f5201 | 1349 | targetBraking /= tbScalar; //0.0000345 * 4 |
TickTock | 171:355e284f5201 | 1350 | regenBraking = motorAmps; |
TickTock | 171:355e284f5201 | 1351 | regenBraking *= motorSpeed; |
TickTock | 171:355e284f5201 | 1352 | regenBraking /= rbScalar; //0.00002875 * 4 |
TickTock | 171:355e284f5201 | 1353 | frictionBraking *= motorSpeed; |
TickTock | 171:355e284f5201 | 1354 | frictionBraking /= fbScalar; //0.0019 * 4 |
TickTock | 171:355e284f5201 | 1355 | |
TickTock | 171:355e284f5201 | 1356 | // Plot available regen brackets |
TickTock | 170:7ee98e3611bc | 1357 | if(availableRegen>lar){ |
TickTock | 171:355e284f5201 | 1358 | tt.fillrect(273,238-availableRegen,275,239-lar,White); |
TickTock | 171:355e284f5201 | 1359 | tt.fillrect(317,238-availableRegen,319,239-lar,White); |
TickTock | 174:cd27e80f197d | 1360 | if(availableRegen>0){ |
TickTock | 174:cd27e80f197d | 1361 | for(i=0;i<=availableRegen;i+=24){ |
TickTock | 171:355e284f5201 | 1362 | tt.fillrect(270,238-i,272,239-i,White); |
TickTock | 171:355e284f5201 | 1363 | } |
TickTock | 171:355e284f5201 | 1364 | } |
TickTock | 170:7ee98e3611bc | 1365 | lar=availableRegen; |
TickTock | 170:7ee98e3611bc | 1366 | }else if(availableRegen<lar){ |
TickTock | 171:355e284f5201 | 1367 | tt.fillrect(270,238-lar,275,239-availableRegen,Navy); |
TickTock | 171:355e284f5201 | 1368 | tt.fillrect(317,238-lar,319,239-availableRegen,Navy); |
TickTock | 170:7ee98e3611bc | 1369 | lar=availableRegen; |
TickTock | 170:7ee98e3611bc | 1370 | } |
TickTock | 170:7ee98e3611bc | 1371 | |
TickTock | 171:355e284f5201 | 1372 | t = (unsigned char) regenBraking+frictionBraking; |
TickTock | 171:355e284f5201 | 1373 | if (t>160) t=160; |
TickTock | 171:355e284f5201 | 1374 | r = (unsigned char) regenBraking; |
TickTock | 171:355e284f5201 | 1375 | if (r>160) r=160; |
TickTock | 171:355e284f5201 | 1376 | if (r>t) t=r; //Should never happen |
TickTock | 171:355e284f5201 | 1377 | if(lr!=r||lt!=t){ |
TickTock | 171:355e284f5201 | 1378 | if (t<160) tt.fillrect(277,239-160,315,238-t,Navy); |
TickTock | 171:355e284f5201 | 1379 | if (r<t) tt.fillrect(277,239-t,315,238-r,Red); |
TickTock | 171:355e284f5201 | 1380 | if (0<r) tt.fillrect(277,239-r,315,238,Green); |
TickTock | 108:29b5a760adc2 | 1381 | } |
TickTock | 171:355e284f5201 | 1382 | lt=t; |
TickTock | 171:355e284f5201 | 1383 | lr=r; |
TickTock | 37:fea2c1d52c5f | 1384 | } |
TickTock | 37:fea2c1d52c5f | 1385 | |
TickTock | 150:ef46ce63345c | 1386 | void testDisplay (bool force, bool showButtons){ |
TickTock | 158:059abeb44ba1 | 1387 | static unsigned short maxPS=0, oldData[8]={0}; |
TickTock | 158:059abeb44ba1 | 1388 | unsigned char i, uData[8];//, year, month, day, hour, minute, second; |
TickTock | 148:6e3b9135fad2 | 1389 | CANMessage msg; |
TickTock | 148:6e3b9135fad2 | 1390 | |
TickTock | 148:6e3b9135fad2 | 1391 | tt.set_font((unsigned char*) Arial24x23); |
TickTock | 148:6e3b9135fad2 | 1392 | tt.foreground(Yellow); |
TickTock | 148:6e3b9135fad2 | 1393 | tt.background(Navy); |
TickTock | 148:6e3b9135fad2 | 1394 | if(force){ |
TickTock | 148:6e3b9135fad2 | 1395 | tt.cls(); |
TickTock | 148:6e3b9135fad2 | 1396 | } |
TickTock | 158:059abeb44ba1 | 1397 | if(logEn){ |
TickTock | 158:059abeb44ba1 | 1398 | if(pointerSep>maxPS){maxPS=pointerSep;} |
TickTock | 158:059abeb44ba1 | 1399 | tt.locate(10,10); |
TickTock | 170:7ee98e3611bc | 1400 | printf("%3d sep %3d max\n",pointerSep,maxPS); |
TickTock | 170:7ee98e3611bc | 1401 | }else{ |
TickTock | 170:7ee98e3611bc | 1402 | tt.locate(10,10); |
TickTock | 170:7ee98e3611bc | 1403 | printf("%d maxT\n",maxTarget); |
TickTock | 158:059abeb44ba1 | 1404 | } |
TickTock | 158:059abeb44ba1 | 1405 | |
TickTock | 152:a4d66901785d | 1406 | for (i=0; i<8; i++){ |
TickTock | 152:a4d66901785d | 1407 | msg = lastMsg[indexLastMsg[(uMsgId[i]>>4)]]; |
TickTock | 152:a4d66901785d | 1408 | uData[i] = msg.data[(uMsgId[i]&0x000f)]; |
TickTock | 158:059abeb44ba1 | 1409 | if(i%2==0){ |
TickTock | 158:059abeb44ba1 | 1410 | tt.locate(10,90+(i/2)*30); |
TickTock | 158:059abeb44ba1 | 1411 | }else{ |
TickTock | 158:059abeb44ba1 | 1412 | tt.locate(170,90+(i/2)*30); |
TickTock | 158:059abeb44ba1 | 1413 | } |
TickTock | 158:059abeb44ba1 | 1414 | if(clearTest){ |
TickTock | 169:84d790ac18a2 | 1415 | maxPS=0; |
TickTock | 158:059abeb44ba1 | 1416 | oldData[i]=uData[i]; |
TickTock | 158:059abeb44ba1 | 1417 | tt.foreground(Yellow); |
TickTock | 158:059abeb44ba1 | 1418 | tt.background(Navy); |
TickTock | 158:059abeb44ba1 | 1419 | printf("%4x:%2x\n",uMsgId[i],uData[i]); |
TickTock | 158:059abeb44ba1 | 1420 | }else if(uData[i]!=oldData[i]){ |
TickTock | 158:059abeb44ba1 | 1421 | tt.foreground(Navy); |
TickTock | 158:059abeb44ba1 | 1422 | tt.background(Yellow); |
TickTock | 158:059abeb44ba1 | 1423 | printf("%4x:%2x\n",uMsgId[i],uData[i]); |
TickTock | 159:577e9d015693 | 1424 | oldData[i]=uData[i]; |
TickTock | 158:059abeb44ba1 | 1425 | }else if(force){ |
TickTock | 158:059abeb44ba1 | 1426 | tt.foreground(Yellow); |
TickTock | 158:059abeb44ba1 | 1427 | tt.background(Navy); |
TickTock | 158:059abeb44ba1 | 1428 | printf("%4x:%2x\n",uMsgId[i],uData[i]); |
TickTock | 158:059abeb44ba1 | 1429 | } |
TickTock | 152:a4d66901785d | 1430 | } |
TickTock | 158:059abeb44ba1 | 1431 | clearTest=false; |
TickTock | 158:059abeb44ba1 | 1432 | showButton(3,0,"Reset","flags",4,4); |
TickTock | 148:6e3b9135fad2 | 1433 | } |
TickTock | 148:6e3b9135fad2 | 1434 | |
TickTock | 180:5fdeeb86f3a3 | 1435 | void whpgDisplay(bool force, bool showButtons, bool showWh){ |
TickTock | 184:5ca7b78297fe | 1436 | unsigned short maxGid, minGid, i, y, maxWg; |
TickTock | 179:e4094e55f079 | 1437 | static unsigned short lmg; |
TickTock | 179:e4094e55f079 | 1438 | |
TickTock | 179:e4094e55f079 | 1439 | tt.foreground(White); |
TickTock | 179:e4094e55f079 | 1440 | tt.background(Navy); |
TickTock | 179:e4094e55f079 | 1441 | tt.set_font((unsigned char*) Arial12x12_prop); // select the font |
TickTock | 179:e4094e55f079 | 1442 | |
TickTock | 179:e4094e55f079 | 1443 | maxGid=0; |
TickTock | 179:e4094e55f079 | 1444 | minGid=9999; |
TickTock | 178:bf6404312c45 | 1445 | |
TickTock | 178:bf6404312c45 | 1446 | if(force){ |
TickTock | 179:e4094e55f079 | 1447 | lmg=281; |
TickTock | 179:e4094e55f079 | 1448 | } |
TickTock | 179:e4094e55f079 | 1449 | |
TickTock | 184:5ca7b78297fe | 1450 | // find max/min/maxWg |
TickTock | 180:5fdeeb86f3a3 | 1451 | if(showWh){ |
TickTock | 182:10017d74de67 | 1452 | for(i=0; i<300; i++){ |
TickTock | 180:5fdeeb86f3a3 | 1453 | if(wh[i]>0){ |
TickTock | 180:5fdeeb86f3a3 | 1454 | if(i>maxGid) maxGid=i; |
TickTock | 180:5fdeeb86f3a3 | 1455 | if(i<minGid) minGid=i; |
TickTock | 180:5fdeeb86f3a3 | 1456 | } |
TickTock | 180:5fdeeb86f3a3 | 1457 | } |
TickTock | 184:5ca7b78297fe | 1458 | maxWg = wh[maxGid]; |
TickTock | 180:5fdeeb86f3a3 | 1459 | }else{ |
TickTock | 182:10017d74de67 | 1460 | for(i=0; i<300; i++){ |
TickTock | 180:5fdeeb86f3a3 | 1461 | if(whpg[i]>0){ |
TickTock | 180:5fdeeb86f3a3 | 1462 | if(i>maxGid) maxGid=i; |
TickTock | 180:5fdeeb86f3a3 | 1463 | if(i<minGid) minGid=i; |
TickTock | 180:5fdeeb86f3a3 | 1464 | } |
TickTock | 178:bf6404312c45 | 1465 | } |
TickTock | 184:5ca7b78297fe | 1466 | maxWg = whpg[minGid]; |
TickTock | 179:e4094e55f079 | 1467 | } |
TickTock | 178:bf6404312c45 | 1468 | |
TickTock | 182:10017d74de67 | 1469 | if (force||(minGid<lmg)){ //update if new data |
TickTock | 179:e4094e55f079 | 1470 | lmg = minGid; |
TickTock | 178:bf6404312c45 | 1471 | //------------------ |
TickTock | 178:bf6404312c45 | 1472 | tt.cls(); |
TickTock | 178:bf6404312c45 | 1473 | |
TickTock | 178:bf6404312c45 | 1474 | // show as vertical bar plot |
TickTock | 178:bf6404312c45 | 1475 | int xWinMin = 26; |
TickTock | 178:bf6404312c45 | 1476 | int xWinMax = 316; |
TickTock | 179:e4094e55f079 | 1477 | int yWinMin = 20; |
TickTock | 179:e4094e55f079 | 1478 | int yWinMax = 200; |
TickTock | 179:e4094e55f079 | 1479 | // draw the Frame, 2 pixels wide |
TickTock | 179:e4094e55f079 | 1480 | tt.rect( xWinMin-1,yWinMin-1, xWinMax+1,yWinMax+1, Red); |
TickTock | 179:e4094e55f079 | 1481 | tt.rect( xWinMin-2,yWinMin-2, xWinMax+2,yWinMax+2, Green); |
TickTock | 181:396fdcceefd2 | 1482 | // draw grid |
TickTock | 182:10017d74de67 | 1483 | for( i=0; i<yWinMax-yWinMin; i+=20){ |
TickTock | 181:396fdcceefd2 | 1484 | tt.line(xWinMin,yWinMax-i,xWinMax,yWinMax-i,DarkGrey); |
TickTock | 182:10017d74de67 | 1485 | if(i%40 == 0){ |
TickTock | 182:10017d74de67 | 1486 | // label the y axis each 40 |
TickTock | 182:10017d74de67 | 1487 | tt.line( xWinMin-8,yWinMax-i, xWinMin-2,yWinMax-i, White ); // a white tick mark |
TickTock | 182:10017d74de67 | 1488 | tt.locate( 0, yWinMax-i-4 ); |
TickTock | 182:10017d74de67 | 1489 | printf("%d\n", i ); |
TickTock | 182:10017d74de67 | 1490 | } |
TickTock | 181:396fdcceefd2 | 1491 | } |
TickTock | 182:10017d74de67 | 1492 | for( i=0; i<xWinMax-xWinMin; i+=10){ |
TickTock | 182:10017d74de67 | 1493 | // tic mark the x axis each 10 |
TickTock | 182:10017d74de67 | 1494 | tt.line( i+xWinMin,yWinMax+2, i+xWinMin,yWinMax+4, White ); // a white tick mark |
TickTock | 182:10017d74de67 | 1495 | if(i%40 == 0){ |
TickTock | 182:10017d74de67 | 1496 | // label the x axis each 40 |
TickTock | 182:10017d74de67 | 1497 | tt.line( i+xWinMin,yWinMax+2, i+xWinMin,yWinMax+8, White ); // a white tick mark |
TickTock | 182:10017d74de67 | 1498 | if(i<100){ |
TickTock | 182:10017d74de67 | 1499 | tt.locate( i+xWinMin-7, yWinMax+8 ); |
TickTock | 182:10017d74de67 | 1500 | }else{ |
TickTock | 182:10017d74de67 | 1501 | tt.locate( i+xWinMin-15, yWinMax+8 ); |
TickTock | 182:10017d74de67 | 1502 | } |
TickTock | 182:10017d74de67 | 1503 | printf("%d\n", i ); |
TickTock | 182:10017d74de67 | 1504 | } |
TickTock | 182:10017d74de67 | 1505 | if(i%20 == 0){ |
TickTock | 182:10017d74de67 | 1506 | tt.line(xWinMin+i,yWinMin,xWinMin+i,yWinMax,DarkGrey); |
TickTock | 182:10017d74de67 | 1507 | } |
TickTock | 181:396fdcceefd2 | 1508 | } |
TickTock | 178:bf6404312c45 | 1509 | |
TickTock | 182:10017d74de67 | 1510 | // plot |
TickTock | 182:10017d74de67 | 1511 | if( maxGid >= minGid ) { |
TickTock | 182:10017d74de67 | 1512 | tt.locate( xWinMin+4, yWinMin+4); |
TickTock | 184:5ca7b78297fe | 1513 | printf("%3.1f avg\n", (float) maxWg/(maxGid-minGid+1) ); |
TickTock | 182:10017d74de67 | 1514 | if(debugMode){ |
TickTock | 182:10017d74de67 | 1515 | tt.locate( xWinMin+4, yWinMin+20); |
TickTock | 182:10017d74de67 | 1516 | printf("minGids=%d; maxGids=%d\n", minGid,maxGid); |
TickTock | 182:10017d74de67 | 1517 | tt.locate( xWinMin+4, yWinMin+36); |
TickTock | 184:5ca7b78297fe | 1518 | if(showWh){ |
TickTock | 184:5ca7b78297fe | 1519 | printf("minwh=%3.1f; maxwh=%3.1f\n", wh[minGid],wh[maxGid]); |
TickTock | 184:5ca7b78297fe | 1520 | }else{ |
TickTock | 184:5ca7b78297fe | 1521 | printf("minwhpg=%d; maxwhpg=%d\n", whpg[minGid],whpg[maxGid]); |
TickTock | 184:5ca7b78297fe | 1522 | } |
TickTock | 182:10017d74de67 | 1523 | } |
TickTock | 179:e4094e55f079 | 1524 | |
TickTock | 184:5ca7b78297fe | 1525 | for( i=3; i<=287; i++) { |
TickTock | 181:396fdcceefd2 | 1526 | if(showWh){ |
TickTock | 181:396fdcceefd2 | 1527 | y = wh[i]-wh[i-1]; |
TickTock | 181:396fdcceefd2 | 1528 | tt.fillcircle(i+xWinMin,yWinMax-y,2,Green); |
TickTock | 181:396fdcceefd2 | 1529 | }else{ |
TickTock | 184:5ca7b78297fe | 1530 | if((whpg[i-3]>0)&&(whpg[i+3]>0)){ |
TickTock | 184:5ca7b78297fe | 1531 | y = (whpg[i-3]-whpg[i+3])/6; |
TickTock | 181:396fdcceefd2 | 1532 | }else{ |
TickTock | 184:5ca7b78297fe | 1533 | y = 0; |
TickTock | 181:396fdcceefd2 | 1534 | } |
TickTock | 184:5ca7b78297fe | 1535 | if((y>0) && (y<180)){ |
TickTock | 181:396fdcceefd2 | 1536 | tt.fillcircle(i+xWinMin,yWinMax-y,2,Yellow); |
TickTock | 181:396fdcceefd2 | 1537 | } |
TickTock | 181:396fdcceefd2 | 1538 | } |
TickTock | 178:bf6404312c45 | 1539 | } |
TickTock | 178:bf6404312c45 | 1540 | } |
TickTock | 178:bf6404312c45 | 1541 | } |
TickTock | 178:bf6404312c45 | 1542 | } |
TickTock | 178:bf6404312c45 | 1543 | |
TickTock | 36:dbd39c315258 | 1544 | void updateDisplay(char display){ |
TickTock | 122:138a40892a4c | 1545 | bool changed,showButtons; |
TickTock | 164:46ed06263b0e | 1546 | changed = (dMode[display]!=lastDMode[display]); |
TickTock | 122:138a40892a4c | 1547 | showButtons = (display==whichTouched)&&(sMode==1); |
TickTock | 36:dbd39c315258 | 1548 | tt.set_display(display); |
TickTock | 36:dbd39c315258 | 1549 | switch (dMode[display]) { |
TickTock | 36:dbd39c315258 | 1550 | case logScreen: |
TickTock | 122:138a40892a4c | 1551 | printLog(changed,showButtons); |
TickTock | 36:dbd39c315258 | 1552 | break; |
TickTock | 41:8d4609ea7259 | 1553 | case mainScreen: |
TickTock | 122:138a40892a4c | 1554 | mainDisplay(changed,showButtons); |
TickTock | 36:dbd39c315258 | 1555 | break; |
TickTock | 36:dbd39c315258 | 1556 | case brakeScreen: |
TickTock | 122:138a40892a4c | 1557 | braking(changed,showButtons); |
TickTock | 36:dbd39c315258 | 1558 | break; |
TickTock | 41:8d4609ea7259 | 1559 | case dteScreen: |
TickTock | 122:138a40892a4c | 1560 | dteDisplay(changed,showButtons,true); |
TickTock | 37:fea2c1d52c5f | 1561 | break; |
TickTock | 50:83d5864c64a0 | 1562 | case effScreen: |
TickTock | 122:138a40892a4c | 1563 | dteDisplay(changed,showButtons,false); |
TickTock | 50:83d5864c64a0 | 1564 | break; |
TickTock | 50:83d5864c64a0 | 1565 | case monitorScreen: |
TickTock | 122:138a40892a4c | 1566 | printLast(changed,showButtons); |
TickTock | 36:dbd39c315258 | 1567 | break; |
TickTock | 36:dbd39c315258 | 1568 | case changedScreen: |
TickTock | 122:138a40892a4c | 1569 | printChanged(changed,showButtons); |
TickTock | 36:dbd39c315258 | 1570 | break; |
TickTock | 36:dbd39c315258 | 1571 | case cpScreen: |
TickTock | 122:138a40892a4c | 1572 | cpData(changed||showCP,showButtons); |
TickTock | 36:dbd39c315258 | 1573 | break; |
leafman | 98:9f8bab96edff | 1574 | case configScreen: |
TickTock | 122:138a40892a4c | 1575 | config(changed,showButtons); |
TickTock | 36:dbd39c315258 | 1576 | break; |
TickTock | 157:1a100a5ed06f | 1577 | case config2Screen: |
TickTock | 157:1a100a5ed06f | 1578 | config2(changed,showButtons); |
TickTock | 157:1a100a5ed06f | 1579 | break; |
TickTock | 38:155ec32c5e91 | 1580 | case playbackScreen: |
TickTock | 122:138a40892a4c | 1581 | pbScreen(changed,showButtons); |
TickTock | 36:dbd39c315258 | 1582 | break; |
TickTock | 36:dbd39c315258 | 1583 | case dateScreen: |
TickTock | 122:138a40892a4c | 1584 | showDateTime(changed,showButtons); |
TickTock | 36:dbd39c315258 | 1585 | break; |
TickTock | 44:6262a9fd1e56 | 1586 | case cpHistScreen: // gg - hist |
TickTock | 122:138a40892a4c | 1587 | cpHistogram(changed||showCP,showButtons); |
TickTock | 44:6262a9fd1e56 | 1588 | break; |
TickTock | 48:d1ce92104a1f | 1589 | case cpBarScreen: // gg - cpbars |
TickTock | 122:138a40892a4c | 1590 | cpBarPlot(changed||showCP,showButtons); |
TickTock | 48:d1ce92104a1f | 1591 | break; |
garygid | 67:2022fce701d0 | 1592 | case indexScreen: |
TickTock | 122:138a40892a4c | 1593 | showIndex(changed,showButtons); |
garygid | 67:2022fce701d0 | 1594 | break; |
TickTock | 107:e9be732c1ad4 | 1595 | case tripScreen: |
TickTock | 168:9227024c4e3a | 1596 | tripDisplay(changed,showButtons,false); |
TickTock | 168:9227024c4e3a | 1597 | break; |
TickTock | 168:9227024c4e3a | 1598 | case ccTripScreen: |
TickTock | 168:9227024c4e3a | 1599 | tripDisplay(changed,showButtons,true); |
TickTock | 107:e9be732c1ad4 | 1600 | break; |
TickTock | 118:02010b18efdc | 1601 | case healthScreen: |
TickTock | 122:138a40892a4c | 1602 | healthDisplay(changed,showButtons); |
garygid | 67:2022fce701d0 | 1603 | break; |
TickTock | 150:ef46ce63345c | 1604 | case testScreen: |
TickTock | 150:ef46ce63345c | 1605 | testDisplay(changed,showButtons); |
TickTock | 148:6e3b9135fad2 | 1606 | break; |
TickTock | 178:bf6404312c45 | 1607 | case whpgScreen: |
TickTock | 180:5fdeeb86f3a3 | 1608 | whpgDisplay(changed,showButtons,false); |
TickTock | 180:5fdeeb86f3a3 | 1609 | break; |
TickTock | 180:5fdeeb86f3a3 | 1610 | case whScreen: |
TickTock | 180:5fdeeb86f3a3 | 1611 | whpgDisplay(changed,showButtons,true); |
TickTock | 178:bf6404312c45 | 1612 | break; |
TickTock | 36:dbd39c315258 | 1613 | default: |
TickTock | 43:e7f6f80590e3 | 1614 | if (changed){ |
TickTock | 43:e7f6f80590e3 | 1615 | tt.background(Black); |
TickTock | 43:e7f6f80590e3 | 1616 | tt.cls(); |
TickTock | 43:e7f6f80590e3 | 1617 | } |
TickTock | 36:dbd39c315258 | 1618 | break; |
TickTock | 36:dbd39c315258 | 1619 | } |
TickTock | 36:dbd39c315258 | 1620 | lastDMode[display]=dMode[display]; |
TickTock | 36:dbd39c315258 | 1621 | |
TickTock | 42:4533b13b297d | 1622 | if(display==whichTouched){ |
TickTock | 42:4533b13b297d | 1623 | switch (sMode) { |
TickTock | 42:4533b13b297d | 1624 | case 1: // Select screens |
garygid | 54:6ce808d0995e | 1625 | showButton(0,tNavRow," <-Prev","",4,4); // gg - 4x4 |
garygid | 67:2022fce701d0 | 1626 | // col 1 see below |
garygid | 67:2022fce701d0 | 1627 | showButton(2,tNavRow," Go To"," Index",4,4); // gg - index |
garygid | 54:6ce808d0995e | 1628 | showButton(3,tNavRow," Next->","",4,4); // gg - move next |
TickTock | 154:90ea16ca7475 | 1629 | if (enableSound) { |
TickTock | 154:90ea16ca7475 | 1630 | sprintf(sTemp1," Mute"); |
TickTock | 154:90ea16ca7475 | 1631 | } else { |
TickTock | 154:90ea16ca7475 | 1632 | sprintf(sTemp1,"Un-Mute"); |
TickTock | 154:90ea16ca7475 | 1633 | } |
garygid | 67:2022fce701d0 | 1634 | // col 1 in Nav row |
TickTock | 42:4533b13b297d | 1635 | switch (dMode[display]) { |
TickTock | 44:6262a9fd1e56 | 1636 | case offScreen: |
TickTock | 154:90ea16ca7475 | 1637 | showButton(3,0,sTemp1,"",4,4); |
garygid | 54:6ce808d0995e | 1638 | sprintf(sTemp2," Off"); |
TickTock | 42:4533b13b297d | 1639 | break; |
TickTock | 44:6262a9fd1e56 | 1640 | case logScreen: |
TickTock | 154:90ea16ca7475 | 1641 | showButton(3,0,sTemp1,"",4,4); |
garygid | 54:6ce808d0995e | 1642 | sprintf(sTemp2," Log"); |
TickTock | 42:4533b13b297d | 1643 | break; |
TickTock | 44:6262a9fd1e56 | 1644 | case mainScreen: |
TickTock | 154:90ea16ca7475 | 1645 | showButton(3,0,sTemp1,"",4,4); |
garygid | 54:6ce808d0995e | 1646 | sprintf(sTemp2," Main"); |
TickTock | 42:4533b13b297d | 1647 | break; |
TickTock | 44:6262a9fd1e56 | 1648 | case brakeScreen: |
TickTock | 154:90ea16ca7475 | 1649 | showButton(3,0,sTemp1,"",4,4); |
garygid | 54:6ce808d0995e | 1650 | sprintf(sTemp2,"Braking"); |
TickTock | 42:4533b13b297d | 1651 | break; |
TickTock | 44:6262a9fd1e56 | 1652 | case dteScreen: |
TickTock | 154:90ea16ca7475 | 1653 | showButton(3,0,sTemp1,"",4,4); |
garygid | 54:6ce808d0995e | 1654 | sprintf(sTemp2," DTE"); |
TickTock | 42:4533b13b297d | 1655 | break; |
TickTock | 50:83d5864c64a0 | 1656 | case effScreen: |
TickTock | 154:90ea16ca7475 | 1657 | showButton(3,0,sTemp1,"",4,4); |
garygid | 54:6ce808d0995e | 1658 | sprintf(sTemp2," Eff"); |
TickTock | 50:83d5864c64a0 | 1659 | break; |
TickTock | 44:6262a9fd1e56 | 1660 | case monitorScreen: |
TickTock | 154:90ea16ca7475 | 1661 | showButton(3,0,sTemp1,"",4,4); |
garygid | 54:6ce808d0995e | 1662 | sprintf(sTemp2," Monitor"); |
TickTock | 42:4533b13b297d | 1663 | break; |
TickTock | 44:6262a9fd1e56 | 1664 | case changedScreen: |
TickTock | 154:90ea16ca7475 | 1665 | showButton(3,0,sTemp1,"",4,4); |
garygid | 54:6ce808d0995e | 1666 | sprintf(sTemp2,"DeltaMon"); |
TickTock | 42:4533b13b297d | 1667 | break; |
TickTock | 44:6262a9fd1e56 | 1668 | case cpScreen: |
TickTock | 154:90ea16ca7475 | 1669 | showButton(3,0,sTemp1,"",4,4); |
garygid | 67:2022fce701d0 | 1670 | sprintf(sTemp2,"CP Data"); |
TickTock | 42:4533b13b297d | 1671 | break; |
leafman | 98:9f8bab96edff | 1672 | case configScreen: |
garygid | 54:6ce808d0995e | 1673 | sprintf(sTemp2," Config"); |
leafman | 98:9f8bab96edff | 1674 | break; |
TickTock | 157:1a100a5ed06f | 1675 | case config2Screen: |
TickTock | 157:1a100a5ed06f | 1676 | sprintf(sTemp2,"Config2"); |
TickTock | 157:1a100a5ed06f | 1677 | break; |
TickTock | 44:6262a9fd1e56 | 1678 | case playbackScreen: |
TickTock | 154:90ea16ca7475 | 1679 | showButton(3,0,sTemp1,"",4,4); |
garygid | 54:6ce808d0995e | 1680 | sprintf(sTemp2,"Playback"); |
TickTock | 42:4533b13b297d | 1681 | break; |
TickTock | 44:6262a9fd1e56 | 1682 | case dateScreen: |
TickTock | 154:90ea16ca7475 | 1683 | showButton(3,0,sTemp1,"",4,4); |
garygid | 54:6ce808d0995e | 1684 | sprintf(sTemp2,"Set Time"); |
TickTock | 42:4533b13b297d | 1685 | break; |
TickTock | 44:6262a9fd1e56 | 1686 | case cpHistScreen: // gg - hist |
TickTock | 154:90ea16ca7475 | 1687 | showButton(3,0,sTemp1,"",4,4); |
garygid | 54:6ce808d0995e | 1688 | sprintf(sTemp2,"CP Hist"); |
TickTock | 44:6262a9fd1e56 | 1689 | break; |
TickTock | 48:d1ce92104a1f | 1690 | case cpBarScreen: // gg - cpbars |
TickTock | 154:90ea16ca7475 | 1691 | showButton(3,0,sTemp1,"",4,4); |
garygid | 54:6ce808d0995e | 1692 | sprintf(sTemp2,"CP Bars"); |
TickTock | 48:d1ce92104a1f | 1693 | break; |
TickTock | 107:e9be732c1ad4 | 1694 | case tripScreen: |
TickTock | 154:90ea16ca7475 | 1695 | showButton(3,0,sTemp1,"",4,4); |
TickTock | 107:e9be732c1ad4 | 1696 | sprintf(sTemp2," Trip"); |
TickTock | 107:e9be732c1ad4 | 1697 | break; |
TickTock | 118:02010b18efdc | 1698 | case healthScreen: |
TickTock | 154:90ea16ca7475 | 1699 | showButton(3,0,sTemp1,"",4,4); |
TickTock | 118:02010b18efdc | 1700 | sprintf(sTemp2,"Health"); |
TickTock | 118:02010b18efdc | 1701 | break; |
TickTock | 150:ef46ce63345c | 1702 | case testScreen: |
TickTock | 150:ef46ce63345c | 1703 | sprintf(sTemp2," Test"); |
TickTock | 150:ef46ce63345c | 1704 | break; |
garygid | 67:2022fce701d0 | 1705 | case indexScreen: // gg - index |
garygid | 67:2022fce701d0 | 1706 | sprintf(sTemp2," Index"); |
garygid | 67:2022fce701d0 | 1707 | break; |
TickTock | 178:bf6404312c45 | 1708 | case whpgScreen: // gg - index |
TickTock | 178:bf6404312c45 | 1709 | sprintf(sTemp2," WHPG"); |
TickTock | 178:bf6404312c45 | 1710 | break; |
TickTock | 180:5fdeeb86f3a3 | 1711 | case whScreen: // gg - index |
TickTock | 180:5fdeeb86f3a3 | 1712 | sprintf(sTemp2," WH"); |
TickTock | 180:5fdeeb86f3a3 | 1713 | break; |
TickTock | 42:4533b13b297d | 1714 | } |
garygid | 54:6ce808d0995e | 1715 | showButton(1,tNavRow," Select",sTemp2,4,4); |
garygid | 54:6ce808d0995e | 1716 | |
TickTock | 42:4533b13b297d | 1717 | wait_ms(100); // pause a moment to reduce flicker |
TickTock | 42:4533b13b297d | 1718 | break; |
garygid | 54:6ce808d0995e | 1719 | |
TickTock | 42:4533b13b297d | 1720 | case 2: // numpad |
TickTock | 151:3047ebb3c9a8 | 1721 | showButton(0,0," 1","",4,4); |
TickTock | 151:3047ebb3c9a8 | 1722 | showButton(1,0," 2","",4,4); |
TickTock | 151:3047ebb3c9a8 | 1723 | showButton(2,0," 3","",4,4); |
TickTock | 151:3047ebb3c9a8 | 1724 | showButton(0,1," 4","",4,4); |
TickTock | 151:3047ebb3c9a8 | 1725 | showButton(1,1," 5","",4,4); |
TickTock | 151:3047ebb3c9a8 | 1726 | showButton(2,1," 6","",4,4); |
TickTock | 151:3047ebb3c9a8 | 1727 | showButton(0,2," 7","",4,4); |
TickTock | 151:3047ebb3c9a8 | 1728 | showButton(1,2," 8","",4,4); |
TickTock | 151:3047ebb3c9a8 | 1729 | showButton(2,2," 9","",4,4); |
TickTock | 151:3047ebb3c9a8 | 1730 | showButton(1,3," 0","",4,4); |
garygid | 54:6ce808d0995e | 1731 | |
TickTock | 151:3047ebb3c9a8 | 1732 | showButton(0,3,"<--","",4,4); |
TickTock | 151:3047ebb3c9a8 | 1733 | showButton(2,3,"-->","",4,4); |
TickTock | 151:3047ebb3c9a8 | 1734 | showButton(3,3,"return","",4,4); |
TickTock | 42:4533b13b297d | 1735 | case 3: |
TickTock | 42:4533b13b297d | 1736 | break; |
TickTock | 42:4533b13b297d | 1737 | default: |
TickTock | 42:4533b13b297d | 1738 | break; |
TickTock | 42:4533b13b297d | 1739 | } |
TickTock | 36:dbd39c315258 | 1740 | } |
TickTock | 121:553faf139a20 | 1741 | tock=false; |
TickTock | 121:553faf139a20 | 1742 | } // updateDisplay |
TickTock | 36:dbd39c315258 | 1743 | |
garygid | 58:4d06288d75a2 | 1744 | //--------------------- |
garygid | 58:4d06288d75a2 | 1745 | // gg - highlight |
TickTock | 62:ffd15edb5431 | 1746 | void highlightButton(unsigned char column, unsigned char row, unsigned char tScn, unsigned char columns, unsigned char rows){ |
TickTock | 62:ffd15edb5431 | 1747 | |
garygid | 58:4d06288d75a2 | 1748 | unsigned short x1,x2,y1,y2; |
garygid | 58:4d06288d75a2 | 1749 | |
garygid | 58:4d06288d75a2 | 1750 | x1=column*(320/columns)+btnGap/2; |
garygid | 58:4d06288d75a2 | 1751 | x2=(column+1)*(320/columns)-btnGap/2; |
garygid | 58:4d06288d75a2 | 1752 | y1=row*(240/rows)+btnGap/2; |
garygid | 58:4d06288d75a2 | 1753 | y2=(row+1)*(240/rows)-btnGap/2; |
garygid | 65:821fc79cd7fe | 1754 | |
garygid | 65:821fc79cd7fe | 1755 | tt.set_display(tScn); |
garygid | 65:821fc79cd7fe | 1756 | |
garygid | 65:821fc79cd7fe | 1757 | if( skin == ggSkin ){ |
garygid | 65:821fc79cd7fe | 1758 | // paint the whole button box, for a better visual effect |
garygid | 65:821fc79cd7fe | 1759 | // especially on a screen with a yellow background |
garygid | 65:821fc79cd7fe | 1760 | if( tScn == 0 ) |
garygid | 65:821fc79cd7fe | 1761 | tt.fillrect(x1,y1,x2,y2,White); // DarkCyan); |
garygid | 65:821fc79cd7fe | 1762 | else |
garygid | 65:821fc79cd7fe | 1763 | tt.fillrect(x1,y1,x2,y2,Green); // DarkCyan); |
TickTock | 66:b7476ce7a59e | 1764 | } else { |
TickTock | 66:b7476ce7a59e | 1765 | tt.fillrect(x1,y1,x2,y2,Green); // DarkCyan); |
garygid | 65:821fc79cd7fe | 1766 | } |
garygid | 58:4d06288d75a2 | 1767 | |
garygid | 58:4d06288d75a2 | 1768 | // paint the outer pixel as a yellow frame |
garygid | 58:4d06288d75a2 | 1769 | tt.rect(x1,y1,x2,y2,Yellow) ; // DarkCyan); |
garygid | 58:4d06288d75a2 | 1770 | } |
garygid | 58:4d06288d75a2 | 1771 | |
garygid | 58:4d06288d75a2 | 1772 | //--------------------- |
TickTock | 36:dbd39c315258 | 1773 | void showButton(unsigned char column, unsigned char row, char * text1, char * text2, unsigned char columns, unsigned char rows){ |
TickTock | 36:dbd39c315258 | 1774 | unsigned short x1,x2,y1,y2; |
garygid | 54:6ce808d0995e | 1775 | |
TickTock | 36:dbd39c315258 | 1776 | x1=column*(320/columns)+btnGap/2; |
TickTock | 36:dbd39c315258 | 1777 | x2=(column+1)*(320/columns)-btnGap/2; |
TickTock | 36:dbd39c315258 | 1778 | y1=row*(240/rows)+btnGap/2; |
TickTock | 36:dbd39c315258 | 1779 | y2=(row+1)*(240/rows)-btnGap/2; |
TickTock | 36:dbd39c315258 | 1780 | tt.fillrect(x1,y1,x2,y2,DarkCyan); |
TickTock | 151:3047ebb3c9a8 | 1781 | |
TickTock | 151:3047ebb3c9a8 | 1782 | tt.foreground(Yellow); |
TickTock | 151:3047ebb3c9a8 | 1783 | tt.background(DarkCyan); |
TickTock | 151:3047ebb3c9a8 | 1784 | tt.set_font((unsigned char*) Arial12x12); |
garygid | 54:6ce808d0995e | 1785 | |
garygid | 54:6ce808d0995e | 1786 | // adapt formatting of text to the smaller 4x4 box |
garygid | 54:6ce808d0995e | 1787 | tt.locate(x1+btnGap/2,y1+btnGap); // gg - 4x4 |
TickTock | 36:dbd39c315258 | 1788 | printf("%s\n",text1); |
garygid | 54:6ce808d0995e | 1789 | |
garygid | 54:6ce808d0995e | 1790 | tt.locate(x1+btnGap/2,y1+btnGap+20); |
TickTock | 36:dbd39c315258 | 1791 | printf("%s\n",text2); |
TickTock | 36:dbd39c315258 | 1792 | } |
garygid | 54:6ce808d0995e | 1793 | |
TickTock | 13:62e0f7f39ff5 | 1794 | |
leafman | 98:9f8bab96edff | 1795 | //The temps are stored as metric, distances as imperial... I'm assuming the input based on that - LM |
TickTock | 148:6e3b9135fad2 | 1796 | float convertC(float input) |
leafman | 98:9f8bab96edff | 1797 | { |
leafman | 98:9f8bab96edff | 1798 | if (!metric) { |
TickTock | 150:ef46ce63345c | 1799 | //convert! |
leafman | 98:9f8bab96edff | 1800 | float output = input *1.8f; |
leafman | 98:9f8bab96edff | 1801 | output += 32.0f; |
leafman | 98:9f8bab96edff | 1802 | return output; |
TickTock | 23:cd03f9c3395e | 1803 | } |
leafman | 98:9f8bab96edff | 1804 | return input; |
leafman | 98:9f8bab96edff | 1805 | } |
TickTock | 148:6e3b9135fad2 | 1806 | |
TickTock | 148:6e3b9135fad2 | 1807 | float convertF(float input) |
TickTock | 148:6e3b9135fad2 | 1808 | { |
TickTock | 148:6e3b9135fad2 | 1809 | if (metric) { |
TickTock | 150:ef46ce63345c | 1810 | //convert! |
TickTock | 148:6e3b9135fad2 | 1811 | float output = input -32.0f; |
TickTock | 148:6e3b9135fad2 | 1812 | output /= 1.8f; |
TickTock | 148:6e3b9135fad2 | 1813 | return output; |
TickTock | 148:6e3b9135fad2 | 1814 | } |
TickTock | 148:6e3b9135fad2 | 1815 | return input; |
TickTock | 148:6e3b9135fad2 | 1816 | } |
leafman | 98:9f8bab96edff | 1817 | float convertDistance(float input) |
leafman | 98:9f8bab96edff | 1818 | { |
leafman | 98:9f8bab96edff | 1819 | if (metric) { |
leafman | 98:9f8bab96edff | 1820 | return input / 0.62137f; |
TickTock | 13:62e0f7f39ff5 | 1821 | } |
leafman | 98:9f8bab96edff | 1822 | return input; |
leafman | 98:9f8bab96edff | 1823 | } |
leafman | 98:9f8bab96edff | 1824 | char* distanceUnit() |
leafman | 98:9f8bab96edff | 1825 | { |
leafman | 98:9f8bab96edff | 1826 | if(metric) |
leafman | 98:9f8bab96edff | 1827 | return "km"; |
leafman | 98:9f8bab96edff | 1828 | return "mi"; |
leafman | 98:9f8bab96edff | 1829 | } |
leafman | 98:9f8bab96edff | 1830 | char* temperatureUnit() |
leafman | 98:9f8bab96edff | 1831 | { |
leafman | 98:9f8bab96edff | 1832 | if(metric) |
leafman | 98:9f8bab96edff | 1833 | return "C"; |
leafman | 98:9f8bab96edff | 1834 | return "F"; |
leafman | 98:9f8bab96edff | 1835 | } |