Ekran

Dependencies:   mbed LCD_DISCO_F469NIa CANlibrary SD_DISCO_F469NI BSP_DISCO_F469NIa EEPROM_DISCO_F469NI

draw_library.cpp

Committer:
stefan996
Date:
2019-11-16
Revision:
0:3bd86fc3a252
Child:
1:dad6a10be1f7

File content as of revision 0:3bd86fc3a252:

#include "draw_library.h"
#include "gears.h"
#include "font_100.h"
#include "font_50.h"
#include "font_24.h"

extern LCD_DISCO_F469NI lcd;
extern Serial pc;

void PrintChar_24(CHAR Char, uint16_t StartXPos, uint16_t StartYPos, uint32_t TextColor)
{
    uint16_t width=Char.width;
    uint16_t height=Char.height;
    uint16_t horpos,vertpos;
    uint16_t bitloc;
    uint32_t DrawColor;
    uint16_t x,y;
    
    // pos[0-7] = string(uint8_t), pos[8] = '\0'
    char pos[9];                            
    int bitMapPos = 0;
    
    for(vertpos=0; vertpos<height; ++vertpos)
    {   
        // We divide by 8 because we plot uint8_t.                             
        for(horpos=0; horpos<width/8; ++horpos)        
        {
            // sprintf - Instead of printing on console, it store output on char buffer which are specified in sprintf.
            // Convert uint8_t from hex to binary. 1 to fill, 0 to skip.
            sprintf(pos,BYTE_TO_BINARY_PATTERN,BYTE_TO_BINARY(Char.bitmap[bitMapPos])); 
            ++bitMapPos;  
            //pc.printf("%d. %s\n",horpos*height/8+vertpos,pos);
            for(bitloc=0;bitloc<8;bitloc++) 
            {
                if (pos[bitloc]=='1') 
                {
                    DrawColor=TextColor;
                }
                else
                {
                    DrawColor=lcd.GetBackColor();
                }
                
                x = StartXPos-vertpos;
                y = StartYPos+horpos*8+bitloc;
                
                
                lcd.DrawPixel(x, y, DrawColor);
                //pc.printf("%d,%d\n",StartXPos+horpos,StartYPos+vertpos*8+bitloc);                   
            }
        }
    }
    lcd.SetTextColor(LCD_COLOR_WHITE);
}


void PrintChar(CHAR Char, uint16_t StartXPos, uint16_t StartYPos, uint32_t TextColor)
{
    uint16_t width=Char.width;
    uint16_t height=Char.height;
    uint16_t horpos,vertpos;
    uint16_t bitloc;
    uint32_t DrawColor;
    uint16_t x,y;
    
    // pos[0-7] = string(uint8_t), pos[8] = '\0'
    char pos[9];                            
    int bitMapPos = 0;
    
    for(horpos=0; horpos<width; ++horpos)
    {   
        // We divide by 8 because we plot uint8_t.                             
        for(vertpos=0; vertpos<height/8; ++vertpos)        
        {
            // sprintf - Instead of printing on console, it store output on char buffer which are specified in sprintf.
            // Convert uint8_t from hex to binary. 1 to fill, 0 to skip.
            sprintf(pos,BYTE_TO_BINARY_PATTERN,BYTE_TO_BINARY(Char.bitmap[bitMapPos])); 
            ++bitMapPos;  
            //pc.printf("%d. %s\n",horpos*height/8+vertpos,pos);
            for(bitloc=0;bitloc<8;bitloc++) 
            {
                if (pos[bitloc]=='1') 
                {
                    DrawColor=TextColor;
                }
                else
                {
                    DrawColor=lcd.GetBackColor();
                }
                
                x = StartXPos-vertpos*8-bitloc;
                y = StartYPos+horpos;
                
                lcd.DrawPixel(x, y, DrawColor);
                //pc.printf("%d,%d\n",StartXPos+horpos,StartYPos+vertpos*8+bitloc);                   
            }
        }
    }
    lcd.SetTextColor(LCD_COLOR_WHITE);
}

void PrintString(char str[], uint8_t font, uint16_t StartXPos, uint16_t StartYPos, uint32_t TextColor)
{
    char *a=str;
    int p=0;
    switch(font)
    {
        case 24:
            while(a[p])
            {
                for(int i=0; i<62; ++i)
                {
                    if((*font24[i]).name==a[p])
                    {
                        PrintChar_24(*font24[i], StartXPos, StartYPos, TextColor);
                        StartYPos += (*font24[i]).width;
                        break;
                    }    
                }
                p++;
            }
            break;
                
        case 50:
            while(a[p])
            {
                for(int i=0; i<69; ++i)
                {
                    if((*font50[i]).name==a[p])
                    {
                        PrintChar(*font50[i], StartXPos, StartYPos, TextColor);
                        StartYPos += (*font50[i]).width;
                        break;
                    }    
                }
                p++;
            }
            break;        
    }
}

void PrintMain()
{
    PrintChar(Gear1, GearXVPos, GearYVPos, LCD_COLOR_BLACK);   // 0xFF029C33 zelena razer
    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);
    
    // 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);
    
    // 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);
    }
    lcd.SetTextColor(LCD_COLOR_BLACK);
    
    PrintString("Oil Temp", 24, 280, 58, LCD_COLOR_BLACK);
    PrintString("Water Temp", 24, 280, 277, LCD_COLOR_BLACK);
}