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

Dependencies:   SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2_ILI9341 mbed

Fork of CANary_corrupt by Tick Tock

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

User Guide

Eagle Schematic and Board design

/media/uploads/TickTock/canaryr6.zip

/media/uploads/TickTock/canary_sch.jpg

/media/uploads/TickTock/canaryr6brd.jpg

For LCD Rev 1.01:

/media/uploads/TickTock/lcdsch.jpg

For VCD Rev 2.00:

/media/uploads/TickTock/lcdr2.jpg

Parts List

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

Assembly

1) LCD Displays

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

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

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

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

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

Examples of REV1.01 boards:

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

Examples of REV2.00:

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

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

2) PCB

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

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

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

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

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

3) Testing

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

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

4) Enclosure

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

5) Final Assembly

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

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

Committer:
TickTock
Date:
Thu Oct 24 19:51:31 2013 +0000
Revision:
156:4e5d30535cf9
Parent:
155:f31006516956
Child:
157:1a100a5ed06f
// Changed efficency screen braking monitor to use actual motor amps instead of target regen signal; // Changed braking screen to use actual regen signal instead of target regen signal;

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