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 May 03 11:25:03 2013 +0000
Revision:
94:c3a14b3975d6
Parent:
93:c2402e8cd0e2
Child:
95:248b3c25a7df
Cleaned up dte miles remaining display (right justified and clear old values better)

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