Welcome to the EyeBot  Version 7 - RPi1
A Controller For Various Hardware IO
lcd.h
Go to the documentation of this file.
1 
9 #ifndef LCD_H_
10 #define LCD_H_
11 
12 #define _GNU_SOURCE
13 
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <unistd.h>
18 
19 #include <X11/Xlib.h>
20 #include <X11/keysym.h>
21 #include <jpeglib.h>
22 #include <jerror.h>
23 
24 #include <X11/Xutil.h>
25 #include <X11/Xresource.h>
26 #include <X11/keysym.h>
27 
28 #include "types.h"
29 #include <stdarg.h>
30 #include "system.h"
31 #include "globals.h"
32 
33 #include "key.h"
34 #include "listmenu.h"
35 #include <math.h>
36 
37 //defining the Font Names
38 #define HELVETICA 0
39 #define TIMES 1
40 #define COURIER 2
41 
42 //defining the font variations
43 #define NORMAL 0
44 #define BOLD 1
45 #define ITALICS 2
46 
47 #define MIN(a,b) (((a)<(b))?(a):(b))
48 #define MAX(a,b) (((a)>(b))?(a):(b))
49 
50 #define LCD_MAX_LIST_ITEM MAX(1,(gLCDHandle->height/(gLCDHandle->fontHeight*2))-2)
51 
52 //defining the colours
53 #define LCD_WHITE getColor("white")
54 #define LCD_SILVER getColor("light gray")
55 #define LCD_LIGHTGRAY getColor("light gray")
56 #define LCD_LIGHTGREY getColor("light grey")
57 #define LCD_GRAY getColor("gray")
58 #define LCD_DARKGRAY getColor("dark gray")
59 #define LCD_DARKGREY getColor("dark grey")
60 #define LCD_BLACK getColor("black")
61 #define LCD_BLUE getColor("blue")
62 #define LCD_NAVY getColor("navy")
63 #define LCD_AQUA getColor("aquamarine")
64 #define LCD_CYAN getColor("cyan")
65 #define LCD_TEAL getColor("dark cyan")
66 #define LCD_FUCHSIA getColor("magenta")
67 #define LCD_MAGENTA getColor("magenta")
68 #define LCD_PURPLE getColor("purple")
69 #define LCD_RED getColor("red")
70 #define LCD_MAROON getColor("maroon")
71 #define LCD_YELLOW getColor("yellow")
72 #define LCD_OLIVE getColor("dark olive green")
73 #define LCD_LIME getColor("lime green")
74 #define LCD_GREEN getColor("green")
75 
76 //defining RGB Colours
77 #define RED 0xFF00000
78 #define GREEN 0x00FF00
79 #define BLUE 0x0000FF
80 #define WHITE 0xFFFFFF
81 #define GRAY 0x808080
82 #define BLACK 0x000000
83 #define SILVER 0xC0C0C0
84 #define LIGHTGRAY 0xD3D3D3
85 #define DARKGRAY 0xA9A9A9
86 #define NAVY 0x000080
87 #define CYAN 0x00EEEE
88 #define TEAL 0x008080
89 #define MAGENTA 0xFF00FF
90 #define PURPLE 0x800080
91 #define MAROON 0x800000
92 #define YELLOW 0xFFFF00
93 #define OLIVE 0x9ACD32
94 #define ORANGE 0xFFA500
95 
96 /* constants for text colorflags */
97 #define LCD_BGCOL_TRANSPARENT 0x01
98 #define LCD_BGCOL_NOTRANSPARENT 0x10
99 
100 #define LCD_BGCOL_INVERSE 0x02
101 #define LCD_BGCOL_NOINVERSE 0x20
102 
103 #define LCD_FGCOL_INVERSE 0x04
104 #define LCD_FGCOL_NOINVERSE 0x40
105 
106 /* constants for lcd modes */
107 #define LCD_AUTOREFRESH 0x0001
108 #define LCD_NOAUTOREFRESH 0x0100
109 
110 #define LCD_SCROLLING 0x0002
111 #define LCD_NOSCROLLING 0x0200
112 
113 #define LCD_LINEFEED 0x0004
114 #define LCD_NOLINEFEED 0x0400
115 
116 #define LCD_SHOWMENU 0x0008
117 #define LCD_HIDEMENU 0x0800
118 
119 #define LCD_LISTMENU 0x0010
120 #define LCD_CLASSICMENU 0x1000
121 
122 #define LCD_FB_ROTATE 0x0080
123 #define LCD_FB_NOROTATION 0x8000
124 
125 /*
126  * define fonts using their alias
127  * font aliases can be found in the following file:
128  * /etc/X11/fonts/misc/xfonts-base.alias
129  */
130 #define FONTDEFAULT "6x13"
131 #define FONTBOLD "6x13bold"
132 
133 //for Rpi2: 7x14
134 
135 int LCD_INITIAL;
136 int IM_TYPE;
137 int IM_LEFT;
138 int IM_TOP;
139 int IM_WIDTH;
140 int IM_LENGTH;
141 
142 int LCDDrawFrame(int x1, int y1, int x2, int y2, XColor color);
143 int LCDDrawMenu(void);
144 int LCDDrawList(void);
145 
146 int LCDInit();
147 int LCDClear(void);
148 
149 int LCDSetMode(HWORD mode);
150 // Set LCD Mode (0=default, XXX)
151 
152 HWORD LCDGetMode(void);
153 int LCDResetMode(HWORD mode);
154 int LCDMenu(char *string1, char *string2, char *string3, char *string4);
155 
156 
157 int LCDMenuIRaw(int pos, char *string, XColor fgcol, XColor bgcol, void* userp);
158 int LCDMenuI(int pos, char *string, COLOR fg, COLOR bg);
159 
160 MENU_ITEM* LCDMenuItem(int index);
161 
162 int LCDList(LIST_MENU *menulist);
163 int LCDSetList(LIST_MENU* menulist);
164 LIST_MENU* LCDGetList(void);
165 RECT* LCDListBox(int pos);
167 
168 XColor getColor(char* colorName);
169 XColor InvertColor(XColor color);
170 
171 int LCDNeedRefresh(void);
172 
173 //same as LCDRect?
174 int LCDAreaRaw(int x1, int y1, int x2, int y2, XColor color);
175 int LCDArea(int x1, int y1, int x2, int y2, COLOR col, int fill);
176 
177 int LCDSetPixel(int x, int y, XColor color);
178 int LCDPixel(int x, int y, COLOR col);
179 
180 XColor LCDGetPixel(int x, int y);
181 int LCDPixelInvert(int x, int y);
182 
183 int LCDLineRaw(int x1, int y1, int x2, int y2, XColor color);
184 int LCDLine(int x1, int y1, int x2, int y2, COLOR col);
185 
186 int LCDLineInvert(int x1, int y1, int x2, int y2);
187 int LCDAreaInvert(int x1, int y1, int x2, int y2);
188 
189 int LCDCircle(int x1, int y1, int size, COLOR col, int fill); // Draw filled/hollow circle
190 int LCDCircleInvert(int x1, int y1, int size); // Invert circle
191 
192 int LCDFrame(int x1, int y1, int x2, int y2, XColor color);
193 int LCDRect(int x1, int y1, int x2, int y2, COLOR col);
194 
195 int LCDTextColor(XColor fgcol, XColor bgcol, char colorflags);
196 int LCDSetColor(COLOR fg, COLOR bg);
197 
198 int LCDPrintf(const char *format, ...);
199 int LCDPrintfFont(EYEFONT eyeFont,const char *format, ...);
200 int LCDSetPrintf(int row, int column, const char *format, ...);
201 int LCDSetPrintfFont(int row, int column, EYEFONT eyeFont, const char *format, ...);
202 
203 int LCDSetPos(int row, int column);
204 int LCDGetPos(int *row, int *column);
205 
206 RECT LCDTextBar(int row, int column, int length, int fill, XColor color);
207 
208 int LCDRelease();
209 int LCDRefresh(void);
210 int LCDGetFBInfo(FBINFO* pinfo);
211 int LCDListCount(void);
212 int LCDListIndex(int index);
213 int LCDListScrollUp(void);
214 int LCDListScrollDown(void);
215 
216 //check up on these
217 int LCDPutImageRGB(int xpos, int ypos, int xsize, int ysize, BYTE* data);
218 int LCDPutImageGrey(int xpos, int ypos, int xsize, int ysize, BYTE* data);
219 
220 int LCDPutImageJPG(int xpos, int ypos, int xsize, int ysize, char *path);
221 
222 int LCDImageStart(int t, int x, int y, int xs, int ys); // Define image type, start position and size (default QQVGA; 0,0; full)
223 int LCDImage(BYTE *img); // Print color image at screen start pos. and size
224 int LCDImageGray(BYTE *g); // Print gray image
225 
226 int LCDSetFontRaw(char *fontAlias);
227 int LCDSetFont(int font, int variation);
228 int LCDSetFontSize(int fontsize);
229 
230 int LCDGetSize(int* x, int* y); // Get LCD resolution in pixels
231 
232 #endif /* LCD_H_ */
int LCDArea(int x1, int y1, int x2, int y2, COLOR col, int fill)
A wrapper for LCDAreaRaw.
Definition: lcd.c:623
int LCDTextColor(XColor fgcol, XColor bgcol, char colorflags)
Set the default color for text (including background) and related flags (e.g. for transparent backgro...
Definition: lcd.c:676
int LCDPutImageGrey(int xpos, int ypos, int xsize, int ysize, BYTE *data)
Place a Grey image (24bpp) at (xpos,ypos) position on the LCD screen.
Definition: lcd.c:1782
int LCDSetMode(HWORD mode)
Update the internal mode flag bits.
Definition: lcd.c:364
int LCDFrame(int x1, int y1, int x2, int y2, XColor color)
Draw a color rectangle frame with (x1,y1) as top-left coordinate and (x2,y2) as the bottom-right coor...
Definition: lcd.c:650
Defines types used for the EyeBot 7.
int LCDRect(int x1, int y1, int x2, int y2, COLOR col)
A wrapper for LCDDrawFrame.
Definition: lcd.c:76
int LCDLineRaw(int x1, int y1, int x2, int y2, XColor color)
Draw a color line from (x1,y1) to (x2,y2).
Definition: lcd.c:1277
int LCDDrawFrame(int x1, int y1, int x2, int y2, XColor color)
Draw a bordered frame.
Definition: lcd.c:56
int LCDSetFontSize(int fontsize)
Sets the font size.
Definition: lcd.c:808
int LCDMenuIRaw(int pos, char *string, XColor fgcol, XColor bgcol, void *userp)
Set specific menu entry in KEY_CLASSIC mode (index given by pos). Color customization for specific ke...
Definition: lcd.c:458
int LCDGetFBInfo(FBINFO *pinfo)
Get display information and save to structure pointed by pinfo. Cursor info needs LCDInit() for texts...
Definition: lcd.c:1522
Structure defining the Framebuffer info for the LCD.
Definition: types.h:138
Structure defining a menu item.
Definition: types.h:222
Structure defining a menu.
Definition: types.h:232
int LCDSetPos(int row, int column)
Set the text cursor position to (row, column).
Definition: lcd.c:1085
int LCDList(LIST_MENU *menulist)
Setup the list menu display and update appropriate info in the LIST_MENU structure pointed by menulis...
Definition: lcd.c:516
int LCDImageStart(int t, int x, int y, int xs, int ys)
Sets the parameters for subsequent image draws.
Definition: lcd.c:1811
XColor LCDGetPixel(int x, int y)
Get the RGB color value of the pixel at (x,y) coordinate.
Definition: lcd.c:1156
int LCDPrintf(const char *format,...)
Print formatted string to LCD and refresh LCD. Cursor position is updated.
Definition: lcd.c:896
Header file for global variables.
int LCDSetPixel(int x, int y, XColor color)
Sets the color of the pixel at (x,y) coordinate to color.
Definition: lcd.c:1120
int LCDImageGray(BYTE *g)
Draws a grey image to the LCD.
Definition: lcd.c:1845
int LCDInit()
Initialize the LCD.
Definition: lcd.c:216
int LCDDrawList(void)
Draw the list.
Definition: lcd.c:146
int LCDLine(int x1, int y1, int x2, int y2, COLOR col)
A wrapper for LCDLineRaw.
Definition: lcd.c:1297
Structure defining a LCD fontcolour/name.
Definition: types.h:435
int LCDNeedRefresh(void)
Indicate if the LCD need to be refreshed.
Definition: lcd.c:1400
int LCDLineInvert(int x1, int y1, int x2, int y2)
Draw a line from (x1,y1) to (x2,y2). The line pixels will invert the color of existing pixels...
Definition: lcd.c:1316
int LCDResetMode(HWORD mode)
Reset the internal mode flag bits to a previously saved mode.
Definition: lcd.c:410
int LCDListScrollUp(void)
Scrolls the list display up. Menu index is not altered. If the active menu item goes out of focus...
Definition: lcd.c:1575
int LCDAreaInvert(int x1, int y1, int x2, int y2)
Draw a rectangle with (x1,y1) as top-left coordinate and (x2,y2) as the bottom-right coordinate...
Definition: lcd.c:1341
int LCDCircleInvert(int x1, int y1, int size)
Inverts the pixels inside of the given circle.
Definition: lcd.c:1251
int LCDPixelInvert(int x, int y)
Bit-invert the color of the pixel at (x,y) coordinate.
Definition: lcd.c:1207
int LCDSetFont(int font, int variation)
Sets the font using fontName and variation.
Definition: lcd.c:739
int LCDGetPos(int *row, int *column)
Get the text cursor position.
Definition: lcd.c:1102
int LCDImage(BYTE *img)
Draws a colour (RGB) image to the LCD.
Definition: lcd.c:1830
int LCDListCount(void)
Get the number of list items supported by the current display (text) configuration. This includes the item for title bar - thus, different from count variable in LIST_MENU as updated by an LCDList() call.
Definition: lcd.c:1545
int LCDRefresh(void)
Refresh the screen (i.e write display buffers to the framebuffer device). Refreshes the menu...
Definition: lcd.c:1460
MENU_ITEM * LCDMenuItem(int index)
Return the menuitem at a given position.
Definition: lcd.c:501
int LCDDrawMenu(void)
Draw the menu.
Definition: lcd.c:93
LIST_MENU * LCDGetList(void)
Get the currently active list menu.
Definition: lcd.c:551
int LCDSetPrintfFont(int row, int column, EYEFONT eyeFont, const char *format,...)
LCDPrintf with text position and text colour specified.
Definition: lcd.c:1029
creates lists
int LCDListIndex(int index)
Set the list index.
Definition: lcd.c:1559
MENU_ITEM * LCDListActiveItem(void)
Get the selected menuitem in the list menu – using index & start variable in LIST_MENU. Will return 0x0 (NUL) if no item is currently selected.
Definition: lcd.c:584
int LCDPixel(int x, int y, COLOR col)
A wrapper for LCDSet Pixel.
Definition: lcd.c:1138
int LCDRelease()
Release the LCD.
Definition: lcd.c:1437
int LCDSetFontRaw(char *fontAlias)
Sets the font using alias in Xlib.
Definition: lcd.c:714
int LCDClear(void)
Clear the LCD display and all display buffers ie. turn it black.
Definition: lcd.c:345
RECT LCDTextBar(int row, int column, int length, int fill, XColor color)
Draw a textbar for text starting at position (row, column) until (row, column+length). The textbar will take about 25%-50% of text height & width to draw its frame. The fill parameter will define how much of the text bar should be 'filled' with color (like a progress bar).
Definition: lcd.c:1369
Header file for system functions.
int LCDGetSize(int *x, int *y)
Get LCD resolution in pixels.
Definition: lcd.c:1859
int LCDPutImageRGB(int xpos, int ypos, int xsize, int ysize, BYTE *data)
Place a RGB color image (24bpp) at (xpos,ypos) position on the LCD screen.
Definition: lcd.c:1738
int LCDSetList(LIST_MENU *menulist)
Unlike LCDList(), this will blindly assign menulist to the mainlist for display. Doesn't update anyth...
Definition: lcd.c:535
RECT * LCDListBox(int pos)
Get the frame info of a specific list item in form of a RECT structure.
Definition: lcd.c:565
HWORD LCDGetMode(void)
Get the internal mode flag bits.
Definition: lcd.c:395
Structure representing a rectangle.
Definition: types.h:277
int LCDSetColor(COLOR fg, COLOR bg)
A wrapper for LCDTextColor.
Definition: lcd.c:695
Header file for the key functions.
int LCDPrintfFont(EYEFONT eyeFont, const char *format,...)
Print formatted string to LCD and refresh LCD. Cursor position is updated.
Definition: lcd.c:833
int LCDMenuI(int pos, char *string, COLOR fg, COLOR bg)
A wrapper for LCDMenuIRaw.
Definition: lcd.c:481
int LCDMenu(char *string1, char *string2, char *string3, char *string4)
Set menu entries in KEY_CLASSIC mode (4-buttons). Also sets the LCD_SHOWMENU flag and refresh the LCD...
Definition: lcd.c:430
int LCDAreaRaw(int x1, int y1, int x2, int y2, XColor color)
Draw a color-filled rectangle with (x1,y1) as top-left coordinate and (x2,y2) as the bottom-right coo...
Definition: lcd.c:603
int LCDSetPrintf(int row, int column, const char *format,...)
LCDPrintf with text position specified.
Definition: lcd.c:965
int LCDListScrollDown(void)
Scrolls the list display down. Menu index is not altered. If the active menu item goes out of focus...
Definition: lcd.c:1599
XColor InvertColor(XColor color)
Invert a RGB color.
Definition: lcd.c:1187
XColor getColor(char *colorName)
Return the XColor color from the color name.
Definition: lcd.c:26
int LCDCircle(int x1, int y1, int size, COLOR col, int fill)
Draws a circle.
Definition: lcd.c:1226