Working backspace and fixed bug with cursor
Before this commit the cursor would be incremented (automatically by hardware) after printing the last character on the line, which would leave it the next line in memory, which doesn't necessarily correspond to the next physical line on the display. This would be corrected when the next character is received but is incorrect behavior; the cursor should always be at where the next character is to inserted. This was due to an off-by-one logical error. This commit solves this bug. Along with the bug fix, keycodes from the serial terminal are now deciphered correctly and the corresponding key or keys are sent to the LCD accordingly. Further work is required with regards to updating the serial console (the connected client) so that their serial console looks exactly like the LCD they are connected to. Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
This commit is contained in:
parent
3a6800a2b0
commit
3d3b9ab5fb
41
lcdLib.c
41
lcdLib.c
@ -200,7 +200,19 @@ void writeCharToLCD(char c) {
|
||||
case '\a': // Alarm
|
||||
break;
|
||||
;
|
||||
case '\b': // Backspace
|
||||
case '\b': // Backspace (non-destructive)
|
||||
if (currentLineChars == 0 && currentLineNum == 0) {
|
||||
// At first line, first column; there is no where to move; do nothing
|
||||
break;
|
||||
} else if (currentLineChars == 0) {
|
||||
// At beginning of line, need to move the end of previous line
|
||||
currentLineChars = LCD_CHARACTERS_PER_LINE - 1;
|
||||
writeLCDInstr(INSTR_DDRAM_ADDR | (lineBeginnings[--currentLineNum] + currentLineChars));
|
||||
} else {
|
||||
// OK, simply go back one character
|
||||
writeLCDInstr(INSTR_DDRAM_ADDR | (lineBeginnings[currentLineNum] + --currentLineChars));
|
||||
}
|
||||
|
||||
break;
|
||||
;
|
||||
case '\r': // Carriage return
|
||||
@ -208,19 +220,24 @@ void writeCharToLCD(char c) {
|
||||
currentLineChars = 0;
|
||||
break;
|
||||
;
|
||||
case '\f': // Form feed
|
||||
clearDisplay();
|
||||
break;
|
||||
;
|
||||
default:
|
||||
if (currentLineChars == LCD_CHARACTERS_PER_LINE) {
|
||||
if (currentLineNum == LCD_NUMBER_OF_LINES - 1) {
|
||||
clearDisplay();
|
||||
} else {
|
||||
writeLCDInstr(INSTR_DDRAM_ADDR | lineBeginnings[++currentLineNum]);
|
||||
currentLineChars = 0;
|
||||
}
|
||||
}
|
||||
if (currentLineChars == LCD_CHARACTERS_PER_LINE - 1 && currentLineNum == LCD_NUMBER_OF_LINES - 1) {
|
||||
clearDisplay();
|
||||
} else if (currentLineChars == LCD_CHARACTERS_PER_LINE - 1) {
|
||||
loop_until_LCD_BF_clear(); // Wait until LCD is ready for new instructions
|
||||
writeCharToLCD_(c);
|
||||
currentLineChars = 0;
|
||||
|
||||
loop_until_LCD_BF_clear(); // Wait until LCD is ready for new instructions
|
||||
writeCharToLCD_(c);
|
||||
currentLineChars++;
|
||||
writeLCDInstr(INSTR_DDRAM_ADDR | lineBeginnings[++currentLineNum]);
|
||||
} else {
|
||||
loop_until_LCD_BF_clear(); // Wait until LCD is ready for new instructions
|
||||
writeCharToLCD_(c);
|
||||
currentLineChars++;
|
||||
}
|
||||
;
|
||||
}
|
||||
}
|
||||
|
17
lcdOutput.c
17
lcdOutput.c
@ -46,8 +46,21 @@ int main(void) {
|
||||
|
||||
while (1) {
|
||||
serialChar = receiveByte();
|
||||
writeCharToLCD(serialChar);
|
||||
transmitByte(serialChar); // Echo character back to serial console
|
||||
|
||||
switch (serialChar) {
|
||||
case '\r':
|
||||
writeStringToLCD("\r\n");
|
||||
break;
|
||||
;
|
||||
case 0x7f: // Backspace (sent as delete)
|
||||
writeStringToLCD("\b \b");
|
||||
break;
|
||||
;
|
||||
default:
|
||||
writeCharToLCD(serialChar);
|
||||
transmitByte(serialChar); // Echo character back to serial console
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user