-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththinkpad_thermal.js
134 lines (114 loc) · 3.6 KB
/
thinkpad_thermal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const Lang = imports.lang;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Mainloop = imports.mainloop;
const Panel = imports.ui.main.panel;
const Gettext = imports.gettext;
const _ = Gettext.gettext;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const { ThinkPadThermalStatusIcon } = Me.imports.thinkpad_thermal_status_icon.exports;
class ThinkPadThermal {
_load() {
this.timer = 1000;
this._sensorNames = Array("CPU");
this._sensorUnits = Array("\u00b0C");
this._sensorValues = Array("0");
this._fanNames = Array("status", "speed", "level");
this._fanUnits = Array(null, "RPM", null);
this._fanValues = Array("0", "0", "0");
this._hwmonIndex = 0;
}
_update() {
let newSensorNames = Array();
let newSensorValues = Array();
let tempFile = GLib.file_get_contents(
`/sys/class/hwmon/hwmon${this._hwmonIndex}/temp1_input`
);
let tempString = imports.byteArray.toString(tempFile[1], 'utf8');
let tmpNumeric = tempString / 1000;
newSensorNames.push("CPU");
newSensorValues.push(tmpNumeric);
this._sensorValues = newSensorValues;
this._sensorNames = newSensorNames;
let fanFile = GLib.file_get_contents('/proc/acpi/ibm/fan');
let fanString = (
"" + imports.byteArray.toString(fanFile[1], 'utf8')
).split("\n");
this._fanValues[0] = ("" + fanString[0]).replace("status:\t\t", "");
this._fanValues[1] = ("" + fanString[1]).replace("speed:\t\t", "");
this._fanValues[2] = ("" + fanString[2]).replace("level:\t\t", "");
}
_update_speeds() {
this._update();
this._status_icon._set_values(this._sensorValues[0], this._fanValues[1]);
for (let i = 0; i < this._sensorValues.length; i++) {
this._sensorValues[i] += " \u00b0C";
};
this._fanValues[1] += " RPM";
this._updatedSensorValues = this._sensorValues.concat(
this._fanValues[0],
this._fanValues[1],
this._fanValues[2]
);
this._status_icon.update_values(this._updatedSensorValues);
return true;
}
_create_menu() {
if (!this._menu_created) {
this._status_icon.create_menu(
"Thermal Sensors",
this._sensorNames,
this._sensorValues,
this._sensorUnits
);
this._status_icon.create_menu(
"Fan Control",
this._fanNames,
this._fanValues,
this._fanUnits
);
this._menu_created = true;
}
}
_findHwmonIndex() {
let hwmons = GLib.file_get_contents('/sys/class/hwmon/hwmon*/name');
let hwmonsString = (
"" + imports.byteArray.toString(fanFile[1], 'utf8')
).split("\n");
this._hwmonIndex = hwmons.findIndex('coretemp');
}
enable() {
this._menu_created = false;
this._sensorValues = new Array();
this._sensorNames = new Array();
this._sensorUnits = new Array();
this._fanValues = new Array();
this._fanNames = new Array();
this._fanUnits = new Array();
global.log("Loading ...");
this._load();
global.log("Status_icon will be created");
this._status_icon = new ThinkPadThermalStatusIcon();
global.log("Global timer will be created");
this._timerid = Mainloop.timeout_add(
this.timer,
Lang.bind(this, this._update_speeds)
);
global.log("Panel addes");
Panel.addToStatusArea('thinkpadthermal', this._status_icon, 0);
global.log("menu creation");
this._create_menu();
global.log("Value update");
this._update();
}
disable() {
this._status_icon.destroy();
if (this._timerid != 0) {
Mainloop.source_remove(this._timerid);
this._timerid = 0;
}
}
};
var exports = {
ThinkPadThermal
}