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 Jun 28 20:26:11 2013 +0000
Branch:
Metric
Revision:
106:f016912a03db
Parent:
103:1389e9efe8c3
Child:
107:e9be732c1ad4
added logging indicator on main screen

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