The Code Repository for the REV0 Steering Wheel.
Dependencies: CANBuffer KS0108_fork mbed-rtos mbed CAN Addresses
Fork of REVO_Updated_Steering by
Steering.h@35:b42afc973902, 2014-11-22 (annotated)
- Committer:
- palimar
- Date:
- Sat Nov 22 22:24:53 2014 +0000
- Revision:
- 35:b42afc973902
- Parent:
- 32:535acb159709
- Child:
- 36:8544a8900884
Added linked list, also graphics updates only when variables change.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kiran_mbed | 0:313541d8f8be | 1 | #ifndef _STEERING_H |
kiran_mbed | 0:313541d8f8be | 2 | #define _STEERING_H |
kiran_mbed | 0:313541d8f8be | 3 | |
kiran_mbed | 0:313541d8f8be | 4 | #include "mbed.h" |
palimar | 3:fcec60c7f2c6 | 5 | #include "rtos.h" |
kiran_mbed | 0:313541d8f8be | 6 | #include "KS0108.h" |
kiran_mbed | 0:313541d8f8be | 7 | |
tmccurbin | 32:535acb159709 | 8 | #include "Arial10.h" |
kiran_mbed | 0:313541d8f8be | 9 | #include "Arial12.h" |
kiran_mbed | 0:313541d8f8be | 10 | #include "Arial14.h" |
kiran_mbed | 0:313541d8f8be | 11 | #include "Comic24.h" |
kiran_mbed | 0:313541d8f8be | 12 | #include "vivaldi16.h" |
palimar | 16:d2953809fb31 | 13 | #include "CANBuffer.h" |
palimar | 35:b42afc973902 | 14 | #include "variables.h" |
palimar | 35:b42afc973902 | 15 | |
kiran_mbed | 0:313541d8f8be | 16 | |
palimar | 17:e97c889873e2 | 17 | #include "LPCDigitalIn.h" |
palimar | 17:e97c889873e2 | 18 | |
kiran_mbed | 0:313541d8f8be | 19 | #define SWITCH_ID 410 |
kiran_mbed | 0:313541d8f8be | 20 | |
kiran_mbed | 0:313541d8f8be | 21 | #define BATTERY_VOLTAGE_ID 0x304 |
kiran_mbed | 0:313541d8f8be | 22 | #define BATTERY_POWER_ID 0x306 |
kiran_mbed | 0:313541d8f8be | 23 | #define BATTERY_CURRENT_ID 0x305 |
kiran_mbed | 0:313541d8f8be | 24 | |
palimar | 21:56890c41ecf1 | 25 | #define PCM_STATE_ID 0x201 |
kiran_mbed | 0:313541d8f8be | 26 | |
kiran_mbed | 0:313541d8f8be | 27 | #define BATTERY_MIN_CELLVOLTAGE_ID 0x301 |
kiran_mbed | 0:313541d8f8be | 28 | #define BATTERY_MAX_CELLVOLTAGE_ID 0x300 |
kiran_mbed | 0:313541d8f8be | 29 | #define BATTERY_AVG_CELLVOLTAGE_ID 0x302 |
kiran_mbed | 0:313541d8f8be | 30 | |
kiran_mbed | 0:313541d8f8be | 31 | #define BATTERY_MIN_CELLTEMPERATURE_ID 0x30A |
kiran_mbed | 0:313541d8f8be | 32 | #define BATTERY_MAX_CELLTEMPERATURE_ID 0x309 |
kiran_mbed | 0:313541d8f8be | 33 | #define BATTERY_AVG_CELLTEMPERATURE_ID 0x30B |
kiran_mbed | 0:313541d8f8be | 34 | #define AMS_BATTERY_STATE 0x30E // AIRS 7 and 6 // Precharge 3 |
kiran_mbed | 0:313541d8f8be | 35 | |
palimar | 35:b42afc973902 | 36 | #define NUM_SCREEN 2 |
palimar | 35:b42afc973902 | 37 | |
palimar | 26:e0256fd314eb | 38 | #define HOME_SCREEN 0 |
tmccurbin | 32:535acb159709 | 39 | #define BATTERY_SCREEN 1 |
palimar | 26:e0256fd314eb | 40 | |
kiran_mbed | 0:313541d8f8be | 41 | Serial pc(USBTX,USBRX); |
palimar | 23:6681a38918c6 | 42 | CANBuffer CAN_Steering_Buffer(CAN1, MEDIUM, p3_26); |
palimar | 16:d2953809fb31 | 43 | |
kiran_mbed | 0:313541d8f8be | 44 | |
kiran_mbed | 0:313541d8f8be | 45 | KS0108 display(p26, p21, p22, p23, p25, p24, p8, p7, p6, p5, p13, p14, p12, p11); |
palimar | 23:6681a38918c6 | 46 | //Ticker call_ledstream; |
kiran_mbed | 0:313541d8f8be | 47 | |
palimar | 16:d2953809fb31 | 48 | LPCDigitalOut l1(p1_28,1);// SW2 |
palimar | 16:d2953809fb31 | 49 | LPCDigitalOut l2(p1_26,1);// SW4 |
kiran_mbed | 0:313541d8f8be | 50 | |
palimar | 16:d2953809fb31 | 51 | LPCDigitalOut l3(p1_24,1);// SW6 |
palimar | 16:d2953809fb31 | 52 | LPCDigitalOut l4(p0_24,1);// SW8 |
kiran_mbed | 0:313541d8f8be | 53 | |
palimar | 16:d2953809fb31 | 54 | LPCDigitalOut u1(p1_14,0);// SW9 |
palimar | 16:d2953809fb31 | 55 | LPCDigitalOut u2(p1_9,0);// SW11 |
kiran_mbed | 0:313541d8f8be | 56 | |
palimar | 16:d2953809fb31 | 57 | LPCDigitalOut u3(p1_4,0);// SW13 |
palimar | 16:d2953809fb31 | 58 | LPCDigitalOut u4(p1_0,0);// SW15 |
kiran_mbed | 0:313541d8f8be | 59 | |
kiran_mbed | 0:313541d8f8be | 60 | AnalogOut ledstream(p18); |
kiran_mbed | 0:313541d8f8be | 61 | |
kiran_mbed | 0:313541d8f8be | 62 | //SW1 - SW3 |
palimar | 16:d2953809fb31 | 63 | LPCDigitalOut boSW1(p1_29,1); |
palimar | 18:674450a9d98d | 64 | LPCDigitalIn biSWBR(p1_27, PullDown); //BRight |
kiran_mbed | 0:313541d8f8be | 65 | |
palimar | 16:d2953809fb31 | 66 | LPCDigitalOut boSW5(p1_25,1); |
palimar | 18:674450a9d98d | 67 | LPCDigitalIn biSWBL(p1_22, PullDown); //BLeft |
kiran_mbed | 0:313541d8f8be | 68 | |
palimar | 16:d2953809fb31 | 69 | LPCDigitalOut boSW10(p1_10,1); |
palimar | 18:674450a9d98d | 70 | LPCDigitalIn biSWTR(p1_8, PullDown); //TRight |
kiran_mbed | 0:313541d8f8be | 71 | |
palimar | 16:d2953809fb31 | 72 | LPCDigitalOut boSW14(p1_1,1); |
palimar | 18:674450a9d98d | 73 | LPCDigitalIn biSWTL(p0_25, PullDown); //TLeft |
kiran_mbed | 0:313541d8f8be | 74 | |
kiran_mbed | 0:313541d8f8be | 75 | typedef union convert{ |
kiran_mbed | 0:313541d8f8be | 76 | float FLOAT; |
kiran_mbed | 0:313541d8f8be | 77 | char C_FLOAT[4]; |
kiran_mbed | 0:313541d8f8be | 78 | }ftc; |
kiran_mbed | 0:313541d8f8be | 79 | |
kiran_mbed | 0:313541d8f8be | 80 | char SwitchName[15][13]={ |
kiran_mbed | 0:313541d8f8be | 81 | "fuse", |
kiran_mbed | 0:313541d8f8be | 82 | "ams", |
kiran_mbed | 0:313541d8f8be | 83 | "imd", |
kiran_mbed | 0:313541d8f8be | 84 | "pcm", |
kiran_mbed | 0:313541d8f8be | 85 | "brkp", |
kiran_mbed | 0:313541d8f8be | 86 | "lft", |
kiran_mbed | 0:313541d8f8be | 87 | "intl", |
kiran_mbed | 0:313541d8f8be | 88 | "brko", |
kiran_mbed | 0:313541d8f8be | 89 | "ckpt", |
kiran_mbed | 0:313541d8f8be | 90 | "rgt", |
kiran_mbed | 0:313541d8f8be | 91 | "hvd", |
kiran_mbed | 0:313541d8f8be | 92 | "tsms" |
kiran_mbed | 0:313541d8f8be | 93 | }; |
kiran_mbed | 0:313541d8f8be | 94 | |
kiran_mbed | 0:313541d8f8be | 95 | int SwitchPosition[13][2]={ |
kiran_mbed | 0:313541d8f8be | 96 | {0,16}, //fuse |
kiran_mbed | 0:313541d8f8be | 97 | {25,16}, //ams |
kiran_mbed | 0:313541d8f8be | 98 | {50,16}, //imd |
kiran_mbed | 0:313541d8f8be | 99 | {70,16}, //pcm |
kiran_mbed | 0:313541d8f8be | 100 | {93,16}, //brkp |
kiran_mbed | 0:313541d8f8be | 101 | {117,16}, //lft |
kiran_mbed | 0:313541d8f8be | 102 | {0,32}, //intl |
kiran_mbed | 0:313541d8f8be | 103 | {17,32}, //brko |
kiran_mbed | 0:313541d8f8be | 104 | {42,32}, //ckpt |
kiran_mbed | 0:313541d8f8be | 105 | {65,32}, //rgt |
kiran_mbed | 0:313541d8f8be | 106 | {81,32}, //hvd |
kiran_mbed | 0:313541d8f8be | 107 | {102,32}, //tsm |
kiran_mbed | 0:313541d8f8be | 108 | }; |
kiran_mbed | 0:313541d8f8be | 109 | |
palimar | 35:b42afc973902 | 110 | int curr_screen; |
palimar | 35:b42afc973902 | 111 | int screen_flags[NUM_SCREEN]; |
palimar | 35:b42afc973902 | 112 | bool should_redraw; |
palimar | 9:e946cafa3cae | 113 | |
palimar | 9:e946cafa3cae | 114 | char drive_status; |
palimar | 13:1f05dcd9ae0e | 115 | char drive_status_request; |
palimar | 9:e946cafa3cae | 116 | char reset_body; |
palimar | 9:e946cafa3cae | 117 | |
palimar | 35:b42afc973902 | 118 | node * id_node = NULL; |
palimar | 35:b42afc973902 | 119 | variables * vars_list; |
palimar | 23:6681a38918c6 | 120 | |
palimar | 9:e946cafa3cae | 121 | |
palimar | 21:56890c41ecf1 | 122 | Mutex ds_mutex; |
palimar | 21:56890c41ecf1 | 123 | |
palimar | 35:b42afc973902 | 124 | /* |
palimar | 35:b42afc973902 | 125 | void read_messages(void const *args) { |
palimar | 35:b42afc973902 | 126 | |
palimar | 35:b42afc973902 | 127 | while (true) { |
palimar | 35:b42afc973902 | 128 | CANMessage Rxmsg; |
palimar | 35:b42afc973902 | 129 | |
palimar | 35:b42afc973902 | 130 | if(CAN_Steering_Buffer.rxRead(Rxmsg)) |
palimar | 35:b42afc973902 | 131 | if(Rxmsg.id == PCM_STATE_ID){ |
palimar | 35:b42afc973902 | 132 | |
palimar | 35:b42afc973902 | 133 | // Mutex to protex shared variables |
palimar | 35:b42afc973902 | 134 | ds_mutex.lock(); |
palimar | 35:b42afc973902 | 135 | drive_status = Rxmsg.data[0]; |
palimar | 35:b42afc973902 | 136 | ds_mutex.unlock(); |
palimar | 35:b42afc973902 | 137 | } |
palimar | 35:b42afc973902 | 138 | |
palimar | 35:b42afc973902 | 139 | if(Rxmsg.id == BATTERY_POWER_ID) |
palimar | 35:b42afc973902 | 140 | { |
palimar | 35:b42afc973902 | 141 | float power_ratio; |
palimar | 35:b42afc973902 | 142 | ftc rcv; |
palimar | 35:b42afc973902 | 143 | rcv.FLOAT=0.0; |
palimar | 35:b42afc973902 | 144 | |
palimar | 35:b42afc973902 | 145 | for(int i=0; i<4; i++){ |
palimar | 35:b42afc973902 | 146 | rcv.C_FLOAT[i] = Rxmsg.data[i]; |
palimar | 35:b42afc973902 | 147 | } |
palimar | 35:b42afc973902 | 148 | power_ratio=rcv.FLOAT/80000; |
palimar | 35:b42afc973902 | 149 | ledstream.write(power_ratio); |
palimar | 35:b42afc973902 | 150 | } |
palimar | 35:b42afc973902 | 151 | } |
palimar | 35:b42afc973902 | 152 | } |
palimar | 35:b42afc973902 | 153 | */ |
palimar | 35:b42afc973902 | 154 | |
kiran_mbed | 0:313541d8f8be | 155 | #endif /* STEERING_H */ |