Ekran

Dependencies:   mbed LCD_DISCO_F469NIa CANlibrary SD_DISCO_F469NI BSP_DISCO_F469NIa EEPROM_DISCO_F469NI

Files at this revision

API Documentation at this revision

Comitter:
stefan996
Date:
Wed Jan 29 19:56:33 2020 +0000
Parent:
0:3bd86fc3a252
Commit message:
Ekran

Changed in this revision

CANlibrary.lib Show annotated file Show diff for this revision Revisions of this file
RxCAN.cpp Show annotated file Show diff for this revision Revisions of this file
RxCAN.h Show annotated file Show diff for this revision Revisions of this file
draw_library.cpp Show annotated file Show diff for this revision Revisions of this file
draw_library.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 3bd86fc3a252 -r dad6a10be1f7 CANlibrary.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CANlibrary.lib	Wed Jan 29 19:56:33 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/renemagrit/code/CANlibrary/#b42c40844d4c
diff -r 3bd86fc3a252 -r dad6a10be1f7 RxCAN.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RxCAN.cpp	Wed Jan 29 19:56:33 2020 +0000
@@ -0,0 +1,1 @@
+#include "RxCAN.h"
\ No newline at end of file
diff -r 3bd86fc3a252 -r dad6a10be1f7 RxCAN.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RxCAN.h	Wed Jan 29 19:56:33 2020 +0000
@@ -0,0 +1,15 @@
+extern uint16_t gearValue0;
+extern uint16_t brakeValue0;
+extern uint16_t speedValue0;
+extern uint16_t waterTempValue0;
+extern uint16_t oilTempValue0;
+extern uint16_t tpsValue0;
+
+extern uint16_t gearValue;
+extern uint16_t brakeValue;
+extern uint16_t speedValue;
+extern uint16_t waterTempValue;
+extern uint16_t oilTempValue;
+extern uint16_t tpsValue;
+
+void UpdateInfo(void);
\ No newline at end of file
diff -r 3bd86fc3a252 -r dad6a10be1f7 draw_library.cpp
--- a/draw_library.cpp	Sat Nov 16 13:24:00 2019 +0000
+++ b/draw_library.cpp	Wed Jan 29 19:56:33 2020 +0000
@@ -7,6 +7,142 @@
 extern LCD_DISCO_F469NI lcd;
 extern Serial pc;
 
+
+void DrawTpsBar(void)
+{
+    lcd.DrawRect(350,10,440,100);
+    lcd.SetTextColor(LCD_COLOR_BLUE);
+    for(int x=350; x<790; x+=11)
+    {
+        lcd.DrawRect(x,10,11,100);
+    }
+    lcd.SetTextColor(LCD_COLOR_BLACK);  
+}
+
+
+void DrawBrakeBar(void)
+{
+    lcd.DrawRect(350,370,440,100);;
+    lcd.SetTextColor(LCD_COLOR_RED);
+    for(int x=350; x<790; x+=9)
+    {
+        lcd.DrawRect(x,370,9,100);
+    }
+}
+
+void UpdateTpsBar(uint16_t tpsValue)
+{
+    uint16_t barXPos = 350;
+    uint16_t barYPos = 10;
+    uint16_t barHeight = 11;
+    uint16_t barWidth = 100;
+    // tps range from 12 to 95
+    uint8_t tpsRange = tpsValue-12;
+    //uint8_t tpsRange0 = tpsValue0-12;
+    // 2 tps range = 1 tps bar
+    uint8_t tpsNumberBar = tpsRange/2;
+    //uint8_t tpsNumberBar0 = tpsRange0/2;
+    
+    
+    if(tpsValue<=12)
+    {
+        lcd.SetTextColor(LCD_COLOR_BLUE);
+        for(int i=barXPos; i<790; i+=barHeight)
+        {
+            lcd.DrawRect(barXPos,barYPos,barHeight,barWidth);
+        }
+        lcd.SetTextColor(LCD_COLOR_BLACK);
+    }
+    else if(tpsValue>=94)
+    {
+        lcd.SetTextColor(LCD_COLOR_BLUE);
+        for(int i=0; i<40; ++i)
+        {
+            lcd.FillRect(barXPos, barYPos, barHeight, barWidth);
+            barXPos += barHeight;
+        }
+        lcd.SetTextColor(LCD_COLOR_BLACK);
+    }
+    else
+    {
+        lcd.SetTextColor(LCD_COLOR_BLUE);
+        for(int i=0; i<tpsNumberBar; ++i)
+        {
+            lcd.FillRect(barXPos, barYPos, barHeight, barWidth);
+            barXPos += barHeight;
+        }
+        lcd.SetTextColor(LCD_COLOR_BLACK);   
+    }
+}
+
+
+
+void UpdateBrakeBar(uint16_t brakeValue)
+{
+    uint16_t barXPos = 350;
+    uint16_t barYPos = 370;
+    uint16_t barHeight = 9;
+    uint16_t barWidth = 100;
+    // 2 brake value = 1 brake bar
+    uint8_t brakeNumberBar = brakeValue/2;
+    //uint8_t tpsNumberBar0 = tpsRange0/2;
+    
+    
+    if(brakeValue<=0)
+    {
+        lcd.SetTextColor(LCD_COLOR_RED);
+        for(int i=barXPos; i<790; i+=barHeight)
+        {
+            lcd.DrawRect(barXPos,barYPos,barHeight,barWidth);
+        }
+        lcd.SetTextColor(LCD_COLOR_BLACK);
+    }
+    else if(brakeValue>=100)
+    {
+        lcd.SetTextColor(LCD_COLOR_RED);
+        for(int i=0; i<49; ++i)
+        {
+            lcd.FillRect(barXPos, barYPos, barHeight, barWidth);
+            barXPos += barHeight;
+        }
+        lcd.SetTextColor(LCD_COLOR_BLACK);
+    }
+    else
+    {
+        lcd.SetTextColor(LCD_COLOR_RED);
+        for(int i=0; i<brakeNumberBar; ++i)
+        {
+            lcd.FillRect(barXPos, barYPos, barHeight, barWidth);
+            barXPos += barHeight;
+        }
+        lcd.SetTextColor(LCD_COLOR_BLACK);   
+    }
+}
+
+
+void ChangeCommand(void)
+{                           
+    change_flag = 1;                              // Enable Interrupt flag
+}
+
+
+void ChangeScreen(void)
+{
+    switch(screen_flag)
+    {
+        case(2):
+            screen_flag = 1;                      // Change flag to new value (current screen)
+            SetMain();                            // Set Main Screne.
+            break;
+        case(1):
+            screen_flag = 2;                      // Change flag to new value (current screen)
+            SetAux();                             // Set Aux Screne.
+            break;
+    }
+    change_flag=0;                                // Disable Interrupt flag
+}
+
+
 void PrintChar_24(CHAR Char, uint16_t StartXPos, uint16_t StartYPos, uint32_t TextColor)
 {
     uint16_t width=Char.width;
@@ -54,6 +190,11 @@
 }
 
 
+
+
+
+
+
 void PrintChar(CHAR Char, uint16_t StartXPos, uint16_t StartYPos, uint32_t TextColor)
 {
     uint16_t width=Char.width;
@@ -99,6 +240,12 @@
     lcd.SetTextColor(LCD_COLOR_WHITE);
 }
 
+
+
+
+
+
+
 void PrintString(char str[], uint8_t font, uint16_t StartXPos, uint16_t StartYPos, uint32_t TextColor)
 {
     char *a=str;
@@ -139,48 +286,197 @@
     }
 }
 
-void PrintMain()
+
+
+
+
+
+void SetNumber(int num,int Font,uint16_t StartXPos,uint16_t StartYPos, int digits, int dec_point, int sign)
+{
+    int digit[3],sum=0,aux=0;
+    CHAR **font;
+    
+    if (Font==50)
+    {
+        font=font50;
+    }
+    else if (Font==100)
+    {
+        font=font100;
+    }
+    
+    lcd.SetTextColor(LCD_COLOR_BLACK);
+    uint8_t char_width=(*font[0]).width;
+    
+    if(num<pow(float(10),digits))
+    {
+        digit[0]=abs(num)/pow((float)10,(float)(digits-1));
+        for(int i=1; i<digits; ++i)
+        {
+            sum=(sum+digit[i-1])*10;
+            digit[i]=abs(num)/pow((float)10,(float)(digits-1-i))-sum;
+        }
+        
+        if(sign==1)
+        {
+            if(num<0)                           // Print minus if number lower than 0
+            {                                                          
+                PrintChar(*font[10],StartXPos,StartYPos,lcd.GetTextColor());
+            }
+            else if(num>=0)                     // Print blank if number lower than 0
+            {                                                    
+                lcd.SetTextColor(LCD_COLOR_WHITE);
+                lcd.FillRect(StartXPos, StartYPos, (*font[10]).width, (*font[10]).height);
+                lcd.SetTextColor(LCD_COLOR_BLACK);
+            }
+            aux+=(*font[10]).width;
+        }
+              
+        for(int i=0; i<digits; ++i)
+        { 
+            if(dec_point==i & dec_point>0)       // Default is for font50. This is not an universal solution, but it is in use because all font 100 infos are integers
+            {  
+                PrintChar(CharDot_50, StartXPos, StartYPos+dec_point*char_width, LCD_COLOR_BLACK);
+                aux+=CharDot_50.width;
+            }
+            
+            PrintChar(*font[digit[i]], StartXPos, StartYPos+i*char_width+aux, LCD_COLOR_BLACK);
+        }
+    }  
+} 
+
+
+
+
+
+
+
+//Function only changes the decimals that change. If number changes from 146 to 147, it only changes 6 to 7.
+void ChangeNumber(int num, int num0, uint8_t Font, uint16_t StartXPos, uint16_t StartYPos, int digits, int dec_point, int sign)
 {
-    PrintChar(Gear1, GearXVPos, GearYVPos, LCD_COLOR_BLACK);   // 0xFF029C33 zelena razer
+    int digit[digits];
+    int digit0[digits];
+    int sum=0,sum0=0,aux=0;
+    CHAR **font;
+    if(abs(num)<pow(float(10),digits))
+    {
+        digit[0]=abs(num)/pow((float)10,(float)(digits-1));
+        digit0[0]=abs(num0)/pow((float)10,(float)(digits-1));
+        for(int i=1; i<digits; ++i)
+        {
+            sum=(sum+digit[i-1])*10;
+            digit[i]=abs(num)/pow((float)10, (float)(digits-1-i))-sum;
+            sum0=(sum0+digit0[i-1])*10;
+            digit0[i]=abs(num0)/pow((float)10, (float)(digits-1-i))-sum0;
+        }
+        
+        if(Font==50)
+        {
+            font = font50;
+        }
+        else if(Font==100)
+        {
+            font = font100;
+        }
+        
+        lcd.SetTextColor(LCD_COLOR_BLACK);
+        uint8_t char_width=(*font[0]).width;
+        
+        if(sign==1)
+        {
+            if(num<0 & num0>=0)                 // Print minus if number lower than 0
+            {
+                PrintChar(*font[10], StartXPos, StartYPos, LCD_COLOR_BLACK);
+            }
+            else if(num>=0 & num0<0)            // Print blank if number lower than 0
+            {
+                lcd.SetTextColor(LCD_COLOR_WHITE);
+                lcd.FillRect(StartXPos, StartYPos, (*font[10]).width, (*font[10]).height);
+                lcd.SetTextColor(LCD_COLOR_BLACK);
+            }
+            aux+=(*font[10]).width;
+        }
+        
+        for(int i=0; i<digits; ++i)
+        {
+            if(dec_point==i & dec_point>0)
+            {
+               PrintChar(CharDot_50, StartXPos, StartYPos+dec_point*char_width, LCD_COLOR_BLACK); 
+               aux+=CharDot_50.width;
+            }
+            if(digit[i]!=digit0[i])
+            {
+                PrintChar(*font[digit[i]], StartXPos, StartYPos+i*char_width+aux, LCD_COLOR_BLACK);
+            }
+        }
+    }    
+}
+
+
+
+
+
+
+void SetMain(void)
+{
+    lcd.SetTextColor(LCD_COLOR_WHITE);
+    lcd.FillRect(0, 0, 800, 480);
     lcd.SetTextColor(LCD_COLOR_BLACK);
 
-    // Position for Oil Temp
-    lcd.DrawRect(140,10,150,225);
-    
-    // Position for Water Temp
-    lcd.DrawRect(140,245,150,225);
-    
-    // Position for Speed
-    lcd.DrawRect(10,60,120,360);
+/************************************** Tps position **************************/
+    DrawTpsBar();
+    SetNumber(tpsValue,50,tpsXPos,tpsYPos,3,0,0);
+    PrintString("TPS", 24, 345, 120, LCD_COLOR_BLACK);
+/******************************************************************************/
+
+
     
-    // Position for Tps
-    lcd.DrawRect(350,10,440,100);
-    lcd.DrawRect(300,10,50,225);
-    lcd.SetTextColor(LCD_COLOR_BLUE);
-    for(int x=350; x<778; x+=22)
-    {
-        lcd.DrawRect(x,10,22,100);
-    }
-    for(int x=350; x<450; x+=22)
-    {
-        lcd.FillRect(x,10,22,100);
-    }
-    lcd.SetTextColor(LCD_COLOR_BLACK);
+/*************************************** Brake position ***********************/
+    DrawBrakeBar();
+    SetNumber(brakeValue,50,brakeXPos,brakeYPos,3,0,0);
+    PrintString("BRAKE", 24, 345, 280, LCD_COLOR_BLACK);
+/******************************************************************************/
+
+
+
+/*************************************** Gear position ************************/     
+    PrintChar(Gear1, gearXVPos, gearYVPos, LCD_COLOR_BLACK);
+/******************************************************************************/
+
+
+
+/*************************************** Oil Temp position ********************/    
+    SetNumber(oilTempValue,100,oilTempXPos,oilTempYPos,3,0,0);
+    PrintString("Oil Temp", 24, 170, 50, LCD_COLOR_BLACK);
+/******************************************************************************/
+
+
+
+/*************************************** Water Temp position ******************/    
+    SetNumber(waterTempValue,100,waterTempXPos,waterTempYPos,3,0,0);
+    PrintString("Water Temp", 24, 170, 290, LCD_COLOR_BLACK);
+/******************************************************************************/
     
-    // Position for Rpm
-    lcd.DrawRect(350,370,440,100);
-    lcd.DrawRect(300,245,50,225);
-    lcd.SetTextColor(LCD_COLOR_RED);
-    for(int x=350; x<778; x+=22)
-    {
-        lcd.DrawRect(x,370,22,100);
-    }
-    for(int x=350; x<550; x+=22)
-    {
-        lcd.FillRect(x,370,22,100);
-    }
+    
+    
+/*************************************** Speed position ***********************/    
+    SetNumber(speedValue,100,speedXPos,speedYPos,3,0,0);
+    PrintString("km", 50, 125, 320, LCD_COLOR_BLACK);
+    PrintString("h", 50, 65, 345, LCD_COLOR_BLACK);
     lcd.SetTextColor(LCD_COLOR_BLACK);
+    lcd.DrawVLine(70,315,100);
+    lcd.DrawVLine(71,315,100);
+/******************************************************************************/
+
+    ChangeNumber(78, waterTempValue, 100, waterTempXPos, waterTempYPos, 3, 0, 0);
+    ChangeNumber(23, tpsValue, 50, tpsXPos, tpsYPos, 3, 0, 0);
+    ChangeNumber(67, brakeValue, 50, brakeXPos, brakeYPos, 3, 0, 0);
+    UpdateTpsBar(23);
+    UpdateBrakeBar(67);
+}
+
+
+void SetAux(void)
+{
     
-    PrintString("Oil Temp", 24, 280, 58, LCD_COLOR_BLACK);
-    PrintString("Water Temp", 24, 280, 277, LCD_COLOR_BLACK);
-}
+}
\ No newline at end of file
diff -r 3bd86fc3a252 -r dad6a10be1f7 draw_library.h
--- a/draw_library.h	Sat Nov 16 13:24:00 2019 +0000
+++ b/draw_library.h	Wed Jan 29 19:56:33 2020 +0000
@@ -1,6 +1,6 @@
 #include "LCD_DISCO_F469NI.h"
 
-#define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c"               //Pattern which converts uint8_t to binary(array of 8 chars)
+#define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c"              // Pattern which converts uint8_t to binary(array of 8 chars)
 #define BYTE_TO_BINARY(byte)\
   (byte & 0x80 ? '1' : '0'),\
   (byte & 0x40 ? '1' : '0'),\
@@ -19,11 +19,47 @@
     uint8_t *bitmap;
 } GEAR,CHAR;
 
+extern uint8_t change_flag;
+extern uint8_t screen_flag;                          // Current screen flag. 1=Main Screen, 2=Aux Screen 
 
-const uint16_t GearXVPos=750,GearYVPos=112;
+extern uint16_t gearValue;
+extern uint16_t tpsValue;
+extern uint16_t brakeValue;
+extern uint16_t oilTempValue;
+extern uint16_t waterTempValue;
+extern uint16_t speedValue;
+
+// Positions of Informations on screen
+const uint16_t gearXVPos=750, gearYVPos=112;
+const uint16_t tpsXPos=345, tpsYPos=4;
+const uint16_t brakeXPos=345, brakeYPos=362;
+const uint16_t oilTempXPos=270, oilTempYPos=2;
+const uint16_t waterTempXPos=270, waterTempYPos=260;
+const uint16_t speedXPos=115, speedYPos=80;
+
+
 
-void PrintChar_24(CHAR Char, uint16_t StartXPos, uint16_t StartYPos, uint32_t TextColor);
-void PrintChar(CHAR Char, uint16_t StartXPos, uint16_t StartYPos, uint32_t TextColor);
-void PrintString(char str[], uint8_t font, uint16_t StartXPos, uint16_t StartYPos, uint32_t TextColor);
+void PrintChar_24(CHAR Char, uint16_t StartXPos, uint16_t StartYPos, uint32_t TextColor);                                               // Print Char 24 function - vertical  
+void PrintChar(CHAR Char, uint16_t StartXPos, uint16_t StartYPos, uint32_t TextColor);                                                  // Print Char 50 and Char 100 function - vertical
+void PrintString(char str[], uint8_t font, uint16_t StartXPos, uint16_t StartYPos, uint32_t TextColor);                                 // Print String (all Char) function - vertical
+void SetNumber(int num,int Font,uint16_t StartXPos,uint16_t StartYPos, int digits, int dec_point, int sign);                            // Set number to specific value function - vertical
+void ChangeNumber(int num, int num0, uint8_t font, uint16_t StartXPos, uint16_t StartYPos, int digits, int dec_point, int sign);        // Update number function
+void DrawTpsBar(void);                                                                                                                  // Draw TPS bar function
+void DrawBrakeBar(void);                                                                                                                // Draw BRAKE bar function
+void UpdateTpsBar(uint16_t tpsValue);                                                                                                   // Update TPS bar function    
+void UpdateBrakeBar(uint16_t brakeValue);                                                                                               // Update BRAKE bar function
 
-void PrintMain();
\ No newline at end of file
+void ChangeCommand(void);                                                                                                               // Interrupt function for registering change command
+void ChangeScreen(void);                                                                                                                // Changes the screen if needed
+
+void SetMain(void);                                                                                                                     // Set Main Screen function
+void SetAux(void);                                                                                                                      // Set Aux Screen function
+
+
+
+
+
+
+
+
+
diff -r 3bd86fc3a252 -r dad6a10be1f7 main.cpp
--- a/main.cpp	Sat Nov 16 13:24:00 2019 +0000
+++ b/main.cpp	Wed Jan 29 19:56:33 2020 +0000
@@ -1,23 +1,53 @@
 #include "EEPROM_DISCO_F469NI.h"
 #include "draw_library.h"
 #include "mbed.h"
+#include "CANlibrary.h"
 
-LCD_DISCO_F469NI lcd;
-Serial pc(USBTX, USBRX, 115200);
+LCD_DISCO_F469NI lcd;                                   // Initialization LCD Display
+Serial pc(USBTX, USBRX, 115200);                        // Initialization Serial. This is used only while debuging code
+InterruptIn change_screen_input(D0);                    // Initialization Digital input for Change screen button
+CAN can(PB_5, PB_13);                                   // Initialization CAN, RX - PB_5  TX - PB_13
+
+uint8_t change_flag = 0;
+uint8_t screen_flag = 0x01;                             // Current screen flag. 1=Main Screen, 2=Aux Screen 
 
-void setMain();
+uint16_t gearValue0 = 0;
+uint16_t brakeValue0 = 0;
+uint16_t speedValue0 = 0;
+uint16_t waterTempValue0 = 0;
+uint16_t oilTempValue0 = 0;
+uint16_t tpsValue0 = 0;
+
+uint16_t gearValue = 0;
+uint16_t brakeValue = 0;
+uint16_t speedValue = 0;
+uint16_t waterTempValue = 0;
+uint16_t oilTempValue = 0;
+uint16_t tpsValue = 0;
+
 
 int main()
 { 
-    setMain();
-}
-
-void setMain()
-{
-    lcd.SetTextColor(LCD_COLOR_WHITE);
-    lcd.FillRect(0,0,800,480);
-    lcd.SetTextColor(LCD_COLOR_BLACK);
-    PrintMain();   
+    can.frequency(100000);                              // Set CAN Frequency
+    can_initRX();                                       // Initialization RX CAN
+    change_screen_input.rise(&ChangeCommand);           // Attach interrupt function to rising edge of DigitalIn for changing screen.
+    SetMain();                                          // First screen is main by default
+    while(1)
+    {
+        if(change_flag)                                 // Check if screen is changed           
+        {                       
+            ChangeScreen();                         
+        }
+        UpdateInfo();                           // Update info for DTA values in every iteration
+//        switch(screen_flag){                    // Display only changes visible on current screen
+//            case(1):
+//                MainUpdate();
+//                break;
+//            case(2):
+//                AuxUpdate();
+//                break;
+//        }    
+    }
 }
 
 
@@ -31,3 +61,20 @@
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+