# HG changeset patch # User Michiel Broek # Date 1447011004 -3600 # Node ID d9b7e0705f56037e07fb44b048b398e387734706 # Parent 0fa885045e20aa01d454754ec190fe2270174cce Added cursor control, but no blinking yet. diff -r 0fa885045e20 -r d9b7e0705f56 brewpanel/sdlgui.c --- a/brewpanel/sdlgui.c Sun Nov 08 17:55:50 2015 +0100 +++ b/brewpanel/sdlgui.c Sun Nov 08 20:30:04 2015 +0100 @@ -223,18 +223,20 @@ /* * Draw the cursor */ -void SDLGui_Cursor(int x, int y) +void SDLGui_Cursor(int x, int y, int on, int blink) { SDL_Rect dr; Uint32 color = SDL_MapRGB(pSdlGuiScrn->format, 53, 59, 61); - dr.x=x; - dr.y=y; - dr.w=fontwidth; - dr.h=fontheight; + if (on) { + dr.x = x; + dr.y = y + fontheight - 2; + dr.w = fontwidth; + dr.h = 2; - SDL_FillRect(pSdlGuiScrn, &dr, color); - SDL_UpdateRect(pSdlGuiScrn, x, y, fontwidth, fontheight); + SDL_FillRect(pSdlGuiScrn, &dr, color); + SDL_UpdateRect(pSdlGuiScrn, x, y, fontwidth, fontheight); + } } diff -r 0fa885045e20 -r d9b7e0705f56 brewpanel/sdlgui.h --- a/brewpanel/sdlgui.h Sun Nov 08 17:55:50 2015 +0100 +++ b/brewpanel/sdlgui.h Sun Nov 08 20:30:04 2015 +0100 @@ -45,7 +45,7 @@ -void SDLGui_Cursor(int x, int y); +void SDLGui_Cursor(int x, int y, int on, int blink); void SDLGui_Char(int x, int y, Uint8 c, int); int SDLGui_Init(void); int SDLGui_UnInit(void); diff -r 0fa885045e20 -r d9b7e0705f56 brewpanel/slcd.c --- a/brewpanel/slcd.c Sun Nov 08 17:55:50 2015 +0100 +++ b/brewpanel/slcd.c Sun Nov 08 20:30:04 2015 +0100 @@ -33,25 +33,24 @@ // HD44780U Commands -#define SLCD_CLEAR 0x01 -#define SLCD_HOME 0x02 -#define SLCD_ENTRY 0x04 -#define SLCD_CTRL 0x08 -#define SLCD_CDSHIFT 0x10 -#define SLCD_FUNC 0x20 -#define SLCD_CGRAM 0x40 -#define SLCD_DGRAM 0x80 +//#define SLCD_CLEAR 0x01 +//#define SLCD_HOME 0x02 +//#define SLCD_ENTRY 0x04 +//#define SLCD_CTRL 0x08 +//#define SLCD_CDSHIFT 0x10 +//#define SLCD_FUNC 0x20 +//#define SLCD_CGRAM 0x40 +//#define SLCD_DGRAM 0x80 // // Bits in the entry register // // #define LCD_ENTRY_SH 0x01 // #define LCD_ENTRY_ID 0x02 -// -// // Bits in the control register -// -// #define LCD_BLINK_CTRL 0x01 -// #define LCD_CURSOR_CTRL 0x02 -// #define LCD_DISPLAY_CTRL 0x04 + +// Bits in the control register +#define SLCD_BLINK_CTRL 0x01 +#define SLCD_CURSOR_CTRL 0x02 +#define SLCD_DISPLAY_CTRL 0x04 struct slcdDataStruct @@ -65,21 +64,11 @@ int cx; /* Cursor x position */ int cy; /* Cursor y position */ Uint8 cgram[8][8]; /* Characters in CGRAM */ + int control; /* Control register */ }; struct slcdDataStruct *slcds [MAX_SLCDS] ; -/* Low level */ - -void sendDataCmd (struct slcdDataStruct *slcd, unsigned char data) -{ -} - - -void putCommand (struct slcdDataStruct *slcd, unsigned char command) -{ -} - void slcdHome(int fd) @@ -87,6 +76,7 @@ struct slcdDataStruct *lcd = slcds [fd]; lcd->cx = lcd->cy = 0; + SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); } @@ -94,32 +84,51 @@ void slcdClear(int fd) { struct slcdDataStruct *lcd = slcds [fd]; + int i; lcd->cx = lcd->cy = 0; + for (i = 0; i < (lcd->cols * lcd->rows); i++) + slcdPutchar(fd, ' '); + lcd->cx = lcd->cy = 0; + SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); } void slcdDisplay(int fd, int state) { + struct slcdDataStruct *lcd = slcds [fd]; + + if (state) + lcd->control |= SLCD_DISPLAY_CTRL; + else + lcd->control &= ~SLCD_DISPLAY_CTRL; } void slcdCursor(int fd, int state) { + struct slcdDataStruct *lcd = slcds [fd]; + + if (state) + lcd->control |= SLCD_CURSOR_CTRL; + else + lcd->control &= ~SLCD_CURSOR_CTRL; + SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); } void slcdCursorBlink(int fd, int state) { -} - + struct slcdDataStruct *lcd = slcds [fd]; - -void slcdSendCommand(int fd, Uint8 command) -{ + if (state) + lcd->control |= SLCD_BLINK_CTRL; + else + lcd->control &= ~SLCD_BLINK_CTRL; + SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); } @@ -133,10 +142,9 @@ if ((y > lcd->rows) || (y < 0)) return ; - // putCommand (lcd, x + (LCD_DGRAM | rowOff [y])) ; - lcd->cx = x ; lcd->cy = y ; + SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); } @@ -164,7 +172,7 @@ if (++lcd->cy == lcd->rows) lcd->cy = 0; } - SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8); + SDLGui_Cursor(lcd->x + (lcd->cx * 12) + 12, lcd->y + (lcd->cy * 18) + 8, lcd->control & SLCD_CURSOR_CTRL, lcd->control & SLCD_BLINK_CTRL); } @@ -230,6 +238,7 @@ for (i = 0; i < 8; i++) for (j = 0; j < 8; j++) lcd->cgram[i][j] = 0; + lcd->control = 0; slcds[fd] = lcd; @@ -244,6 +253,11 @@ for (i = 0; i < lcd->cols; i++) slcdPutchar(fd, 0x0ff); + slcdDisplay(fd, TRUE); + slcdCursor(fd, FALSE); + slcdCursorBlink(fd, FALSE); + slcdClear(fd); + return fd; }