Konacan kod

Dependencies:   BSP_DISCO_F469NIa LCD_DISCO_F469NIa SD_DISCO_F469NI mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "CAN_library.h"
00002 #include "screen_library.h"
00003 
00004 LCD_DISCO_F469NI lcd;                       //Initialize LCD Display
00005 SD_DISCO_F469NI sd;                         //Initialize SD Card
00006 Serial pc(USBTX, USBRX);                  //Initialize Serial. This is used only while debuging code.
00007 CAN can(PB_5, PB_13);                       //Initialize CAN.
00008 InterruptIn change_screen_input(D0);        //Initialize Digital input for Change screen button
00009 
00010 // Variables received from DTA, LVDTs and brakes
00011 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;
00012 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;
00013 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;
00014 //Referrent LVDT values. First received value is referrent.
00015 int FL_LVDT_Ref,FR_LVDT_Ref,RL_LVDT_Ref,RR_LVDT_Ref;
00016 
00017 uint8_t change_flag=0;
00018 uint16_t rx_flag=0x0000;        // Receive specific CAN data message
00019 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.
00020 uint8_t screen_flag=0x01;       // Current screen flag. 1=Main, 2=First Aux, 3=Second Aux.
00021 uint8_t ft_main_flag=1;         // Detect first time Main screne in loop
00022 uint8_t ft_2aux_flag=1;         // Detect first time Second Aux screne in loop
00023 
00024 // CAN Message variables, one variable for each ID
00025 // If new IDs are added, add variables for them
00026 CANMessage msgDTA1;         // RPM, TPS %, Water temp C, Air temp C
00027 CANMessage msgDTA2;         // MAP Kpa, Lambda x1000, KPH x10, Oil P Kpa
00028 CANMessage msgDTA3;         // Fuel P Kpa, Oil temp C, Volts x10, Fuel Con. L/Hr x10
00029 CANMessage msgDTA4;         // Gear, Advance Deg x10, Injection ms x100, Fuel Con L/100km x10
00030 CANMessage msgDTA5;         // Ana1 mV, Ana2 mV, Ana3 mV, Cam Advance x10
00031 CANMessage msgDTA6;         // Cam Targ x10, Cam PWM x10, Crank Errors, Cam Errors
00032 CANMessage msgLVDTFront;    // Left, Right, Steering Wheel 
00033 CANMessage msgLVDTRear;     // Left, Right
00034 CANMessage msgBrakes;       // Brake system preassure, Braking On/Off
00035 
00036 
00037 int main(){    
00038     can.attach(&CANMsgReceive,CAN::RxIrq);      // Attach interrupt function to CAN RX
00039     change_screen_input.rise(&ChangeCommand);   //Attach interrupt function to rising edge of DigitalIn for changing screen.
00040     SetIntro();                                 // Display logo when starting display
00041     SetMain();                                  // First screen is main by default
00042     while(1){
00043         if(change_flag){                        // Check if screen is changed
00044             ChangeScreen();                         
00045         };
00046         UpdateInfo();                           // Update info for DTA values in every iteration
00047         switch(screen_flag){                    // Display only changes visible on current screen
00048             case(1):
00049                 MainUpdate();
00050                 break;
00051             case(2):
00052                 FirstAuxUpdate();
00053                 break;
00054             case(3):
00055                 SecondAuxUpdate();
00056                 break;
00057         };
00058     };
00059 };