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:
Tue Dec 03 20:45:05 2013 +0000
Revision:
167:58d4edf403d4
Parent:
166:ec3951ba9701
Child:
168:9227024c4e3a
// Added climate control impact to best case and worst case DTE (bug fix);

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