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:
Sun Dec 29 12:38:00 2013 +0000
Revision:
172:53548bf8bf85
Parent:
171:355e284f5201
Child:
173:9815b1467039
// added wh/gid display to Health screen;

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 172:53548bf8bf85 425 printf("%4d gids (%0.0f)\n",gids,1000*(kWh_trip[0]+CCkWh_trip[0])/(startGids-gids));
TickTock 170:7ee98e3611bc 426 }else{
TickTock 170:7ee98e3611bc 427 printf("%4d 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 122:138a40892a4c 433 printf(" %4.1f%s \n",(float)SOC_x10/10,"% SOC");
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 170:7ee98e3611bc 438 printf(" %d%s,%3.1f%s \n",SOH_x2/2,"% SOH",(float)SOH2_x100/100," Hx");
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 120:041edeec08f5 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 148:6e3b9135fad2 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 120:041edeec08f5 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 120:041edeec08f5 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 iBinIndxMax = 300 ;
TickTock 44:6262a9fd1e56 879 int iBinValMax = max - min ; // zero to N
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 161:71ac85d11f03 912 tt.rect( xWinMin-1,yWinMin-1, xWinMax+1,yWinMax+1,Red);
TickTock 161:71ac85d11f03 913 tt.rect( xWinMin-2,yWinMin-2, xWinMax+2,yWinMax+2,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 161:71ac85d11f03 922 int nBarWidth = (xWinMax-xWinMin-2)/iBinValMax-1; //3
TickTock 161:71ac85d11f03 923 int nBarSpace = 1 ;
TickTock 44:6262a9fd1e56 924
TickTock 44:6262a9fd1e56 925 int xPos = (xWinMin + xWinMax) / 2 ;
TickTock 44:6262a9fd1e56 926 xPos -= (avg-min) * (nBarWidth + nBarSpace) ;
TickTock 161:71ac85d11f03 927
TickTock 44:6262a9fd1e56 928 for( int i=0; i<=iBinValMax; i++) {
TickTock 44:6262a9fd1e56 929 height = 4 * nBin[i] ;
TickTock 44:6262a9fd1e56 930 if( height > 100 ) height = 100 ; // clip tops
TickTock 44:6262a9fd1e56 931
TickTock 44:6262a9fd1e56 932 // if inside the window, draw the bar
TickTock 44:6262a9fd1e56 933 if( ( xPos + nBarWidth < xWinMax ) && ( xPos > xWinMin ) )
TickTock 44:6262a9fd1e56 934 tt.fillrect( xPos,yWinMax-height, xPos+nBarWidth-1,yWinMax, Green);
TickTock 44:6262a9fd1e56 935
TickTock 44:6262a9fd1e56 936 // step to the next bar position
TickTock 44:6262a9fd1e56 937 xPos += nBarWidth + nBarSpace ;
TickTock 44:6262a9fd1e56 938 }
TickTock 44:6262a9fd1e56 939
TickTock 44:6262a9fd1e56 940 showCP=false;
TickTock 44:6262a9fd1e56 941 }
TickTock 44:6262a9fd1e56 942
TickTock 44:6262a9fd1e56 943 // handle the button
TickTock 47:9cc7d876dd6d 944 if(sMode==1&&showButtons){
garygid 54:6ce808d0995e 945 showButton(1,0,"Request","CP Data",4,4);
TickTock 162:c6545fc0164a 946 }
TickTock 36:dbd39c315258 947 }
TickTock 36:dbd39c315258 948
TickTock 48:d1ce92104a1f 949 //---------------
leafman 98:9f8bab96edff 950 void config(bool force, bool showButtons){
TickTock 36:dbd39c315258 951 if (force) {
TickTock 36:dbd39c315258 952 tt.background(Black);
TickTock 36:dbd39c315258 953 tt.cls();
TickTock 36:dbd39c315258 954 }
garygid 65:821fc79cd7fe 955 //-------- top row --------
TickTock 161:71ac85d11f03 956 showButton(1,0," Reset","CANary",4,4);
TickTock 131:0d926c080a65 957 showButton(2,0," Save"," Config",4,4);
TickTock 158:059abeb44ba1 958
TickTock 48:d1ce92104a1f 959 //------- second row -----
TickTock 108:29b5a760adc2 960 if (logEn&&usbEn) {
garygid 54:6ce808d0995e 961 sprintf(sTemp1,"Disable");
TickTock 36:dbd39c315258 962 } else {
garygid 54:6ce808d0995e 963 sprintf(sTemp1,"Enable");
TickTock 36:dbd39c315258 964 }
garygid 54:6ce808d0995e 965 showButton(0,1,sTemp1,"Logging",4,4);
TickTock 48:d1ce92104a1f 966
TickTock 36:dbd39c315258 967 if (repeatPoll) {
garygid 54:6ce808d0995e 968 sprintf(sTemp1,"Disable");
TickTock 36:dbd39c315258 969 } else {
garygid 54:6ce808d0995e 970 sprintf(sTemp1,"Enable");
TickTock 36:dbd39c315258 971 }
garygid 54:6ce808d0995e 972 showButton(1,1,sTemp1,"Auto CP",4,4);
TickTock 48:d1ce92104a1f 973
TickTock 48:d1ce92104a1f 974 // add Enable/Disable Batt Log gg - yesBattLog
TickTock 48:d1ce92104a1f 975 if (yesBattLog) {
garygid 54:6ce808d0995e 976 sprintf(sTemp1,"Disable");
TickTock 48:d1ce92104a1f 977 } else {
garygid 54:6ce808d0995e 978 sprintf(sTemp1,"Enable");
TickTock 48:d1ce92104a1f 979 }
garygid 54:6ce808d0995e 980 showButton(2,1,sTemp1,"Batt Log",4,4);
TickTock 157:1a100a5ed06f 981
TickTock 158:059abeb44ba1 982 //------- third row -----
TickTock 157:1a100a5ed06f 983 if(brakeMon)
TickTock 157:1a100a5ed06f 984 showButton(0,2,"Disable","BrkMon",4,4);
TickTock 157:1a100a5ed06f 985 else
TickTock 157:1a100a5ed06f 986 showButton(0,2," Enable"," BrkMon",4,4);
TickTock 157:1a100a5ed06f 987
TickTock 157:1a100a5ed06f 988 if(regenMon)
TickTock 157:1a100a5ed06f 989 showButton(1,2,"Disable","RegMon",4,4);
TickTock 157:1a100a5ed06f 990 else
TickTock 157:1a100a5ed06f 991 showButton(1,2," Enable"," RegMon",4,4);
TickTock 159:577e9d015693 992
TickTock 159:577e9d015693 993 if(heaterMon)
TickTock 159:577e9d015693 994 showButton(2,2,"Disable","HeatMon",4,4);
TickTock 159:577e9d015693 995 else
TickTock 159:577e9d015693 996 showButton(2,2," Enable","HeatMon",4,4);
TickTock 159:577e9d015693 997
TickTock 157:1a100a5ed06f 998 }
TickTock 157:1a100a5ed06f 999
TickTock 157:1a100a5ed06f 1000 void config2(bool force, bool showButtons){
TickTock 157:1a100a5ed06f 1001 if (force) {
TickTock 157:1a100a5ed06f 1002 tt.background(Black);
TickTock 157:1a100a5ed06f 1003 tt.cls();
TickTock 157:1a100a5ed06f 1004 }
TickTock 157:1a100a5ed06f 1005 //-------- top row --------
TickTock 157:1a100a5ed06f 1006 showButton(0,0,"Calibrate"," Touch",4,4); // gg - 4x4
TickTock 161:71ac85d11f03 1007 showButton(1,0," Reset","Max/Min",4,4);
TickTock 169:84d790ac18a2 1008 if (showHealth) {
TickTock 169:84d790ac18a2 1009 sprintf(sTemp1," Hide");
TickTock 169:84d790ac18a2 1010 } else {
TickTock 169:84d790ac18a2 1011 sprintf(sTemp1," Show");
TickTock 169:84d790ac18a2 1012 }
TickTock 169:84d790ac18a2 1013 showButton(2,0,sTemp1," Health",4,4);
TickTock 169:84d790ac18a2 1014
TickTock 157:1a100a5ed06f 1015 // a button to step to the next skin
TickTock 157:1a100a5ed06f 1016 unsigned int nextSkin = skin + 1 ;
TickTock 157:1a100a5ed06f 1017 if( nextSkin > maxSkin ) nextSkin = 0 ;
TickTock 157:1a100a5ed06f 1018
TickTock 157:1a100a5ed06f 1019 if( nextSkin == ttSkin ) sprintf(sTemp1,"Skin TT");
TickTock 157:1a100a5ed06f 1020 else if( nextSkin == ggSkin ) sprintf(sTemp1,"Skin GG");
TickTock 157:1a100a5ed06f 1021 else sprintf(sTemp1,"Skin %d",nextSkin);
TickTock 157:1a100a5ed06f 1022
TickTock 157:1a100a5ed06f 1023 showButton(3,0," Use",sTemp1,4,4);
TickTock 157:1a100a5ed06f 1024
TickTock 157:1a100a5ed06f 1025 //------- second row -----
TickTock 157:1a100a5ed06f 1026 // add Enable/Disable Debug - debugMode
garygid 87:46ac3f2519d6 1027 if (debugMode) {
TickTock 131:0d926c080a65 1028 sprintf(sTemp1," Disable");
garygid 87:46ac3f2519d6 1029 } else {
TickTock 131:0d926c080a65 1030 sprintf(sTemp1," Enable");
garygid 87:46ac3f2519d6 1031 }
garygid 87:46ac3f2519d6 1032 showButton(3,1,sTemp1," Debug",4,4);
TickTock 157:1a100a5ed06f 1033
TickTock 158:059abeb44ba1 1034 //------- third row -----
TickTock 158:059abeb44ba1 1035 if (autoSync) {
TickTock 158:059abeb44ba1 1036 sprintf(sTemp1," Disable");
TickTock 158:059abeb44ba1 1037 } else {
TickTock 158:059abeb44ba1 1038 sprintf(sTemp1," Enable");
TickTock 158:059abeb44ba1 1039 }
TickTock 158:059abeb44ba1 1040 showButton(0,2,sTemp1," tSync",4,4);
TickTock 131:0d926c080a65 1041 showButton(1,2," Set"," Time",4,4);
TickTock 169:84d790ac18a2 1042 showButton(2,2," Update"," Config",4,4);
TickTock 169:84d790ac18a2 1043 showButton(3,2," Update","Firmware",4,4);
TickTock 36:dbd39c315258 1044 }
TickTock 36:dbd39c315258 1045
TickTock 42:4533b13b297d 1046 void pbScreen(bool force, bool showButtons){
TickTock 36:dbd39c315258 1047 if (force) {
TickTock 36:dbd39c315258 1048 tt.background(Black);
TickTock 36:dbd39c315258 1049 tt.cls();
TickTock 36:dbd39c315258 1050 }
TickTock 36:dbd39c315258 1051 if(playbackOpen){
garygid 54:6ce808d0995e 1052 showButton(0,0,"Slower"," <--",4,4);
garygid 54:6ce808d0995e 1053
TickTock 36:dbd39c315258 1054 if(playbackEn){
garygid 54:6ce808d0995e 1055 sprintf(sTemp1,"Pause");
TickTock 36:dbd39c315258 1056 }else{
garygid 54:6ce808d0995e 1057 sprintf(sTemp1," Run");
TickTock 36:dbd39c315258 1058 }
garygid 54:6ce808d0995e 1059 sprintf(sTemp2,"%4.3f ",playbackInt);
garygid 54:6ce808d0995e 1060 showButton(1,0,sTemp1,sTemp2,4,4);
garygid 54:6ce808d0995e 1061
garygid 54:6ce808d0995e 1062 showButton(2,0,"Faster"," -->",4,4);
TickTock 36:dbd39c315258 1063 }
TickTock 36:dbd39c315258 1064 if(playbackOpen){
TickTock 36:dbd39c315258 1065 sprintf(sTemp1," Stop");
TickTock 36:dbd39c315258 1066 }else{
garygid 54:6ce808d0995e 1067 sprintf(sTemp1,"Start");
TickTock 36:dbd39c315258 1068 }
garygid 54:6ce808d0995e 1069 showButton(1,1,sTemp1,"Playback",4,4);
TickTock 36:dbd39c315258 1070 }
TickTock 36:dbd39c315258 1071
TickTock 42:4533b13b297d 1072 void showDateTime(bool force, bool showButtons){
TickTock 152:a4d66901785d 1073 CANMessage msg;
TickTock 36:dbd39c315258 1074 struct tm t; // pointer to a static tm structure
TickTock 36:dbd39c315258 1075 time_t seconds ;
TickTock 36:dbd39c315258 1076 tt.foreground(Yellow);
TickTock 44:6262a9fd1e56 1077 tt.background(Black);
TickTock 152:a4d66901785d 1078 if (force||tock) {
TickTock 36:dbd39c315258 1079 tt.cls();
TickTock 36:dbd39c315258 1080 tt.locate(10,10);
TickTock 43:e7f6f80590e3 1081 tt.set_font((unsigned char*) Arial12x12);
TickTock 152:a4d66901785d 1082 if(accOn){
TickTock 152:a4d66901785d 1083 seconds = time(NULL);
TickTock 153:e94cfe3c339c 1084 t = *localtime(&seconds);
TickTock 153:e94cfe3c339c 1085
TickTock 153:e94cfe3c339c 1086 if(modelYear<2013){
TickTock 153:e94cfe3c339c 1087 msg = lastMsg[indexLastMsg[0x5fa]];
TickTock 153:e94cfe3c339c 1088 t.tm_mon = (msg.data[5]>>4)-1;
TickTock 153:e94cfe3c339c 1089 t.tm_mday = msg.data[2]>>3;
TickTock 153:e94cfe3c339c 1090 // Have not figured out where the year is on MY2011
TickTock 153:e94cfe3c339c 1091 msg = lastMsg[indexLastMsg[0x5fc]];
TickTock 153:e94cfe3c339c 1092 t.tm_hour = msg.data[0]>>3;
TickTock 153:e94cfe3c339c 1093 t.tm_min = (msg.data[1]<<4&0x30)+(msg.data[2]>>4);
TickTock 153:e94cfe3c339c 1094 t.tm_sec = msg.data[1]>>2;
TickTock 153:e94cfe3c339c 1095 }else{
TickTock 153:e94cfe3c339c 1096 // Have not figured out where Year, Month, or Day is for MY2013
TickTock 153:e94cfe3c339c 1097 msg = lastMsg[indexLastMsg[0x5f9]];
TickTock 153:e94cfe3c339c 1098 t.tm_hour = msg.data[5]>>3;
TickTock 153:e94cfe3c339c 1099 t.tm_min = msg.data[4];
TickTock 153:e94cfe3c339c 1100 msg = lastMsg[indexLastMsg[0x509]];
TickTock 153:e94cfe3c339c 1101 t.tm_sec = msg.data[2]>>2;
TickTock 153:e94cfe3c339c 1102 }
TickTock 153:e94cfe3c339c 1103
TickTock 152:a4d66901785d 1104 strftime(sTemp1, 32, "%a %m/%d/%Y %X \n", &t);
TickTock 152:a4d66901785d 1105 printf("Leaf: %s",sTemp1);
TickTock 152:a4d66901785d 1106 }
TickTock 152:a4d66901785d 1107 seconds = time(NULL);
TickTock 152:a4d66901785d 1108 t = *localtime(&seconds);
TickTock 36:dbd39c315258 1109 strftime(sTemp1, 32, "%a %m/%d/%Y %X \n", &t);
TickTock 152:a4d66901785d 1110 tt.locate(10,24);
TickTock 152:a4d66901785d 1111 printf("CANary: %s",sTemp1);
TickTock 122:138a40892a4c 1112 if(showButtons){
TickTock 36:dbd39c315258 1113 switch(dtMode){
TickTock 36:dbd39c315258 1114 case 0:
TickTock 36:dbd39c315258 1115 sprintf(sTemp1,"Year");
TickTock 36:dbd39c315258 1116 break;
TickTock 36:dbd39c315258 1117 case 1:
TickTock 36:dbd39c315258 1118 sprintf(sTemp1,"Month");
TickTock 36:dbd39c315258 1119 break;
TickTock 36:dbd39c315258 1120 case 2:
TickTock 36:dbd39c315258 1121 sprintf(sTemp1,"Day");
TickTock 36:dbd39c315258 1122 break;
TickTock 36:dbd39c315258 1123 case 3:
TickTock 36:dbd39c315258 1124 sprintf(sTemp1,"Hour");
TickTock 36:dbd39c315258 1125 break;
TickTock 36:dbd39c315258 1126 case 4:
TickTock 36:dbd39c315258 1127 sprintf(sTemp1,"Minute");
TickTock 36:dbd39c315258 1128 break;
TickTock 36:dbd39c315258 1129 case 5:
TickTock 36:dbd39c315258 1130 sprintf(sTemp1,"Second");
TickTock 36:dbd39c315258 1131 break;
TickTock 36:dbd39c315258 1132 default:
TickTock 36:dbd39c315258 1133 break;
TickTock 36:dbd39c315258 1134 }
TickTock 66:b7476ce7a59e 1135 showButton(0,1,sTemp1,"",4,4);
TickTock 152:a4d66901785d 1136 showButton(1,1," Up","",4,4);
TickTock 152:a4d66901785d 1137 showButton(2,1," Down","",4,4);
TickTock 152:a4d66901785d 1138 if(accOn){
TickTock 152:a4d66901785d 1139 showButton(3,1," Sync","w/ car",4,4);
TickTock 152:a4d66901785d 1140 }
TickTock 152:a4d66901785d 1141 if(autoSync){
TickTock 152:a4d66901785d 1142 showButton(3,2,"disable"," auto",4,4);
TickTock 152:a4d66901785d 1143 }else{
TickTock 152:a4d66901785d 1144 showButton(3,2,"enable"," auto",4,4);
TickTock 152:a4d66901785d 1145 }
TickTock 36:dbd39c315258 1146 }
TickTock 36:dbd39c315258 1147 }
TickTock 36:dbd39c315258 1148 }
TickTock 36:dbd39c315258 1149
TickTock 50:83d5864c64a0 1150 void dteDisplay(bool force, bool showButtons, bool showMiles){
TickTock 66:b7476ce7a59e 1151 unsigned short i,x,y,lx,ly,gids,radius,color,r,t;
TickTock 170:7ee98e3611bc 1152 unsigned char toVal,availableRegen=0;
TickTock 50:83d5864c64a0 1153 static unsigned short lgids=0;
TickTock 50:83d5864c64a0 1154 static unsigned char leff[39]={0};
TickTock 50:83d5864c64a0 1155 CANMessage msg;
TickTock 171:355e284f5201 1156 unsigned long targetBraking, regenBraking, motorSpeed, motorAmps, frictionBraking;
TickTock 170:7ee98e3611bc 1157 static unsigned char lr=0, lt=0, lar=0;
TickTock 50:83d5864c64a0 1158
TickTock 50:83d5864c64a0 1159 msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids
TickTock 50:83d5864c64a0 1160 gids = (msg.data[0]<<2)+(msg.data[1]>>6);
TickTock 50:83d5864c64a0 1161 if(gids==0){
TickTock 83:52b1f330a62d 1162 gids=281; // Display new, fully charged capacity until real data obtained
TickTock 50:83d5864c64a0 1163 }
TickTock 50:83d5864c64a0 1164
TickTock 37:fea2c1d52c5f 1165 tt.background(Navy);
TickTock 49:a3d2c5bb3cfa 1166 tt.foreground(Yellow);
TickTock 52:d5385fbf4ea1 1167 if(force){
TickTock 97:a25940fd7b5b 1168 tt.set_font((unsigned char*) Arial12x12);
TickTock 52:d5385fbf4ea1 1169 tt.cls();
TickTock 49:a3d2c5bb3cfa 1170 x=50+0*6;
TickTock 52:d5385fbf4ea1 1171 tt.locate(x-10,226);
TickTock 49:a3d2c5bb3cfa 1172 printf("sec\n");
TickTock 50:83d5864c64a0 1173 tt.line(x,10,x,220,DarkGrey);
TickTock 49:a3d2c5bb3cfa 1174 x=50+9*6;
TickTock 52:d5385fbf4ea1 1175 tt.locate(x-10,226);
TickTock 49:a3d2c5bb3cfa 1176 printf("min\n");
TickTock 50:83d5864c64a0 1177 tt.line(x,10,x,220,DarkGrey);
TickTock 49:a3d2c5bb3cfa 1178 x=50+18*6;
TickTock 52:d5385fbf4ea1 1179 tt.locate(x-10,226);
TickTock 49:a3d2c5bb3cfa 1180 printf("hour\n");
TickTock 83:52b1f330a62d 1181 tt.line(x,10,x,220,DarkGrey);
TickTock 49:a3d2c5bb3cfa 1182 x=50+25*6;
TickTock 52:d5385fbf4ea1 1183 tt.locate(x-10,226);
TickTock 49:a3d2c5bb3cfa 1184 printf("day\n");
TickTock 50:83d5864c64a0 1185 tt.line(x,10,x,220,DarkGrey);
TickTock 49:a3d2c5bb3cfa 1186 x=50+32*6;
TickTock 52:d5385fbf4ea1 1187 tt.locate(x-10,226);
TickTock 49:a3d2c5bb3cfa 1188 printf("mon\n");
TickTock 50:83d5864c64a0 1189 tt.line(x,10,x,220,DarkGrey);
TickTock 49:a3d2c5bb3cfa 1190 x=50+38*6;
TickTock 170:7ee98e3611bc 1191 lar=0;
TickTock 162:c6545fc0164a 1192 }
TickTock 162:c6545fc0164a 1193 toVal=33;
TickTock 83:52b1f330a62d 1194 if(force||lgids!=gids){ // update Y axis when kWh changes
TickTock 97:a25940fd7b5b 1195 tt.set_font((unsigned char*) Arial24x23);
TickTock 131:0d926c080a65 1196 for(i=2;i<7;i++){
TickTock 131:0d926c080a65 1197 y=200-(i-2)*40;
TickTock 97:a25940fd7b5b 1198 tt.locate(0,y-8);
TickTock 83:52b1f330a62d 1199 if (showMiles){
leafman 98:9f8bab96edff 1200 printf("%3.0f\n",convertDistance(i*((float)(gids-5)*.075))); // LM - Added metric support
TickTock 83:52b1f330a62d 1201 }else{
TickTock 83:52b1f330a62d 1202 printf("%d.0\n",i);
TickTock 50:83d5864c64a0 1203 }
TickTock 97:a25940fd7b5b 1204 tt.line(48,y,toVal*6+56,y,DarkGrey);
TickTock 83:52b1f330a62d 1205 }
TickTock 50:83d5864c64a0 1206 lgids=gids;
TickTock 50:83d5864c64a0 1207 }
TickTock 121:553faf139a20 1208 if(tock||force){
TickTock 131:0d926c080a65 1209 for(i=2;i<7;i++){
TickTock 131:0d926c080a65 1210 y=200-(i-2)*40;
TickTock 83:52b1f330a62d 1211 tt.line(40,y,158,y,DarkGrey);
TickTock 50:83d5864c64a0 1212 }
TickTock 50:83d5864c64a0 1213
TickTock 50:83d5864c64a0 1214 x=50+0*6;
TickTock 50:83d5864c64a0 1215 tt.line(x,10,x,220,DarkGrey);
TickTock 50:83d5864c64a0 1216 x=50+9*6;
TickTock 50:83d5864c64a0 1217 tt.line(x,10,x,220,DarkGrey);
TickTock 50:83d5864c64a0 1218 x=50+18*6;
TickTock 50:83d5864c64a0 1219 tt.line(x,10,x,220,DarkGrey);
TickTock 83:52b1f330a62d 1220 //x=50+25*6;
TickTock 83:52b1f330a62d 1221 //tt.line(x,60,x,220,DarkGrey);
TickTock 83:52b1f330a62d 1222 //x=50+32*6;
TickTock 83:52b1f330a62d 1223 //tt.line(x,60,x,220,DarkGrey);
TickTock 66:b7476ce7a59e 1224 //x=50+38*6;
TickTock 66:b7476ce7a59e 1225 //tt.line(x,60,x,220,DarkGrey);
TickTock 50:83d5864c64a0 1226 tt.set_font((unsigned char*) SCProSB31x55);
TickTock 164:46ed06263b0e 1227 tt.foreground(Yellow);
TickTock 50:83d5864c64a0 1228 if (showMiles){
TickTock 93:c2402e8cd0e2 1229 float miles = mpkWh[dtePeriod]*((float)(gids-5)*.075);
leafman 98:9f8bab96edff 1230 miles = convertDistance(miles); // LM - Metric support
TickTock 93:c2402e8cd0e2 1231 // Right justify
TickTock 94:c3a14b3975d6 1232 if (miles>99.9){ //space=18; num=31; . = 23
TickTock 163:3b6fab958773 1233 tt.locate(161,1);
TickTock 94:c3a14b3975d6 1234 printf("%4.1f\n",miles);
TickTock 93:c2402e8cd0e2 1235 } else if (miles>9.9){
TickTock 163:3b6fab958773 1236 tt.locate(156,1);
TickTock 94:c3a14b3975d6 1237 printf(" %3.1f\n",miles);
TickTock 93:c2402e8cd0e2 1238 } else {
TickTock 163:3b6fab958773 1239 tt.locate(151,1);
TickTock 94:c3a14b3975d6 1240 printf(" %2.1f\n",miles);
TickTock 93:c2402e8cd0e2 1241 }
TickTock 164:46ed06263b0e 1242 if(CCon) {
TickTock 169:84d790ac18a2 1243 tt.foreground(GreenYellow);
TickTock 164:46ed06263b0e 1244 tt.set_font((unsigned char*) Arial24x23);
TickTock 165:4daa921730dd 1245 miles = (mpkWh_noCC-mpkWh[dtePeriod])*((float)(gids-5)*.075);
TickTock 164:46ed06263b0e 1246 miles = convertDistance(miles); // LM - Metric support
TickTock 164:46ed06263b0e 1247 // Right justify
TickTock 165:4daa921730dd 1248 if (miles>9.9){
TickTock 165:4daa921730dd 1249 tt.locate(190,52);
TickTock 165:4daa921730dd 1250 printf(" +%3.1f \n",miles);
TickTock 165:4daa921730dd 1251 } else {
TickTock 164:46ed06263b0e 1252 tt.locate(182,52);
TickTock 165:4daa921730dd 1253 printf(" +%2.1f \n",miles);
TickTock 164:46ed06263b0e 1254 }
TickTock 162:c6545fc0164a 1255 }
TickTock 50:83d5864c64a0 1256 } else {
TickTock 163:3b6fab958773 1257 tt.locate(200,1);
TickTock 66:b7476ce7a59e 1258 printf("%3.1f \n",mpkWh[dtePeriod]);
TickTock 164:46ed06263b0e 1259 if(CCon) {
TickTock 169:84d790ac18a2 1260 tt.foreground(GreenYellow);
TickTock 164:46ed06263b0e 1261 tt.set_font((unsigned char*) Arial24x23);
TickTock 165:4daa921730dd 1262 tt.locate(190,52);
TickTock 165:4daa921730dd 1263 printf(" +%2.1f \n",(mpkWh_noCC-mpkWh[dtePeriod]));
TickTock 164:46ed06263b0e 1264 }
TickTock 50:83d5864c64a0 1265 }
TickTock 49:a3d2c5bb3cfa 1266 lx=50;
TickTock 97:a25940fd7b5b 1267 ly=mpkWh[0]*40;
TickTock 50:83d5864c64a0 1268 if(dtePeriod==0){
TickTock 52:d5385fbf4ea1 1269 radius=6;
TickTock 79:68f0dd8d1f19 1270 color=Yellow;
TickTock 50:83d5864c64a0 1271 }else{
TickTock 50:83d5864c64a0 1272 radius=2;
TickTock 50:83d5864c64a0 1273 color=Green;
TickTock 50:83d5864c64a0 1274 }
TickTock 131:0d926c080a65 1275 if(ly<60){
TickTock 97:a25940fd7b5b 1276 ly=220;
TickTock 97:a25940fd7b5b 1277 color=Red;
TickTock 131:0d926c080a65 1278 }else if(ly<280) {
TickTock 131:0d926c080a65 1279 ly=280-ly;
TickTock 97:a25940fd7b5b 1280 }else{
TickTock 97:a25940fd7b5b 1281 ly=0;
TickTock 97:a25940fd7b5b 1282 }
TickTock 50:83d5864c64a0 1283 tt.fillcircle(lx,leff[0],radius,Navy);
TickTock 50:83d5864c64a0 1284 tt.fillcircle(lx,ly,radius,color);
TickTock 49:a3d2c5bb3cfa 1285
TickTock 79:68f0dd8d1f19 1286 for(i=1;i<toVal;i++){
TickTock 49:a3d2c5bb3cfa 1287 x=50+i*6;
TickTock 97:a25940fd7b5b 1288 y=mpkWh[i]*40;
TickTock 50:83d5864c64a0 1289 if(i==dtePeriod){
TickTock 79:68f0dd8d1f19 1290 radius=6;
TickTock 79:68f0dd8d1f19 1291 color=Yellow;
TickTock 50:83d5864c64a0 1292 }else{
TickTock 50:83d5864c64a0 1293 radius=2;
TickTock 50:83d5864c64a0 1294 color=Green;
TickTock 50:83d5864c64a0 1295 }
TickTock 131:0d926c080a65 1296 if(y<60){
TickTock 97:a25940fd7b5b 1297 y=220;
TickTock 97:a25940fd7b5b 1298 color=Red;
TickTock 131:0d926c080a65 1299 }else if(y<280) {
TickTock 131:0d926c080a65 1300 y=280-y;
TickTock 97:a25940fd7b5b 1301 }else{
TickTock 97:a25940fd7b5b 1302 y=0;
TickTock 97:a25940fd7b5b 1303 }
TickTock 50:83d5864c64a0 1304 tt.fillcircle(x,leff[i],radius,Navy);
TickTock 50:83d5864c64a0 1305 tt.line(x-6,leff[i-1],x,leff[i],Navy);
TickTock 50:83d5864c64a0 1306 leff[i-1]=ly;
TickTock 52:d5385fbf4ea1 1307 if(y>0){
TickTock 52:d5385fbf4ea1 1308 tt.fillcircle(x,y,radius,color);
TickTock 52:d5385fbf4ea1 1309 }
TickTock 49:a3d2c5bb3cfa 1310 tt.line(lx,ly,x,y,White);
TickTock 49:a3d2c5bb3cfa 1311 lx=x;
TickTock 49:a3d2c5bb3cfa 1312 ly=y;
TickTock 49:a3d2c5bb3cfa 1313 }
TickTock 50:83d5864c64a0 1314 leff[i-1]=y;
TickTock 37:fea2c1d52c5f 1315 }
TickTock 66:b7476ce7a59e 1316
TickTock 171:355e284f5201 1317 // Plot Braking friction/regen bar graph
TickTock 171:355e284f5201 1318 msg = lastMsg[indexLastMsg[0x176]]; //Get RPMs
TickTock 171:355e284f5201 1319 motorSpeed = (msg.data[2]<<8)+msg.data[3];
TickTock 170:7ee98e3611bc 1320 msg = lastMsg[indexLastMsg[0x260]]; //Get available regen
TickTock 171:355e284f5201 1321 availableRegen = msg.data[1]*4;
TickTock 171:355e284f5201 1322 msg = lastMsg[indexLastMsg[0x1cb]]; //Get target total braking
TickTock 171:355e284f5201 1323 targetBraking = (msg.data[2]<<3)+(msg.data[3]>>5);
TickTock 171:355e284f5201 1324 msg = lastMsg[indexLastMsg[0x292]]; //Get friction braking
TickTock 171:355e284f5201 1325 frictionBraking = msg.data[6];
TickTock 171:355e284f5201 1326 msg = lastMsg[indexLastMsg[0x180]]; //Get motor amps
TickTock 171:355e284f5201 1327 motorAmps = (msg.data[2]<<4)+(msg.data[3]>>4);
TickTock 171:355e284f5201 1328 if(motorAmps>0x7ff){ // invert and chop positive current
TickTock 171:355e284f5201 1329 motorAmps=0x1000-motorAmps;
TickTock 171:355e284f5201 1330 }else{
TickTock 171:355e284f5201 1331 motorAmps=0;
TickTock 171:355e284f5201 1332 }
TickTock 170:7ee98e3611bc 1333
TickTock 171:355e284f5201 1334 targetBraking *= motorSpeed;
TickTock 171:355e284f5201 1335 targetBraking /= tbScalar; //0.0000345 * 4
TickTock 171:355e284f5201 1336 regenBraking = motorAmps;
TickTock 171:355e284f5201 1337 regenBraking *= motorSpeed;
TickTock 171:355e284f5201 1338 regenBraking /= rbScalar; //0.00002875 * 4
TickTock 171:355e284f5201 1339 frictionBraking *= motorSpeed;
TickTock 171:355e284f5201 1340 frictionBraking /= fbScalar; //0.0019 * 4
TickTock 171:355e284f5201 1341
TickTock 171:355e284f5201 1342 // Plot available regen brackets
TickTock 170:7ee98e3611bc 1343 if(availableRegen>lar){
TickTock 171:355e284f5201 1344 tt.fillrect(273,238-availableRegen,275,239-lar,White);
TickTock 171:355e284f5201 1345 tt.fillrect(317,238-availableRegen,319,239-lar,White);
TickTock 171:355e284f5201 1346 if(availableRegen>=24){
TickTock 171:355e284f5201 1347 for(i=24;i<=availableRegen;i+=24){
TickTock 171:355e284f5201 1348 tt.fillrect(270,238-i,272,239-i,White);
TickTock 171:355e284f5201 1349 }
TickTock 171:355e284f5201 1350 }
TickTock 170:7ee98e3611bc 1351 lar=availableRegen;
TickTock 170:7ee98e3611bc 1352 }else if(availableRegen<lar){
TickTock 171:355e284f5201 1353 tt.fillrect(270,238-lar,275,239-availableRegen,Navy);
TickTock 171:355e284f5201 1354 tt.fillrect(317,238-lar,319,239-availableRegen,Navy);
TickTock 170:7ee98e3611bc 1355 lar=availableRegen;
TickTock 170:7ee98e3611bc 1356 }
TickTock 170:7ee98e3611bc 1357
TickTock 171:355e284f5201 1358 t = (unsigned char) regenBraking+frictionBraking;
TickTock 171:355e284f5201 1359 if (t>160) t=160;
TickTock 171:355e284f5201 1360 r = (unsigned char) regenBraking;
TickTock 171:355e284f5201 1361 if (r>160) r=160;
TickTock 171:355e284f5201 1362 if (r>t) t=r; //Should never happen
TickTock 171:355e284f5201 1363 if(lr!=r||lt!=t){
TickTock 171:355e284f5201 1364 if (t<160) tt.fillrect(277,239-160,315,238-t,Navy);
TickTock 171:355e284f5201 1365 if (r<t) tt.fillrect(277,239-t,315,238-r,Red);
TickTock 171:355e284f5201 1366 if (0<r) tt.fillrect(277,239-r,315,238,Green);
TickTock 108:29b5a760adc2 1367 }
TickTock 171:355e284f5201 1368 lt=t;
TickTock 171:355e284f5201 1369 lr=r;
TickTock 37:fea2c1d52c5f 1370 }
TickTock 37:fea2c1d52c5f 1371
TickTock 150:ef46ce63345c 1372 void testDisplay (bool force, bool showButtons){
TickTock 158:059abeb44ba1 1373 static unsigned short maxPS=0, oldData[8]={0};
TickTock 158:059abeb44ba1 1374 unsigned char i, uData[8];//, year, month, day, hour, minute, second;
TickTock 148:6e3b9135fad2 1375 CANMessage msg;
TickTock 148:6e3b9135fad2 1376
TickTock 148:6e3b9135fad2 1377 tt.set_font((unsigned char*) Arial24x23);
TickTock 148:6e3b9135fad2 1378 tt.foreground(Yellow);
TickTock 148:6e3b9135fad2 1379 tt.background(Navy);
TickTock 148:6e3b9135fad2 1380 if(force){
TickTock 148:6e3b9135fad2 1381 tt.cls();
TickTock 148:6e3b9135fad2 1382 }
TickTock 158:059abeb44ba1 1383 if(logEn){
TickTock 158:059abeb44ba1 1384 if(pointerSep>maxPS){maxPS=pointerSep;}
TickTock 158:059abeb44ba1 1385 tt.locate(10,10);
TickTock 170:7ee98e3611bc 1386 printf("%3d sep %3d max\n",pointerSep,maxPS);
TickTock 170:7ee98e3611bc 1387 }else{
TickTock 170:7ee98e3611bc 1388 tt.locate(10,10);
TickTock 170:7ee98e3611bc 1389 printf("%d maxT\n",maxTarget);
TickTock 158:059abeb44ba1 1390 }
TickTock 158:059abeb44ba1 1391
TickTock 152:a4d66901785d 1392 for (i=0; i<8; i++){
TickTock 152:a4d66901785d 1393 msg = lastMsg[indexLastMsg[(uMsgId[i]>>4)]];
TickTock 152:a4d66901785d 1394 uData[i] = msg.data[(uMsgId[i]&0x000f)];
TickTock 158:059abeb44ba1 1395 if(i%2==0){
TickTock 158:059abeb44ba1 1396 tt.locate(10,90+(i/2)*30);
TickTock 158:059abeb44ba1 1397 }else{
TickTock 158:059abeb44ba1 1398 tt.locate(170,90+(i/2)*30);
TickTock 158:059abeb44ba1 1399 }
TickTock 158:059abeb44ba1 1400 if(clearTest){
TickTock 169:84d790ac18a2 1401 maxPS=0;
TickTock 158:059abeb44ba1 1402 oldData[i]=uData[i];
TickTock 158:059abeb44ba1 1403 tt.foreground(Yellow);
TickTock 158:059abeb44ba1 1404 tt.background(Navy);
TickTock 158:059abeb44ba1 1405 printf("%4x:%2x\n",uMsgId[i],uData[i]);
TickTock 158:059abeb44ba1 1406 }else if(uData[i]!=oldData[i]){
TickTock 158:059abeb44ba1 1407 tt.foreground(Navy);
TickTock 158:059abeb44ba1 1408 tt.background(Yellow);
TickTock 158:059abeb44ba1 1409 printf("%4x:%2x\n",uMsgId[i],uData[i]);
TickTock 159:577e9d015693 1410 oldData[i]=uData[i];
TickTock 158:059abeb44ba1 1411 }else if(force){
TickTock 158:059abeb44ba1 1412 tt.foreground(Yellow);
TickTock 158:059abeb44ba1 1413 tt.background(Navy);
TickTock 158:059abeb44ba1 1414 printf("%4x:%2x\n",uMsgId[i],uData[i]);
TickTock 158:059abeb44ba1 1415 }
TickTock 152:a4d66901785d 1416 }
TickTock 158:059abeb44ba1 1417 clearTest=false;
TickTock 158:059abeb44ba1 1418 showButton(3,0,"Reset","flags",4,4);
TickTock 148:6e3b9135fad2 1419 }
TickTock 148:6e3b9135fad2 1420
TickTock 36:dbd39c315258 1421 void updateDisplay(char display){
TickTock 122:138a40892a4c 1422 bool changed,showButtons;
TickTock 164:46ed06263b0e 1423 changed = (dMode[display]!=lastDMode[display]);
TickTock 122:138a40892a4c 1424 showButtons = (display==whichTouched)&&(sMode==1);
TickTock 36:dbd39c315258 1425 tt.set_display(display);
TickTock 36:dbd39c315258 1426 switch (dMode[display]) {
TickTock 36:dbd39c315258 1427 case logScreen:
TickTock 122:138a40892a4c 1428 printLog(changed,showButtons);
TickTock 36:dbd39c315258 1429 break;
TickTock 41:8d4609ea7259 1430 case mainScreen:
TickTock 122:138a40892a4c 1431 mainDisplay(changed,showButtons);
TickTock 36:dbd39c315258 1432 break;
TickTock 36:dbd39c315258 1433 case brakeScreen:
TickTock 122:138a40892a4c 1434 braking(changed,showButtons);
TickTock 36:dbd39c315258 1435 break;
TickTock 41:8d4609ea7259 1436 case dteScreen:
TickTock 122:138a40892a4c 1437 dteDisplay(changed,showButtons,true);
TickTock 37:fea2c1d52c5f 1438 break;
TickTock 50:83d5864c64a0 1439 case effScreen:
TickTock 122:138a40892a4c 1440 dteDisplay(changed,showButtons,false);
TickTock 50:83d5864c64a0 1441 break;
TickTock 50:83d5864c64a0 1442 case monitorScreen:
TickTock 122:138a40892a4c 1443 printLast(changed,showButtons);
TickTock 36:dbd39c315258 1444 break;
TickTock 36:dbd39c315258 1445 case changedScreen:
TickTock 122:138a40892a4c 1446 printChanged(changed,showButtons);
TickTock 36:dbd39c315258 1447 break;
TickTock 36:dbd39c315258 1448 case cpScreen:
TickTock 122:138a40892a4c 1449 cpData(changed||showCP,showButtons);
TickTock 36:dbd39c315258 1450 break;
leafman 98:9f8bab96edff 1451 case configScreen:
TickTock 122:138a40892a4c 1452 config(changed,showButtons);
TickTock 36:dbd39c315258 1453 break;
TickTock 157:1a100a5ed06f 1454 case config2Screen:
TickTock 157:1a100a5ed06f 1455 config2(changed,showButtons);
TickTock 157:1a100a5ed06f 1456 break;
TickTock 38:155ec32c5e91 1457 case playbackScreen:
TickTock 122:138a40892a4c 1458 pbScreen(changed,showButtons);
TickTock 36:dbd39c315258 1459 break;
TickTock 36:dbd39c315258 1460 case dateScreen:
TickTock 122:138a40892a4c 1461 showDateTime(changed,showButtons);
TickTock 36:dbd39c315258 1462 break;
TickTock 44:6262a9fd1e56 1463 case cpHistScreen: // gg - hist
TickTock 122:138a40892a4c 1464 cpHistogram(changed||showCP,showButtons);
TickTock 44:6262a9fd1e56 1465 break;
TickTock 48:d1ce92104a1f 1466 case cpBarScreen: // gg - cpbars
TickTock 122:138a40892a4c 1467 cpBarPlot(changed||showCP,showButtons);
TickTock 48:d1ce92104a1f 1468 break;
garygid 67:2022fce701d0 1469 case indexScreen:
TickTock 122:138a40892a4c 1470 showIndex(changed,showButtons);
garygid 67:2022fce701d0 1471 break;
TickTock 107:e9be732c1ad4 1472 case tripScreen:
TickTock 168:9227024c4e3a 1473 tripDisplay(changed,showButtons,false);
TickTock 168:9227024c4e3a 1474 break;
TickTock 168:9227024c4e3a 1475 case ccTripScreen:
TickTock 168:9227024c4e3a 1476 tripDisplay(changed,showButtons,true);
TickTock 107:e9be732c1ad4 1477 break;
TickTock 118:02010b18efdc 1478 case healthScreen:
TickTock 122:138a40892a4c 1479 healthDisplay(changed,showButtons);
garygid 67:2022fce701d0 1480 break;
TickTock 150:ef46ce63345c 1481 case testScreen:
TickTock 150:ef46ce63345c 1482 testDisplay(changed,showButtons);
TickTock 148:6e3b9135fad2 1483 break;
TickTock 36:dbd39c315258 1484 default:
TickTock 43:e7f6f80590e3 1485 if (changed){
TickTock 43:e7f6f80590e3 1486 tt.background(Black);
TickTock 43:e7f6f80590e3 1487 tt.cls();
TickTock 43:e7f6f80590e3 1488 }
TickTock 36:dbd39c315258 1489 break;
TickTock 36:dbd39c315258 1490 }
TickTock 36:dbd39c315258 1491 lastDMode[display]=dMode[display];
TickTock 36:dbd39c315258 1492
TickTock 42:4533b13b297d 1493 if(display==whichTouched){
TickTock 42:4533b13b297d 1494 switch (sMode) {
TickTock 42:4533b13b297d 1495 case 1: // Select screens
garygid 54:6ce808d0995e 1496 showButton(0,tNavRow," <-Prev","",4,4); // gg - 4x4
garygid 67:2022fce701d0 1497 // col 1 see below
garygid 67:2022fce701d0 1498 showButton(2,tNavRow," Go To"," Index",4,4); // gg - index
garygid 54:6ce808d0995e 1499 showButton(3,tNavRow," Next->","",4,4); // gg - move next
TickTock 154:90ea16ca7475 1500 if (enableSound) {
TickTock 154:90ea16ca7475 1501 sprintf(sTemp1," Mute");
TickTock 154:90ea16ca7475 1502 } else {
TickTock 154:90ea16ca7475 1503 sprintf(sTemp1,"Un-Mute");
TickTock 154:90ea16ca7475 1504 }
garygid 67:2022fce701d0 1505 // col 1 in Nav row
TickTock 42:4533b13b297d 1506 switch (dMode[display]) {
TickTock 44:6262a9fd1e56 1507 case offScreen:
TickTock 154:90ea16ca7475 1508 showButton(3,0,sTemp1,"",4,4);
garygid 54:6ce808d0995e 1509 sprintf(sTemp2," Off");
TickTock 42:4533b13b297d 1510 break;
TickTock 44:6262a9fd1e56 1511 case logScreen:
TickTock 154:90ea16ca7475 1512 showButton(3,0,sTemp1,"",4,4);
garygid 54:6ce808d0995e 1513 sprintf(sTemp2," Log");
TickTock 42:4533b13b297d 1514 break;
TickTock 44:6262a9fd1e56 1515 case mainScreen:
TickTock 154:90ea16ca7475 1516 showButton(3,0,sTemp1,"",4,4);
garygid 54:6ce808d0995e 1517 sprintf(sTemp2," Main");
TickTock 42:4533b13b297d 1518 break;
TickTock 44:6262a9fd1e56 1519 case brakeScreen:
TickTock 154:90ea16ca7475 1520 showButton(3,0,sTemp1,"",4,4);
garygid 54:6ce808d0995e 1521 sprintf(sTemp2,"Braking");
TickTock 42:4533b13b297d 1522 break;
TickTock 44:6262a9fd1e56 1523 case dteScreen:
TickTock 154:90ea16ca7475 1524 showButton(3,0,sTemp1,"",4,4);
garygid 54:6ce808d0995e 1525 sprintf(sTemp2," DTE");
TickTock 42:4533b13b297d 1526 break;
TickTock 50:83d5864c64a0 1527 case effScreen:
TickTock 154:90ea16ca7475 1528 showButton(3,0,sTemp1,"",4,4);
garygid 54:6ce808d0995e 1529 sprintf(sTemp2," Eff");
TickTock 50:83d5864c64a0 1530 break;
TickTock 44:6262a9fd1e56 1531 case monitorScreen:
TickTock 154:90ea16ca7475 1532 showButton(3,0,sTemp1,"",4,4);
garygid 54:6ce808d0995e 1533 sprintf(sTemp2," Monitor");
TickTock 42:4533b13b297d 1534 break;
TickTock 44:6262a9fd1e56 1535 case changedScreen:
TickTock 154:90ea16ca7475 1536 showButton(3,0,sTemp1,"",4,4);
garygid 54:6ce808d0995e 1537 sprintf(sTemp2,"DeltaMon");
TickTock 42:4533b13b297d 1538 break;
TickTock 44:6262a9fd1e56 1539 case cpScreen:
TickTock 154:90ea16ca7475 1540 showButton(3,0,sTemp1,"",4,4);
garygid 67:2022fce701d0 1541 sprintf(sTemp2,"CP Data");
TickTock 42:4533b13b297d 1542 break;
leafman 98:9f8bab96edff 1543 case configScreen:
garygid 54:6ce808d0995e 1544 sprintf(sTemp2," Config");
leafman 98:9f8bab96edff 1545 break;
TickTock 157:1a100a5ed06f 1546 case config2Screen:
TickTock 157:1a100a5ed06f 1547 sprintf(sTemp2,"Config2");
TickTock 157:1a100a5ed06f 1548 break;
TickTock 44:6262a9fd1e56 1549 case playbackScreen:
TickTock 154:90ea16ca7475 1550 showButton(3,0,sTemp1,"",4,4);
garygid 54:6ce808d0995e 1551 sprintf(sTemp2,"Playback");
TickTock 42:4533b13b297d 1552 break;
TickTock 44:6262a9fd1e56 1553 case dateScreen:
TickTock 154:90ea16ca7475 1554 showButton(3,0,sTemp1,"",4,4);
garygid 54:6ce808d0995e 1555 sprintf(sTemp2,"Set Time");
TickTock 42:4533b13b297d 1556 break;
TickTock 44:6262a9fd1e56 1557 case cpHistScreen: // gg - hist
TickTock 154:90ea16ca7475 1558 showButton(3,0,sTemp1,"",4,4);
garygid 54:6ce808d0995e 1559 sprintf(sTemp2,"CP Hist");
TickTock 44:6262a9fd1e56 1560 break;
TickTock 48:d1ce92104a1f 1561 case cpBarScreen: // gg - cpbars
TickTock 154:90ea16ca7475 1562 showButton(3,0,sTemp1,"",4,4);
garygid 54:6ce808d0995e 1563 sprintf(sTemp2,"CP Bars");
TickTock 48:d1ce92104a1f 1564 break;
TickTock 107:e9be732c1ad4 1565 case tripScreen:
TickTock 154:90ea16ca7475 1566 showButton(3,0,sTemp1,"",4,4);
TickTock 107:e9be732c1ad4 1567 sprintf(sTemp2," Trip");
TickTock 107:e9be732c1ad4 1568 break;
TickTock 118:02010b18efdc 1569 case healthScreen:
TickTock 154:90ea16ca7475 1570 showButton(3,0,sTemp1,"",4,4);
TickTock 118:02010b18efdc 1571 sprintf(sTemp2,"Health");
TickTock 118:02010b18efdc 1572 break;
TickTock 150:ef46ce63345c 1573 case testScreen:
TickTock 150:ef46ce63345c 1574 sprintf(sTemp2," Test");
TickTock 150:ef46ce63345c 1575 break;
garygid 67:2022fce701d0 1576 case indexScreen: // gg - index
garygid 67:2022fce701d0 1577 sprintf(sTemp2," Index");
garygid 67:2022fce701d0 1578 break;
TickTock 42:4533b13b297d 1579 }
garygid 54:6ce808d0995e 1580 showButton(1,tNavRow," Select",sTemp2,4,4);
garygid 54:6ce808d0995e 1581
TickTock 42:4533b13b297d 1582 wait_ms(100); // pause a moment to reduce flicker
TickTock 42:4533b13b297d 1583 break;
garygid 54:6ce808d0995e 1584
TickTock 42:4533b13b297d 1585 case 2: // numpad
TickTock 151:3047ebb3c9a8 1586 showButton(0,0," 1","",4,4);
TickTock 151:3047ebb3c9a8 1587 showButton(1,0," 2","",4,4);
TickTock 151:3047ebb3c9a8 1588 showButton(2,0," 3","",4,4);
TickTock 151:3047ebb3c9a8 1589 showButton(0,1," 4","",4,4);
TickTock 151:3047ebb3c9a8 1590 showButton(1,1," 5","",4,4);
TickTock 151:3047ebb3c9a8 1591 showButton(2,1," 6","",4,4);
TickTock 151:3047ebb3c9a8 1592 showButton(0,2," 7","",4,4);
TickTock 151:3047ebb3c9a8 1593 showButton(1,2," 8","",4,4);
TickTock 151:3047ebb3c9a8 1594 showButton(2,2," 9","",4,4);
TickTock 151:3047ebb3c9a8 1595 showButton(1,3," 0","",4,4);
garygid 54:6ce808d0995e 1596
TickTock 151:3047ebb3c9a8 1597 showButton(0,3,"<--","",4,4);
TickTock 151:3047ebb3c9a8 1598 showButton(2,3,"-->","",4,4);
TickTock 151:3047ebb3c9a8 1599 showButton(3,3,"return","",4,4);
TickTock 42:4533b13b297d 1600 case 3:
TickTock 42:4533b13b297d 1601 break;
TickTock 42:4533b13b297d 1602 default:
TickTock 42:4533b13b297d 1603 break;
TickTock 42:4533b13b297d 1604 }
TickTock 36:dbd39c315258 1605 }
TickTock 121:553faf139a20 1606 tock=false;
TickTock 121:553faf139a20 1607 } // updateDisplay
TickTock 36:dbd39c315258 1608
garygid 58:4d06288d75a2 1609 //---------------------
garygid 58:4d06288d75a2 1610 // gg - highlight
TickTock 62:ffd15edb5431 1611 void highlightButton(unsigned char column, unsigned char row, unsigned char tScn, unsigned char columns, unsigned char rows){
TickTock 62:ffd15edb5431 1612
garygid 58:4d06288d75a2 1613 unsigned short x1,x2,y1,y2;
garygid 58:4d06288d75a2 1614
garygid 58:4d06288d75a2 1615 x1=column*(320/columns)+btnGap/2;
garygid 58:4d06288d75a2 1616 x2=(column+1)*(320/columns)-btnGap/2;
garygid 58:4d06288d75a2 1617 y1=row*(240/rows)+btnGap/2;
garygid 58:4d06288d75a2 1618 y2=(row+1)*(240/rows)-btnGap/2;
garygid 65:821fc79cd7fe 1619
garygid 65:821fc79cd7fe 1620 tt.set_display(tScn);
garygid 65:821fc79cd7fe 1621
garygid 65:821fc79cd7fe 1622 if( skin == ggSkin ){
garygid 65:821fc79cd7fe 1623 // paint the whole button box, for a better visual effect
garygid 65:821fc79cd7fe 1624 // especially on a screen with a yellow background
garygid 65:821fc79cd7fe 1625 if( tScn == 0 )
garygid 65:821fc79cd7fe 1626 tt.fillrect(x1,y1,x2,y2,White); // DarkCyan);
garygid 65:821fc79cd7fe 1627 else
garygid 65:821fc79cd7fe 1628 tt.fillrect(x1,y1,x2,y2,Green); // DarkCyan);
TickTock 66:b7476ce7a59e 1629 } else {
TickTock 66:b7476ce7a59e 1630 tt.fillrect(x1,y1,x2,y2,Green); // DarkCyan);
garygid 65:821fc79cd7fe 1631 }
garygid 58:4d06288d75a2 1632
garygid 58:4d06288d75a2 1633 // paint the outer pixel as a yellow frame
garygid 58:4d06288d75a2 1634 tt.rect(x1,y1,x2,y2,Yellow) ; // DarkCyan);
garygid 58:4d06288d75a2 1635 }
garygid 58:4d06288d75a2 1636
garygid 58:4d06288d75a2 1637 //---------------------
TickTock 36:dbd39c315258 1638 void showButton(unsigned char column, unsigned char row, char * text1, char * text2, unsigned char columns, unsigned char rows){
TickTock 36:dbd39c315258 1639 unsigned short x1,x2,y1,y2;
garygid 54:6ce808d0995e 1640
TickTock 36:dbd39c315258 1641 x1=column*(320/columns)+btnGap/2;
TickTock 36:dbd39c315258 1642 x2=(column+1)*(320/columns)-btnGap/2;
TickTock 36:dbd39c315258 1643 y1=row*(240/rows)+btnGap/2;
TickTock 36:dbd39c315258 1644 y2=(row+1)*(240/rows)-btnGap/2;
TickTock 36:dbd39c315258 1645 tt.fillrect(x1,y1,x2,y2,DarkCyan);
TickTock 151:3047ebb3c9a8 1646
TickTock 151:3047ebb3c9a8 1647 tt.foreground(Yellow);
TickTock 151:3047ebb3c9a8 1648 tt.background(DarkCyan);
TickTock 151:3047ebb3c9a8 1649 tt.set_font((unsigned char*) Arial12x12);
garygid 54:6ce808d0995e 1650
garygid 54:6ce808d0995e 1651 // adapt formatting of text to the smaller 4x4 box
garygid 54:6ce808d0995e 1652 tt.locate(x1+btnGap/2,y1+btnGap); // gg - 4x4
TickTock 36:dbd39c315258 1653 printf("%s\n",text1);
garygid 54:6ce808d0995e 1654
garygid 54:6ce808d0995e 1655 tt.locate(x1+btnGap/2,y1+btnGap+20);
TickTock 36:dbd39c315258 1656 printf("%s\n",text2);
TickTock 36:dbd39c315258 1657 }
garygid 54:6ce808d0995e 1658
TickTock 13:62e0f7f39ff5 1659
leafman 98:9f8bab96edff 1660 //The temps are stored as metric, distances as imperial... I'm assuming the input based on that - LM
TickTock 148:6e3b9135fad2 1661 float convertC(float input)
leafman 98:9f8bab96edff 1662 {
leafman 98:9f8bab96edff 1663 if (!metric) {
TickTock 150:ef46ce63345c 1664 //convert!
leafman 98:9f8bab96edff 1665 float output = input *1.8f;
leafman 98:9f8bab96edff 1666 output += 32.0f;
leafman 98:9f8bab96edff 1667 return output;
TickTock 23:cd03f9c3395e 1668 }
leafman 98:9f8bab96edff 1669 return input;
leafman 98:9f8bab96edff 1670 }
TickTock 148:6e3b9135fad2 1671
TickTock 148:6e3b9135fad2 1672 float convertF(float input)
TickTock 148:6e3b9135fad2 1673 {
TickTock 148:6e3b9135fad2 1674 if (metric) {
TickTock 150:ef46ce63345c 1675 //convert!
TickTock 148:6e3b9135fad2 1676 float output = input -32.0f;
TickTock 148:6e3b9135fad2 1677 output /= 1.8f;
TickTock 148:6e3b9135fad2 1678 return output;
TickTock 148:6e3b9135fad2 1679 }
TickTock 148:6e3b9135fad2 1680 return input;
TickTock 148:6e3b9135fad2 1681 }
leafman 98:9f8bab96edff 1682 float convertDistance(float input)
leafman 98:9f8bab96edff 1683 {
leafman 98:9f8bab96edff 1684 if (metric) {
leafman 98:9f8bab96edff 1685 return input / 0.62137f;
TickTock 13:62e0f7f39ff5 1686 }
leafman 98:9f8bab96edff 1687 return input;
leafman 98:9f8bab96edff 1688 }
leafman 98:9f8bab96edff 1689 char* distanceUnit()
leafman 98:9f8bab96edff 1690 {
leafman 98:9f8bab96edff 1691 if(metric)
leafman 98:9f8bab96edff 1692 return "km";
leafman 98:9f8bab96edff 1693 return "mi";
leafman 98:9f8bab96edff 1694 }
leafman 98:9f8bab96edff 1695 char* temperatureUnit()
leafman 98:9f8bab96edff 1696 {
leafman 98:9f8bab96edff 1697 if(metric)
leafman 98:9f8bab96edff 1698 return "C";
leafman 98:9f8bab96edff 1699 return "F";
leafman 98:9f8bab96edff 1700 }