Gbulmer ... reduced function application code:
/*
Description: uLCD-32PT QVGA Touch --> Maple x-Touch
Author: Hacker
Date: 9/28/10
Time: xxxx
Platform: Win XP SP3
Device: Maple red rev. 3
Maple IDE: 0.0.8 / with x893 systick patch
Additions:
#1. ulcd 5 min screen saver
#2. Added DS3231 RTC
#3. Added time/date to ulcd display
#4. Added 12 touch buttons to ulcd - includes case for code execution
Pending Additions:
When IDE 0.0.7 is released do the following test on com1:
Change speed for display to 256K and change Maple baud to 281K
Works -OK
----------
Status: OK
----------
*/
//---------------------
// Code begin
//---------------------
// Includes / defines
#include <uLCD.h>
#include <colors.h>
#include <Wire.h> // <----- software I2C wire library (alpha) with patch fix
#include <MapleCoOS.h> // <----- CoOS
// General Defines
#define COMM Serial1
#define DIAG Serial2
#define BLUE_LED_PIN 13 // on board blue LED
// MapleCoOS Task Priorities defines
#define Task_2_PRI 10 /* Priority of 'task_2' task. Highest priority Touch Display uLCD Re-Wake 10 */
#define Task_3_PRI 20 /* Priority of 'task_3' task. Higher priority RTC Display 20 */
#define Task_4_PRI 30 /* Priority of 'task_4' task. Lower priority 5 min uLCD Screen Saver 30*/
#define Task_1_PRI 40 /* Priority of 'task_1' task. Lowest priority Touch Screen Processing 40*/
//MapleCoOS Task Size - use default 128
OS_STK Task_1_Stack[TASK_STK_SIZE]; /* Stack of 'task_1' task. */
OS_STK Task_2_Stack[TASK_STK_SIZE]; /* Stack of 'task_2' task. */
OS_STK Task_3_Stack[TASK_STK_SIZE]; /* Stack of 'task_3' task. */
OS_STK Task_4_Stack[TASK_STK_SIZE]; /* Stack of 'task_4' task. */
OS_MutexID mut_uart1; /* Save id of mutex. uLCD */
OS_MutexID mut_uart2; /* Save id of mutex. Diag port */
OS_MutexID mut_soft_I2C; /* Save id of mutex. I2C RTC */
//--------------------------------------------------------------------------------
// MapleCoOS Task Routines
//--------------------------------------------------------------------------------
// Task 1
void task_1(void *pdata) // Get touch co-ordinate and execute switch statement
{
// portait uLCD-32PT(SGC)
ulcd.x_res = 240;
ulcd.y_res = 340;
// ulcd.x_res is the horizontal resolution of the display u are using.
// ulcd.y_res is the vertical resolution of the display u are using.
for (;;)
{
CoSchedLock();
//----------------------------
// Main Button Processing Loop
//----------------------------
toggle ^= 1; // CPU running blue LED
digitalWrite(BLUE_LED_PIN, toggle); // CPU running blue LED
button_Press_Nbr = 0; // reset button number return
get_Touch(); // <--------------<<<< returns button number pressed in global variable "button_Press_Nbr"
ulcd.Text(2, 23, LARGE_FONT, 0xFFFF, " ", 1); // opague
switch (button_Press_Nbr){
case 0:
// do nothing - timeout or no touch button pressed
break;
case 1:
ulcd.Text(2, 23, LARGE_FONT, 0xFFFF, "But 1 Processing", 1); // opague
break;
case 2:
ulcd.Text(2, 23, LARGE_FONT, 0xFFFF, "But 2 Processing", 1); // opague
break;
case 3:
ulcd.Text(2, 23, LARGE_FONT, 0xFFFF, "But 3 Processing", 1); // opague
break;
case 4:
ulcd.Text(2, 23, LARGE_FONT, 0xFFFF, "But 4 Processing", 1); // opague
break;
case 5:
ulcd.Text(2, 23, LARGE_FONT, 0xFFFF, "But 5 Processing", 1); // opague
break;
case 6:
ulcd.Text(2, 23, LARGE_FONT, 0xFFFF, "But 6 Processing", 1); // opague
break;
case 7:
ulcd.Text(2, 23, LARGE_FONT, 0xFFFF, "But 7 Processing", 1); // opague
break;
case 8:
ulcd.Text(2, 23, LARGE_FONT, 0xFFFF, "But 8 Processing", 1); // opague
break;
case 9:
ulcd.Text(2, 23, LARGE_FONT, 0xFFFF, "But 9 Processing", 1); // opague
break;
case 10:
ulcd.Text(2, 23, LARGE_FONT, 0xFFFF, "But 10 Processing", 1); // opague
break;
case 11:
ulcd.Text(2, 23, LARGE_FONT, 0xFFFF, "But 11 Processing", 1); // opague
break;
case 12:
ulcd.Text(2, 23, LARGE_FONT, 0xFFFF, "But 12 Processing", 1); // opague
break;
default:
ulcd.Text(2, 23, LARGE_FONT, 0xFFFF, "But Press Unknown", 1); // opague
// if nothing else matches, do the default
// default is optional
}// end of case
// Display Time Date on ulcd
CoSchedUnlock();
//CoTickDelay(1000); // systick delay? 1ms x 1000 = 1 sec
}
}
// End of Task_1
//--------------------------------------------------------------------------------------
// Task 2
void task_2(void *pdata) // Check touch status to re-awaken from low power mode
{
for (;;)
{
//-------------------------------------------------------------------------
// Touch Scan every second - for LCD display re-awakening from Screen Saver
//-------------------------------------------------------------------------
if ((millis() - startTime_T_Scan) >= interval_T_Scan)
{
CoSchedLock();
get_Touch_Status(); // <--------------<<<<
startTime_T_Scan = millis(); // restart millis timer
CoSchedUnlock();
} // end of millis "if"
CoTickDelay(1000); // systick delay? 1ms x 1000 = 1 sec
}
}
// End of Task_2
//--------------------------------------------------------------------------------------
// Task 3
void task_3(void *pdata) // Get time date from I2C DS3231 and display on uLCD
{
for (;;)
{
// Get Time Date from DS3231 & store in global variables
CoSchedLock();
getDateDS3231(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year); // <----- uses global variables !!!!
// display time date
display_Time_Date();
CoSchedUnlock();
CoTickDelay(1000); // systick delay? 1ms x 1000 = 1 sec
}
}
// End of Task_3
//--------------------------------------------------------------------------------------
// Task 4
void task_4(void *pdata) // Screen Saver 5 min
{
for (;;)
{
//------------------------------
// Blank LCD screen after 5 minutes
//------------------------------
if ((millis() - startTime_Screen_Saver) >= interval_Screen_Saver)
{
CoSchedLock();
ulcd.SetDisplayState (0x00); // display off
ulcd.DisplayControl(0x00, 0x00); // backlight off
CoSchedUnlock();
startTime_Screen_Saver = millis();
ss_Flag = true;
}
CoTickDelay(10000); // systick delay? 1ms x 10000 = 10 sec
}
}
// End of Task_4
//--------------------------------------------------------------------------------------
//----------------------------------------------------------------------
// Setup
//----------------------------------------------------------------------
void setup()
{
DIAG.begin(9600); // Default comport for uLCD display @ 9600
COMM.begin(9600); // Diag comport - for program ack/nak/info
delay(10000); // wait 10 seconds for POR for display and memory card init. Will show splash screen
// move to 3 seconds to skip splash screen
DIAG.println("Check Comm. to 4D Labs Display"); //
ulcd.begin(9600, &COMM); // serial speed 9600
// reset and initialize the display
check_Res(); // check response and print to Diag port
COMM.flush(); // clear serial buffer
delay(100);
DIAG.println("Change or step baud rate up to 256,000 max. baud"); // uLCD does not have autobaud!
ulcd.step_baud_up(); // new baud rate in uLED.cpp (adjustable) set for 256K
delay(100);
check_Res(); // check response
COMM.end(); // end "old" serial comm and restart at the new higher baudrate
COMM.begin(281000); // this value should match the same in uLED.cpp (adjustable) <--- not for 256K !!!!!!! needs 281K
delay(100);
COMM.flush(); // clear serial buffer
//no contrast or brightness control on uLCD <--------------<<<<<<<<<<<<<< ?????????????
//DIAG.println("Set Contrast to 5");
//ulcd.SetContrast(5); // set the contrast of the display to 5 (0 to 15 default (not always) is 8)
//check_Res(); // check response
//delay(500);
DIAG.println("Show Device Display Info");
ulcd.DeviceInfo(); // display some hardware/software info of the screen
COMM.flush(); // clear serial buffer - info also when to the serial port! flush it.
delay(3000); // info will be on screen for 3 seconds
DIAG.println("Clear screen");
ulcd.Cls(); // clears the screen of everything on it. It uses the background color (at this moment it's at default black)
ulcd.Cls(); // keep <---- bug fix - no res without it - needs 2 of them?
check_Res(); // check response
//Set up the LED to blink - for CPU running indicator
pinMode(BLUE_LED_PIN, OUTPUT);
DIAG.println("Redraw display with buttons");
draw_uLCD_Display();
startTime_T_Scan = millis();
delay(10);
startTime_Screen_Saver = millis();
DIAG.println("Turn Touch On");
ulcd.DisplayControl(0x05,0x00); // turn touch on
check_Res(); // check response
DIAG.println("Detect Touch Region"); // The whole screen touch region enabled
ulcd.detect_Touch_Region(0,0,239,319); // whole region <------ modify per application
check_Res(); // check response
DIAG.println("Set Opaque Text");
ulcd.set_Transparent_Opaque_Text(0x01); // Opaque attritube for text mode
check_Res(); // check response
Wire.begin(); // DS3231 I2C pins setup default in cpp >>>-------> I2C- SDA D30 SCL D29
//set_Time_Date(); //<-------------<<<< use once and comment out
delay(1000);
// Initialize / Start RTOS
CoInitOS();
CoCreateTask(task_1, (void *)0, Task_1_PRI, &Task_1_Stack[TASK_STK_SIZE - 1], TASK_STK_SIZE ); //
CoCreateTask(task_2, (void *)0, Task_2_PRI, &Task_2_Stack[TASK_STK_SIZE - 1], TASK_STK_SIZE ); //
CoCreateTask(task_3, (void *)0, Task_3_PRI, &Task_3_Stack[TASK_STK_SIZE - 1], TASK_STK_SIZE ); //
CoCreateTask(task_4, (void *)0, Task_4_PRI, &Task_4_Stack[TASK_STK_SIZE - 1], TASK_STK_SIZE ); //
CoStartOS ();
//------------------------------------------------------------------
} // End of setup
//------------------------------------------------------------------
// the loop() method runs over and over again
void loop()
{
// Do not insert any code here! <-------<<<<<<< !!!!!!
}