Dual CANbus monitor and instrumentation cluster

Eagle Schematic and Board design

/media/uploads/TickTock/canaryr5.zip

/media/uploads/TickTock/sch_r4.jpg /media/uploads/TickTock/lcdsch.jpg /media/uploads/TickTock/brd_r4.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
1R1R392M12063.9K resistor
4R2,R4-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
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

Assembly

1) LCD Displays

I found ribbon cable is a nice way to organize the wires to the displays. You'll need 12 conductors and I connected them in the following order:

1LED+
2LED-
3RSTB
4MOSI
5SCLK
6CSB
7X+
8X-
9Y+
10Y-
11VDD
12GND

First I connected all the GND connections (IM0, IM1, IM3, & 2 GND). 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. Take a break and repeat for the second display. /media/uploads/TickTock/lcdtop.jpg /media/uploads/TickTock/lcdbot.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.

/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

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. 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.

5) Final Assembly

Committer:
TickTock
Date:
Fri May 03 14:31:07 2013 +0000
Revision:
96:a6c6a6fd1d28
Parent:
95:248b3c25a7df
Fixed mistake (battTemp is char not short)

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