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:
Sun Jul 21 11:27:43 2013 +0000
Branch:
Metric
Revision:
127:27c739fd6d71
Parent:
126:e0d039096891
Child:
128:25314f339565
Recovered from failed attempt to restore default

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