#ifndef TASKWATCH_C
#define TASKWATCH_C
#include "TaskWatch.h"
// Casio Watch - FE10-1A Menu Emulation
int startTaskWatch( xTaskWatchResources *pxResources ){
if( pxResources->xQueueSound == NULL ){
if( NULL == ( pxResources->xQueueSound = xQueueCreate( 5, sizeof( xMessageWatchSound ) ) ) )
return -1;
vQueueAddToRegistry( pxResources->xQueueSound, ( signed portCHAR * )"xQueueWatchSound" );
}
if( pxResources->xQueueKey == NULL ){
if( NULL == ( pxResources->xQueueKey = xQueueCreate( 5, sizeof( xMessageWatchKey ) ) ) )
return -1;
vQueueAddToRegistry( pxResources->xQueueKey, ( signed portCHAR * )"xQueueWatchKey" );
}
if( pxResources->xQueuePrimitive == NULL ){
if( NULL == ( pxResources->xQueuePrimitive = xQueueCreate( 10, sizeof( xMessageWatchPrimitive ) ) ) )
return -1;
vQueueAddToRegistry( pxResources->xQueuePrimitive, ( signed portCHAR * )"xQueueWatchPrimitive" );
}
if( pdPASS != xTaskCreate( vTaskWatch, ( signed portCHAR * ) "Watch", configMINIMAL_STACK_SIZE, pxResources, pxResources->uxPriority, &pxResources->xHandle ) )
return -1;
return 0;
}
void vTaskWatch( void *pvParameters ){
xTaskWatchResources *pxResources;
pxResources = (xTaskWatchResources*)pvParameters;
xMessageWatchKey xMessageKey;
xMessageWatchSound xMessageSound;
xMessageWatchPrimitive xMessagePrimitive;
char text_message[20]; // make sure _sprint no write out of array.
Watch watch1;
int tmp=-1;
int i;
int refresh2 = 0;
WatchConstruct( &watch1 );
vTaskSuspend(NULL);
Qglcd_textArial( 4, 0, "MLS09", 1 );
Qglcd_update();
vTaskDelay(8000);
while(1){
vTaskDelay( 250 );
if( watch1.SIG && watch1.timedate.f.min == 0 && watch1.timedate.f.sec == 0 ){
xMessageSound.reps = 0x5050;
xMessageSound.
time = xTaskGetTickCount
(); xQueueSend( pxResources->xQueueSound, ( void * )&xMessageSound, portMAX_DELAY );
vTaskDelay( 2000 );
}
WatchProcessClock( &watch1 ); // Update clock from RTCC
while( xQueueReceive( pxResources->xQueueKey, &xMessageKey, 0 ) ){
if( 1 == watch1.menu1.state%5 && xMessageKey.key == 3 ){
xMessageSound.reps = 0x5050;
xMessageSound.
time = xTaskGetTickCount
(); xQueueSend( pxResources->xQueueSound, ( void * )&xMessageSound, portMAX_DELAY );
xMessageSound.reps = 0x5050;
xMessageSound.
time = xTaskGetTickCount
(); xQueueSend( pxResources->xQueueSound, ( void * )&xMessageSound, portMAX_DELAY );
}
WatchProcessKey( &watch1, xMessageKey.key ); // insert value to internal FSM
// MenuPrint( Menu *this );
// If you have change a menu redraw.
if( tmp != watch1.menu1.state%5 ){
tmp = watch1.menu1.state%5;
glcd_fillScreen( 0 );
Qglcd_textArial( 15, 0, MenuGetNodeName( &watch1.menu1 ), 1 );
Qglcd_update();
// Delay 4000 Ticks. If Queue received, resume task.
if( xQueuePeek( pxResources->xQueueKey, &xMessageKey, 4000 ) )
continue;
// MenuFunctionsPrint( Menu *this );
// If press "unusable" function key, show "usable" keys.
}else if( watch1.menu1.tree[watch1.menu1.state].connections[xMessageKey.key].pfunction == NULL ){
glcd_fillScreen( 0 );
Qglcd_pixel( 6, 2, 1 );
Qglcd_pixel( 6, 4, 1 );
Qglcd_pixel( 6, 6, 1 );
Qglcd_pixel( 6, 10, 1 );
Qglcd_pixel( 6, 12, 1 );
Qglcd_pixel( 6, 14, 1 );
Qglcd_pixel( 6, 18, 1 );
Qglcd_pixel( 6, 20, 1 );
Qglcd_pixel( 6, 22, 1 );
Qglcd_line( 64, 2, 64, 7, 1 );
Qglcd_line( 64, 10, 64, 15, 1 );
Qglcd_line( 64, 18, 64, 23, 1 );
Qglcd_text57( 10, 3, MenuGetNodeFunctionName( &watch1.menu1, 0 ), 1, 1 );
Qglcd_text57( 10, 10, MenuGetNodeChildName( &watch1.menu1, 1 ), 1, 1 );
Qglcd_text57( 10, 16, MenuGetNodeFunctionName( &watch1.menu1, 2 ), 1, 1 );
Qglcd_text57( 70, 3, MenuGetNodeFunctionName( &watch1.menu1, 3 ), 1, 1 );
Qglcd_text57( 70, 10, MenuGetNodeFunctionName( &watch1.menu1, 4 ), 1, 1 );
Qglcd_text57( 70, 16, MenuGetNodeFunctionName( &watch1.menu1, 5 ), 1, 1 );
Qglcd_update();
// Delay 4000 Ticks. If Queue received, resume task.
if( xQueuePeek( pxResources->xQueueKey, &xMessageKey, 4000 ) )
continue; // Implicit because his position.
}
}
// Show watch status...WatchPrint( Watch *this );
glcd_fillScreen( 0 );
switch( watch1.menu1.state ){
case 0:
case 5+0:
// FORMATO:
// LUNES P 23:59 ALM
// 31-12 23:59 59 SIG
Qglcd_text57( 9, 16, wday_names[ watch1.timedate.f.wday ], 1, 1 );
_sprintf( text_message, "%02x-%02x", watch1.timedate.f.mday, watch1.timedate.f.mon );
Qglcd_text57( 9, 7, text_message, 1, 1 )
if( watch1.PM24 ){
// ...Conver hour to 12 hour format...
int hour = DECtoBCD( BCDtoDEC(watch1.timedate.f.hour)%12 );
_sprintf( text_message, "%2x:%02x", hour, watch1.timedate.f.min );
}else{
_sprintf( text_message, "%02x:%02x", watch1.timedate.f.hour, watch1.timedate.f.min );
}
Qglcd_text57( 38, 7, text_message, 2, 1 );
_sprintf( text_message, "%02x", watch1.timedate.f.sec );
Qglcd_text57( 93, 7, text_message, 1, 1 );
if( watch1.PM24 ){ Qglcd_text57( 32, 14, "P", 1, 1 );}
if( watch1.ALM ){ Qglcd_text57( 108, 16, "ALM", 1, 1 );}
if( watch1.SIG ){ Qglcd_text57( 108, 7, "SIG", 1, 1 );}
Qglcd_update();
vTaskDelay(2000);
break;
case 1:
case 5+1:
// FORMATO:
// ALARM 23:59 ALM
// 23:59 SIG
Qglcd_text57( 9, 16, "ALAR", 1, 1 );
if( watch1.PM24 ){
// ...Conver hour to 12 hour format...
_sprintf( text_message, "%02x:%02x", watch1.alarm.f.hour, watch1.alarm.f.min );
}else{
_sprintf( text_message, "%02x:%02x", watch1.alarm.f.hour, watch1.alarm.f.min );
}
Qglcd_text57( 38, 7, text_message, 2, 1 );
if( watch1.PM24 ){ Qglcd_text57( 32, 14, "P", 1, 1 );}
if( watch1.ALM ){ Qglcd_text57( 108, 16, "ALM", 1, 1 );}
if( watch1.SIG ){ Qglcd_text57( 108, 7, "SIG", 1, 1 );}
Qglcd_update();
vTaskDelay(2000);
break;
case 2:
case 5+2:
// FORMATO:
// ALARM __:__ ALM
// __:__ SIG
Qglcd_text57( 9, 16, "ALAR", 1, 1 );
if( watch1.PM24 ){
// ...Conver hour to 12 hour format...
_sprintf( text_message, "%02x:%02x", watch1.alarm.f.hour, watch1.alarm.f.min );
}else{
_sprintf( text_message, "%02x:%02x", watch1.alarm.f.hour, watch1.alarm.f.min );
}
Qglcd_text57( 38, 7, text_message, 2, 1 );
if( watch1.PM24 ){ Qglcd_text57( 32, 14, "P", 1, 1 );}
if( watch1.ALM ){ Qglcd_text57( 108, 16, "ALM", 1, 1 );}
if( watch1.SIG ){ Qglcd_text57( 108, 7, "SIG", 1, 1 );}
if( (xTaskGetTickCount()/500)%2 ){
switch( watch1.ChangeAlarmCounter ){
case 0: Qglcd_line( 40, 5, 60, 5, 1 ); break;
case 1: Qglcd_line( 70, 5, 90, 5, 1 ); break;
default: break;
}
}
Qglcd_update();
vTaskDelay(2000);
break;
case 3:
case 5+3:
// FORMATO:
// STOP 23:59 SPL
// 23:59 59
Qglcd_text57( 9, 16, "STOP", 1, 1 );
_sprintf( text_message, "%02d:%02d", (int)(watch1.out/3600)%24, (int)(watch1.out/60)%24 );
Qglcd_text57( 38, 7, text_message, 2, 1 )
_sprintf( text_message, "%02d", (int)(watch1.out)%60 );
Qglcd_text57( 93, 7, text_message, 1, 1 );
if( watch1.SPL ){ Qglcd_text57( 92, 14, "SPL", 1, 1 );}
Qglcd_update();
vTaskDelay(2000);
break;
case 4:
case 5+4:
// FORMATO:
// _____ P __:__
// __-__ __:__ __
Qglcd_text57( 9, 16, wday_names[ watch1.timedate.f.wday ], 1, 1 );
_sprintf( text_message, "%02x-%02x", watch1.timedate.f.mday, watch1.timedate.f.mon );
Qglcd_text57( 9, 7, text_message, 1, 1 )
if( watch1.PM24 ){
// ...Conver hour to 12 hour format...
int hour = DECtoBCD( BCDtoDEC(watch1.timedate.f.hour)%12 );
_sprintf( text_message, "%02x:%02x", hour, watch1.timedate.f.min );
}else{
_sprintf( text_message, "%02x:%02x", watch1.timedate.f.hour, watch1.timedate.f.min );
}
Qglcd_text57( 38, 7, text_message, 2, 1 );
_sprintf( text_message, "%02x", watch1.timedate.f.sec );
Qglcd_text57( 93, 7, text_message, 1, 1 );
if( watch1.PM24 ){ Qglcd_text57( 32, 14, "P", 1, 1 );}
if( (xTaskGetTickCount()/500)%2 ){
switch( watch1.ChangeTimeCounter ){
case 0: Qglcd_line( 93, 5, 103, 5, 1 ); break;
case 1: Qglcd_line( 40, 5, 60, 5, 1 ); break;
case 2: Qglcd_line( 70, 5, 90, 5, 1 ); break;
case 3: Qglcd_line( 24, 5, 34, 5, 1 ); break;
case 4: Qglcd_line( 9, 5, 19, 5, 1 ); break;
case 5: Qglcd_line( 9, 15, 34, 15, 1 ); break;
default: break;
}
}
Qglcd_update();
vTaskDelay(2000);
break;
default:
break;
}
}
}
#endif // #ifndef TASKWATCH_H