Thermal display (closes #99) (#102)

* Display the temperature status. Moved statusGet code from drawNetwork() into drawStatus(). Added types in common.h to fix building with latest libnx nacp.h, with the pc-build.
This commit is contained in:
yellows8 2019-09-17 11:47:58 -04:00 committed by GitHub
parent 42efd240de
commit 793b912efd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 77 additions and 16 deletions

View File

@ -9,7 +9,7 @@ EXTRA_CFLAGS="-D__USE_MINGW_ANSI_STDIO"
EXTRA_LDFLAGS="-lws2_32" EXTRA_LDFLAGS="-lws2_32"
endif endif
test : pc_main/main.cpp pc_main/pc_launch.c pc_main/pc_power.c pc_main/pc_netstatus.c \ test : pc_main/main.cpp pc_main/pc_launch.c pc_main/pc_power.c pc_main/pc_netstatus.c pc_main/pc_thermalstatus.c \
common/menu.c common/font.c common/language.c common/launch.c common/worker.c common/status.c \ common/menu.c common/font.c common/language.c common/launch.c common/worker.c common/status.c \
common/menu-entry.c common/menu-list.c common/message-box.c common/text.c \ common/menu-entry.c common/menu-list.c common/message-box.c common/text.c \
common/ui.c common/assets.c common/math.c common/theme.c \ common/ui.c common/assets.c common/math.c common/theme.c \

View File

@ -23,6 +23,8 @@
typedef uint8_t u8; typedef uint8_t u8;
typedef uint32_t u32; typedef uint32_t u32;
typedef uint64_t u64; typedef uint64_t u64;
typedef int8_t s8;
typedef int32_t s32;
typedef u32 Result; typedef u32 Result;
typedef void (*workerThreadFunc)(void *); typedef void (*workerThreadFunc)(void *);
@ -65,6 +67,7 @@ typedef union {
#include "power.h" #include "power.h"
#include "netloader.h" #include "netloader.h"
#include "netstatus.h" #include "netstatus.h"
#include "thermalstatus.h"
#include "status.h" #include "status.h"
void menuStartupPath(void); void menuStartupPath(void);

View File

@ -487,18 +487,17 @@ void drawCharge() {
} }
} }
void drawNetwork(int tmpX) { void drawNetwork(int tmpX, AssetId id) {
bool netstatusFlag=0; drawIcon(tmpX, 0 + 47 + 10 + 3, 24, 24, assetsGetDataBuffer(id), themeCurrent.textColor);
AssetId id;
if (statusGet(&netstatusFlag, &id)) {
if (netstatusFlag)
drawIcon(tmpX, 0 + 47 + 10 + 3, 24, 24, assetsGetDataBuffer(id), themeCurrent.textColor);
}
} }
u32 drawStatus() { u32 drawStatus() {
bool netstatusFlag=0;
bool temperatureFlag=0;
s32 temperature=0;
AssetId id;
char timeString[9]; char tmpstr[32];
time_t unixTime = time(NULL); time_t unixTime = time(NULL);
struct tm* timeStruct = localtime((const time_t *)&unixTime); struct tm* timeStruct = localtime((const time_t *)&unixTime);
@ -507,14 +506,21 @@ u32 drawStatus() {
int minutes = timeStruct->tm_min; int minutes = timeStruct->tm_min;
int seconds = timeStruct->tm_sec; int seconds = timeStruct->tm_sec;
sprintf(timeString, "%02d:%02d:%02d", hours, minutes, seconds); snprintf(tmpstr, sizeof(tmpstr)-1, "%02d:%02d:%02d", hours, minutes, seconds);
u32 tmpX = GetTextXCoordinate(interuimedium20, 1180, timeString, 'r'); u32 tmpX = GetTextXCoordinate(interuimedium20, 1180, tmpstr, 'r');
DrawText(interuimedium20, tmpX, 0 + 47 + 10, themeCurrent.textColor, timeString); DrawText(interuimedium20, tmpX, 0 + 47 + 10, themeCurrent.textColor, tmpstr);
drawCharge(); drawCharge();
drawNetwork(tmpX);
if (statusGet(&netstatusFlag, &id, &temperatureFlag, &temperature)) {
if (netstatusFlag) drawNetwork(tmpX, id);
if (temperatureFlag) {
snprintf(tmpstr, sizeof(tmpstr)-1, "%.1f°C", ((float)temperature) / 1000);
DrawText(interuiregular14, 1180 + 4, 0 + 47 + 10 + + 21 + 6, themeCurrent.textColor, tmpstr);
}
}
return tmpX; return tmpX;
} }

View File

@ -10,6 +10,8 @@ static bool s_statusExit;
static bool s_statusReady; static bool s_statusReady;
static bool s_statusNetFlag; static bool s_statusNetFlag;
static AssetId s_statusNetAssetId; static AssetId s_statusNetAssetId;
static bool s_statusTemperatureFlag;
static s32 s_statusTemperature;
// This uses netstatusGetDetails from a dedicated thread, since nifmGetInternetConnectionStatus can block for a few seconds. // This uses netstatusGetDetails from a dedicated thread, since nifmGetInternetConnectionStatus can block for a few seconds.
@ -18,8 +20,13 @@ static int statusThreadProc(void* unused)
mtx_lock(&s_statusMtx); mtx_lock(&s_statusMtx);
struct timespec timeout = {0}; struct timespec timeout = {0};
bool tmpflag; bool tmpflag=0;
bool thermalflag=0;
bool thermal_initialized=0;
AssetId tmpid; AssetId tmpid;
s32 temperature;
thermal_initialized = thermalstatusInit();
clock_gettime(CLOCK_MONOTONIC, &timeout); clock_gettime(CLOCK_MONOTONIC, &timeout);
timeout.tv_sec++; timeout.tv_sec++;
@ -32,12 +39,16 @@ static int statusThreadProc(void* unused)
break; break;
tmpflag = netstatusGetDetails(&tmpid); tmpflag = netstatusGetDetails(&tmpid);
if (thermal_initialized) thermalflag = thermalstatusGetDetails(&temperature);
mtx_lock(&s_statusAccessMtx); mtx_lock(&s_statusAccessMtx);
s_statusNetFlag = tmpflag; s_statusNetFlag = tmpflag;
s_statusNetAssetId = tmpid; s_statusNetAssetId = tmpid;
s_statusTemperatureFlag = thermalflag;
s_statusTemperature = temperature;
s_statusReady = 1; s_statusReady = 1;
mtx_unlock(&s_statusAccessMtx); mtx_unlock(&s_statusAccessMtx);
@ -48,10 +59,12 @@ static int statusThreadProc(void* unused)
mtx_unlock(&s_statusMtx); mtx_unlock(&s_statusMtx);
if (thermal_initialized) thermalstatusExit();
return 0; return 0;
} }
bool statusGet(bool *netstatusFlag, AssetId *netstatusAssetId) { bool statusGet(bool *netstatusFlag, AssetId *netstatusAssetId, bool *temperatureFlag, s32 *temperature) {
if (!s_statusReady) return 0; if (!s_statusReady) return 0;
mtx_lock(&s_statusAccessMtx); mtx_lock(&s_statusAccessMtx);
@ -59,6 +72,9 @@ bool statusGet(bool *netstatusFlag, AssetId *netstatusAssetId) {
*netstatusFlag = s_statusNetFlag; *netstatusFlag = s_statusNetFlag;
*netstatusAssetId = s_statusNetAssetId; *netstatusAssetId = s_statusNetAssetId;
*temperatureFlag = s_statusTemperatureFlag;
*temperature = s_statusTemperature;
mtx_unlock(&s_statusAccessMtx); mtx_unlock(&s_statusAccessMtx);
return 1; return 1;

View File

@ -3,5 +3,5 @@
bool statusInit(void); bool statusInit(void);
void statusExit(void); void statusExit(void);
bool statusGet(bool *netstatusFlag, AssetId *netstatusAssetId); bool statusGet(bool *netstatusFlag, AssetId *netstatusAssetId, bool *temperatureFlag, s32 *temperature);

7
common/thermalstatus.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
#include "common.h"
bool thermalstatusInit(void);
void thermalstatusExit(void);
bool thermalstatusGetDetails(s32 *temperature);

View File

@ -0,0 +1,14 @@
#include "../common/common.h"
bool thermalstatusInit(void) {
return R_SUCCEEDED(tsInitialize());
}
void thermalstatusExit(void) {
tsExit();
}
bool thermalstatusGetDetails(s32 *temperature) {
return R_SUCCEEDED(tsGetTemperatureMilliC(TsLocation_Internal, temperature));
}

View File

@ -0,0 +1,15 @@
#include "../common/common.h"
bool thermalstatusInit(void) {
return false;
}
void thermalstatusExit(void) {
}
bool thermalstatusGetDetails(s32 *temperature) {
*temperature = 0;
return false;
}