The Code Repository for the REV0 Steering Wheel.

Dependencies:   CANBuffer KS0108_fork mbed-rtos mbed CAN Addresses

Fork of REVO_Updated_Steering by Penn Electric

Committer:
jayf
Date:
Sat May 30 02:26:23 2015 +0000
Revision:
47:5d3c6f85fa29
Parent:
37:c9b9057079d9
Fixed all known steering wheel issues

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tmccurbin 37:c9b9057079d9 1 /*
tmccurbin 37:c9b9057079d9 2 Steering.cpp
tmccurbin 37:c9b9057079d9 3 #include "Steering.h"
tmccurbin 37:c9b9057079d9 4
tmccurbin 37:c9b9057079d9 5 bool NOT_biSWBL_HELD;
tmccurbin 37:c9b9057079d9 6 bool NOT_biSWTR_HELD;
tmccurbin 37:c9b9057079d9 7
tmccurbin 37:c9b9057079d9 8 void update_display(void const *args){
tmccurbin 37:c9b9057079d9 9
tmccurbin 37:c9b9057079d9 10 while(true){
tmccurbin 37:c9b9057079d9 11
tmccurbin 37:c9b9057079d9 12 if(screen_flags[curr_screen] || should_redraw){
tmccurbin 37:c9b9057079d9 13 screen_flags[curr_screen] = 0;
tmccurbin 37:c9b9057079d9 14 should_redraw = false;
tmccurbin 37:c9b9057079d9 15 switch(curr_screen){
tmccurbin 37:c9b9057079d9 16
tmccurbin 37:c9b9057079d9 17 case HOME_SCREEN:{
tmccurbin 37:c9b9057079d9 18
tmccurbin 37:c9b9057079d9 19 display.ClearScreen();
tmccurbin 37:c9b9057079d9 20 display.SelectFont(Arial10,BLACK,ReadData);
tmccurbin 37:c9b9057079d9 21 display.GotoXY(37,0);
tmccurbin 37:c9b9057079d9 22 display.PrintString(" Home Screen");
tmccurbin 37:c9b9057079d9 23
tmccurbin 37:c9b9057079d9 24 printf("Battery Voltage: %d\n\r", vars_list->get_value(PCM_STATE_ID));
tmccurbin 37:c9b9057079d9 25
tmccurbin 37:c9b9057079d9 26 display.GotoXY(16,16);
tmccurbin 37:c9b9057079d9 27 if(vars_list->get_value(PCM_STATE_ID) == 0){
tmccurbin 37:c9b9057079d9 28 display.PutString(3, 30, "Drive Status: OFF");
tmccurbin 37:c9b9057079d9 29 }
tmccurbin 37:c9b9057079d9 30 else{
tmccurbin 37:c9b9057079d9 31 display.PrintString("Drive Status: ON");
tmccurbin 37:c9b9057079d9 32 }
tmccurbin 37:c9b9057079d9 33 break;
tmccurbin 37:c9b9057079d9 34 }
tmccurbin 37:c9b9057079d9 35
tmccurbin 37:c9b9057079d9 36 case BATTERY_SCREEN:
tmccurbin 37:c9b9057079d9 37
tmccurbin 37:c9b9057079d9 38 display.ClearScreen();
tmccurbin 37:c9b9057079d9 39 display.SelectF ont(Arial10,BLACK,ReadData);
tmccurbin 37:c9b9057079d9 40 display.GotoXY(33,0);
tmccurbin 37:c9b9057079d9 41 display.PrintString(" Battery Screen");
tmccurbin 37:c9b9057079d9 42 break;
tmccurbin 37:c9b9057079d9 43
tmccurbin 37:c9b9057079d9 44 default:
tmccurbin 37:c9b9057079d9 45 break;
tmccurbin 37:c9b9057079d9 46
tmccurbin 37:c9b9057079d9 47 }
tmccurbin 37:c9b9057079d9 48 }
tmccurbin 37:c9b9057079d9 49 wait(2);
tmccurbin 37:c9b9057079d9 50 }
tmccurbin 37:c9b9057079d9 51 }
tmccurbin 37:c9b9057079d9 52
tmccurbin 37:c9b9057079d9 53 void toggle_screen(){
tmccurbin 37:c9b9057079d9 54 should_redraw = true;
tmccurbin 37:c9b9057079d9 55 curr_screen = (curr_screen+1) % NUM_SCREEN;
tmccurbin 37:c9b9057079d9 56 }
tmccurbin 37:c9b9057079d9 57
tmccurbin 37:c9b9057079d9 58 void request_status_change(){
tmccurbin 37:c9b9057079d9 59
tmccurbin 37:c9b9057079d9 60 char drive_status_request;
tmccurbin 37:c9b9057079d9 61 ds_mutex.lock();
tmccurbin 37:c9b9057079d9 62 drive_status_request = !(vars_list->get_value(PCM_STATE_ID));
tmccurbin 37:c9b9057079d9 63
tmccurbin 37:c9b9057079d9 64 ds_mutex.unlock();
tmccurbin 37:c9b9057079d9 65 char * status_string;
tmccurbin 37:c9b9057079d9 66
tmccurbin 37:c9b9057079d9 67 if(drive_status_request){
tmccurbin 37:c9b9057079d9 68 status_string = "ON";
tmccurbin 37:c9b9057079d9 69 }
tmccurbin 37:c9b9057079d9 70 else{
tmccurbin 37:c9b9057079d9 71 status_string = "OFF";
tmccurbin 37:c9b9057079d9 72 }
tmccurbin 37:c9b9057079d9 73
tmccurbin 37:c9b9057079d9 74 CANMessage Txmsg_drive_status_request(0x501,&drive_status_request,1);//Encode Tx messages
tmccurbin 37:c9b9057079d9 75 for(int i = 0; i < 10; i++){
tmccurbin 37:c9b9057079d9 76 CAN_Steering_Buffer.txWrite(Txmsg_drive_status_request);
tmccurbin 37:c9b9057079d9 77 }
tmccurbin 37:c9b9057079d9 78
tmccurbin 37:c9b9057079d9 79 printf("%s\n\r", status_string);
tmccurbin 37:c9b9057079d9 80 return;
tmccurbin 37:c9b9057079d9 81 }
tmccurbin 37:c9b9057079d9 82
tmccurbin 37:c9b9057079d9 83 void reset()
tmccurbin 37:c9b9057079d9 84 {
tmccurbin 37:c9b9057079d9 85 reset_body = 1;
tmccurbin 37:c9b9057079d9 86 CANMessage Txmsg_reset(0x502,&reset_body,1); //Encode Tx messages
tmccurbin 37:c9b9057079d9 87 for(int i = 0; i < 10; i++){
tmccurbin 37:c9b9057079d9 88 CAN_Steering_Buffer.txWriteDirect(Txmsg_reset);
tmccurbin 37:c9b9057079d9 89 }
tmccurbin 37:c9b9057079d9 90 NVIC_SystemReset();
tmccurbin 37:c9b9057079d9 91 display.ClearScreen();
tmccurbin 37:c9b9057079d9 92 display.SelectFont(Arial12,BLACK,ReadData);
tmccurbin 37:c9b9057079d9 93 display.GotoXY(16,16);
tmccurbin 37:c9b9057079d9 94 printf("Reset Initiated\n\r");
tmccurbin 37:c9b9057079d9 95
tmccurbin 37:c9b9057079d9 96 return;
tmccurbin 37:c9b9057079d9 97 }
tmccurbin 37:c9b9057079d9 98
tmccurbin 37:c9b9057079d9 99 void Init()
tmccurbin 37:c9b9057079d9 100 {
tmccurbin 37:c9b9057079d9 101 should_redraw = true;
tmccurbin 37:c9b9057079d9 102 pc.baud(921600);
tmccurbin 37:c9b9057079d9 103 curr_screen = HOME_SCREEN;
tmccurbin 37:c9b9057079d9 104 drive_status = 0;
tmccurbin 37:c9b9057079d9 105 drive_status_request = 1;
tmccurbin 37:c9b9057079d9 106 reset_body = 0;
tmccurbin 37:c9b9057079d9 107 ledstream.write(0);
tmccurbin 37:c9b9057079d9 108 NOT_biSWBL_HELD = true;
tmccurbin 37:c9b9057079d9 109 NOT_biSWTR_HELD = true;
tmccurbin 37:c9b9057079d9 110
tmccurbin 37:c9b9057079d9 111 vars_list = new variables();//Avoid Heap
tmccurbin 37:c9b9057079d9 112
tmccurbin 37:c9b9057079d9 113 vars_list->add(PCM_STATE_ID, HOME_SCREEN);
tmccurbin 37:c9b9057079d9 114 vars_list->add(BATTERY_VOLTAGE_ID, BATTERY_SCREEN);
tmccurbin 37:c9b9057079d9 115 vars_list->add(BATTERY_POWER_ID, BATTERY_SCREEN);
tmccurbin 37:c9b9057079d9 116 vars_list->add(BATTERY_CURRENT_ID, BATTERY_SCREEN);
tmccurbin 37:c9b9057079d9 117
tmccurbin 37:c9b9057079d9 118 }
tmccurbin 37:c9b9057079d9 119
tmccurbin 37:c9b9057079d9 120 void read_messages(void const *args) {
tmccurbin 37:c9b9057079d9 121
tmccurbin 37:c9b9057079d9 122 while (true) {
tmccurbin 37:c9b9057079d9 123
tmccurbin 37:c9b9057079d9 124 CANMessage Rxmsg;
tmccurbin 37:c9b9057079d9 125 if(CAN_Steering_Buffer.rxRead(Rxmsg)){
tmccurbin 37:c9b9057079d9 126 id_node = vars_list->get_node(Rxmsg.id);
tmccurbin 37:c9b9057079d9 127 if(id_node != NULL){
tmccurbin 37:c9b9057079d9 128 if(id_node->value != Rxmsg.data[0]){
tmccurbin 37:c9b9057079d9 129 screen_flags[id_node->screen] = 1;
tmccurbin 37:c9b9057079d9 130 }
tmccurbin 37:c9b9057079d9 131 id_node->value = Rxmsg.data[0];
tmccurbin 37:c9b9057079d9 132 }
tmccurbin 37:c9b9057079d9 133 }
tmccurbin 37:c9b9057079d9 134 }
tmccurbin 37:c9b9057079d9 135 }
tmccurbin 37:c9b9057079d9 136
tmccurbin 37:c9b9057079d9 137 int main(){
tmccurbin 37:c9b9057079d9 138 // Initialize, set all variables.
tmccurbin 37:c9b9057079d9 139 Init();
tmccurbin 37:c9b9057079d9 140 wait(0.1);
tmccurbin 37:c9b9057079d9 141
tmccurbin 37:c9b9057079d9 142 //Init Display
tmccurbin 37:c9b9057079d9 143 display.GotoXY(10,16);
tmccurbin 37:c9b9057079d9 144 display.SelectFont(Arial_14,BLACK,ReadData);
tmccurbin 37:c9b9057079d9 145 display.PrintString("Penn Electric Racing");
tmccurbin 37:c9b9057079d9 146 CAN_Steering_Buffer.mode(NoAck);
tmccurbin 37:c9b9057079d9 147
tmccurbin 37:c9b9057079d9 148 wait(0.5);
tmccurbin 37:c9b9057079d9 149
tmccurbin 37:c9b9057079d9 150 //New thread to read messages.
tmccurbin 37:c9b9057079d9 151 Thread update_thread(read_messages); //Prioritise
tmccurbin 37:c9b9057079d9 152
tmccurbin 37:c9b9057079d9 153 // display the screen.
tmccurbin 37:c9b9057079d9 154 Thread display_thread(update_display); //Prioritise
tmccurbin 37:c9b9057079d9 155
tmccurbin 37:c9b9057079d9 156
tmccurbin 37:c9b9057079d9 157 // Start to read buttons on main thread
tmccurbin 37:c9b9057079d9 158 while(1)
tmccurbin 37:c9b9057079d9 159 {
tmccurbin 37:c9b9057079d9 160 // Thread::wait(100);
tmccurbin 37:c9b9057079d9 161 if(biSWBL.read() && NOT_biSWBL_HELD){
tmccurbin 37:c9b9057079d9 162 request_status_change();
tmccurbin 37:c9b9057079d9 163 NOT_biSWBL_HELD = false;
tmccurbin 37:c9b9057079d9 164 }
tmccurbin 37:c9b9057079d9 165
tmccurbin 37:c9b9057079d9 166 else if(!biSWBL.read()){
tmccurbin 37:c9b9057079d9 167 NOT_biSWBL_HELD = true;
tmccurbin 37:c9b9057079d9 168 }
tmccurbin 37:c9b9057079d9 169
tmccurbin 37:c9b9057079d9 170 else{
tmccurbin 37:c9b9057079d9 171 // ignore BiSWBL.read()
tmccurbin 37:c9b9057079d9 172 }
tmccurbin 37:c9b9057079d9 173
tmccurbin 37:c9b9057079d9 174 if(biSWTR.read() && NOT_biSWTR_HELD){
tmccurbin 37:c9b9057079d9 175 toggle_screen();
tmccurbin 37:c9b9057079d9 176 NOT_biSWTR_HELD = false;
tmccurbin 37:c9b9057079d9 177 }
tmccurbin 37:c9b9057079d9 178
tmccurbin 37:c9b9057079d9 179 else if(!biSWTR.read()){
tmccurbin 37:c9b9057079d9 180 NOT_biSWTR_HELD = true;
tmccurbin 37:c9b9057079d9 181 }
tmccurbin 37:c9b9057079d9 182
tmccurbin 37:c9b9057079d9 183 else{
tmccurbin 37:c9b9057079d9 184 // ignore BiSWTR.read()
tmccurbin 37:c9b9057079d9 185 }
tmccurbin 37:c9b9057079d9 186
tmccurbin 37:c9b9057079d9 187 if(biSWBR.read()){
tmccurbin 37:c9b9057079d9 188 reset();
tmccurbin 37:c9b9057079d9 189 }
tmccurbin 37:c9b9057079d9 190 }
tmccurbin 37:c9b9057079d9 191 }
tmccurbin 37:c9b9057079d9 192
tmccurbin 37:c9b9057079d9 193 --------------------------------------------------------------------------------------------------------------
tmccurbin 37:c9b9057079d9 194 Steering.h
tmccurbin 37:c9b9057079d9 195 #ifndef _STEERING_H
tmccurbin 37:c9b9057079d9 196 #define _STEERING_H
tmccurbin 37:c9b9057079d9 197
tmccurbin 37:c9b9057079d9 198 #include "mbed.h"
tmccurbin 37:c9b9057079d9 199 #include "rtos.h"
tmccurbin 37:c9b9057079d9 200 #include "KS0108.h"
tmccurbin 37:c9b9057079d9 201
tmccurbin 37:c9b9057079d9 202 #include "Arial10.h"
tmccurbin 37:c9b9057079d9 203 #include "Arial12.h"
tmccurbin 37:c9b9057079d9 204 #include "Arial14.h"
tmccurbin 37:c9b9057079d9 205 #include "Comic24.h"
tmccurbin 37:c9b9057079d9 206 #include "vivaldi16.h"
tmccurbin 37:c9b9057079d9 207 #include "CANBuffer.h"
tmccurbin 37:c9b9057079d9 208 #include "variables.h"
tmccurbin 37:c9b9057079d9 209
tmccurbin 37:c9b9057079d9 210
tmccurbin 37:c9b9057079d9 211 #include "LPCDigitalIn.h"
tmccurbin 37:c9b9057079d9 212
tmccurbin 37:c9b9057079d9 213 #define SWITCH_ID 410
tmccurbin 37:c9b9057079d9 214
tmccurbin 37:c9b9057079d9 215 #define BATTERY_VOLTAGE_ID 0x304
tmccurbin 37:c9b9057079d9 216 #define BATTERY_POWER_ID 0x306
tmccurbin 37:c9b9057079d9 217 #define BATTERY_CURRENT_ID 0x305
tmccurbin 37:c9b9057079d9 218
tmccurbin 37:c9b9057079d9 219 #define PCM_STATE_ID 0x201
tmccurbin 37:c9b9057079d9 220
tmccurbin 37:c9b9057079d9 221 #define BATTERY_MIN_CELLVOLTAGE_ID 0x301
tmccurbin 37:c9b9057079d9 222 #define BATTERY_MAX_CELLVOLTAGE_ID 0x300
tmccurbin 37:c9b9057079d9 223 #define BATTERY_AVG_CELLVOLTAGE_ID 0x302
tmccurbin 37:c9b9057079d9 224
tmccurbin 37:c9b9057079d9 225 #define BATTERY_MIN_CELLTEMPERATURE_ID 0x30A
tmccurbin 37:c9b9057079d9 226 #define BATTERY_MAX_CELLTEMPERATURE_ID 0x309
tmccurbin 37:c9b9057079d9 227 #define BATTERY_AVG_CELLTEMPERATURE_ID 0x30B
tmccurbin 37:c9b9057079d9 228 #define AMS_BATTERY_STATE 0x30E // AIRS 7 and 6 // Precharge 3
tmccurbin 37:c9b9057079d9 229
tmccurbin 37:c9b9057079d9 230 #define NUM_SCREEN 2
tmccurbin 37:c9b9057079d9 231
tmccurbin 37:c9b9057079d9 232 #define HOME_SCREEN 0
tmccurbin 37:c9b9057079d9 233 #define BATTERY_SCREEN 1
tmccurbin 37:c9b9057079d9 234
tmccurbin 37:c9b9057079d9 235 Serial pc(USBTX,USBRX);
tmccurbin 37:c9b9057079d9 236 CANBuffer CAN_Steering_Buffer(CAN1, MEDIUM, p3_26);
tmccurbin 37:c9b9057079d9 237
tmccurbin 37:c9b9057079d9 238
tmccurbin 37:c9b9057079d9 239 KS0108 display(p26, p21, p22, p23, p25, p24, p8, p7, p6, p5, p13, p14, p12, p11);
tmccurbin 37:c9b9057079d9 240 //Ticker call_ledstream;
tmccurbin 37:c9b9057079d9 241
tmccurbin 37:c9b9057079d9 242 LPCDigitalOut l1(p1_28,1);// SW2
tmccurbin 37:c9b9057079d9 243 LPCDigitalOut l2(p1_26,1);// SW4
tmccurbin 37:c9b9057079d9 244
tmccurbin 37:c9b9057079d9 245 LPCDigitalOut l3(p1_24,1);// SW6
tmccurbin 37:c9b9057079d9 246 LPCDigitalOut l4(p0_24,1);// SW8
tmccurbin 37:c9b9057079d9 247
tmccurbin 37:c9b9057079d9 248 LPCDigitalOut u1(p1_14,0);// SW9
tmccurbin 37:c9b9057079d9 249 LPCDigitalOut u2(p1_9,0);// SW11
tmccurbin 37:c9b9057079d9 250
tmccurbin 37:c9b9057079d9 251 LPCDigitalOut u3(p1_4,0);// SW13
tmccurbin 37:c9b9057079d9 252 LPCDigitalOut u4(p1_0,0);// SW15
tmccurbin 37:c9b9057079d9 253
tmccurbin 37:c9b9057079d9 254 AnalogOut ledstream(p18); // This appears to iniialize the pin as an analog out, and probably defaults to low. Without this, the LED bar would have a few lights on.
tmccurbin 37:c9b9057079d9 255
tmccurbin 37:c9b9057079d9 256 //SW1 - SW3
tmccurbin 37:c9b9057079d9 257 LPCDigitalOut boSW1(p1_29,1);
tmccurbin 37:c9b9057079d9 258 LPCDigitalIn biSWBR(p1_27, PullDown); //BRight
tmccurbin 37:c9b9057079d9 259
tmccurbin 37:c9b9057079d9 260 LPCDigitalOut boSW5(p1_25,1);
tmccurbin 37:c9b9057079d9 261 LPCDigitalIn biSWBL(p1_22, PullDown); //BLeft
tmccurbin 37:c9b9057079d9 262
tmccurbin 37:c9b9057079d9 263 LPCDigitalOut boSW10(p1_10,1);
tmccurbin 37:c9b9057079d9 264 LPCDigitalIn biSWTR(p1_8, PullDown); //TRight
tmccurbin 37:c9b9057079d9 265
tmccurbin 37:c9b9057079d9 266 LPCDigitalOut boSW14(p1_1,1);
tmccurbin 37:c9b9057079d9 267 LPCDigitalIn biSWTL(p0_25, PullDown); //TLeft
tmccurbin 37:c9b9057079d9 268
tmccurbin 37:c9b9057079d9 269 typedef union convert{
tmccurbin 37:c9b9057079d9 270 float FLOAT;
tmccurbin 37:c9b9057079d9 271 char C_FLOAT[4];
tmccurbin 37:c9b9057079d9 272 }ftc;
tmccurbin 37:c9b9057079d9 273
tmccurbin 37:c9b9057079d9 274 char SwitchName[15][13]={
tmccurbin 37:c9b9057079d9 275 "fuse",
tmccurbin 37:c9b9057079d9 276 "ams",
tmccurbin 37:c9b9057079d9 277 "imd",
tmccurbin 37:c9b9057079d9 278 "pcm",
tmccurbin 37:c9b9057079d9 279 "brkp",
tmccurbin 37:c9b9057079d9 280 "lft",
tmccurbin 37:c9b9057079d9 281 "intl",
tmccurbin 37:c9b9057079d9 282 "brko",
tmccurbin 37:c9b9057079d9 283 "ckpt",
tmccurbin 37:c9b9057079d9 284 "rgt",
tmccurbin 37:c9b9057079d9 285 "hvd",
tmccurbin 37:c9b9057079d9 286 "tsms"
tmccurbin 37:c9b9057079d9 287 };
tmccurbin 37:c9b9057079d9 288
tmccurbin 37:c9b9057079d9 289 int SwitchPosition[13][2]={
tmccurbin 37:c9b9057079d9 290 {0,16}, //fuse
tmccurbin 37:c9b9057079d9 291 {25,16}, //ams
tmccurbin 37:c9b9057079d9 292 {50,16}, //imd
tmccurbin 37:c9b9057079d9 293 {70,16}, //pcm
tmccurbin 37:c9b9057079d9 294 {93,16}, //brkp
tmccurbin 37:c9b9057079d9 295 {117,16}, //lft
tmccurbin 37:c9b9057079d9 296 {0,32}, //intl
tmccurbin 37:c9b9057079d9 297 {17,32}, //brko
tmccurbin 37:c9b9057079d9 298 {42,32}, //ckpt
tmccurbin 37:c9b9057079d9 299 {65,32}, //rgt
tmccurbin 37:c9b9057079d9 300 {81,32}, //hvd
tmccurbin 37:c9b9057079d9 301 {102,32}, //tsm
tmccurbin 37:c9b9057079d9 302 };
tmccurbin 37:c9b9057079d9 303
tmccurbin 37:c9b9057079d9 304 int curr_screen;
tmccurbin 37:c9b9057079d9 305 int screen_flags[NUM_SCREEN];
tmccurbin 37:c9b9057079d9 306 bool should_redraw;
tmccurbin 37:c9b9057079d9 307
tmccurbin 37:c9b9057079d9 308 char drive_status;
tmccurbin 37:c9b9057079d9 309 char drive_status_request;
tmccurbin 37:c9b9057079d9 310 char reset_body;
tmccurbin 37:c9b9057079d9 311
tmccurbin 37:c9b9057079d9 312 node * id_node = NULL;
tmccurbin 37:c9b9057079d9 313 variables * vars_list;
tmccurbin 37:c9b9057079d9 314
tmccurbin 37:c9b9057079d9 315
tmccurbin 37:c9b9057079d9 316 Mutex ds_mutex;
tmccurbin 37:c9b9057079d9 317
tmccurbin 37:c9b9057079d9 318 /*
tmccurbin 37:c9b9057079d9 319 void read_messages(void const *args) {
tmccurbin 37:c9b9057079d9 320
tmccurbin 37:c9b9057079d9 321 while (true) {
tmccurbin 37:c9b9057079d9 322 CANMessage Rxmsg;
tmccurbin 37:c9b9057079d9 323
tmccurbin 37:c9b9057079d9 324 if(CAN_Steering_Buffer.rxRead(Rxmsg))
tmccurbin 37:c9b9057079d9 325 if(Rxmsg.id == PCM_STATE_ID){
tmccurbin 37:c9b9057079d9 326
tmccurbin 37:c9b9057079d9 327 // Mutex to protex shared variables
tmccurbin 37:c9b9057079d9 328 ds_mutex.lock();
tmccurbin 37:c9b9057079d9 329 drive_status = Rxmsg.data[0];
tmccurbin 37:c9b9057079d9 330 ds_mutex.unlock();
tmccurbin 37:c9b9057079d9 331 }
tmccurbin 37:c9b9057079d9 332
tmccurbin 37:c9b9057079d9 333 if(Rxmsg.id == BATTERY_POWER_ID)
tmccurbin 37:c9b9057079d9 334 {
tmccurbin 37:c9b9057079d9 335 float power_ratio;
tmccurbin 37:c9b9057079d9 336 ftc rcv;
tmccurbin 37:c9b9057079d9 337 rcv.FLOAT=0.0;
tmccurbin 37:c9b9057079d9 338
tmccurbin 37:c9b9057079d9 339 for(int i=0; i<4; i++){
tmccurbin 37:c9b9057079d9 340 rcv.C_FLOAT[i] = Rxmsg.data[i];
tmccurbin 37:c9b9057079d9 341 }
tmccurbin 37:c9b9057079d9 342 power_ratio=rcv.FLOAT/80000;
tmccurbin 37:c9b9057079d9 343 ledstream.write(power_ratio);
tmccurbin 37:c9b9057079d9 344 }
tmccurbin 37:c9b9057079d9 345 }
tmccurbin 37:c9b9057079d9 346 }
tmccurbin 37:c9b9057079d9 347 */
tmccurbin 37:c9b9057079d9 348
tmccurbin 37:c9b9057079d9 349 #endif /* STEERING_H */
tmccurbin 37:c9b9057079d9 350 -----------------------------------------------------------------------------------------------------------------------------
tmccurbin 37:c9b9057079d9 351 Variables.h
tmccurbin 37:c9b9057079d9 352 #include "node.h"
tmccurbin 37:c9b9057079d9 353
tmccurbin 37:c9b9057079d9 354 class variables{
tmccurbin 37:c9b9057079d9 355
tmccurbin 37:c9b9057079d9 356 public:
tmccurbin 37:c9b9057079d9 357
tmccurbin 37:c9b9057079d9 358 variables();
tmccurbin 37:c9b9057079d9 359 ~variables();
tmccurbin 37:c9b9057079d9 360 void add(int i, int s);
tmccurbin 37:c9b9057079d9 361 int get_screen(int i);
tmccurbin 37:c9b9057079d9 362 char get_value(int i);
tmccurbin 37:c9b9057079d9 363 int set_value(int i, char v);
tmccurbin 37:c9b9057079d9 364 node * get_node(int i);
tmccurbin 37:c9b9057079d9 365
tmccurbin 37:c9b9057079d9 366
tmccurbin 37:c9b9057079d9 367 int size;
tmccurbin 37:c9b9057079d9 368 node * head;
tmccurbin 37:c9b9057079d9 369 node * tail;
tmccurbin 37:c9b9057079d9 370
tmccurbin 37:c9b9057079d9 371 };
tmccurbin 37:c9b9057079d9 372
tmccurbin 37:c9b9057079d9 373 variables::variables(){
tmccurbin 37:c9b9057079d9 374 size = 0;
tmccurbin 37:c9b9057079d9 375 head = NULL;
tmccurbin 37:c9b9057079d9 376 tail = NULL;
tmccurbin 37:c9b9057079d9 377 }
tmccurbin 37:c9b9057079d9 378
tmccurbin 37:c9b9057079d9 379 variables::~variables(){
tmccurbin 37:c9b9057079d9 380
tmccurbin 37:c9b9057079d9 381 node * curr = head;
tmccurbin 37:c9b9057079d9 382 node * next = head;
tmccurbin 37:c9b9057079d9 383
tmccurbin 37:c9b9057079d9 384 while(curr != NULL){
tmccurbin 37:c9b9057079d9 385 next = curr->next;
tmccurbin 37:c9b9057079d9 386 delete(curr);
tmccurbin 37:c9b9057079d9 387 curr = next;
tmccurbin 37:c9b9057079d9 388 }
tmccurbin 37:c9b9057079d9 389
tmccurbin 37:c9b9057079d9 390 head = NULL;
tmccurbin 37:c9b9057079d9 391 tail = NULL;
tmccurbin 37:c9b9057079d9 392 size = 0;
tmccurbin 37:c9b9057079d9 393 }
tmccurbin 37:c9b9057079d9 394
tmccurbin 37:c9b9057079d9 395 void variables::add(int i, int s){
tmccurbin 37:c9b9057079d9 396
tmccurbin 37:c9b9057079d9 397 if(head == NULL){
tmccurbin 37:c9b9057079d9 398 head = new node(i, s);
tmccurbin 37:c9b9057079d9 399 tail = head;
tmccurbin 37:c9b9057079d9 400 }
tmccurbin 37:c9b9057079d9 401
tmccurbin 37:c9b9057079d9 402 else{
tmccurbin 37:c9b9057079d9 403 tail->next = new node(i,s);
tmccurbin 37:c9b9057079d9 404 tail = tail->next;
tmccurbin 37:c9b9057079d9 405 }
tmccurbin 37:c9b9057079d9 406 size++;
tmccurbin 37:c9b9057079d9 407 }
tmccurbin 37:c9b9057079d9 408
tmccurbin 37:c9b9057079d9 409 node * variables::get_node(int i){
tmccurbin 37:c9b9057079d9 410
tmccurbin 37:c9b9057079d9 411 node * curr = head;
tmccurbin 37:c9b9057079d9 412
tmccurbin 37:c9b9057079d9 413 while(curr != NULL){
tmccurbin 37:c9b9057079d9 414 if(curr->id == i){
tmccurbin 37:c9b9057079d9 415 return curr;
tmccurbin 37:c9b9057079d9 416 }
tmccurbin 37:c9b9057079d9 417 else{
tmccurbin 37:c9b9057079d9 418 curr = curr->next;
tmccurbin 37:c9b9057079d9 419 }
tmccurbin 37:c9b9057079d9 420 }
tmccurbin 37:c9b9057079d9 421 return NULL;
tmccurbin 37:c9b9057079d9 422 }
tmccurbin 37:c9b9057079d9 423
tmccurbin 37:c9b9057079d9 424 int variables::get_screen(int i){
tmccurbin 37:c9b9057079d9 425
tmccurbin 37:c9b9057079d9 426 node * curr = head;
tmccurbin 37:c9b9057079d9 427
tmccurbin 37:c9b9057079d9 428 while(curr != NULL){
tmccurbin 37:c9b9057079d9 429 if(curr->id == i){
tmccurbin 37:c9b9057079d9 430 return curr->screen;
tmccurbin 37:c9b9057079d9 431 }
tmccurbin 37:c9b9057079d9 432 else{
tmccurbin 37:c9b9057079d9 433 curr = curr->next;
tmccurbin 37:c9b9057079d9 434 }
tmccurbin 37:c9b9057079d9 435 }
tmccurbin 37:c9b9057079d9 436 return -1;
tmccurbin 37:c9b9057079d9 437 }
tmccurbin 37:c9b9057079d9 438
tmccurbin 37:c9b9057079d9 439 int variables::set_value(int i, char v){
tmccurbin 37:c9b9057079d9 440
tmccurbin 37:c9b9057079d9 441 node * curr = head;
tmccurbin 37:c9b9057079d9 442
tmccurbin 37:c9b9057079d9 443 while(curr != NULL){
tmccurbin 37:c9b9057079d9 444 if(curr->id == i){
tmccurbin 37:c9b9057079d9 445 curr->set_val(v);
tmccurbin 37:c9b9057079d9 446 return 0;
tmccurbin 37:c9b9057079d9 447 }
tmccurbin 37:c9b9057079d9 448 else{
tmccurbin 37:c9b9057079d9 449 curr = curr->next;
tmccurbin 37:c9b9057079d9 450 }
tmccurbin 37:c9b9057079d9 451 }
tmccurbin 37:c9b9057079d9 452 return -1;
tmccurbin 37:c9b9057079d9 453 }
tmccurbin 37:c9b9057079d9 454
tmccurbin 37:c9b9057079d9 455 char variables::get_value(int i){
tmccurbin 37:c9b9057079d9 456
tmccurbin 37:c9b9057079d9 457 node * curr = head;
tmccurbin 37:c9b9057079d9 458
tmccurbin 37:c9b9057079d9 459 while(curr != NULL){
tmccurbin 37:c9b9057079d9 460 if(curr->id == i){
tmccurbin 37:c9b9057079d9 461 return curr->value;
tmccurbin 37:c9b9057079d9 462 }
tmccurbin 37:c9b9057079d9 463 else{
tmccurbin 37:c9b9057079d9 464 curr = curr->next;
tmccurbin 37:c9b9057079d9 465 }
tmccurbin 37:c9b9057079d9 466 }
tmccurbin 37:c9b9057079d9 467 return 0;
tmccurbin 37:c9b9057079d9 468 }
tmccurbin 37:c9b9057079d9 469 --------------------------------------------------------------------------------------------------------------
tmccurbin 37:c9b9057079d9 470 Node.h
tmccurbin 37:c9b9057079d9 471 class node{
tmccurbin 37:c9b9057079d9 472
tmccurbin 37:c9b9057079d9 473 public:
tmccurbin 37:c9b9057079d9 474
tmccurbin 37:c9b9057079d9 475 node();
tmccurbin 37:c9b9057079d9 476 node(int id, int screen);
tmccurbin 37:c9b9057079d9 477 void set_val(char v);
tmccurbin 37:c9b9057079d9 478 ~node();
tmccurbin 37:c9b9057079d9 479
tmccurbin 37:c9b9057079d9 480 int screen;
tmccurbin 37:c9b9057079d9 481 int id;
tmccurbin 37:c9b9057079d9 482 char value;
tmccurbin 37:c9b9057079d9 483 node * next;
tmccurbin 37:c9b9057079d9 484
tmccurbin 37:c9b9057079d9 485 };
tmccurbin 37:c9b9057079d9 486
tmccurbin 37:c9b9057079d9 487 node::node(){
tmccurbin 37:c9b9057079d9 488 screen = 0;
tmccurbin 37:c9b9057079d9 489 id = 0;
tmccurbin 37:c9b9057079d9 490 next = NULL;
tmccurbin 37:c9b9057079d9 491 }
tmccurbin 37:c9b9057079d9 492
tmccurbin 37:c9b9057079d9 493 node::node(int i, int s){
tmccurbin 37:c9b9057079d9 494 id = i;
tmccurbin 37:c9b9057079d9 495 screen = s;
tmccurbin 37:c9b9057079d9 496 next = NULL;
tmccurbin 37:c9b9057079d9 497 }
tmccurbin 37:c9b9057079d9 498
tmccurbin 37:c9b9057079d9 499 void node::set_val(char v){
tmccurbin 37:c9b9057079d9 500 value = v;
tmccurbin 37:c9b9057079d9 501 }
tmccurbin 37:c9b9057079d9 502
tmccurbin 37:c9b9057079d9 503 node::~node(){
tmccurbin 37:c9b9057079d9 504 }
tmccurbin 37:c9b9057079d9 505 */