Dual CANbus monitor and instrumentation cluster. Presently tuned for the Nissan Leaf EV.

Dependencies:   SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2_ILI9341 mbed

Fork of CANary_corrupt by Tick Tock

After adding the LPC1768 platform, import as a program and do not select the "update to latest revision" box

User Guide

Eagle Schematic and Board design

/media/uploads/TickTock/canaryr6.zip

/media/uploads/TickTock/canary_sch.jpg

/media/uploads/TickTock/canaryr6brd.jpg

For LCD Rev 1.01:

/media/uploads/TickTock/lcdsch.jpg

For VCD Rev 2.00:

/media/uploads/TickTock/lcdr2.jpg

Parts List

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

Assembly

1) LCD Displays

I found ribbon cable is a nice way to organize the wires to the displays. There are two versions of the display and each must be wired differently. The original project used HW REV. 1.01. For that version, you'll need 12 conductors and I connected them in the following order:

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

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

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

First I connected all the GND connections (2 GND & IM0, IM1, IM3 for REV1.01 or 2 GND, RD, & IM0 for REV2.00). Do not connect the bottom GND until you have the ribbon cable connected. After making all the ribbon cable connections (connecting the GND of the ribbon cable to the bottom GND pad), solder the GND bar from the previous step to the back of the bottom GND connection. Finally, make a connection from the back side 3.3V pin to IM2 for REV1.01 or to IM1,IM2,&IM3 for REV2.00. Take a break and repeat for the second display.

Examples of REV1.01 boards:

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

Examples of REV2.00:

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

Once the two displays are complete combine all wires except CS0, CS1, X+, X-, Y+, and Y-. Connect X- of the left display to X+ of the right. Similarly connect Y- of the left display to Y+ of the right. Insulate any exposed wires.

2) PCB

Refer to the schematics to place all the components on the board. If you plan to install into the CANary 3D enclosure, DO NOT install the battery holder or the socket for the mbed and, instead, connect two wires to the VB and GND pads nearby. You will have to install the battery holder against the back wall to avoid interfering with the right-hand display and the mbed will have to be directly soldered. I have not found a socket with a low enough profile to fit in the space provided (depth of enclosure is limited by the space behind the center console). Also, I recommend keeping as much lead as possible on the Zener diode (bending it as shown to clear the back wall). Although it is operating well within parameters, the Zener gets quite hot during extended operation and the leads help dissipate the heat and keep it away from the PCB and other components.Update: Several Zeners have failed resulting in damage to some users boards so I recommend using a DC-DC converter instead to bring the 12V down to 7V.

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

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

Update: The Zener diodes tended to fail after a few months so I am recommending removing them and replacing with a DC-DC converter. This will run cooler and waste less energy, too. To install, remove the left display panel to gain access to the Zener. From there, the Zener can be removed and it's pads used to connect to the DC-DC converter. I recommend setting the output voltage on the bench before installing since the trim pot is tricky to reach once installed. Set it to 7V. The input can be connected to the left pad previously occupied by the zener and the output can connect to the right. GND(-) can be connected to the bottom right pad on the 2x6 header below the flex cable connector. Make sure the GND wire lies flat so it doesn't interfere with the connection of the flex cable. /media/uploads/TickTock/dcdcinst2.jpg

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

3) Testing

1)First step is to buzz out all connections from the LCDs to the pins in the main board
2)Next check the touch screen connections. On the main board, place an Ohm meter across X+ and X-. You should read 700 Ohms. Repeat for Y+ and Y-. Then test the resistance from X+ to Y+. With nothing touching the screens, it should read >100K Ohms and <1K when touching either screen.
3)When all connections are checked, solder in the mbed. Download and install the touch2 program http://mbed.org/users/TickTock/code/touch2/ to test the basic operation of the mbed and touch screens.
tips:
Touch screen is sensitive - excess flux on X+,X-,Y+,Y- connection on mbed can result in flakey operation
If touch is not working, double-check the LCD0_CS and LCD1_CS are not swapped. LCD0_CS must connect to the CS of the LCD that has X- & Y- connected to the mbed. LCD1_CS must connect to the CS of the LCD that has X+ & Y+ connected to the mbed.
4)Once touch2 works, it is time to connect to the OBD connector. I highly recommend double checking all connections from the OBD to the PCB with the cable in place before connecting to the Leaf. Buzz out all the pins in the OBS to make sure none are shorting to each other, Check that the 12V goes to the Zener (and nothing else) and the switched 12V to the resistor divider (and nothing else). Test the ground connection properly connects to ground and nothing else.
5)Once you are confident there are no shorts or wrong connections from the OBD connector, take a deep breath and plug it into your leaf. Touch2 program should come up and function. Unplug and install the latest CANary firmware. If you have the REV2.00 LCD boards, you will need to edit the precompile.h file in the TOUCH_TFTx2_w9341 library and set USE_ILI9341 to 1. Test all features before installing into the enclosure (gids, cellpair, menu system, logging) since installing and removing from the enclosure is a PITA.

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

4) Enclosure

The 3D printer leaves a lot of powder behind - I used a strong spray of water to get it out of all the cracks. The enclosure comes with a rather rough finish. I recommend convincing yourself you like it, then simply lightly sand then paint before assembly. Sanding is very difficult - the nylon is very nicely fused and doesn't want to sand. I tried sandblasting and that didn't work either. I had some limited success with filler and then sanding, but only on the outside - it is too difficult to sand the face. /media/uploads/TickTock/enclosure.jpg

5) Final Assembly

Make sure you are well rested with lots of patience before attempting assembly. It is a puzzle figuring out how to get both displays and the PCB in place. Enclosure was too expensive for me to keep iterating to optimize for assembly. I ended up snipping the thin display posts shorter and using various tools to push the displays into place. Also, some USB connectors are taller than others. If you have one of the taller ones, you will have to deflect the back wall a bit while inserting the PCB (being careful not to bend the housing) to get it to it's opening in the back wall. Do use a screw in the provided post to secure the PCB as USB insertion will otherwise dislodge it.

I added an additional safety line which wraps around the center post to prevent the enclosure from becoming a projectile in the event of an accident. /media/uploads/TickTock/safety.jpg Installed: /media/uploads/TickTock/installed.jpg

Committer:
TickTock
Date:
Tue Mar 25 19:57:08 2014 +0000
Revision:
181:396fdcceefd2
Parent:
180:5fdeeb86f3a3
Child:
182:10017d74de67
// Added grid to whpg displays

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