This repository has been archived by the owner on Aug 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LCD System (MENU IS CURRENTLY BROKEN)
- Loading branch information
Showing
2 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* lcd.h | ||
* Defines a basic LCD library, with support for a little more than PROS provides by default | ||
*/ | ||
|
||
#pragma once | ||
|
||
|
||
namespace lcd { | ||
|
||
void init(); | ||
|
||
// Utility | ||
static const char * centerText(const char * text); | ||
|
||
// Basic writing | ||
void write(int line, char * buffer); | ||
void center(int line, char * buffer); | ||
|
||
// Menu system | ||
void menu(std::vector<std::string> options[16][12], void(*callback)(int choice)); | ||
void menuReset(); | ||
|
||
bool menuActive; | ||
unsigned int menuPoint = 0; | ||
std::vector<std::string> menuOptions[16][12]; | ||
void ( * menuCallback) (int choice); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* lcd.cpp | ||
* Implements a basic LCD library, with support for a little more than PROS provides by default | ||
*/ | ||
|
||
#include "main.h" | ||
#include "includes/lcd.h" | ||
#include "includes/util.h" | ||
#include <stdlib.h> | ||
|
||
|
||
/** | ||
* Runs in the background, to perform LCD actions | ||
*/ | ||
static void lcdTask(void * param) { | ||
|
||
lcdInit(uart1); | ||
lcdSetBacklight(uart1, true); | ||
|
||
// Initalization Message | ||
lcd::center(1, "Initalizing..."); | ||
lcd::center(2, "Please wait"); | ||
|
||
while(true) { | ||
// The state of the buttons is reflected in a bitmask | ||
int buttonMask = lcdReadButtons(uart1); | ||
|
||
// Menu Implementation | ||
if(lcd::menuActive) { | ||
// Control the state of the menu | ||
switch(buttonMask) { | ||
// Go Back | ||
case 0x100: | ||
case 0x101: | ||
case 0x110: | ||
case 0x111: | ||
if (lcd::menuPoint > 0) lcd::menuPoint--; | ||
break; | ||
|
||
// Confirm | ||
case 0x010: | ||
lcd::menuCallback(lcd::menuPoint); | ||
lcd::menuReset(); | ||
break; | ||
|
||
// Go Forward | ||
case 0x001: | ||
case 0x011: | ||
if (lcd::menuPoint < sizeof(lcd::menuOptions)) lcd::menuPoint++; | ||
break; | ||
|
||
default: break; | ||
} | ||
|
||
// Display the current menu state | ||
lcdPrint(uart1, 1, "< %s >", lcd::menuOptions[lcd::menuPoint]); | ||
lcd::center(2, "< ok >"); | ||
} | ||
delay(50); | ||
} | ||
|
||
} | ||
|
||
namespace lcd { | ||
|
||
void init() { | ||
taskCreate(lcdTask, TASK_DEFAULT_STACK_SIZE, NULL, TASK_PRIORITY_DEFAULT); | ||
} | ||
|
||
/** | ||
* Converted from @PixelToast's LCD library | ||
* https://lab.pxtst.com/PixelToast/8762A-2016/ | ||
*/ | ||
static const char * centerText(const char * text) { | ||
static char buffer[17]; | ||
strcpy(buffer, " "); | ||
size_t strsize = strlen(text); | ||
size_t start = 8 - (strsize / 2); | ||
for (size_t i = 0; i < strsize; i++) buffer[start + i] = text[i]; | ||
return buffer; | ||
} | ||
|
||
/** | ||
* Basic write functions to make life easier | ||
*/ | ||
static void write(int line, const char * buffer) { | ||
lcdSetText(uart1, line, buffer); | ||
} | ||
|
||
static void center(int line, const char * buffer) { | ||
lcdSetText(uart1, line, lcd::centerText(buffer)); | ||
} | ||
|
||
|
||
/** | ||
* Menu functions | ||
*/ | ||
void menu(std::vector<std::string> options[] , void(*callback)(int choice)) { | ||
lcd::menuOptions = options; | ||
lcd::menuCallback = callback; | ||
} | ||
|
||
void menuReset() { | ||
lcd::menuActive = false; | ||
lcd::menuPoint = 0; | ||
} | ||
} |