aa
Dependencies: mbed LCD_DISCO_F469NIa SD_DISCO_F469NI BSP_DISCO_F469NIa EEPROM_DISCO_F469NI
main.cpp@6:d6e001d7cf16, 2020-02-12 (annotated)
- Committer:
- formulas
- Date:
- Wed Feb 12 18:49:12 2020 +0000
- Revision:
- 6:d6e001d7cf16
- Parent:
- 4:0e8413277df8
aaa
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 | 2:f54f01527ebb | 3 | #include "EEPROM_DISCO_F469NI.h" |
formulas | 2:f54f01527ebb | 4 | |
formulas | 0:38c3afd99aeb | 5 | |
formulas | 0:38c3afd99aeb | 6 | LCD_DISCO_F469NI lcd; //Initialize LCD Display |
formulas | 0:38c3afd99aeb | 7 | SD_DISCO_F469NI sd; //Initialize SD Card |
formulas | 2:f54f01527ebb | 8 | //EEPROM_DISCO_F469NI eep; //Initialize EEPROM Internal memory |
formulas | 6:d6e001d7cf16 | 9 | Serial pc(USBTX, USBRX,115200); //Initialize Serial. This is used only while debuging code. |
nemanja1994 | 3:a06e417a5a2c | 10 | CAN can(PB_5, PB_13,1000000); //Initialize CAN. |
nemanja1994 | 3:a06e417a5a2c | 11 | I2C i2c(D14, D15); |
nemanja1994 | 3:a06e417a5a2c | 12 | DigitalOut reset(D8); |
formulas | 0:38c3afd99aeb | 13 | InterruptIn change_screen_input(D0); //Initialize Digital input for Change screen button |
formulas | 2:f54f01527ebb | 14 | Timer t_int,t_store; |
formulas | 0:38c3afd99aeb | 15 | |
formulas | 0:38c3afd99aeb | 16 | // Variables received from DTA, LVDTs and brakes |
formulas | 6:d6e001d7cf16 | 17 | uint16_t Capacity0=0,HV_Voltage0=0,Rpm0=0,Speed0=0,Gear0=0,Water_Temp0=0,Bat_Temp0=0,TPS0=0,Brakes0=0,MAP0=0,Air_Temp0=0,Lambda0=0,Volts0=0; |
formulas | 6:d6e001d7cf16 | 18 | uint16_t Capacity=80,HV_Voltage=542,Rpm=0,Speed=720,Gear=0,Water_Temp=47,Bat_Temp=34,TPS=69,Brakes=0,MAP=0,Air_Temp=0,Lambda=0,Volts=0; |
formulas | 0:38c3afd99aeb | 19 | 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 | 20 | //Referrent LVDT values. First received value is referrent. |
formulas | 0:38c3afd99aeb | 21 | int FL_LVDT_Ref,FR_LVDT_Ref,RL_LVDT_Ref,RR_LVDT_Ref; |
formulas | 4:0e8413277df8 | 22 | //float Meter_counter=0,Meter_counter0=0; |
formulas | 6:d6e001d7cf16 | 23 | uint8_t Acc_Temperature[70],Acc_Temperature0[70]; |
formulas | 0:38c3afd99aeb | 24 | |
formulas | 0:38c3afd99aeb | 25 | uint8_t change_flag=0; |
formulas | 0:38c3afd99aeb | 26 | uint16_t rx_flag=0x0000; // Receive specific CAN data message |
formulas | 2:f54f01527ebb | 27 | uint8_t distance_flag=0; |
formulas | 2:f54f01527ebb | 28 | 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 | 29 | uint8_t screen_flag=0x01; // Current screen flag. 1=Main, 2=First Aux, 3=Second Aux. |
formulas | 0:38c3afd99aeb | 30 | uint8_t ft_main_flag=1; // Detect first time Main screne in loop |
formulas | 0:38c3afd99aeb | 31 | uint8_t ft_2aux_flag=1; // Detect first time Second Aux screne in loop |
formulas | 0:38c3afd99aeb | 32 | |
formulas | 0:38c3afd99aeb | 33 | // CAN Message variables, one variable for each ID |
formulas | 0:38c3afd99aeb | 34 | // If new IDs are added, add variables for them |
formulas | 0:38c3afd99aeb | 35 | CANMessage msgDTA1; // RPM, TPS %, Water temp C, Air temp C |
formulas | 0:38c3afd99aeb | 36 | CANMessage msgDTA2; // MAP Kpa, Lambda x1000, KPH x10, Oil P Kpa |
formulas | 0:38c3afd99aeb | 37 | CANMessage msgDTA3; // Fuel P Kpa, Oil temp C, Volts x10, Fuel Con. L/Hr x10 |
formulas | 0:38c3afd99aeb | 38 | CANMessage msgDTA4; // Gear, Advance Deg x10, Injection ms x100, Fuel Con L/100km x10 |
formulas | 0:38c3afd99aeb | 39 | CANMessage msgDTA5; // Ana1 mV, Ana2 mV, Ana3 mV, Cam Advance x10 |
formulas | 0:38c3afd99aeb | 40 | CANMessage msgDTA6; // Cam Targ x10, Cam PWM x10, Crank Errors, Cam Errors |
formulas | 0:38c3afd99aeb | 41 | CANMessage msgLVDTFront; // Left, Right, Steering Wheel |
formulas | 0:38c3afd99aeb | 42 | CANMessage msgLVDTRear; // Left, Right |
formulas | 0:38c3afd99aeb | 43 | CANMessage msgBrakes; // Brake system preassure, Braking On/Off |
formulas | 2:f54f01527ebb | 44 | CANMessage msgDistance; // Total distance |
formulas | 0:38c3afd99aeb | 45 | |
nemanja1994 | 3:a06e417a5a2c | 46 | // LED Bar for RPM |
formulas | 0:38c3afd99aeb | 47 | |
nemanja1994 | 3:a06e417a5a2c | 48 | char cmd[3]; |
nemanja1994 | 3:a06e417a5a2c | 49 | int addr = 0x74<<1; |
nemanja1994 | 3:a06e417a5a2c | 50 | |
nemanja1994 | 3:a06e417a5a2c | 51 | void LEDInitialize(){ |
nemanja1994 | 3:a06e417a5a2c | 52 | reset.write(1); |
nemanja1994 | 3:a06e417a5a2c | 53 | // set port as output |
nemanja1994 | 3:a06e417a5a2c | 54 | cmd[0]=0x06; |
nemanja1994 | 3:a06e417a5a2c | 55 | cmd[1]=0x00; |
nemanja1994 | 3:a06e417a5a2c | 56 | cmd[2]=0x00; |
nemanja1994 | 3:a06e417a5a2c | 57 | i2c.write(addr,cmd,3); |
nemanja1994 | 3:a06e417a5a2c | 58 | } |
nemanja1994 | 3:a06e417a5a2c | 59 | |
nemanja1994 | 3:a06e417a5a2c | 60 | void showLedRpm(int RPM){ |
formulas | 6:d6e001d7cf16 | 61 | //pc.printf("%d\n",RPM); |
nemanja1994 | 3:a06e417a5a2c | 62 | if(RPM<1000) { |
nemanja1994 | 3:a06e417a5a2c | 63 | cmd[1]=0xFF; |
nemanja1994 | 3:a06e417a5a2c | 64 | cmd[2]=0xFF; |
nemanja1994 | 3:a06e417a5a2c | 65 | } |
nemanja1994 | 3:a06e417a5a2c | 66 | else if (RPM<2000) { |
nemanja1994 | 3:a06e417a5a2c | 67 | cmd[1]=0xFF; |
nemanja1994 | 3:a06e417a5a2c | 68 | cmd[2]=0xDF; |
nemanja1994 | 3:a06e417a5a2c | 69 | } |
nemanja1994 | 3:a06e417a5a2c | 70 | else if (RPM <3000) { |
nemanja1994 | 3:a06e417a5a2c | 71 | cmd[1]=0xFF; |
nemanja1994 | 3:a06e417a5a2c | 72 | cmd[2]=0xCF; |
nemanja1994 | 3:a06e417a5a2c | 73 | } |
nemanja1994 | 3:a06e417a5a2c | 74 | else if (RPM <4000) { |
nemanja1994 | 3:a06e417a5a2c | 75 | cmd[1]=0xFF; |
nemanja1994 | 3:a06e417a5a2c | 76 | cmd[2]=0xC7; |
nemanja1994 | 3:a06e417a5a2c | 77 | } |
nemanja1994 | 3:a06e417a5a2c | 78 | else if (RPM <5000) { |
nemanja1994 | 3:a06e417a5a2c | 79 | cmd[1]=0xFF; |
nemanja1994 | 3:a06e417a5a2c | 80 | cmd[2]=0xC3; |
nemanja1994 | 3:a06e417a5a2c | 81 | } |
nemanja1994 | 3:a06e417a5a2c | 82 | else if (RPM <6000) { |
nemanja1994 | 3:a06e417a5a2c | 83 | cmd[1]=0xFF; |
nemanja1994 | 3:a06e417a5a2c | 84 | cmd[2]=0xC1; |
nemanja1994 | 3:a06e417a5a2c | 85 | } |
nemanja1994 | 3:a06e417a5a2c | 86 | else if (RPM <7000) { |
nemanja1994 | 3:a06e417a5a2c | 87 | cmd[1]=0xFF; |
nemanja1994 | 3:a06e417a5a2c | 88 | cmd[2]=0xC0; |
nemanja1994 | 3:a06e417a5a2c | 89 | } |
nemanja1994 | 3:a06e417a5a2c | 90 | else if (RPM <8000) { |
nemanja1994 | 3:a06e417a5a2c | 91 | cmd[1]=0xBF; |
nemanja1994 | 3:a06e417a5a2c | 92 | cmd[2]=0xC0; |
nemanja1994 | 3:a06e417a5a2c | 93 | } |
nemanja1994 | 3:a06e417a5a2c | 94 | else if (RPM <9000) { |
nemanja1994 | 3:a06e417a5a2c | 95 | cmd[1]=0x9F; |
nemanja1994 | 3:a06e417a5a2c | 96 | cmd[2]=0xC0; |
nemanja1994 | 3:a06e417a5a2c | 97 | } |
nemanja1994 | 3:a06e417a5a2c | 98 | else if (RPM <10000) { |
nemanja1994 | 3:a06e417a5a2c | 99 | cmd[1]=0x8F; |
nemanja1994 | 3:a06e417a5a2c | 100 | cmd[2]=0xC0; |
nemanja1994 | 3:a06e417a5a2c | 101 | } |
nemanja1994 | 3:a06e417a5a2c | 102 | else if (RPM <11000) { |
nemanja1994 | 3:a06e417a5a2c | 103 | cmd[1]=0x87; |
nemanja1994 | 3:a06e417a5a2c | 104 | cmd[2]=0xC0; |
nemanja1994 | 3:a06e417a5a2c | 105 | } |
nemanja1994 | 3:a06e417a5a2c | 106 | else if (RPM <12000) { |
nemanja1994 | 3:a06e417a5a2c | 107 | cmd[1]=0x83; |
nemanja1994 | 3:a06e417a5a2c | 108 | cmd[2]=0xC0; |
nemanja1994 | 3:a06e417a5a2c | 109 | } |
nemanja1994 | 3:a06e417a5a2c | 110 | else if (RPM <13000) { |
nemanja1994 | 3:a06e417a5a2c | 111 | cmd[1]=0x81; |
nemanja1994 | 3:a06e417a5a2c | 112 | cmd[2]=0xC0; |
nemanja1994 | 3:a06e417a5a2c | 113 | } |
nemanja1994 | 3:a06e417a5a2c | 114 | else { |
nemanja1994 | 3:a06e417a5a2c | 115 | cmd[1]=0x80; |
nemanja1994 | 3:a06e417a5a2c | 116 | cmd[2]=0xC0; |
nemanja1994 | 3:a06e417a5a2c | 117 | } |
nemanja1994 | 3:a06e417a5a2c | 118 | cmd[0]=0x02; |
nemanja1994 | 3:a06e417a5a2c | 119 | i2c.write(addr, cmd, 3); |
nemanja1994 | 3:a06e417a5a2c | 120 | } |
nemanja1994 | 3:a06e417a5a2c | 121 | |
nemanja1994 | 3:a06e417a5a2c | 122 | |
nemanja1994 | 3:a06e417a5a2c | 123 | int main(){ |
formulas | 6:d6e001d7cf16 | 124 | //pc.printf("proba\n"); |
nemanja1994 | 3:a06e417a5a2c | 125 | LEDInitialize(); |
formulas | 0:38c3afd99aeb | 126 | can.attach(&CANMsgReceive,CAN::RxIrq); // Attach interrupt function to CAN RX |
formulas | 0:38c3afd99aeb | 127 | change_screen_input.rise(&ChangeCommand); //Attach interrupt function to rising edge of DigitalIn for changing screen. |
formulas | 6:d6e001d7cf16 | 128 | //SetIntro(); // Display logo when starting display |
formulas | 6:d6e001d7cf16 | 129 | SetMain(); |
formulas | 6:d6e001d7cf16 | 130 | lcd.SetTextColor(LCD_COLOR_BLACK); // First screen is main by default |
nemanja1994 | 3:a06e417a5a2c | 131 | sd.Init(); |
formulas | 6:d6e001d7cf16 | 132 | for (uint8_t k = 1 ; k <= 70 ; k++){ |
formulas | 6:d6e001d7cf16 | 133 | Acc_Temperature0[k] = 0; |
formulas | 6:d6e001d7cf16 | 134 | }; |
formulas | 6:d6e001d7cf16 | 135 | SetFixedAccTemp(); |
formulas | 0:38c3afd99aeb | 136 | while(1){ |
formulas | 0:38c3afd99aeb | 137 | if(change_flag){ // Check if screen is changed |
formulas | 0:38c3afd99aeb | 138 | ChangeScreen(); |
formulas | 0:38c3afd99aeb | 139 | }; |
formulas | 0:38c3afd99aeb | 140 | UpdateInfo(); // Update info for DTA values in every iteration |
formulas | 6:d6e001d7cf16 | 141 | //pc.printf("proba2\n"); |
formulas | 0:38c3afd99aeb | 142 | switch(screen_flag){ // Display only changes visible on current screen |
formulas | 0:38c3afd99aeb | 143 | case(1): |
formulas | 0:38c3afd99aeb | 144 | MainUpdate(); |
formulas | 0:38c3afd99aeb | 145 | break; |
formulas | 0:38c3afd99aeb | 146 | case(2): |
formulas | 0:38c3afd99aeb | 147 | FirstAuxUpdate(); |
formulas | 0:38c3afd99aeb | 148 | break; |
formulas | 0:38c3afd99aeb | 149 | case(3): |
formulas | 0:38c3afd99aeb | 150 | SecondAuxUpdate(); |
formulas | 0:38c3afd99aeb | 151 | break; |
formulas | 0:38c3afd99aeb | 152 | }; |
formulas | 0:38c3afd99aeb | 153 | }; |
nemanja1994 | 3:a06e417a5a2c | 154 | |
formulas | 0:38c3afd99aeb | 155 | }; |