opt.: temperature parse

This commit is contained in:
lollipopkit
2023-10-13 13:12:21 +08:00
parent a2bb4f1287
commit 3cce2c1e1b

View File

@@ -2,17 +2,9 @@ class Temperatures {
final Map<String, double> _map = {}; final Map<String, double> _map = {};
void parse(String type, String value) { void parse(String type, String value) {
const noMatch = "/sys/class/thermal/thermal_zone*/type";
// Not support to get CPU temperature
if (type.contains(noMatch) || value.isEmpty || type.isEmpty) {
return;
}
final typeSplited = type.split('\n'); final typeSplited = type.split('\n');
final valueSplited = value.split('\n'); final valueSplited = value.split('\n');
if (typeSplited.length != valueSplited.length) { for (var i = 0; i < typeSplited.length && i < valueSplited.length; i++) {
return;
}
for (var i = 0; i < typeSplited.length; i++) {
final t = typeSplited[i]; final t = typeSplited[i];
final v = valueSplited[i]; final v = valueSplited[i];
if (t.isEmpty || v.isEmpty) { if (t.isEmpty || v.isEmpty) {
@@ -27,10 +19,6 @@ class Temperatures {
} }
} }
void add(String name, double value) {
_map[name] = value;
}
double? get(String name) { double? get(String name) {
return _map[name]; return _map[name];
} }
@@ -56,4 +44,6 @@ class Temperatures {
} }
} }
final cpuTempReg = RegExp(r'(x86_pkg_temp|cpu_thermal)'); /// soc: mobile phone
/// cpu_thermal / x86_pkg_temp: x86
final cpuTempReg = RegExp(r'(x86_pkg_temp|cpu_thermal|soc)');