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:
Thu Mar 06 15:37:40 2014 +0000
Revision:
177:6fda79c2fda1
Parent:
175:0357b4159b40
Child:
178:bf6404312c45
// Changed effciency counter to check after charging after 3am; // Added cancel day data button to trip display; // Base best and worse case on full round trip (per charge efficiency); // Track daily wh/gid

Who changed what in which revision?

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