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

Dependencies:   SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2_ILI9341 mbed

Fork of CANary_corrupt by Tick Tock

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

User Guide

Eagle Schematic and Board design

/media/uploads/TickTock/canaryr6.zip

/media/uploads/TickTock/canary_sch.jpg

/media/uploads/TickTock/canaryr6brd.jpg

For LCD Rev 1.01:

/media/uploads/TickTock/lcdsch.jpg

For VCD Rev 2.00:

/media/uploads/TickTock/lcdr2.jpg

Parts List

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

Assembly

1) LCD Displays

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

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

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

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

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

Examples of REV1.01 boards:

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

Examples of REV2.00:

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

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

2) PCB

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

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

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

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

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

3) Testing

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

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

4) Enclosure

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

5) Final Assembly

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

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

Committer:
TickTock
Date:
Thu Jul 11 05:29:18 2013 +0000
Branch:
Metric
Revision:
121:553faf139a20
Parent:
120:041edeec08f5
Child:
122:138a40892a4c
Added shunt identification to cpbars display

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