Konacan kod

Dependencies:   BSP_DISCO_F469NIa EEPROM_DISCO_F469NI LCD_DISCO_F469NIa SD_DISCO_F469NI mbed

Fork of IntegrationCAN by Nenad Djalovic

Committer:
formulas
Date:
Thu Jun 28 16:33:23 2018 +0000
Revision:
2:f54f01527ebb
Parent:
0:38c3afd99aeb
a

Who changed what in which revision?

UserRevisionLine numberNew 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 2:f54f01527ebb 9 Serial pc(USBTX, USBRX); //Initialize Serial. This is used only while debuging code.
formulas 0:38c3afd99aeb 10 CAN can(PB_5, PB_13); //Initialize CAN.
formulas 0:38c3afd99aeb 11 InterruptIn change_screen_input(D0); //Initialize Digital input for Change screen button
formulas 2:f54f01527ebb 12 Timer t_int,t_store;
formulas 0:38c3afd99aeb 13
formulas 0:38c3afd99aeb 14 // Variables received from DTA, LVDTs and brakes
formulas 0:38c3afd99aeb 15 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 16 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 17 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 18 //Referrent LVDT values. First received value is referrent.
formulas 0:38c3afd99aeb 19 int FL_LVDT_Ref,FR_LVDT_Ref,RL_LVDT_Ref,RR_LVDT_Ref;
formulas 2:f54f01527ebb 20 float Meter_counter=0,Meter_counter0=0;
formulas 0:38c3afd99aeb 21
formulas 0:38c3afd99aeb 22 uint8_t change_flag=0;
formulas 0:38c3afd99aeb 23 uint16_t rx_flag=0x0000; // Receive specific CAN data message
formulas 2:f54f01527ebb 24 uint8_t distance_flag=0;
formulas 2:f54f01527ebb 25 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 26 uint8_t screen_flag=0x01; // Current screen flag. 1=Main, 2=First Aux, 3=Second Aux.
formulas 0:38c3afd99aeb 27 uint8_t ft_main_flag=1; // Detect first time Main screne in loop
formulas 0:38c3afd99aeb 28 uint8_t ft_2aux_flag=1; // Detect first time Second Aux screne in loop
formulas 0:38c3afd99aeb 29
formulas 0:38c3afd99aeb 30 // CAN Message variables, one variable for each ID
formulas 0:38c3afd99aeb 31 // If new IDs are added, add variables for them
formulas 0:38c3afd99aeb 32 CANMessage msgDTA1; // RPM, TPS %, Water temp C, Air temp C
formulas 0:38c3afd99aeb 33 CANMessage msgDTA2; // MAP Kpa, Lambda x1000, KPH x10, Oil P Kpa
formulas 0:38c3afd99aeb 34 CANMessage msgDTA3; // Fuel P Kpa, Oil temp C, Volts x10, Fuel Con. L/Hr x10
formulas 0:38c3afd99aeb 35 CANMessage msgDTA4; // Gear, Advance Deg x10, Injection ms x100, Fuel Con L/100km x10
formulas 0:38c3afd99aeb 36 CANMessage msgDTA5; // Ana1 mV, Ana2 mV, Ana3 mV, Cam Advance x10
formulas 0:38c3afd99aeb 37 CANMessage msgDTA6; // Cam Targ x10, Cam PWM x10, Crank Errors, Cam Errors
formulas 0:38c3afd99aeb 38 CANMessage msgLVDTFront; // Left, Right, Steering Wheel
formulas 0:38c3afd99aeb 39 CANMessage msgLVDTRear; // Left, Right
formulas 0:38c3afd99aeb 40 CANMessage msgBrakes; // Brake system preassure, Braking On/Off
formulas 2:f54f01527ebb 41 CANMessage msgDistance; // Total distance
formulas 0:38c3afd99aeb 42
formulas 0:38c3afd99aeb 43
formulas 0:38c3afd99aeb 44 int main(){
formulas 0:38c3afd99aeb 45 can.attach(&CANMsgReceive,CAN::RxIrq); // Attach interrupt function to CAN RX
formulas 0:38c3afd99aeb 46 change_screen_input.rise(&ChangeCommand); //Attach interrupt function to rising edge of DigitalIn for changing screen.
formulas 0:38c3afd99aeb 47 SetIntro(); // Display logo when starting display
formulas 0:38c3afd99aeb 48 SetMain(); // First screen is main by default
formulas 2:f54f01527ebb 49 //sd.Init();
formulas 0:38c3afd99aeb 50 while(1){
formulas 0:38c3afd99aeb 51 if(change_flag){ // Check if screen is changed
formulas 0:38c3afd99aeb 52 ChangeScreen();
formulas 0:38c3afd99aeb 53 };
formulas 0:38c3afd99aeb 54 UpdateInfo(); // Update info for DTA values in every iteration
formulas 0:38c3afd99aeb 55 switch(screen_flag){ // Display only changes visible on current screen
formulas 0:38c3afd99aeb 56 case(1):
formulas 0:38c3afd99aeb 57 MainUpdate();
formulas 0:38c3afd99aeb 58 break;
formulas 0:38c3afd99aeb 59 case(2):
formulas 0:38c3afd99aeb 60 FirstAuxUpdate();
formulas 0:38c3afd99aeb 61 break;
formulas 0:38c3afd99aeb 62 case(3):
formulas 0:38c3afd99aeb 63 SecondAuxUpdate();
formulas 0:38c3afd99aeb 64 break;
formulas 0:38c3afd99aeb 65 };
formulas 0:38c3afd99aeb 66 };
formulas 0:38c3afd99aeb 67 };