diff --git a/msposd.c b/msposd.c index 8749b55..4b4d290 100644 --- a/msposd.c +++ b/msposd.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -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; } diff --git a/osd.c b/osd.c index 07fda86..8997ae0 100644 --- a/osd.c +++ b/osd.c @@ -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; @@ -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; @@ -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); @@ -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