Fix folder structure
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
|
||||
char customCharArray[64] = {
|
||||
0b00000,0b01000,0b11111,0b01000,0b00010,0b11111,0b00010,0b00000, //Web sync true
|
||||
0b00000,0b00100,0b01110,0b00000,0b00000,0b01110,0b00100,0b00000, //Up Down
|
||||
0b00100,0b01110,0b01110,0b01110,0b11111,0b00000,0b00100,0b00000, //Alarm Clock
|
||||
0b00000,0b00100,0b01101,0b11101,0b01101,0b00100,0b00000,0b00000, //Volume ON
|
||||
0b00000,0b00100,0b01100,0b11100,0b01100,0b00100,0b00000,0b00000, //Volume OFF
|
||||
0b00000,0b00001,0b00011,0b00111,0b01111,0b11111,0b00000,0b00000, //Network TRUE
|
||||
0b00000,0b01000,0b01100,0b01110,0b01100,0b01000,0b00000,0b00000, //PLAY
|
||||
0b00000,0b01110,0b10101,0b10111,0b10001,0b01110,0b00000,0b00000 //Time Sync TRUE
|
||||
};
|
||||
|
||||
|
||||
void LcdClear()
|
||||
{
|
||||
LcdWriteByte(WRITE_COMMAND, 0x01); // display clear
|
||||
NutDelay(5);
|
||||
LcdWriteByte(WRITE_COMMAND, 0x80); // DD-RAM address counter (cursor pos) to '0'
|
||||
}
|
||||
|
||||
void LcdLine(u_char line, char text[])
|
||||
{
|
||||
int i;
|
||||
|
||||
if(line == 0) //Top line
|
||||
{
|
||||
LcdWriteByte(WRITE_COMMAND, 0x80); // command to write to line 1
|
||||
for(i = 0; i< 16; i++)
|
||||
{
|
||||
LcdChar(32); //Clear the line
|
||||
}
|
||||
LcdWriteByte(WRITE_COMMAND, 0x80); // command to write to line 1
|
||||
}
|
||||
else if(line == 1) //Bottom line
|
||||
{
|
||||
LcdWriteByte(WRITE_COMMAND, 0xC0); // command to write to line 2
|
||||
for(i = 0; i< 16; i++)
|
||||
{
|
||||
LcdChar(32); //Clear the line
|
||||
}
|
||||
LcdWriteByte(WRITE_COMMAND, 0xC0); // command to write to line 1
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
|
||||
while(text[count] != '\0')
|
||||
{
|
||||
//Replace ~n with the decimal n
|
||||
//This displays the custom character
|
||||
if(text[count] == '~')
|
||||
{
|
||||
count++;
|
||||
char num = text[count];
|
||||
|
||||
int number = num - '0';
|
||||
|
||||
LcdWriteByte(WRITE_DATA, number);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Write char to display
|
||||
LcdChar(text[count]);
|
||||
}
|
||||
|
||||
count++;
|
||||
|
||||
if(count > 24)
|
||||
break;
|
||||
|
||||
NutSleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
void LcdScrollLine(u_char line, int pos, char text[])
|
||||
{
|
||||
int i;
|
||||
|
||||
if(line == 0)
|
||||
{
|
||||
LcdWriteByte(WRITE_COMMAND, 0x80); // command to write to line 1
|
||||
for(i = 0; i< 16; i++)
|
||||
{
|
||||
LcdChar(32);
|
||||
}
|
||||
LcdWriteByte(WRITE_COMMAND, 0x80); // command to write to line 1
|
||||
}
|
||||
else if(line == 1)
|
||||
{
|
||||
LcdWriteByte(WRITE_COMMAND, 0xC0); // command to write to line 2
|
||||
for(i = 0; i< 16; i++)
|
||||
{
|
||||
LcdChar(32);
|
||||
}
|
||||
LcdWriteByte(WRITE_COMMAND, 0xC0); // command to write to line 1
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//Start at scroll location
|
||||
int count = pos;
|
||||
|
||||
while(text[count] != '\0')
|
||||
{
|
||||
if(text[count] == '~')
|
||||
{
|
||||
count++;
|
||||
char num = text[count];
|
||||
|
||||
int number = num - '0';
|
||||
|
||||
LcdWriteByte(WRITE_DATA, number);
|
||||
}
|
||||
else
|
||||
{
|
||||
LcdChar(text[count]);
|
||||
}
|
||||
|
||||
count++;
|
||||
|
||||
if(count > 24 + pos)
|
||||
break;
|
||||
|
||||
NutSleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
//Write data to the Custom Character RAM
|
||||
void LcdCGRAM(char *icon, int length)
|
||||
{
|
||||
//SELECT CGRAM
|
||||
LcdWriteByte(WRITE_COMMAND, 0x40);
|
||||
|
||||
int count;
|
||||
|
||||
//Write the array with custom icons
|
||||
for(count = 0; count < length; count++)
|
||||
{
|
||||
LcdChar(icon[count]);
|
||||
NutSleep(1);
|
||||
}
|
||||
|
||||
//Select the display RAM
|
||||
LcdWriteByte(WRITE_COMMAND, 0x80);
|
||||
}
|
||||
|
||||
void LcdSetPosition(int line)
|
||||
{
|
||||
if(line)
|
||||
{
|
||||
LcdWriteByte(WRITE_COMMAND, 0xC0);
|
||||
}
|
||||
else
|
||||
{
|
||||
LcdWriteByte(WRITE_COMMAND, 0x80);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
#ifndef _Display_H
|
||||
#define _Display_H
|
||||
|
||||
extern void LcdSetPosition(int);
|
||||
extern void LcdLine(u_char line, char text[]);
|
||||
extern void LcdScrollLine(u_char line, int pos, char text[]);
|
||||
extern void LcdClear(void);
|
||||
|
||||
#endif
|
||||
+2522
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,48 @@
|
||||
#ifndef MENU_INCLUDE
|
||||
#define MENU_INCLUDE
|
||||
|
||||
/* Defines */
|
||||
#define BL_SWITCH_OFF_DELAY 100 // lcd back-light switches of 10 sec after idle
|
||||
#define MAX_MENU_KEY 4
|
||||
#define LCD_MAX_LINES 2
|
||||
/* Exported functions */
|
||||
void handleMenu(void);
|
||||
void InitMenu(void);
|
||||
void navigateToMenu(unsigned int);
|
||||
|
||||
void AlarmStartedRinging(void);
|
||||
void AlarmStoppedRinging(void);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int menuID; /* (Uniek) MenuID */
|
||||
|
||||
//Navigating
|
||||
void (*fp_onEntry)(void); /* On entry function call */
|
||||
void (*fp_onActive)(void); //On active function call
|
||||
void (*fp_onExit)(void); /* On exit function call */
|
||||
|
||||
//Key events
|
||||
void (*fp_onKeyESC)(void); /* function call for key's */
|
||||
void (*fp_onKeyUP)(void);
|
||||
void (*fp_onKeyDOWN)(void);
|
||||
void (*fp_onKeyLEFT)(void);
|
||||
void (*fp_onKeyRIGHT)(void);
|
||||
void (*fp_onKeyOK)(void);
|
||||
void (*fp_onKeyONE)(void);
|
||||
void (*fp_onKeyTWO)(void);
|
||||
void (*fp_onKeyTHREE)(void);
|
||||
void (*fp_onKeyFOUR)(void);
|
||||
void (*fp_onKeyFIVE)(void);
|
||||
void (*fp_onKeyALT)(void);
|
||||
|
||||
//Quick navigating
|
||||
unsigned int newMenuIdKey[MAX_MENU_KEY]; /* New menuId when key pressed */
|
||||
|
||||
//Text and other data
|
||||
char *txt[LCD_MAX_LINES]; /* LCD_MAX_LINES lines of LCD text (or NULL) */
|
||||
|
||||
} MENU_ITEM_STRUCT;
|
||||
|
||||
#endif
|
||||
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
/* ========================================================================
|
||||
* [PROJECT] SIR
|
||||
* [MODULE] Real Time Clock
|
||||
* [TITLE] High- and low level Routines for INtersil X1205 RTC chip
|
||||
* [FILE] rtc.c
|
||||
* [VSN] 1.0
|
||||
* [CREATED] 13042007
|
||||
* [LASTCHNGD] 131042007
|
||||
* [COPYRIGHT] Copyright (C) STREAMIT BV 2010
|
||||
* [PURPOSE] contains all interface- and low-level routines to
|
||||
* read/write date/time/status strings from the X1205
|
||||
* ======================================================================== */
|
||||
|
||||
#define LOG_MODULE LOG_RTC_MODULE
|
||||
|
||||
#include <cfg/os.h>
|
||||
#include <dev/twif.h>
|
||||
#include <sys/event.h>
|
||||
#include <sys/timer.h>
|
||||
#include <sys/thread.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <net/route.h>
|
||||
#include <pro/dhcp.h>
|
||||
#include <pro/sntp.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <io.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "rtc.h"
|
||||
#include "portio.h"
|
||||
|
||||
//Timezones with offset value and name
|
||||
const int tz[25] = { -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10, +11, +12, +13};
|
||||
const char tzName[25][30] = { "Midway", "Honolulu", "Anchorage", "Los Angeles", "Phoenix", "Chicago", "New York", "Santiago", "Buenos Aires", "South-Georgia", "Azores", "London", "Amsterdam", "Athens", "Moscow", "Dubai", "Pakistan", "Bangladesh", "Bangkok", "Bejing", "Tokyo", "Sydney", "Solomon", "Auckland", "Samoa" };
|
||||
|
||||
|
||||
//Sync the RTC with NTP server and apply timezone offset
|
||||
int X12RTCSyncClock(void)
|
||||
{
|
||||
time_t cur_time = 0;
|
||||
tm *cur_dt = malloc(sizeof(tm));
|
||||
|
||||
uint32_t timeserver = 0;
|
||||
|
||||
timeserver = inet_addr("85.254.217.3");
|
||||
|
||||
int i;
|
||||
//3 attempts are allowed before giving up
|
||||
for (i = 0; i < 3; i++) {
|
||||
|
||||
//Try to get the NTP time
|
||||
if (NutSNTPGetTime(×erver, &cur_time) == 0) {
|
||||
synced = 1; //Mark time as synced
|
||||
|
||||
printf("[RTC] Sync Succesfull\n");
|
||||
|
||||
//TimeZone
|
||||
_timezone = 0;
|
||||
stime(&cur_time);
|
||||
|
||||
_timezone = -GetTimeZone() * 60 * 60; //Apply timezone offset
|
||||
_daylight = 1;
|
||||
time(&cur_time);
|
||||
cur_dt = localtime(&cur_time); //Calculate timezone offset
|
||||
|
||||
X12RtcSetClock(cur_dt); //Set the new time in the RTC
|
||||
break;
|
||||
} else {
|
||||
synced = 0; //Mark time as out of sync
|
||||
NutSleep(500);
|
||||
printf("[RTC] Sync Failed, retrying\n");
|
||||
}
|
||||
}
|
||||
|
||||
free(cur_dt);
|
||||
|
||||
SetConnected(synced); //Mark network connections the same as synced value
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//Format the RTC value to a Time string
|
||||
void GetTimeString(char * str)
|
||||
{
|
||||
if (X12RtcGetClock(&gmt) == 0)
|
||||
{
|
||||
gmt.tm_year = gmt.tm_year + 1900;
|
||||
sprintf(str, "%02d:%02d:%02d", gmt.tm_hour, gmt.tm_min, gmt.tm_sec);
|
||||
}
|
||||
}
|
||||
|
||||
//Format the RTC value to a Date string
|
||||
void GetDateString(char * str)
|
||||
{
|
||||
if (X12RtcGetClock(&gmt) == 0)
|
||||
{
|
||||
gmt.tm_year = gmt.tm_year + 1900;
|
||||
sprintf(str, "%02d-%02d-%04d", gmt.tm_mday, gmt.tm_mon+1, gmt.tm_year );
|
||||
}
|
||||
}
|
||||
|
||||
//Format the RTC value to a DateTime string
|
||||
void GetDateTimeString(char * str)
|
||||
{
|
||||
if (X12RtcGetClock(&gmt) == 0)
|
||||
{
|
||||
gmt.tm_year = gmt.tm_year + 1900;
|
||||
sprintf(str, "%02d:%02d %02d-%02d-%04d", gmt.tm_hour, gmt.tm_min, gmt.tm_mday, gmt.tm_mon+1, gmt.tm_year );
|
||||
}
|
||||
}
|
||||
|
||||
//Get the time struct which is synced using the RTC and NTP
|
||||
tm* GetTimeStruct(void)
|
||||
{
|
||||
if (X12RtcGetClock(&gmt) == 0)
|
||||
{
|
||||
gmt.tm_year = gmt.tm_year + 1900;
|
||||
}
|
||||
|
||||
return &gmt;
|
||||
}
|
||||
|
||||
//Sync time with the NTP server
|
||||
int SyncTime( void )
|
||||
{
|
||||
X12RTCSyncClock();
|
||||
|
||||
if (X12RtcGetClock(&gmt) == 0)
|
||||
{
|
||||
//X12RtcGetClockTimezone(&gmt, GetTimeZone());
|
||||
gmt.tm_year = gmt.tm_year + 1900;
|
||||
printf("[RTC] Time [%02d:%02d:%02d / %02d-%02d-%04d]\n", gmt.tm_hour, gmt.tm_min, gmt.tm_sec, gmt.tm_mday, gmt.tm_mon+1, gmt.tm_year );
|
||||
}
|
||||
|
||||
return synced;
|
||||
}
|
||||
|
||||
int GetTimeSynced(void)
|
||||
{
|
||||
return synced;
|
||||
}
|
||||
|
||||
int GetTimeZoneValue(int i)
|
||||
{
|
||||
return tz[i];
|
||||
}
|
||||
|
||||
void GetTimeZoneName(int i, char * string)
|
||||
{
|
||||
strcpy(string, tzName[i]);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef _RTC_H_
|
||||
#define _RTC_H_
|
||||
|
||||
#include <time.h> // for tm-struct
|
||||
|
||||
tm gmt;
|
||||
int synced;
|
||||
|
||||
extern void GetDateString(char*);
|
||||
extern void GetDateTimeString(char*);
|
||||
extern void GetTimeString(char*);
|
||||
extern tm* GetTimeStruct(void);
|
||||
extern int SyncTime( void );
|
||||
extern int GetTimeSynced( void );
|
||||
|
||||
extern int GetTimeZoneValue(int);
|
||||
extern void GetTimeZoneName(int, char *);
|
||||
|
||||
/* Prototypes */
|
||||
extern int X12Init(void);
|
||||
|
||||
extern int X12RtcGetClock(tm *tm);
|
||||
extern int X12RtcSetClock(CONST tm *tm);
|
||||
extern int X12RtcSyncClock(void);
|
||||
extern int X12RtcWrite(int nv, CONST u_char *buff, size_t len);
|
||||
|
||||
/* End of prototypes */
|
||||
#endif
|
||||
Reference in New Issue
Block a user