NanoComputer Picture SlideShow Application Reference Design
From NanoComputerWiki
Contents |
Overview
This page contains a simple reference design for a NanoComputer application which displays a slideshow of pictures. The application loads the NanoSlideShow.config file and parses it. The config file should contain a list of filenames of pictures delimited by \r\n. For example
Balloon.pic Bird.pic Cow.pic Landscape.pic
To exit, the application, press and hold any key on the keypad for 2 seconds.
Installation
Hint: You may need to right click on the links below and select "Save As"
NanoComputer Application: NanoSlideShow.ihx
Config File: NanoSlideShow.config
Picture: Balloon.pic
Picture: Bird.pic
Picture: Cow.pic
Picture: Landscape.pic
- Install the NanoSlideShow application onto the NanoComputer
- Upload the NanoSlideShow.config file onto the NanoComputer
- Upload the Balloon.pic file onto the NanoComputer
- Upload the Bird.pic file onto the NanoComputer
- Upload the Cow.pic file onto the NanoComputer
- Upload the Landscape.pic file onto the NanoComputer
Source Code
The source code for the NanoComputer Application is available for download here
The NanoComputer SDK was used to build the NanoComputer application.
Known Issues
None
NanoComputer Application Source Code Listing
// --------------------------------------------------
// Includes
// --------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "NanoComputer.h"
#include "PICTURE.h"
// --------------------------------------------------
// Defines
// --------------------------------------------------
#define E_NO_MORE_DATA -100
// --------------------------------------------------
// Functions
// --------------------------------------------------
char ReadNextLineFromFile(NCFS_FileHandle *FileHandle, long* Offset, char* Buf) {
// Variables
unsigned short chunkSize;
char* pBuf;
char retVal;
// Compute chunkSize
chunkSize = 0x100;
if (chunkSize > (FileHandle->Header.Size - *Offset)) chunkSize = FileHandle->Header.Size - *Offset;
// Read in a chunk
memset(Buf, 0x00, 0x100);
retVal = NCFS_ReadFile(FileHandle, *Offset, chunkSize, Buf);
if (retVal != E_OK) return retVal;
// Replace \r\n with 0x00 if \r\n found
pBuf = strstr(Buf, "\r\n");
if (pBuf) *pBuf = 0x00;
// Increment the offset
*Offset = *Offset + strlen(Buf) + 2;
// Check if no more data
if (*Offset > FileHandle->Header.Size) return E_NO_MORE_DATA;
// Success!
return E_OK;
}
void ShowCaption(char* Caption) {
// Variables
unsigned short lcdHeight;
unsigned short lcdWidth;
// Get the LCD Height and Width
BIOS_GetProp(LCD_PROP_HEIGHT, &lcdHeight);
BIOS_GetProp(LCD_PROP_WIDTH, &lcdWidth);
// Write the Background for the caption
LCD_SetColor(BLACK);
LCD_Rect((lcdWidth - strlen(Caption) * 8) / 2, lcdHeight - 22, (lcdWidth + strlen(Caption) * 8) / 2, lcdHeight - 8);
// Write the caption
LCD_SetColor(WHITE);
LCD_Printf((lcdWidth - strlen(Caption) * 8) / 2, lcdHeight - 20, "%s", Caption);
}
void ShowPicture(char* Filename) {
// Variables
COLOR colorBuf[0x800];
PICTURE_Info pictureInfo;
// Clear the Display and show the caption
LCD_ClearDisplay(LCD_MakeColor(0xF0, 0xF0, 0xF0));
// Get the Picture Info
if (PICTURE_GetInfo(Filename, &pictureInfo) == E_OK) {
// Draw the Picture
PICTURE_DrawEx(&pictureInfo, 0, 0, colorBuf, 0x800);
}
// Show the Caption
ShowCaption(Filename);
}
// --------------------------------------------------
// Main
// --------------------------------------------------
void main() {
// Variables
char buf[0x100];
NCFS_FileHandle filehConfig;
long offset;
// Init by making display landscape mode and clearing it with black color
BIOS_SetPropVal(LCD_PROP_MODE, LCD_MODE_ROTATE_90_DEGREES);
LCD_ClearDisplay(BLACK);
// Main Loop
while (1) {
// Load config file
if (NCFS_GetFileHandle("NanoSlideShow.config", &filehConfig) != E_OK) {
// Error Message
LCD_Printf(10, 10, "Missing config file");
LCD_Printf(10, 20, "'NanoSlideShow.config'");
return;
}
// Loop through the picture file names in the config file
offset = 0;
while (ReadNextLineFromFile(&filehConfig, &offset, buf) == E_OK) {
// Show the Picture
ShowPicture(buf);
// Exit if keypad is pressed
if (KEYPAD_IsPressed(KEYPAD_VOL_DOWN) ||
KEYPAD_IsPressed(KEYPAD_VOL_UP) ||
KEYPAD_IsPressed(KEYPAD_MENU) ||
KEYPAD_IsPressed(KEYPAD_NEXT) ||
KEYPAD_IsPressed(KEYPAD_PREV) ||
KEYPAD_IsPressed(KEYPAD_PLAY)) {
return;
}
}
}
}
Navigation
- Click on any of the links below to navigate to a new page
