Skip to content

Commit

Permalink
glob /proc/net/*/*/thermal_state
Browse files Browse the repository at this point in the history
  • Loading branch information
henkwiedig committed Dec 29, 2024
1 parent 07fb941 commit a5e13c3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 22 deletions.
51 changes: 33 additions & 18 deletions msposd.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <getopt.h>
#include <stdio.h>
#include <glob.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
Expand Down Expand Up @@ -353,30 +354,44 @@ uint64_t get_current_time_ms_Old() {

int last_wifi_temp;
static long last_wifi_temp_taken=0;
int Get8812EU2Temp(){
int GetTXTemp(){

if ((get_time_ms() - last_wifi_temp_taken ) < 1000)//Set some caching to keep CPU load low
return last_wifi_temp;
last_wifi_temp_taken= get_time_ms();

FILE *stat = popen("cat /proc/net/rtl88x2eu/wlan0/thermal_state", "r");
if (stat == NULL) {
fprintf(stderr, "Failed to run command\n");
return 1;
}
char buffer[128];
glob_t glob_result;
FILE *stat = NULL;
int temperature=0;
char c[25];
// Read the first line of output
if (fgets(buffer, sizeof(buffer), stat) != NULL) {
if (sscanf(buffer, "rf_path: %*d, thermal_value: %*d, offset: %*d, temperature: %d", &temperature) == 1) {
printf("WiFi Temperature from the first line: %d\n", temperature);
} else {
fprintf(stderr, "Failed to parse wifi temperature\n");
}
}
// Close the pipe
pclose(stat);

if (glob("/proc/net/*/*/thermal_state", GLOB_NOSORT, NULL, &glob_result) == 0) {
if (glob_result.gl_pathc > 0) {
// Open the first match
stat = fopen(glob_result.gl_pathv[0], "r");
if (stat == NULL) {
fprintf(stderr, "Failed to open the thermal_state file: %s\n", glob_result.gl_pathv[0]);
globfree(&glob_result);
return -99;
}
char buffer[128];
// Read the first line of output
if (fgets(buffer, sizeof(buffer), stat) != NULL) {
if (sscanf(buffer, "rf_path: %*d, thermal_value: %*d, offset: %*d, temperature: %d", &temperature) == 1) {
printf("WiFi Temperature from the first line: %d\n", temperature);
} else {
fprintf(stderr, "Failed to parse wifi temperature\n");
}
}
fclose(stat);
} else {
fprintf(stderr, "No thermal_state files found in /proc/net\n");
}
} else {
fprintf(stderr, "Failed to glob /proc/net/*/thermal_state\n");
}

// Clean up
globfree(&glob_result);
last_wifi_temp=temperature;
return temperature;
}
Expand Down
8 changes: 4 additions & 4 deletions osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ extern void ProcessChannels();
extern uint16_t channels[18];
extern int matrix_size;
extern int GetTempSigmaStar();
extern int Get8812EU2Temp();
extern int GetTXTemp();
extern int SendWfbLogToGround();
extern bool monitor_wfb;
extern int last_board_temp;
Expand Down Expand Up @@ -384,7 +384,7 @@ static bool InjectChars(char* payload){
if ( str[0]=='!' && str[1]=='T' && str[2]=='M' && str[3]=='W'&& str[4]=='!'){
int temp = 99;

temp = Get8812EU2Temp();
temp = GetTXTemp();
if (temp<0)
last_board_temp=99;

Expand Down Expand Up @@ -1205,7 +1205,7 @@ static bool first_wfb_read=true;
}else if (str[ipos + 1] == 'W'){//get WiFi 8812EU temp
ipos++;
char c[18];
sprintf(c, "%d", Get8812EU2Temp());
sprintf(c, "%d", GetTXTemp());
strcat(out, c);
opos += strlen(c);

Expand Down Expand Up @@ -1528,7 +1528,7 @@ static bool ReplaceWidgets_Slow(int* x, int* y){
if ( character_map[*x][*y]=='!' && character_map[*x+1][*y]=='T' && character_map[*x+2][*y]=='M' && character_map[*x+3][*y]=='W'&& character_map[*x+4][*y]=='!'){
int temp = 99;
#if __SIGMASTAR__
temp = Get8812EU2Temp();
temp = GetTXTemp();
#else
temp = last_board_temp;
#endif
Expand Down

0 comments on commit a5e13c3

Please sign in to comment.