added settings support and general cleanup
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* UNO Monitor Receiver (4-bit LCD Version)
|
* UNO Monitor Receiver v.0.1.0 (4-bit LCD Version)
|
||||||
* Kidacro <kidacro@archamedis.net>
|
* Kidacro <kidacro@archamedis.net>
|
||||||
*
|
* https://kidacro.archamedis.net/git/kidacro/Arduino/src/branch/main/uno-stats-monitor
|
||||||
|
* uno_reciever.ino - Arduino Receiver
|
||||||
|
*
|
||||||
* Waits for input over serial connection and displays on LCD & LED
|
* Waits for input over serial connection and displays on LCD & LED
|
||||||
* Receives IR events and reports them over serial connection to a daemon
|
* Receives IR events and reports them over serial connection to a daemon
|
||||||
*
|
*
|
||||||
@@ -10,11 +12,16 @@
|
|||||||
* End char is: '@'
|
* End char is: '@'
|
||||||
* 2nd char denotes which line number/mode to use
|
* 2nd char denotes which line number/mode to use
|
||||||
*
|
*
|
||||||
|
* Setting Schema:
|
||||||
|
* LCDLength:LCDDelay:LEDBrightness:LEDDelay
|
||||||
|
* 16:5:1:3
|
||||||
|
*
|
||||||
* Example:
|
* Example:
|
||||||
* Line 1: #1Archamedis Status@
|
* Line 1: #1Archamedis Status@
|
||||||
* Line 2: #299% free / etc.@
|
* Line 2: #299% free / etc.@
|
||||||
* LAVG 3: #324@
|
* LAVG -: #-24@
|
||||||
*
|
* LSET 0: #016:5:1:3@
|
||||||
|
|
||||||
* Output Schema:
|
* Output Schema:
|
||||||
* Multimedia Controls use single characters to denote which button was pressed
|
* Multimedia Controls use single characters to denote which button was pressed
|
||||||
* P power
|
* P power
|
||||||
@@ -56,7 +63,7 @@
|
|||||||
* LCD R/W pin to ground
|
* LCD R/W pin to ground
|
||||||
* LCD VSS pin to ground
|
* LCD VSS pin to ground
|
||||||
* LCD VCC pin to 5V
|
* LCD VCC pin to 5V
|
||||||
* 10K resistor:
|
* 10K potentiometer:
|
||||||
* ends to +5V and ground
|
* ends to +5V and ground
|
||||||
* wiper to LCD VO pin (pin 3)
|
* wiper to LCD VO pin (pin 3)
|
||||||
*/
|
*/
|
||||||
@@ -78,15 +85,14 @@
|
|||||||
// LCD vars
|
// LCD vars
|
||||||
const int LCDRS = 12, LCDEN = 11, LCDD4 = 5, LCDD5 = 4, LCDD6 = 3, LCDD7 = 2;
|
const int LCDRS = 12, LCDEN = 11, LCDD4 = 5, LCDD5 = 4, LCDD6 = 3, LCDD7 = 2;
|
||||||
int LCDLength = 16;
|
int LCDLength = 16;
|
||||||
int LCDDelay = 5;
|
int LCDDelay = 10;
|
||||||
LiquidCrystal LCD(LCDRS, LCDEN, LCDD4, LCDD5, LCDD6, LCDD7);
|
LiquidCrystal LCD(LCDRS, LCDEN, LCDD4, LCDD5, LCDD6, LCDD7);
|
||||||
|
|
||||||
// LED vars
|
// LED vars
|
||||||
const int LEDIN = 10, LEDCS = 9, LEDCLK = 8;
|
const int LEDIN = 10, LEDCS = 9, LEDCLK = 8;
|
||||||
LedControl LEDlc=LedControl(LEDIN,LEDCLK,LEDCS,1);
|
LedControl LEDlc=LedControl(LEDIN,LEDCLK,LEDCS,1);
|
||||||
int LEDBrightness = 1; // default = 8 / max = 15
|
int LEDBrightness = 8; // default = 8 / max = 15
|
||||||
unsigned long LEDdelaytime1=3;
|
unsigned long LEDDelay=10;
|
||||||
unsigned long LEDdelaytime2=3;
|
|
||||||
|
|
||||||
// IR vars
|
// IR vars
|
||||||
const int IRSIG = 13;
|
const int IRSIG = 13;
|
||||||
@@ -131,27 +137,27 @@ void IRSetup(void)
|
|||||||
Irrecv.enableIRIn();
|
Irrecv.enableIRIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LcdL1(boolean wipe = false)
|
// dynamic lines & character wiping (LCDLength)
|
||||||
|
void LcdLd(int line = 1, boolean wipe = false)
|
||||||
{
|
{
|
||||||
delay(LCDDelay);
|
char myline[LCDLength];
|
||||||
LCD.setCursor(0, 0); // Define the cursor position as the 1st position of the 1st line
|
int x = 0;
|
||||||
|
|
||||||
if(wipe) {
|
// physical line #'s to logical
|
||||||
LcdWrite(" "); // 16 spaces for a blank line
|
if(line > 0) {
|
||||||
LCD.setCursor(0, 0);
|
line--;
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(LCDDelay);
|
delay(LCDDelay);
|
||||||
}
|
LCD.setCursor(0, line); // Define the cursor position as the 1st position of the specified line
|
||||||
|
|
||||||
void LcdL2(boolean wipe = false)
|
|
||||||
{
|
|
||||||
delay(LCDDelay);
|
|
||||||
LCD.setCursor(0, 1); // Define the cursor position as the 1st position of the 2nd line
|
|
||||||
|
|
||||||
if(wipe) {
|
if(wipe) {
|
||||||
LcdWrite(" "); // 16 spaces for a blank line
|
for(x=0;x<LCDLength;x++) {
|
||||||
LCD.setCursor(0, 1);
|
myline[x] = ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
LcdWrite(myline);
|
||||||
|
LCD.setCursor(0, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(LCDDelay);
|
delay(LCDDelay);
|
||||||
@@ -159,10 +165,10 @@ void LcdL2(boolean wipe = false)
|
|||||||
|
|
||||||
void LcdIntro(void)
|
void LcdIntro(void)
|
||||||
{
|
{
|
||||||
// Print a "waiting" message to the LCD.
|
// Print a "intro" message to the LCD.
|
||||||
LcdL1();
|
LcdLd(1);
|
||||||
LCD.print("Starting Up...");
|
LCD.print("UnoMonitor 0.1.0");
|
||||||
LcdL2();
|
LcdLd(2);
|
||||||
LCD.print("Waiting for data");
|
LCD.print("Waiting for data");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,13 +176,13 @@ void LcdCls(void)
|
|||||||
{
|
{
|
||||||
delay(LCDDelay);
|
delay(LCDDelay);
|
||||||
LCD.clear(); // The screen is empty
|
LCD.clear(); // The screen is empty
|
||||||
LcdL1(); // the cursor position is zeroed
|
LcdLd(1); // the cursor position is zeroed
|
||||||
delay(LCDDelay);
|
delay(LCDDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO: returns starting position of text or 0 for 1st position
|
TODO: returns starting position of text or 0 for 1st position
|
||||||
void LcdCenter(int mylen)
|
int LcdCenter(int mylen)
|
||||||
{
|
{
|
||||||
int mypos = 0;
|
int mypos = 0;
|
||||||
|
|
||||||
@@ -206,25 +212,24 @@ void LcdWrite(String mymessage)
|
|||||||
// Output character by character
|
// Output character by character
|
||||||
for(i=0; i < mylen; i++) {
|
for(i=0; i < mylen; i++) {
|
||||||
char c = mymessage[i];
|
char c = mymessage[i];
|
||||||
if(c != '\b') {
|
delay(LCDDelay);
|
||||||
delay(10);
|
|
||||||
LCD.print(c);
|
LCD.print(c);
|
||||||
delay(10);
|
delay(LCDDelay);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: make segment_row & segment_col dynamic and configurable
|
||||||
void LedIntro() {
|
void LedIntro() {
|
||||||
for(int row=0;row<8;row++) {
|
for(int row=0;row<8;row++) {
|
||||||
for(int col=0;col<8;col++) {
|
for(int col=0;col<8;col++) {
|
||||||
delay(LEDdelaytime2);
|
delay(LEDDelay);
|
||||||
LEDlc.setLed(0,row,col,true);
|
LEDlc.setLed(0,row,col,true);
|
||||||
delay(LEDdelaytime2);
|
delay(LEDDelay);
|
||||||
for(int i=0;i<col;i++) {
|
for(int i=0;i<col;i++) {
|
||||||
LEDlc.setLed(0,row,col,false);
|
LEDlc.setLed(0,row,col,false);
|
||||||
delay(LEDdelaytime2);
|
delay(LEDDelay);
|
||||||
LEDlc.setLed(0,row,col,true);
|
LEDlc.setLed(0,row,col,true);
|
||||||
delay(LEDdelaytime2);
|
delay(LEDDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,20 +276,21 @@ void LedShowLoad(const char *load)
|
|||||||
// segments as rows
|
// segments as rows
|
||||||
for(int row=0;row<8;row++) {
|
for(int row=0;row<8;row++) {
|
||||||
for(int col=0;col<segments;col++) {
|
for(int col=0;col<segments;col++) {
|
||||||
delay(LEDdelaytime2);
|
delay(LEDDelay);
|
||||||
LEDlc.setLed(0,row,col,true);
|
LEDlc.setLed(0,row,col,true);
|
||||||
delay(LEDdelaytime2);
|
delay(LEDDelay);
|
||||||
for(int i=0;i<col;i++) {
|
for(int i=0;i<col;i++) {
|
||||||
LEDlc.setLed(0,row,col,false);
|
LEDlc.setLed(0,row,col,false);
|
||||||
delay(LEDdelaytime2);
|
delay(LEDDelay);
|
||||||
LEDlc.setLed(0,row,col,true);
|
LEDlc.setLed(0,row,col,true);
|
||||||
delay(LEDdelaytime2);
|
delay(LEDDelay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// IR translator
|
// IR translator
|
||||||
|
// TODO: read codes from setup program for custom remotes
|
||||||
void IRtranslate()
|
void IRtranslate()
|
||||||
{
|
{
|
||||||
switch(IRresults.value) {
|
switch(IRresults.value) {
|
||||||
@@ -358,42 +364,54 @@ void SERrecv()
|
|||||||
// 1st character denotes function:
|
// 1st character denotes function:
|
||||||
// 1 - print on 1st line as is
|
// 1 - print on 1st line as is
|
||||||
// 2 - print on 2nd line as is
|
// 2 - print on 2nd line as is
|
||||||
// 3 - display load on LCD matrix
|
// - - display load on LCD matrix
|
||||||
// 4 - set a setting
|
// 0 - set a setting
|
||||||
void procNewData()
|
void procNewData()
|
||||||
{
|
{
|
||||||
|
int line = 0;
|
||||||
|
|
||||||
if(SERnewData == true) {
|
if(SERnewData == true) {
|
||||||
if(DEBUG) {
|
if(DEBUG) {
|
||||||
Serial.print("Receiver says: ");
|
Serial.print("Receiver says: ");
|
||||||
Serial.println(SERrecvChars);
|
Serial.println(SERrecvChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chooser
|
// print to given line on LCD
|
||||||
// dev: we have to define 1st character (line number) as BS and when printing, search for that BS character to skip printing that 1 character
|
if(SERrecvChars[0] != '-' && SERrecvChars[0] != '0') {
|
||||||
// print on line 1
|
line = SERrecvChars[0] - '0';
|
||||||
if(SERrecvChars[0] == '1') {
|
LcdLd(line,true);
|
||||||
LcdL1(true);
|
memmove(SERrecvChars, SERrecvChars+1, strlen(SERrecvChars));
|
||||||
SERrecvChars[0] = '\b';
|
|
||||||
LcdWrite(SERrecvChars);
|
LcdWrite(SERrecvChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
// print on line 2
|
// show load on LED matrix
|
||||||
else if(SERrecvChars[0] == '2') {
|
if(SERrecvChars[0] == '-') {
|
||||||
LcdL2(true);
|
memmove(SERrecvChars, SERrecvChars+1, strlen(SERrecvChars));
|
||||||
SERrecvChars[0] = '\b';
|
LedShowLoad(SERrecvChars);
|
||||||
LcdWrite(SERrecvChars);
|
|
||||||
}
|
|
||||||
|
|
||||||
// show load on led matrix
|
|
||||||
else if(SERrecvChars[0] == '3') {
|
|
||||||
SERrecvChars[0] = ' ';
|
|
||||||
LedShowLoad(SERrecvChars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load new settings
|
||||||
|
if(SERrecvChars[0] == '0') {
|
||||||
|
memmove(SERrecvChars, SERrecvChars+1, strlen(SERrecvChars));
|
||||||
|
LoadSettings(SERrecvChars);
|
||||||
|
}
|
||||||
|
|
||||||
SERnewData = false;
|
SERnewData = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LoadSettings(char* mysettings)
|
||||||
|
{
|
||||||
|
// Settings schema:
|
||||||
|
// LCDLength:LCDDelay:LEDBrightness:LEDDelay
|
||||||
|
// 16:5:1:3
|
||||||
|
|
||||||
|
LCDLength = atoi(strtok(mysettings, ":"));
|
||||||
|
LCDDelay = atoi(strtok(NULL, ":"));
|
||||||
|
LEDBrightness = atoi(strtok(NULL, ":"));
|
||||||
|
LEDDelay = atoi(strtok(NULL, ":"));
|
||||||
|
}
|
||||||
|
|
||||||
void setup (void)
|
void setup (void)
|
||||||
{
|
{
|
||||||
// init HW
|
// init HW
|
||||||
@@ -414,8 +432,8 @@ void loop (void)
|
|||||||
{
|
{
|
||||||
// process IR signal
|
// process IR signal
|
||||||
if(Irrecv.decode(&IRresults)) {
|
if(Irrecv.decode(&IRresults)) {
|
||||||
IRtranslate();
|
IRtranslate(); // process result
|
||||||
Irrecv.resume(); // receive the next value
|
Irrecv.resume(); // receive the next command
|
||||||
}
|
}
|
||||||
|
|
||||||
// process serial input
|
// process serial input
|
||||||
|
|||||||
Reference in New Issue
Block a user