]> git.karo-electronics.de Git - oswald.git/blobdiff - ui/LcdDisplay.c
Bluetooth handling, screen reworks for icons
[oswald.git] / ui / LcdDisplay.c
index f2652c2b7911412fe047502095cd06d9bde0a8f6..725908a4ab999860fbe6cb865b69ad6bfab5baa1 100644 (file)
@@ -1,17 +1,24 @@
-#include <time.h>
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-
-#include "oswald-ui.h"
+#include "oswald.h"
+#include "oswald_hal.h"
+#include "oswald_strings.h"
 #include "Fonts.h"
 
 #include "LcdDisplay.h"
 
-#define NUM_LCD_ROWS  96
-#define NUM_LCD_COL_BYTES  ( 12 )
-#define MAX_FONT_ROWS ( 19 )
-
+void oswald_draw_bitmap(const uint8_t xstart, const uint8_t ystart, const uint8_t width, const uint8_t height, const void *bmp)
+{
+       uint8_t x, y;
+       uint8_t *cb;
+
+       // we only draw set pixel, unset pixel remain as they are
+       for (y=0; y<height; y++) {
+               for (x=0; x<width; x++) {
+                       cb = (uint8_t *)(bmp + (y * ((width / 8)+((width % 8) ? 1:0))) + (x / 8));
+                       if (*cb & (1 << (x % 8)))
+                               hal_lcd_set_pixel(xstart + x, ystart + y, TRUE);
+               }
+       }
+}
 
 void DrawLcdLineBresenham(u8t xstart, u8t ystart, u8t xend, u8t yend)
 {
@@ -41,7 +48,7 @@ void DrawLcdLineBresenham(u8t xstart, u8t ystart, u8t xend, u8t yend)
        x = xstart;
        y = ystart;
        err = el/2;
-       lcd_set_pixel(x, y, TRUE);
+       hal_lcd_set_pixel(x, y, TRUE);
  
        for (t = 0; t < el; ++t) {
                err -= es; 
@@ -53,8 +60,9 @@ void DrawLcdLineBresenham(u8t xstart, u8t ystart, u8t xend, u8t yend)
                        x += pdx;
                        y += pdy;
                }
-               lcd_set_pixel(x, y, TRUE);
+               hal_lcd_set_pixel(x, y, TRUE);
        }
+       // lcd_update_display();
 }
 
 void DrawLcdLineBresenhamWW(u8t xstart, u8t ystart, u8t xend, u8t yend, u8t thickness)
@@ -85,12 +93,12 @@ void DrawLcdLineBresenhamWW(u8t xstart, u8t ystart, u8t xend, u8t yend, u8t thic
        x = xstart;
        y = ystart;
        err = el/2;
-       lcd_set_pixel(x, y, TRUE);
+       hal_lcd_set_pixel(x, y, TRUE);
        for (i=1; i<thickness; i++) {
-               lcd_set_pixel(x-i, y, TRUE);
-               lcd_set_pixel(x+i, y, TRUE);
-               lcd_set_pixel(x, y-i, TRUE);
-               lcd_set_pixel(x, y+i, TRUE);
+               hal_lcd_set_pixel(x-i, y, TRUE);
+               hal_lcd_set_pixel(x+i, y, TRUE);
+               hal_lcd_set_pixel(x, y-i, TRUE);
+               hal_lcd_set_pixel(x, y+i, TRUE);
        }
  
        for (t = 0; t < el; ++t) {
@@ -103,52 +111,71 @@ void DrawLcdLineBresenhamWW(u8t xstart, u8t ystart, u8t xend, u8t yend, u8t thic
                        x += pdx;
                        y += pdy;
                }
-               lcd_set_pixel(x, y, TRUE);
+               hal_lcd_set_pixel(x, y, TRUE);
                for (i=1; i<thickness; i++) {
-                       lcd_set_pixel(x-i, y, TRUE);
-                       lcd_set_pixel(x+i, y, TRUE);
-                       lcd_set_pixel(x, y-i, TRUE);
-                       lcd_set_pixel(x, y+i, TRUE);
+                       hal_lcd_set_pixel(x-i, y, TRUE);
+                       hal_lcd_set_pixel(x+i, y, TRUE);
+                       hal_lcd_set_pixel(x, y-i, TRUE);
+                       hal_lcd_set_pixel(x, y+i, TRUE);
                }
        }
+       // lcd_update_display();
 }
 
-
 u8t WriteLcdCharacter(u8t x, u8t y, u8t Character)
 {
        u8t CharacterHeight = GetCharacterHeight();
        u8t CharacterWidth = GetCharacterWidth(Character);
-       unsigned int bitmap[MAX_FONT_ROWS];
-       register lx, ly;
+       u16t bitmap[MAX_FONT_ROWS];
+       int lx, ly;
 
-       GetCharacterBitmap(Character,(unsigned int*)&bitmap);
+       GetCharacterBitmap(Character, bitmap);
 
        // printf("cw=%d ch=%d\n", CharacterWidth, CharacterHeight);
        for (ly=0; ly<CharacterHeight; ly++) {
                for (lx=0; lx<CharacterWidth; lx++) {
                        if (bitmap[ly] & (1<<lx)) {
-                               lcd_set_pixel(lx+x, ly+y, TRUE);
+                               hal_lcd_set_pixel(lx+x, ly+y, TRUE);
                                // printf(".");
                        } else {
-                               lcd_set_pixel(lx+x, ly+y, FALSE);
+                               hal_lcd_set_pixel(lx+x, ly+y, FALSE);
                                // printf(" ");
                        }
                }
                // printf("\n");
        }
-
+       // lcd_update_display();
        return CharacterWidth + GetFontSpacing();
 }
 
-void WriteLcdString(u8t x, u8t y, u8t *str)
+u8t WriteLcdString(u8t x, u8t y, char *str)
+{
+       int lx, i, strl;
+
+       strl = oswald_strlen(str);
+       if (strl == 0)
+               return 0;
+
+       lx = x;
+       for (i=0; i<strl; i++) {
+               lx += WriteLcdCharacter(lx, y, str[i]);
+       }
+       return lx;
+}
+
+
+void WriteLcdNumber(u8t x, u8t y, s16t number)
 {
-       register lx, i;
+       int lx, i, strl;
+       char str[8];
 
-       if (str == NULL || strlen(str)==0)
+       itoa(number, str, 10);
+       strl = oswald_strlen(str);
+       if (strl == 0)
                return;
 
        lx = x;
-       for (i=0; i<strlen(str); i++) {
+       for (i=0; i<strl; i++) {
                lx += WriteLcdCharacter(lx, y, str[i]);
        }
 }