From 3cb556acb31cd07b4dbb58f9e04269a03d7bfac1 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 19 Oct 2023 12:40:25 -0700 Subject: [PATCH] ts: update for 17.0.0 --- nx/include/switch/services/ts.h | 13 +++++++++++++ nx/source/services/ts.c | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/nx/include/switch/services/ts.h b/nx/include/switch/services/ts.h index 4f94b5e8..60ccfbfa 100644 --- a/nx/include/switch/services/ts.h +++ b/nx/include/switch/services/ts.h @@ -14,6 +14,15 @@ typedef enum { TsLocation_External = 1, ///< TMP451 External: SoC } TsLocation; +typedef enum { + TsDeviceCode_LocationInternal = 0x41000001u, + TsDeviceCode_LocationExternal = 0x41000002u, +} TsDeviceCode; + +typedef struct { + Service s; +} TsSession; + /// Initialize ts. Result tsInitialize(void); @@ -45,3 +54,7 @@ Result tsGetTemperature(TsLocation location, s32 *temperature); */ Result tsGetTemperatureMilliC(TsLocation location, s32 *temperature); +Result tsOpenSession(TsSession *s, u32 device_code); ///< [8.0.0+] + +Result tsSessionGetTemperature(TsSession *s, float *temperature); ///< [10.0.0+] +void tsSessionClose(TsSession *s); \ No newline at end of file diff --git a/nx/source/services/ts.c b/nx/source/services/ts.c index 3dfca342..715e6aad 100644 --- a/nx/source/services/ts.c +++ b/nx/source/services/ts.c @@ -25,6 +25,9 @@ static Result _tsCmdInU8Out32(u8 inval, u32 *out, u64 cmd_id) { } Result tsGetTemperatureRange(TsLocation location, s32 *min_temperature, s32 *max_temperature) { + if (hosversionAtLeast(17,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + u8 tmp_location = location; struct { @@ -39,6 +42,8 @@ Result tsGetTemperatureRange(TsLocation location, s32 *min_temperature, s32 *max } Result tsGetTemperature(TsLocation location, s32 *temperature) { + if (hosversionAtLeast(17,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); return _tsCmdInU8Out32(location, (u32*)temperature, 1); } @@ -48,3 +53,23 @@ Result tsGetTemperatureMilliC(TsLocation location, s32 *temperature) { return _tsCmdInU8Out32(location, (u32*)temperature, 3); } +Result tsOpenSession(TsSession *s, u32 device_code) { + if (hosversionBefore(8,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchIn(&g_tsSrv, 4, device_code, + .out_num_objects = 1, + .out_objects = &s->s, + ); +} + +Result tsSessionGetTemperature(TsSession *s, float *temperature) { + if (hosversionBefore(10,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + return serviceDispatchOut(&s->s, 4, *temperature); +} + +void tsSessionClose(TsSession *s) { + serviceClose(&s->s); +}