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

Dependencies:   SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2_ILI9341 mbed

Fork of CANary_corrupt by Tick Tock

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

User Guide

Eagle Schematic and Board design

/media/uploads/TickTock/canaryr6.zip

/media/uploads/TickTock/canary_sch.jpg

/media/uploads/TickTock/canaryr6brd.jpg

For LCD Rev 1.01:

/media/uploads/TickTock/lcdsch.jpg

For VCD Rev 2.00:

/media/uploads/TickTock/lcdr2.jpg

Parts List

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

Assembly

1) LCD Displays

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

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

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

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

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

Examples of REV1.01 boards:

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

Examples of REV2.00:

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

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

2) PCB

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

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

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

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

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

3) Testing

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

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

4) Enclosure

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

5) Final Assembly

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

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

Committer:
TickTock
Date:
Sun Jun 30 14:45:01 2013 +0000
Branch:
Metric
Revision:
108:29b5a760adc2
Parent:
107:e9be732c1ad4
Child:
111:d1559bb25c43
Fixed temperature bug but USB logging is disabled

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