From 419186a31ca7529b0f962ff683db29e8edaed31a Mon Sep 17 00:00:00 2001 From: James Benton Date: Wed, 30 May 2018 15:15:59 +0100 Subject: [PATCH] samples: Never miss a second again! --- samples/helloworld/main.c | 13 +++++++++---- samples/helloworld_std_thread/CMakeLists.txt | 3 ++- samples/helloworld_std_thread/main.cpp | 13 +++++++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/samples/helloworld/main.c b/samples/helloworld/main.c index c4a89b7f..918f5027 100644 --- a/samples/helloworld/main.c +++ b/samples/helloworld/main.c @@ -9,6 +9,7 @@ int main(int argc, char **argv) { + int last_tm_sec = -1; OSCalendarTime tm; WHBProcInit(); @@ -17,12 +18,16 @@ main(int argc, char **argv) while(WHBProcIsRunning()) { OSTicksToCalendarTime(OSGetTime(), &tm); - WHBLogPrintf("%02d/%02d/%04d %02d:%02d:%02d I'm still here.", - tm.tm_mday, tm.tm_mon, tm.tm_year, - tm.tm_hour, tm.tm_min, tm.tm_sec); + + if (tm.tm_sec != last_tm_sec) { + WHBLogPrintf("%02d/%02d/%04d %02d:%02d:%02d I'm still here.", + tm.tm_mday, tm.tm_mon, tm.tm_year, + tm.tm_hour, tm.tm_min, tm.tm_sec); + last_tm_sec = tm.tm_sec; + } WHBLogConsoleDraw(); - OSSleepTicks(OSMillisecondsToTicks(1000)); + OSSleepTicks(OSMillisecondsToTicks(100)); } WHBLogPrintf("Exiting... good bye."); diff --git a/samples/helloworld_std_thread/CMakeLists.txt b/samples/helloworld_std_thread/CMakeLists.txt index dfe022bd..5409bf66 100644 --- a/samples/helloworld_std_thread/CMakeLists.txt +++ b/samples/helloworld_std_thread/CMakeLists.txt @@ -14,7 +14,8 @@ target_link_libraries(helloworld_std_thread wut_enable_newlib(helloworld_std_thread) wut_enable_stdcpp(helloworld_std_thread) -wut_create_rpx(helloworld_std_thread.rpx helloworld_std_thread) +wut_create_rpx(helloworld_std_thread.rpx + helloworld_std_thread) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/helloworld_std_thread.rpx" DESTINATION "${CMAKE_INSTALL_PREFIX}") diff --git a/samples/helloworld_std_thread/main.cpp b/samples/helloworld_std_thread/main.cpp index 735ea02e..7a5f5077 100644 --- a/samples/helloworld_std_thread/main.cpp +++ b/samples/helloworld_std_thread/main.cpp @@ -11,17 +11,22 @@ int hello_thread() { + int last_tm_sec = -1; WHBLogPrintf("Hello World from a std::thread!"); while(WHBProcIsRunning()) { OSCalendarTime tm; OSTicksToCalendarTime(OSGetTime(), &tm); - WHBLogPrintf("%02d/%02d/%04d %02d:%02d:%02d I'm still here.", - tm.tm_mday, tm.tm_mon, tm.tm_year, - tm.tm_hour, tm.tm_min, tm.tm_sec); + + if (tm.tm_sec != last_tm_sec) { + WHBLogPrintf("%02d/%02d/%04d %02d:%02d:%02d I'm still here.", + tm.tm_mday, tm.tm_mon, tm.tm_year, + tm.tm_hour, tm.tm_min, tm.tm_sec); + last_tm_sec = tm.tm_sec; + } WHBLogConsoleDraw(); - OSSleepTicks(OSMillisecondsToTicks(1000)); + OSSleepTicks(OSMillisecondsToTicks(100)); } WHBLogPrintf("Exiting... good bye.");