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 17 13:48:51 2013 +0000
Branch:
Metric
Revision:
122:138a40892a4c
Parent:
121:553faf139a20
Child:
123:a8c0042df617
Updated display formatting.  Temporarily dumping all 7bb messages to ascii log for exploration.

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