From 1f375c0a75fc5a42defd41017ed6fe298f709b2c Mon Sep 17 00:00:00 2001 From: Aurelio Mannara Date: Mon, 25 May 2015 10:29:06 +0200 Subject: [PATCH] Update for latest ctrulib Now the example compiles using the latest ctrulib. It also uses standard C Time library to get date and time --- examples/time/rtc/Makefile | 13 ++++++++----- examples/time/rtc/source/main.c | 31 ++++++++++++++----------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/examples/time/rtc/Makefile b/examples/time/rtc/Makefile index 27830f8..d75f548 100755 --- a/examples/time/rtc/Makefile +++ b/examples/time/rtc/Makefile @@ -32,11 +32,10 @@ SOURCES := source DATA := data INCLUDES := include - #--------------------------------------------------------------------------------- # options for code generation #--------------------------------------------------------------------------------- -ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=softfp +ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard CFLAGS := -g -Wall -O2 -mword-relocations \ -fomit-frame-pointer -ffast-math \ @@ -114,6 +113,10 @@ else export APP_ICON := $(TOPDIR)/$(ICON) endif +ifeq ($(strip $(NO_SMDH)),) + export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh +endif + .PHONY: $(BUILD) clean all #--------------------------------------------------------------------------------- @@ -138,10 +141,10 @@ DEPENDS := $(OFILES:.o=.d) # main targets #--------------------------------------------------------------------------------- ifeq ($(strip $(NO_SMDH)),) -.PHONY: all -all : $(OUTPUT).3dsx $(OUTPUT).smdh -endif +$(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh +else $(OUTPUT).3dsx : $(OUTPUT).elf +endif $(OUTPUT).elf : $(OFILES) #--------------------------------------------------------------------------------- diff --git a/examples/time/rtc/source/main.c b/examples/time/rtc/source/main.c index a766898..6139185 100644 --- a/examples/time/rtc/source/main.c +++ b/examples/time/rtc/source/main.c @@ -14,18 +14,12 @@ #include <3ds.h> #include - -#define SECONDS_IN_DAY 86400 -#define SECONDS_IN_HOUR 3600 -#define SECONDS_IN_MINUTE 60 +#include int main(int argc, char **argv) { // Initialize services - srvInit(); - aptInit(); - gfxInit(); - hidInit(NULL); + gfxInitDefault(); //Initialize console on top screen. Using NULL as the second argument tells the console library to use the internal console structure as current one consoleInit(GFX_TOP, NULL); @@ -44,13 +38,18 @@ int main(int argc, char **argv) if (kDown & KEY_START) break; // break in order to return to hbmenu //Print current time - u64 timeInSeconds = osGetTime() / 1000; - u64 dayTime = timeInSeconds % SECONDS_IN_DAY; - u8 hour = dayTime / SECONDS_IN_HOUR; - u8 min = (dayTime % SECONDS_IN_HOUR) / SECONDS_IN_MINUTE; - u8 seconds = dayTime % SECONDS_IN_MINUTE; + time_t unixTime = time(NULL); + struct tm* timeStruct = gmtime((const time_t *)&unixTime); - printf("\x1b[0;0H%02d:%02d:%02d", hour, min, seconds); + int hours = timeStruct->tm_hour; + int minutes = timeStruct->tm_min; + int seconds = timeStruct->tm_sec; + int day = timeStruct->tm_mday; + int month = timeStruct->tm_mon; + int year = timeStruct->tm_year +1900; + + printf("\x1b[0;0H%02i:%02i:%02i", hours, minutes, seconds); + printf("\x1b[1;0H%02i/%02i/%04i", day, month, year); // Flush and swap framebuffers gfxFlushBuffers(); @@ -62,8 +61,6 @@ int main(int argc, char **argv) // Exit services gfxExit(); - hidExit(); - aptExit(); - srvExit(); + return 0; }