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:
Wed Jul 24 11:20:08 2013 +0000
Revision:
131:0d926c080a65
Parent:
130:1a9d2a6d99ce
Child:
132:08748a67280a
Added Health splash screen on ignition on/off.  Added copy of CONFIG.TXT from USB if present during firmware update.  Added alt SOH.  Tweaked graphics.

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