読者です 読者をやめる 読者になる 読者になる

リアルタイムクロックライブラリ。


C標準ライブラリの time ライブラリを
現時間取得に特化させたラッパライブラリです。


日本人なら昭和と平成は外せません。<謎


Rtc library test


プロジェクト一式、ライブラリ&フレームワーク一式


Nitro Developer Style
http://page.freett.com/ntr/


ソース


main.c

/*---------------------------------------------------------------------------------
	
	Rtc library test
	
	version 0.01
	Jun 02, 2010
	
	By REGEKATSU
	
---------------------------------------------------------------------------------*/

#include <stdio.h>
#include <nds.h>
#include "libmy/Rtc.h"


const char *str_wday[] = {
	"Sun", //Sunday
	"Mon", //Monday
	"Tue", //Tuesday
	"Wed", //Wednesday
	"The", //Theursday
	"Fri", //Friday
	"Sat"  //Saturday
};

const char *str_moon[] = {
	"Jan", //January
	"Feb", //February
	"Mar", //March
	"Apr", //April
	"May", //May
	"Jun", //June
	"Jul", //July
	"Aug", //August
	"Sep", //September
	"Oct", //October
	"Nov", //November
	"Dec"  //December
};


void drawRtc(void);


//---------------------------------------------------------------------------------
int main(void){
//---------------------------------------------------------------------------------
	
	consoleDemoInit();
	printf("Rtc library test\n\nversion 0.01\nJun 02, 2010\n\nBy REGEKATSU\n\n\n");
	
	while(1) {
		swiWaitForVBlank();
		drawRtc();
	}
	
}

//---------------------------------------------------------------------------------
void drawRtc(void){
//---------------------------------------------------------------------------------
	
	printf("\x1b[8;0H");
	printf("%2i:%02i:%02i(%s)\n\n", Rtc_GetHour(), Rtc_GetMinute(), Rtc_GetSecond(), str_wday[Rtc_GetWeekDay()]);
	printf("%s %02i, %i\n",  str_moon[Rtc_GetMoon() - 1], Rtc_GetMoonDay(), Rtc_GetYear());
	printf("%s %02i, S%i\n", str_moon[Rtc_GetMoon() - 1], Rtc_GetMoonDay(), Rtc_GetShowa());
	printf("%s %02i, H%i\n", str_moon[Rtc_GetMoon() - 1], Rtc_GetMoonDay(), Rtc_GetHeisei());
	
}

//---------------------------------------------------------------------------------


Rtc.h

/*---------------------------------------------------------------------------------
	
	Rtc library header
	
	version 0.01
	Jun 02, 2010
	
	By REGEKATSU
	
---------------------------------------------------------------------------------*/

#ifndef _RTC_H_
#define _RTC_H_


#ifdef __cplusplus
extern "C" {
#endif


int Rtc_GetSecond(void);
int Rtc_GetMinute(void);
int Rtc_GetHour(void);
int Rtc_GetMoonDay(void);
int Rtc_GetMoon(void);
int Rtc_GetYear(void);
int Rtc_GetShowa(void);
int Rtc_GetHeisei(void);
int Rtc_GetWeekDay(void);
int Rtc_GetYearDay(void);
int Rtc_GetIsDst(void);


#ifdef __cplusplus
}
#endif

#endif	//_RTC_H_


Rtc.c

/*---------------------------------------------------------------------------------
	
	Rtc library routine
	
	version 0.01
	Jun 02, 2010
	
	By REGEKATSU
	
---------------------------------------------------------------------------------*/

#include <time.h>
#include "Rtc.h"


/*
struct tm{
	int tm_sec;     // 秒 (0-60) 60は閏秒用
	int tm_min;     // 分 (0-59)
	int tm_hour;    // 時 (0-23)
	int tm_mday;    // 日 (1-31)
	int tm_mon;     // 月 (0-11)
	int tm_year;    // 年 (年 - 1900)
	int tm_wday;    // 曜日 (0-6)
	int tm_yday;    // 1月1日よりの通し日付
	int tm_isdst;   // 夏時間調整フラグ
};
*/


struct tm *rtc_GetTime(void);


//---------------------------------------------------------------------------------
int Rtc_GetSecond(void){
//---------------------------------------------------------------------------------
	
	struct tm tm;
	
	tm = *rtc_GetTime();
	
	return tm.tm_sec;
	
}

//---------------------------------------------------------------------------------
int Rtc_GetMinute(void){
//---------------------------------------------------------------------------------
	
	struct tm tm;
	
	tm = *rtc_GetTime();
	
	return tm.tm_min;
	
}

//---------------------------------------------------------------------------------
int Rtc_GetHour(void){
//---------------------------------------------------------------------------------
	
	struct tm tm;
	
	tm = *rtc_GetTime();
	
	return tm.tm_hour;
	
}

//---------------------------------------------------------------------------------
int Rtc_GetMoonDay(void){
//---------------------------------------------------------------------------------
	
	struct tm tm;
	
	tm = *rtc_GetTime();
	
	return tm.tm_mday;
	
}

//---------------------------------------------------------------------------------
int Rtc_GetMoon(void){
//---------------------------------------------------------------------------------
	
	struct tm tm;
	
	tm = *rtc_GetTime();
	
	return tm.tm_mon + 1;
	
}

//---------------------------------------------------------------------------------
int Rtc_GetYear(void){
//---------------------------------------------------------------------------------
	
	struct tm tm;
	
	tm = *rtc_GetTime();
	
	return tm.tm_year + 1900;
	
}

//---------------------------------------------------------------------------------
int Rtc_GetShowa(void){
//---------------------------------------------------------------------------------
	
	struct tm tm;
	
	tm = *rtc_GetTime();
	
	return tm.tm_year + 1900 - 1925;
	
}

//---------------------------------------------------------------------------------
int Rtc_GetHeisei(void){
//---------------------------------------------------------------------------------
	
	struct tm tm;
	
	tm = *rtc_GetTime();
	
	return tm.tm_year + 1900 - 1988;
	
}

//---------------------------------------------------------------------------------
int Rtc_GetWeekDay(void){
//---------------------------------------------------------------------------------
	
	struct tm tm;
	
	tm = *rtc_GetTime();
	
	return tm.tm_wday;
	
}

//---------------------------------------------------------------------------------
int Rtc_GetYearDay(void){
//---------------------------------------------------------------------------------
	
	struct tm tm;
	
	tm = *rtc_GetTime();
	
	return tm.tm_yday;
	
}

//---------------------------------------------------------------------------------
int Rtc_GetIsDst(void){
//---------------------------------------------------------------------------------
	
	struct tm tm;
	
	tm = *rtc_GetTime();
	
	return tm.tm_isdst;
	
}

//---------------------------------------------------------------------------------
struct tm* rtc_GetTime(void){
//---------------------------------------------------------------------------------
	
	time_t unix_time;
	
	unix_time = time(NULL);
	
	return gmtime((const time_t *)&unix_time);
	
}

//---------------------------------------------------------------------------------