[Switch] Expose SoC and PCB temperature to scripts - #26
Open
ferrolho wants to merge 1 commit into
Open
Conversation
There was no way to read the console's thermal sensors from a project, which makes diagnosing a suspected overheat impossible after the fact. Adds NintendoSwitch.get_soc_temperature() and get_pcb_temperature(), returning degrees Celsius, or -1.0 when the sensors are unavailable. Prefers the [10.0.0+] session API (tsOpenSession / tsSessionGetTemperature), which returns a float, and falls back to the whole-degree tsGetTemperature() on older firmware. Note tsGetTemperatureMilliC, the obvious choice for precision, is documented [1.0.0-13.2.1] and is absent on current firmware, so it is not used. Sessions are closed and tsExit() called from cleanup().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
There is no way to read the console's thermal sensors from a project, so a suspected overheat cannot be diagnosed after the fact.
OShas no thermal API, so there is nothing to call from GDScript.The change
This follows the pattern already used for the virtual keyboard: methods on the
NintendoSwitchsingleton, bound throughClassDB.tsInitialize()sits next topsmInitialize()inOS_Switch::initialize(), andtsExit()next topsmExit()incleanup().Firmware coverage
tsGetTemperatureMilliC()looks like the obvious choice for precision, but it is documented[1.0.0-13.2.1]and is missing on current firmware, so it is not used here.Instead this prefers the session API (
tsOpenSessionandtsSessionGetTemperature,[10.0.0+], returns a float) and falls back to whole-degreetsGetTemperature()on older firmware. Sessions are opened once. If one fails to open, the ones already opened are closed rather than leaked.Note that
TsLocation_Internalis the PCB andTsLocation_Externalis the SoC, which reads backwards at a glance. The enum here is namedTEMPERATURE_PCBandTEMPERATURE_SOCso callers do not have to remember that.Testing
Tested on a v1 Switch with Atmosphère, docked in an enclosed TV unit, over a 98 minute session sampling at 1 Hz (390 samples):
Values track load and rise slowly over a long session, which is what an enclosed shelf would suggest. Returns -1.0 cleanly when the sensors are unavailable.