![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
hgjh
Dependencies: BSP_DISCO_F469NIa EEPROM_DISCO_F469NI LCD_DISCO_F469NIa SD_DISCO_F469NI mbed
Fork of IntegrationCAN_28jun by
main.cpp@0:38c3afd99aeb, 2018-05-16 (annotated)
- Committer:
- formulas
- Date:
- Wed May 16 14:48:37 2018 +0000
- Revision:
- 0:38c3afd99aeb
- Child:
- 2:f54f01527ebb
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
formulas | 0:38c3afd99aeb | 1 | #include "CAN_library.h" |
formulas | 0:38c3afd99aeb | 2 | #include "screen_library.h" |
formulas | 0:38c3afd99aeb | 3 | |
formulas | 0:38c3afd99aeb | 4 | LCD_DISCO_F469NI lcd; //Initialize LCD Display |
formulas | 0:38c3afd99aeb | 5 | SD_DISCO_F469NI sd; //Initialize SD Card |
formulas | 0:38c3afd99aeb | 6 | Serial pc(USBTX, USBRX); //Initialize Serial. This is used only while debuging code. |
formulas | 0:38c3afd99aeb | 7 | CAN can(PB_5, PB_13); //Initialize CAN. |
formulas | 0:38c3afd99aeb | 8 | InterruptIn change_screen_input(D0); //Initialize Digital input for Change screen button |
formulas | 0:38c3afd99aeb | 9 | |
formulas | 0:38c3afd99aeb | 10 | // Variables received from DTA, LVDTs and brakes |
formulas | 0:38c3afd99aeb | 11 | uint16_t Rpm0=0,Speed0=0,Gear0=0,Water_Temp0=0,Oil_Temp0=0,TPS0=0,Brakes0=0,Oil_P0=0,MAP0=0,Air_Temp0=0,Lambda0=0,Volts0=0,Crank0=0; |
formulas | 0:38c3afd99aeb | 12 | uint16_t Rpm=0,Speed=0,Gear=0,Water_Temp=0,Oil_Temp=0,TPS=0,Brakes=0,Oil_P=0,MAP=0,Air_Temp=0,Lambda=0,Volts=0,Crank=0; |
formulas | 0:38c3afd99aeb | 13 | int FL_LVDT0=0,FR_LVDT0=0,RL_LVDT0=0,RR_LVDT0=0,FL_LVDT=0,FR_LVDT=0,RL_LVDT=0,RR_LVDT=0; |
formulas | 0:38c3afd99aeb | 14 | //Referrent LVDT values. First received value is referrent. |
formulas | 0:38c3afd99aeb | 15 | int FL_LVDT_Ref,FR_LVDT_Ref,RL_LVDT_Ref,RR_LVDT_Ref; |
formulas | 0:38c3afd99aeb | 16 | |
formulas | 0:38c3afd99aeb | 17 | uint8_t change_flag=0; |
formulas | 0:38c3afd99aeb | 18 | uint16_t rx_flag=0x0000; // Receive specific CAN data message |
formulas | 0:38c3afd99aeb | 19 | uint8_t lvdtref=0x0F; // Flag if refferent LVDT value is received (first received LVDT value, 1=no, 0=yes). From highest to lowest bit: LL,LR,RL,RR. |
formulas | 0:38c3afd99aeb | 20 | uint8_t screen_flag=0x01; // Current screen flag. 1=Main, 2=First Aux, 3=Second Aux. |
formulas | 0:38c3afd99aeb | 21 | uint8_t ft_main_flag=1; // Detect first time Main screne in loop |
formulas | 0:38c3afd99aeb | 22 | uint8_t ft_2aux_flag=1; // Detect first time Second Aux screne in loop |
formulas | 0:38c3afd99aeb | 23 | |
formulas | 0:38c3afd99aeb | 24 | // CAN Message variables, one variable for each ID |
formulas | 0:38c3afd99aeb | 25 | // If new IDs are added, add variables for them |
formulas | 0:38c3afd99aeb | 26 | CANMessage msgDTA1; // RPM, TPS %, Water temp C, Air temp C |
formulas | 0:38c3afd99aeb | 27 | CANMessage msgDTA2; // MAP Kpa, Lambda x1000, KPH x10, Oil P Kpa |
formulas | 0:38c3afd99aeb | 28 | CANMessage msgDTA3; // Fuel P Kpa, Oil temp C, Volts x10, Fuel Con. L/Hr x10 |
formulas | 0:38c3afd99aeb | 29 | CANMessage msgDTA4; // Gear, Advance Deg x10, Injection ms x100, Fuel Con L/100km x10 |
formulas | 0:38c3afd99aeb | 30 | CANMessage msgDTA5; // Ana1 mV, Ana2 mV, Ana3 mV, Cam Advance x10 |
formulas | 0:38c3afd99aeb | 31 | CANMessage msgDTA6; // Cam Targ x10, Cam PWM x10, Crank Errors, Cam Errors |
formulas | 0:38c3afd99aeb | 32 | CANMessage msgLVDTFront; // Left, Right, Steering Wheel |
formulas | 0:38c3afd99aeb | 33 | CANMessage msgLVDTRear; // Left, Right |
formulas | 0:38c3afd99aeb | 34 | CANMessage msgBrakes; // Brake system preassure, Braking On/Off |
formulas | 0:38c3afd99aeb | 35 | |
formulas | 0:38c3afd99aeb | 36 | |
formulas | 0:38c3afd99aeb | 37 | int main(){ |
formulas | 0:38c3afd99aeb | 38 | can.attach(&CANMsgReceive,CAN::RxIrq); // Attach interrupt function to CAN RX |
formulas | 0:38c3afd99aeb | 39 | change_screen_input.rise(&ChangeCommand); //Attach interrupt function to rising edge of DigitalIn for changing screen. |
formulas | 0:38c3afd99aeb | 40 | SetIntro(); // Display logo when starting display |
formulas | 0:38c3afd99aeb | 41 | SetMain(); // First screen is main by default |
formulas | 0:38c3afd99aeb | 42 | while(1){ |
formulas | 0:38c3afd99aeb | 43 | if(change_flag){ // Check if screen is changed |
formulas | 0:38c3afd99aeb | 44 | ChangeScreen(); |
formulas | 0:38c3afd99aeb | 45 | }; |
formulas | 0:38c3afd99aeb | 46 | UpdateInfo(); // Update info for DTA values in every iteration |
formulas | 0:38c3afd99aeb | 47 | switch(screen_flag){ // Display only changes visible on current screen |
formulas | 0:38c3afd99aeb | 48 | case(1): |
formulas | 0:38c3afd99aeb | 49 | MainUpdate(); |
formulas | 0:38c3afd99aeb | 50 | break; |
formulas | 0:38c3afd99aeb | 51 | case(2): |
formulas | 0:38c3afd99aeb | 52 | FirstAuxUpdate(); |
formulas | 0:38c3afd99aeb | 53 | break; |
formulas | 0:38c3afd99aeb | 54 | case(3): |
formulas | 0:38c3afd99aeb | 55 | SecondAuxUpdate(); |
formulas | 0:38c3afd99aeb | 56 | break; |
formulas | 0:38c3afd99aeb | 57 | }; |
formulas | 0:38c3afd99aeb | 58 | }; |
formulas | 0:38c3afd99aeb | 59 | }; |