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