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:
Sat Jun 15 12:23:36 2013 +0000
Revision:
97:a25940fd7b5b
Parent:
96:a6c6a6fd1d28
Child:
99:c05abf8e1cdc
.

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