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 Tick Tock

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

/media/uploads/TickTock/canary_sch.jpg

/media/uploads/TickTock/canaryr6brd.jpg

For LCD Rev 1.01:

/media/uploads/TickTock/lcdsch.jpg

For VCD Rev 2.00:

/media/uploads/TickTock/lcdr2.jpg

Parts List

qtyinstancepart #packagesupplierDescription
1BAT3Vhttp://www.ebay.com/itm/10x-CR2032-SMD-Battery-Holder-for-CR2032-Battery-/180938057979?pt=LH_DefaultDomain_0&hash=item2a20bfa8fbLithium 2032 coin battery holder
4C1-C4ECST1DC106R6032Tantalium capacitor 10uF
3FC1-FC3ZF1-20-01-T-WThttp://www.samtec.com/cable-systems/idc-ffc/ffc/zero-insertion.aspx20 conductor 1mm pitch flex cable connector (optional)
1FJ-20-R-08.00-4http://www.samtec.com/cable-systems/idc-ffc/ffc/zero-insertion.aspx8\" 20 conductor 1mm pitch flex connector, end reversed (optional)
2H1-H4(DON'T populate H1-H4 headers - solder mbed directly)
1H5http://www.ebay.com/itm/221186042943?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l26491x12 .1\" pitch header (optional)
1H62x6 .1\" pitch header (optional)
2IC1,IC2VP230LMDSOP8http://www.ebay.com/itm/130488665247?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649canbus transciever
1IC3LM1117-5VSOT2235V regulator
5JP*2 pin .1\" jumper header
1mbedLPC1768http://www.ebay.com/itm/200830573509?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649mbed uC
2Q1,Q22N2222SOT23General purpose NPN transistor
1R1R393M120639K resistor
1R2R103M120610K resistor
4R4-R6R102M12061K resistor
1R3R500M120650 Ohm resistor
2TR1-TR5ZJYS81R5-2PL51TG01http://www.digikey.com/product-detail/en/ZJYS81R5-2PL51T-G01/445-2223-1-ND/765232CM Choke
1Z11N5340BGC1702-15http://www.ebay.com/itm/150878122425?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l26496V, 5W Zener Diode
1Z1DC-DC conveterhttp://www.ebay.com/itm/251142727849?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l264912V-7V, 3W DC-DC converter
1X1USBhttp://www.ebay.com/itm/New-Vertical-USB-2-0-A-pcb-connector-socket-USB-A-Type-/300553895292?pt=LH_DefaultDomain_0&hash=item45fa687d7cvertical USB connector
2LCD0,LCD1TFThttp://www.mikroe.com/add-on-boards/display/tft-proto/320x240 LCD with touch screen
1E0Enclosurehttp://www.shapeways.com/model/1077799/canary.html?li=user-profile&materialId=63d printed enclosure

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:

1LED+
2LED-
3RST
4SDI
5WR/SCLK
6CS
7X+
8X-
9Y+
10Y-
11VDD
12GND

If, instead, you have HW REV 2.0, you will need 13 conductors with the following order:

1LED+
2LED-
3RST
4SDI
5RS (SCLK)
6WR (DC)
7CS
8X+
9X-
10Y+
11Y-
12VDD
13GND

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:

/media/uploads/TickTock/lcdtop.jpg /media/uploads/TickTock/lcdbot.jpg

Examples of REV2.00:

/media/uploads/TickTock/rev2front.jpg /media/uploads/TickTock/rev2back.jpg

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.

/media/uploads/TickTock/pcbtop.jpg /media/uploads/TickTock/pcbbot.jpg

Once the PCB is populated, solder the LCDs to the PCB. CS0 connects to the right display and CS1 connects to the left. /media/uploads/TickTock/brddis.jpg

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. /media/uploads/TickTock/dcdcinst2.jpg

Once soldered in place, the DC-DC converter can easily be mounted to the back wall with double sided tape above the battery holder. /media/uploads/TickTock/dcdcinst3.jpg

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.

/media/uploads/TickTock/pcbdone.jpg /media/uploads/TickTock/functioning.jpg

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. /media/uploads/TickTock/enclosure.jpg

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. /media/uploads/TickTock/safety.jpg Installed: /media/uploads/TickTock/installed.jpg

Committer:
TickTock
Date:
Fri Feb 07 01:59:53 2014 +0000
Revision:
175:0357b4159b40
Parent:
174:cd27e80f197d
Child:
177:6fda79c2fda1
// Added to the temperature lookup table; // Fixed div0 boundary condition bug in CP histogram; // Splash trip meter on second screen when turned off if showHealth is enabled;

Who changed what in which revision?

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