2015-09-29 06:48:09 +00:00
|
|
|
/**
|
|
|
|
* (C) Copyright Collin J. Doering 2015
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* File: lcdOutput.c
|
|
|
|
* Author: Collin J. Doering <collin.doering@rekahsoft.ca>
|
|
|
|
* Date: Sep 17, 2015
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*---------.
|
|
|
|
| Includes |
|
|
|
|
`---------*/
|
|
|
|
|
|
|
|
#include <avr/io.h>
|
|
|
|
#include <avr/interrupt.h>
|
|
|
|
#include <avr/power.h>
|
|
|
|
#include <util/delay.h>
|
2015-10-19 09:04:53 +00:00
|
|
|
#include <stdlib.h>
|
2015-09-29 06:48:09 +00:00
|
|
|
|
|
|
|
#include "lcdLib.h"
|
Simplify entry of ANSI escape sequences
Use pre-processor macros to allow for simple entry of ANSI escape
sequences.
Many escape sequences don't require all characters in all cases.
Example: Cursor movement (up down, forward and back) all take one
parameter (natural number) that defaults to 1, and can be omitted in
this case. Calling the associated macros with 1 will generate the
correct escape but not the smallest one. Now for these single argument
cases (there are others also) the macro of choice can be used with an
empty argument which will generate the smallest ANSI escape sequence.
Eg, the following are equivalent: CUD() === CUD(1)
Another example is use of CUP (cursor position). It takes two arguments
which both default to 1. Similarly to the CUD example above, CUP(1,1)
generates a valid ANSI escape sequence, just not the smallest one. The
smallest one can be achieved by omitting the arguments to CUP: CUP(,).
For more information on ANSI escapes see wikipedia:
https://en.wikipedia.org/wiki/ANSI_escape_code
This is just an initial proof of concept and is not complete;
namely:
- Not all ANSI escapes are implemented
- Macros don't error check for the user; that is, invalid escapes can be
generated (Eg. the argument to ED is constrained to 0, 1, or 2 but
this is not checked by the ED macro)
- Macro's can generate invalid ANSI escapes when the argument that's
given is not a natural number (specified as ASCII)
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-09 05:35:47 +00:00
|
|
|
#include "ansi_escapes.h"
|
2015-10-06 08:23:40 +00:00
|
|
|
#include "USART.h"
|
|
|
|
|
2015-10-15 09:39:07 +00:00
|
|
|
#define STATUS_LED_PORT PORTC
|
|
|
|
#define STATUS_LED_DDR DDRC
|
|
|
|
#define STATUS_LED PC5
|
|
|
|
|
2015-10-19 09:04:53 +00:00
|
|
|
//--------------------------------------------------
|
|
|
|
|
2015-10-15 09:39:07 +00:00
|
|
|
void flashLED(uint8_t times) {
|
|
|
|
while (times > 0) {
|
|
|
|
STATUS_LED_PORT |= 1 << STATUS_LED; // turn on status LED
|
|
|
|
_delay_ms(100);
|
|
|
|
STATUS_LED_PORT &= ~(1 << STATUS_LED); // turn status LED off
|
|
|
|
_delay_ms(100);
|
|
|
|
times--;
|
|
|
|
}
|
|
|
|
}
|
2015-10-19 09:04:53 +00:00
|
|
|
|
2015-10-22 04:44:47 +00:00
|
|
|
//--------------------------------------------------
|
2015-10-15 09:39:07 +00:00
|
|
|
|
2015-09-29 06:48:09 +00:00
|
|
|
int main(void) {
|
|
|
|
clock_prescale_set(clock_div_1);
|
|
|
|
|
|
|
|
STATUS_LED_DDR |= 1 << STATUS_LED; // DEBUG
|
|
|
|
|
2015-10-06 08:23:40 +00:00
|
|
|
initUSART();
|
|
|
|
char serialChar;
|
2015-09-29 10:06:37 +00:00
|
|
|
|
2015-09-29 06:48:09 +00:00
|
|
|
initLCD();
|
2015-09-29 10:06:37 +00:00
|
|
|
//initLCDByInternalReset();
|
2015-10-15 09:39:07 +00:00
|
|
|
flashLED(5); // DEBUG
|
2015-10-06 08:23:40 +00:00
|
|
|
|
2015-09-29 06:48:09 +00:00
|
|
|
while (1) {
|
2015-10-06 08:23:40 +00:00
|
|
|
serialChar = receiveByte();
|
2015-10-08 02:38:57 +00:00
|
|
|
|
|
|
|
switch (serialChar) {
|
|
|
|
case '\r':
|
|
|
|
writeStringToLCD("\r\n");
|
Simplify entry of ANSI escape sequences
Use pre-processor macros to allow for simple entry of ANSI escape
sequences.
Many escape sequences don't require all characters in all cases.
Example: Cursor movement (up down, forward and back) all take one
parameter (natural number) that defaults to 1, and can be omitted in
this case. Calling the associated macros with 1 will generate the
correct escape but not the smallest one. Now for these single argument
cases (there are others also) the macro of choice can be used with an
empty argument which will generate the smallest ANSI escape sequence.
Eg, the following are equivalent: CUD() === CUD(1)
Another example is use of CUP (cursor position). It takes two arguments
which both default to 1. Similarly to the CUD example above, CUP(1,1)
generates a valid ANSI escape sequence, just not the smallest one. The
smallest one can be achieved by omitting the arguments to CUP: CUP(,).
For more information on ANSI escapes see wikipedia:
https://en.wikipedia.org/wiki/ANSI_escape_code
This is just an initial proof of concept and is not complete;
namely:
- Not all ANSI escapes are implemented
- Macros don't error check for the user; that is, invalid escapes can be
generated (Eg. the argument to ED is constrained to 0, 1, or 2 but
this is not checked by the ED macro)
- Macro's can generate invalid ANSI escapes when the argument that's
given is not a natural number (specified as ASCII)
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-09 05:35:47 +00:00
|
|
|
transmitString("\n" CNL(1) "\r");
|
2015-10-08 07:15:25 +00:00
|
|
|
break;
|
|
|
|
case '\f':
|
|
|
|
writeCharToLCD(serialChar);
|
Simplify entry of ANSI escape sequences
Use pre-processor macros to allow for simple entry of ANSI escape
sequences.
Many escape sequences don't require all characters in all cases.
Example: Cursor movement (up down, forward and back) all take one
parameter (natural number) that defaults to 1, and can be omitted in
this case. Calling the associated macros with 1 will generate the
correct escape but not the smallest one. Now for these single argument
cases (there are others also) the macro of choice can be used with an
empty argument which will generate the smallest ANSI escape sequence.
Eg, the following are equivalent: CUD() === CUD(1)
Another example is use of CUP (cursor position). It takes two arguments
which both default to 1. Similarly to the CUD example above, CUP(1,1)
generates a valid ANSI escape sequence, just not the smallest one. The
smallest one can be achieved by omitting the arguments to CUP: CUP(,).
For more information on ANSI escapes see wikipedia:
https://en.wikipedia.org/wiki/ANSI_escape_code
This is just an initial proof of concept and is not complete;
namely:
- Not all ANSI escapes are implemented
- Macros don't error check for the user; that is, invalid escapes can be
generated (Eg. the argument to ED is constrained to 0, 1, or 2 but
this is not checked by the ED macro)
- Macro's can generate invalid ANSI escapes when the argument that's
given is not a natural number (specified as ASCII)
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-09 05:35:47 +00:00
|
|
|
transmitString(ED(2) CUP(1,1));
|
2015-10-08 02:38:57 +00:00
|
|
|
break;
|
|
|
|
case 0x7f: // Backspace (sent as delete)
|
|
|
|
writeStringToLCD("\b \b");
|
Simplify entry of ANSI escape sequences
Use pre-processor macros to allow for simple entry of ANSI escape
sequences.
Many escape sequences don't require all characters in all cases.
Example: Cursor movement (up down, forward and back) all take one
parameter (natural number) that defaults to 1, and can be omitted in
this case. Calling the associated macros with 1 will generate the
correct escape but not the smallest one. Now for these single argument
cases (there are others also) the macro of choice can be used with an
empty argument which will generate the smallest ANSI escape sequence.
Eg, the following are equivalent: CUD() === CUD(1)
Another example is use of CUP (cursor position). It takes two arguments
which both default to 1. Similarly to the CUD example above, CUP(1,1)
generates a valid ANSI escape sequence, just not the smallest one. The
smallest one can be achieved by omitting the arguments to CUP: CUP(,).
For more information on ANSI escapes see wikipedia:
https://en.wikipedia.org/wiki/ANSI_escape_code
This is just an initial proof of concept and is not complete;
namely:
- Not all ANSI escapes are implemented
- Macros don't error check for the user; that is, invalid escapes can be
generated (Eg. the argument to ED is constrained to 0, 1, or 2 but
this is not checked by the ED macro)
- Macro's can generate invalid ANSI escapes when the argument that's
given is not a natural number (specified as ASCII)
Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
2015-10-09 05:35:47 +00:00
|
|
|
transmitString(CUB(1) " " CUB(1));
|
2015-10-08 02:38:57 +00:00
|
|
|
break;
|
2015-10-20 09:21:03 +00:00
|
|
|
case '\e': // Beginning of ANSI escape
|
|
|
|
{
|
|
|
|
char j = receiveByte();
|
|
|
|
|
|
|
|
if (j == '[') {
|
2015-10-22 04:29:08 +00:00
|
|
|
char buf[11] = "\e[";
|
|
|
|
for (uint8_t i = 2, j = receiveByte(); i < 10 && j > 0x20 && j < 0x7e; i++, j = receiveByte()) {
|
2015-10-20 09:21:03 +00:00
|
|
|
buf[i] = j;
|
|
|
|
if (j > 0x40 && j < 0x7e) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
writeStringToLCD(buf);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-10-08 02:38:57 +00:00
|
|
|
default:
|
|
|
|
writeCharToLCD(serialChar);
|
|
|
|
transmitByte(serialChar); // Echo character back to serial console
|
|
|
|
}
|
2015-09-29 06:48:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|