commit 17/10/2025 Add few logs
This commit is contained in:
@@ -16,6 +16,8 @@ import oshi.SystemInfo
|
||||
import oshi.hardware.CentralProcessor
|
||||
import oshi.hardware.GlobalMemory
|
||||
import oshi.hardware.NetworkIF
|
||||
import oshi.hardware.Sensors
|
||||
import oshi.software.os.OperatingSystem
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.time.LocalDateTime
|
||||
@@ -37,6 +39,8 @@ class Somecodes {
|
||||
val processor: CentralProcessor = si.hardware.processor
|
||||
val memory : GlobalMemory = si.hardware.memory
|
||||
val NetworkInfoMap = mutableMapOf<String, NetworkInformation>()
|
||||
val sensor : Sensors = si.hardware.sensors
|
||||
val os : OperatingSystem = si.operatingSystem
|
||||
|
||||
val datetimeformat1: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss")
|
||||
val dateformat1: DateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy")
|
||||
@@ -492,6 +496,35 @@ class Somecodes {
|
||||
sb.append(".wav")
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sensors information using OSHI library.
|
||||
* @return A string representing the CPU temperature, fan speeds, and CPU voltage, or an empty string if not available.
|
||||
*/
|
||||
fun GetSensorsInfo() : String {
|
||||
val cputemp = sensor.cpuTemperature
|
||||
val cpuvolt = sensor.cpuVoltage
|
||||
val fanspeed = sensor.fanSpeeds
|
||||
return if (cpuvolt>0 && cputemp > 0 && fanspeed.isNotEmpty()){
|
||||
String.format("CPU Temp: %.1f °C\nFan Speeds: %s RPM\nCPU Voltage: %.2f V",
|
||||
sensor.cpuTemperature,
|
||||
sensor.fanSpeeds.joinToString("/"),
|
||||
sensor.cpuVoltage
|
||||
)
|
||||
} else ""
|
||||
|
||||
}
|
||||
|
||||
fun GetUptime() : String {
|
||||
val value = os.systemUptime
|
||||
return if (value>0){
|
||||
// number of seconds since system boot
|
||||
val hours = value / 3600
|
||||
val minutes = (value % 3600) / 60
|
||||
val seconds = value % 60
|
||||
String.format("%02d:%02d:%02d", hours, minutes, seconds)
|
||||
} else ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user