From 5d0c4580561ba3c753547a7b38981a935efc27df Mon Sep 17 00:00:00 2001 From: Lauchmelder23 Date: Fri, 20 Nov 2020 13:51:28 +0000 Subject: [PATCH] Added more high-level bindings --- README.md | 49 ++++++++++++++++++++++++++++++++++++++++++----- example/example.c | 4 ++++ raspberrylcd.c | 5 ----- raspberrylcd.h | 8 +++++++- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3957f47..46c46f3 100644 --- a/README.md +++ b/README.md @@ -73,18 +73,22 @@ void sendCommand(LCDScreen* screen, uint8_t command); ``` Sends a command to the LCD screen. If a command takes parameters, you can supply them by bitwise ORing them with the command name: -* `SCREEN_CLEAR` clears the display. Use `clearScreen()` instead (WIP). +* `SCREEN_CLEAR` clears the display. Use `clearScreen()` instead. -* `CURSOR_RETURN` sets the cursor to (0, 0). Use `cursorReturn()` instead (WIP). +* `CURSOR_RETURN` sets the cursor to (0, 0). Use `cursorReturn()` instead. -* `INPUT_SET` sets the writing direction. Use `setWritingDirection()` instead (WIP). +* `INPUT_SET` sets the writing direction. Use `setWritingDirection()` instead. * Either `LEFT_TO_RIGHT` or `RIGHT_TO_LEFT` -* `DISPLAY_SWITCH` can turn the display on/off and change the cursor style +* `DISPLAY_SWITCH` can turn the display on/off and change the cursor style. Use `setDisplaySettings()` instead. * `DISPLAY_ON` / `DISPLAY_OFF` * `CURSOR_ON` / `CURSOR_OFF` * `CURSOR_BLINK` / `CURSOR_STATIC` +* `SHIFT` shifts either the cursor or the entire display. Use `shiftCursor()` or `shiftScreen()` instead. + * `DISPLAY_SHIFT` / `CURSOR_SHIFT` + * `RIGHT_SHIFT` / `LEFT_SHIFT` + * `FUNCTION_SET` if you're using this you're using this library wrong *** @@ -111,6 +115,41 @@ This function sends a variable number of characters to the screen. Use `sendText *** ```c -void setCursor(LCDScreen* screen, uint8_t x, uint8_t y); +void clearScreen(LCDScreen* screen); +``` +This function clears the screen + +*** + +```c +void returnCursor(LCDScreen* screen); +``` +This function sets the cursor position to (0, 0) + +*** + +```c +void setWritingDirection(LCDScreen* screen, direction); +``` +This function sets the writing direction of the display. Can either be `LEFT_TO_RIGHT` or `RIGHT_TO_LEFT`. + +*** + +```c +void shiftCursor(LCDScreen* screen, direction); +``` +This function shifts the cursor in the specified direction. `RIGHT_SHIFT` or `LEFT_SHIFT`. + +*** + +```c +void shiftScreen(LCDScreen* screen, direction); +``` +This function shifts the entire screen in the specified direction. `RIGHT_SHIFT` or `LEFT_SHIFT`. + +*** + +```c +void setCursor(LCDScreen* screen, x, y); ``` This function sets the cursor position on the display. diff --git a/example/example.c b/example/example.c index 21d4440..6ce29f6 100644 --- a/example/example.c +++ b/example/example.c @@ -9,6 +9,10 @@ int main(void) sendText(&screen, "スウェーデン"); setCursor(&screen, 0, 1); sendText(&screen, "オーストラリア"); + shiftScreen(&screen, RIGHT_SHIFT); + shiftScreen(&screen, RIGHT_SHIFT); + shiftScreen(&screen, RIGHT_SHIFT); + setDisplaySettings(&screen, DISPLAY_ON, CURSOR_OFF, CURSOR_STATIC); resetPins(&screen); return 0; diff --git a/raspberrylcd.c b/raspberrylcd.c index 7530e69..5a23983 100644 --- a/raspberrylcd.c +++ b/raspberrylcd.c @@ -244,8 +244,3 @@ void sendChars(LCDScreen* screen, size_t len, ...) va_end(args); } - -void setCursor(LCDScreen* screen, uint8_t x, uint8_t y) -{ - sendCommand(screen, DDRAM_AD_SET | (y << 6) | x); -} \ No newline at end of file diff --git a/raspberrylcd.h b/raspberrylcd.h index e4d7d84..6f2d8d5 100644 --- a/raspberrylcd.h +++ b/raspberrylcd.h @@ -151,6 +151,12 @@ extern void sendData(LCDScreen* screen, uint8_t data); extern void sendText(LCDScreen* screen, const char* text); extern void sendChars(LCDScreen* screen, unsigned int len, ...); -extern void setCursor(LCDScreen* screen, uint8_t x, uint8_t y); +#define clearScreen(screen) sendCommand(screen, SCREEN_CLEAR) +#define returnCursor(screen) sendCommand(screen, CURSOR_RETURN) +#define setWritingDirection(screen, direction) sendCommand(screen, INPUT_SET | direction) +#define setDisplaySettings(screen, display, cursor_shown, cursor_behaviour) sendCommand(screen, DISPLAY_SWITCH | display | cursor_shown | cursor_behaviour) +#define shiftCursor(screen, direction) sendCommand(screen, SHIFT | CURSOR_SHIFT | direction) +#define shiftScreen(screen, direction) sendCommand(screen, SHIFT | DISPLAY_SHIFT | direction) +#define setCursor(screen, x, y) sendCommand(screen, DDRAM_AD_SET | (y << 6) | x) #endif // RASPBERRY_LCD_H \ No newline at end of file