]> git.karo-electronics.de Git - oswald.git/blobdiff - ui/LcdDisplay.c
Add support for more screens
[oswald.git] / ui / LcdDisplay.c
index ee88652ec12ed50b71ea9d5de9b309bf67423846..4f6bf99a3a9922f00c55a6f9775190c9f4d1dfe5 100644 (file)
@@ -1,9 +1,7 @@
-#include <time.h>
-#include <stdio.h>
-#include <string.h>
-
 #include "oswald-ui.h"
+#include "oswald_strings.h"
 #include "Fonts.h"
+
 #include "LcdDisplay.h"
 
 #define NUM_LCD_ROWS  96
 #define MAX_FONT_ROWS ( 19 )
 
 
-gint WriteLcdCharacter(oswald_ui *ui, gint x, gint y, unsigned char Character)
+void DrawLcdLineBresenham(u8t xstart, u8t ystart, u8t xend, u8t yend)
+{
+       int x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
+       dx = xend - xstart;
+       dy = yend - ystart;
+       incx = (dx >= 0) ? 1 : -1;
+       incy = (dy >= 0) ? 1 : -1;
+
+       if (dx<0)
+               dx = -dx;
+       if (dy<0)
+               dy = -dy;
+       if (dx>dy) {
+               pdx = incx; pdy = 0;
+               ddx=incx; ddy=incy;
+               es =dy;   el =dx;
+       } else {
+               pdx=0;    pdy=incy;
+               ddx=incx; ddy=incy;
+               es =dx;   el =dy;
+       }
+       x = xstart;
+       y = ystart;
+       err = el/2;
+       lcd_set_pixel(x, y, TRUE);
+       for (t = 0; t < el; ++t) {
+               err -= es; 
+               if (err < 0) {
+                       err += el;
+                       x += ddx;
+                       y += ddy;
+               } else {
+                       x += pdx;
+                       y += pdy;
+               }
+               lcd_set_pixel(x, y, TRUE);
+       }
+}
+
+void DrawLcdLineBresenhamWW(u8t xstart, u8t ystart, u8t xend, u8t yend, u8t thickness)
 {
-       gint CharacterHeight = GetCharacterHeight();
-       gint CharacterWidth = GetCharacterWidth(Character);
+       int i, x, y, t, dx, dy, incx, incy, pdx, pdy, ddx, ddy, es, el, err;
+       dx = xend - xstart;
+       dy = yend - ystart;
+       incx = (dx >= 0) ? 1 : -1;
+       incy = (dy >= 0) ? 1 : -1;
+
+       if (dx<0)
+               dx = -dx;
+       if (dy<0)
+               dy = -dy;
+       if (dx>dy) {
+               pdx = incx; pdy = 0;
+               ddx=incx; ddy=incy;
+               es =dy;   el =dx;
+       } else {
+               pdx=0;    pdy=incy;
+               ddx=incx; ddy=incy;
+               es =dx;   el =dy;
+       }
+       x = xstart;
+       y = ystart;
+       err = el/2;
+       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);
+       }
+       for (t = 0; t < el; ++t) {
+               err -= es; 
+               if (err < 0) {
+                       err += el;
+                       x += ddx;
+                       y += ddy;
+               } else {
+                       x += pdx;
+                       y += pdy;
+               }
+               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);
+               }
+       }
+}
+
+
+u8t WriteLcdCharacter(u8t x, u8t y, u8t Character)
+{
+       u8t CharacterHeight = GetCharacterHeight();
+       u8t CharacterWidth = GetCharacterWidth(Character);
        unsigned int bitmap[MAX_FONT_ROWS];
-       gint lx, ly;
+       register lx, ly;
 
        GetCharacterBitmap(Character,(unsigned int*)&bitmap);
 
@@ -24,10 +123,10 @@ gint WriteLcdCharacter(oswald_ui *ui, gint x, gint y, unsigned char Character)
        for (ly=0; ly<CharacterHeight; ly++) {
                for (lx=0; lx<CharacterWidth; lx++) {
                        if (bitmap[ly] & (1<<lx)) {
-                               set_pixel(ui, lx+x, ly+y, TRUE);
+                               lcd_set_pixel(lx+x, ly+y, TRUE);
                                // printf(".");
                        } else {
-                               set_pixel(ui, lx+x, ly+y, FALSE);
+                               lcd_set_pixel(lx+x, ly+y, FALSE);
                                // printf(" ");
                        }
                }
@@ -37,37 +136,17 @@ gint WriteLcdCharacter(oswald_ui *ui, gint x, gint y, unsigned char Character)
        return CharacterWidth + GetFontSpacing();
 }
 
-void WriteLcdString(oswald_ui *ui, gint x, gint y, gchar *str)
+void WriteLcdString(u8t x, u8t y, u8t *str)
 {
-       gint lx, i;
+       register lx, i, strl;
 
-       if (str == NULL || strlen(str)==0)
+       strl = oswald_strlen(str);
+       if (strl == 0)
                return;
 
        lx = x;
-       for (i=0; i<strlen(str); i++) {
-               lx += WriteLcdCharacter(ui, lx, y, str[i]);
+       for (i=0; i<strl; i++) {
+               lx += WriteLcdCharacter(lx, y, str[i]);
        }
 }
 
-
-void update_idle_time_date(oswald_ui *ui)
-{
-       gint gRow = 3;
-       gint gColumn = 4;
-       static gchar secs = 0;
-
-       SetFont(MetaWatchTime);
-
-       //gRow += WriteLcdCharacter(ui, gRow, gColumn, TIME_CHARACTER_SPACE_INDEX);
-       gRow += WriteLcdCharacter(ui, gRow, gColumn, 2);
-       gRow += WriteLcdCharacter(ui, gRow, gColumn, 3);
-       gRow += WriteLcdCharacter(ui, gRow, gColumn, TIME_CHARACTER_COLON_INDEX);
-       gRow += WriteLcdCharacter(ui, gRow, gColumn, 1);
-       gRow += WriteLcdCharacter(ui, gRow, gColumn, 7);
-       gRow += WriteLcdCharacter(ui, gRow, gColumn, TIME_CHARACTER_COLON_INDEX);
-       gRow += WriteLcdCharacter(ui, gRow, gColumn, (secs / 10));
-       gRow += WriteLcdCharacter(ui, gRow, gColumn, (secs % 10));
-       secs = ++secs % 60;
-}
-