NanoComputer LCD Smartie Client Reference Design
From NanoComputerWiki
Contents |
Overview
This page contains a simple reference design for a NanoComputer application which turns the NanoComputer into a LCD display that can be used with the LCD Smartie program. The program is unoptimized and intentionally kept simple so it can be used as a skeleton for developers to base other project off of and is NOT intended to show what a well made NanoComputer application is capapble of.
For more information about LCD Smartie, please see http://lcdsmartie.sourceforge.net/
The sample consists of two parts. The first part is the NanoComputer application which should be installed on the NanoComputer, the second part is the display plugin dll which should be installed in LCD Smartie so it can use the NanoComputer as a client.
A blurry video of the application in actions is shown below. Sorry about the music, forgot to turn off the radio before recording.
Installation
Hint: You may need to right click on the links below and select "Save As"
NanoComputer Application: NanoLCDSmartie.ihx
LCD Smartie Display Plugin DLL: LCDSmartie_NanoComputer_Display_Plugin.dll
- Install the NanoLCDSmartie application onto the NanoComputer
- Install the LCD Smartie program from http://lcdsmartie.sourceforge.net/
- Place the LCDSmartie_NanoComputer_Display_Plugin.dll into the displays subdirectory inside LCD Smartie
- In the Setup screen of LCD Smartie set the display plugin to LCDSmartie_NanoComputer_Display_Plugin.dll
Source Code
The source code for both the display plugin dll and the NanoComputer Application are available for download here
LCDSmartieSampleSourceCode.zip
The NanoComputer SDK was used to build the NanoComputer application.
Visual Studio Express C++ was used to build the plugin. It's available for free from Microsoft.
Known Issues
- The NanoComputer application may not terminate correctly on some PCs when the LCD Smartie program is shutdown. If this happens, please reboot the NanoComputer by unplugging the USB cable and then replugging the USB cable.
NanoComputer Application Source Code Listing
// NanoLCDSmartie.c
// v1.00
// --------------------------------------------------
// Includes
// --------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "NanoComputer.h"
#include "stdlib/sscanf.h"
// --------------------------------------------------
// Defines
// --------------------------------------------------
#define CHAR_WIDTH 7
#define CHAR_HEIGHT 10
// --------------------------------------------------
// Global Variables
// --------------------------------------------------
COLOR gLCD_ForeColor = WHITE;
COLOR gLCD_BackColor = BLACK;
unsigned char gLCD_X = 0;
unsigned char gLCD_Y = 0;
unsigned char gOriginX = 0;
unsigned char gOriginY = 40;
// --------------------------------------------------
// Functions
// --------------------------------------------------
void ProcessCommand(char* CmdBuf) {
// Variables
unsigned short i;
char* pStr;
char pStr2[2];
unsigned short x1, y1, x2;
// SetPositition
if (sscanf(CmdBuf, "SETPOSITION %d %d", &gLCD_X, &gLCD_Y) == 2) {
gLCD_X--;
gLCD_Y--;
}
// Write
if (strncmp(CmdBuf, "WRITE ", 6) == 0) {
// Init the string to draw
pStr = CmdBuf + 6;
// Setup some coordinates
x1 = gOriginX + gLCD_X * CHAR_WIDTH;
y1 = gOriginY + gLCD_Y * CHAR_HEIGHT;
// Print the Text
pStr2[1] = 0x00;
for (i = 0; i < strlen(pStr); i++) {
x2 = x1 + i * CHAR_WIDTH;
if (x2 < (220 - CHAR_WIDTH)) {
// Erase the background
LCD_SetColor(gLCD_BackColor);
LCD_Rect(x2, y1, x2 + CHAR_WIDTH - 1, y1 + CHAR_HEIGHT - 1);
// Print the character
LCD_SetColor(gLCD_ForeColor);
LCD_Printf(x2, y1 + 1, "%c", pStr[i]);
}
}
}
}
// --------------------------------------------------
// Main
// --------------------------------------------------
void main() {
// Variables
char cmdBuf[0x100];
char* pCmdBuf;
char rxBuf[1];
unsigned int rxBufSize;
// Clear the LCD Screen with BLUE Color
LCD_ClearDisplay(BLUE);
// Initialize
pCmdBuf = cmdBuf;
// Main Loop
while (1) {
// Read a byte from the USB
rxBufSize = 1;
USB_RX(rxBuf, &rxBufSize);
if (rxBufSize > 0) {
// Append the new byte to the command buffer
*pCmdBuf = *rxBuf;
// Check if this is a command terminator '\n'
if (*rxBuf == '\n') {
// Terminate pCmdBuf String
*pCmdBuf = 0x00;
// Special command of Quit
if (strcmp(cmdBuf, "QUIT") == 0) {
LCD_ClearDisplay(RED);
return;
}
// Process the command
*pCmdBuf = 0x00;
ProcessCommand(cmdBuf);
// Reset the Command Buffer
pCmdBuf = cmdBuf;
} else {
// Advance the Command Buffer Pointer
pCmdBuf++;
}
}
}
}
Navigation
- Click on any of the links below to navigate to a new page
