Advertisement
Guest User

Untitled

a guest
May 30th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.81 KB | None | 0 0
  1. diff --git a/CRT.c b/CRT.c
  2. index 3e8200b..9056961 100644
  3. --- a/CRT.c
  4. +++ b/CRT.c
  5. @@ -78,6 +78,9 @@ typedef enum ColorElements_ {
  6. UPTIME,
  7. BATTERY,
  8. TASKS_RUNNING,
  9. + TEMPERATURE_COOL,
  10. + TEMPERATURE_MEDIUM,
  11. + TEMPERATURE_HOT,
  12. SWAP,
  13. PROCESS,
  14. PROCESS_SHADOW,
  15. @@ -182,6 +185,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
  16. [METER_VALUE] = A_BOLD | ColorPair(Cyan,Black),
  17. [LED_COLOR] = ColorPair(Green,Black),
  18. [TASKS_RUNNING] = A_BOLD | ColorPair(Green,Black),
  19. + [TEMPERATURE_COOL] = A_DIM | ColorPair(Green,Black),
  20. + [TEMPERATURE_MEDIUM] = A_NORMAL | ColorPair(Yellow,Black),
  21. + [TEMPERATURE_HOT] = A_BOLD | ColorPair(Red,Black),
  22. [PROCESS] = A_NORMAL,
  23. [PROCESS_SHADOW] = A_BOLD | ColorPair(Black,Black),
  24. [PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black),
  25. @@ -241,6 +247,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
  26. [METER_VALUE] = A_BOLD,
  27. [LED_COLOR] = A_NORMAL,
  28. [TASKS_RUNNING] = A_BOLD,
  29. + [TEMPERATURE_COOL] = A_DIM,
  30. + [TEMPERATURE_MEDIUM] = A_NORMAL,
  31. + [TEMPERATURE_HOT] = A_BOLD,
  32. [PROCESS] = A_NORMAL,
  33. [PROCESS_SHADOW] = A_DIM,
  34. [PROCESS_TAG] = A_BOLD,
  35. @@ -300,6 +309,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
  36. [METER_VALUE] = ColorPair(Black,White),
  37. [LED_COLOR] = ColorPair(Green,White),
  38. [TASKS_RUNNING] = ColorPair(Green,White),
  39. + [TEMPERATURE_COOL] = ColorPair(Green,White),
  40. + [TEMPERATURE_MEDIUM] = ColorPair(Yellow,White),
  41. + [TEMPERATURE_HOT] = ColorPair(Red,White),
  42. [PROCESS] = ColorPair(Black,White),
  43. [PROCESS_SHADOW] = A_BOLD | ColorPair(Black,White),
  44. [PROCESS_TAG] = ColorPair(White,Blue),
  45. @@ -359,6 +371,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
  46. [METER_VALUE] = ColorPair(Black,Black),
  47. [LED_COLOR] = ColorPair(Green,Black),
  48. [TASKS_RUNNING] = ColorPair(Green,Black),
  49. + [TEMPERATURE_COOL] = ColorPair(Green,Black),
  50. + [TEMPERATURE_MEDIUM] = ColorPair(Yellow,Black),
  51. + [TEMPERATURE_HOT] = ColorPair(Red,Black),
  52. [PROCESS] = ColorPair(Black,Black),
  53. [PROCESS_SHADOW] = A_BOLD | ColorPair(Black,Black),
  54. [PROCESS_TAG] = ColorPair(White,Blue),
  55. @@ -418,6 +433,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
  56. [METER_VALUE] = A_BOLD | ColorPair(Cyan,Blue),
  57. [LED_COLOR] = ColorPair(Green,Blue),
  58. [TASKS_RUNNING] = A_BOLD | ColorPair(Green,Blue),
  59. + [TEMPERATURE_COOL] = A_DIM | ColorPair(Green,Blue),
  60. + [TEMPERATURE_MEDIUM] = A_NORMAL | ColorPair(Yellow,Blue),
  61. + [TEMPERATURE_HOT] = A_BOLD | ColorPair(Red,Blue),
  62. [PROCESS] = ColorPair(White,Blue),
  63. [PROCESS_SHADOW] = A_BOLD | ColorPair(Black,Blue),
  64. [PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Blue),
  65. @@ -477,6 +495,9 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
  66. [METER_VALUE] = ColorPair(Green,Black),
  67. [LED_COLOR] = ColorPair(Green,Black),
  68. [TASKS_RUNNING] = A_BOLD | ColorPair(Green,Black),
  69. + [TEMPERATURE_COOL] = A_DIM | ColorPair(Green,Black),
  70. + [TEMPERATURE_MEDIUM] = A_NORMAL | ColorPair(Yellow,Black),
  71. + [TEMPERATURE_HOT] = A_BOLD | ColorPair(Red,Black),
  72. [PROCESS] = ColorPair(Cyan,Black),
  73. [PROCESS_SHADOW] = A_BOLD | ColorPair(Black,Black),
  74. [PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black),
  75. @@ -552,12 +573,12 @@ void CRT_init(int delay, int colorScheme) {
  76. }
  77. CRT_colors = CRT_colorSchemes[colorScheme];
  78. CRT_colorScheme = colorScheme;
  79. -
  80. +
  81. for (int i = 0; i < LAST_COLORELEMENT; i++) {
  82. unsigned int color = CRT_colorSchemes[COLORSCHEME_DEFAULT][i];
  83. CRT_colorSchemes[COLORSCHEME_BROKENGRAY][i] = color == (A_BOLD | ColorPair(Black,Black)) ? ColorPair(White,Black) : color;
  84. }
  85. -
  86. +
  87. halfdelay(CRT_delay);
  88. nonl();
  89. intrflush(stdscr, false);
  90. @@ -666,7 +687,7 @@ void CRT_setColors(int colorScheme) {
  91. for (int j = 0; j < 8; j++)
  92. init_pair((7-i)*8+j, i, j);
  93. } else {
  94. - for (int i = 0; i < 8; i++)
  95. + for (int i = 0; i < 8; i++)
  96. for (int j = 0; j < 8; j++)
  97. init_pair((7-i)*8+j, i, (j==0?-1:j));
  98. }
  99. diff --git a/CRT.h b/CRT.h
  100. index fb82413..bda5318 100644
  101. --- a/CRT.h
  102. +++ b/CRT.h
  103. @@ -68,6 +68,9 @@ typedef enum ColorElements_ {
  104. UPTIME,
  105. BATTERY,
  106. TASKS_RUNNING,
  107. + TEMPERATURE_COOL,
  108. + TEMPERATURE_MEDIUM,
  109. + TEMPERATURE_HOT,
  110. SWAP,
  111. PROCESS,
  112. PROCESS_SHADOW,
  113. diff --git a/Makefile.am b/Makefile.am
  114. index 19c9eb4..3398b9b 100644
  115. --- a/Makefile.am
  116. +++ b/Makefile.am
  117. @@ -13,7 +13,7 @@ pixmapdir = $(datadir)/pixmaps
  118. pixmap_DATA = htop.png
  119.  
  120. htop_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(top_srcdir)/$(my_htop_platform)"
  121. -htop_LDFLAGS =
  122. +htop_LDFLAGS =
  123. AM_CPPFLAGS = -DNDEBUG
  124.  
  125. myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \
  126. @@ -37,12 +37,12 @@ AffinityPanel.h HostnameMeter.h OpenFilesScreen.h Affinity.h IncSet.h Action.h \
  127. EnvScreen.h InfoScreen.h XAlloc.h
  128.  
  129. if HTOP_LINUX
  130. -htop_CFLAGS += -rdynamic
  131. +htop_CFLAGS += -rdynamic
  132. myhtopplatsources = linux/Platform.c linux/IOPriorityPanel.c linux/IOPriority.c \
  133. -linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c
  134. +linux/LinuxProcess.c linux/LinuxProcessList.c linux/LinuxCRT.c linux/Battery.c TemperatureMeter.c
  135.  
  136. myhtopplatheaders = linux/Platform.h linux/IOPriorityPanel.h linux/IOPriority.h \
  137. -linux/LinuxProcess.h linux/LinuxProcessList.h linux/LinuxCRT.h linux/Battery.h
  138. +linux/LinuxProcess.h linux/LinuxProcessList.h linux/LinuxCRT.h linux/Battery.h TemperatureMeter.h
  139. endif
  140.  
  141. if HTOP_FREEBSD
  142. diff --git a/TemperatureMeter.c b/TemperatureMeter.c
  143. index e69de29..9ee9185 100644
  144. --- a/TemperatureMeter.c
  145. +++ b/TemperatureMeter.c
  146. @@ -0,0 +1,100 @@
  147. +/*
  148. +htop - TemperatureMeter.c
  149. +(C) 2013 Ralf Stemmer
  150. +(C) 2014 Blair Bonnett
  151. +Released under the GNU GPL, see the COPYING file
  152. +in the source distribution for its full text.
  153. +*/
  154. +
  155. +#include "TemperatureMeter.h"
  156. +
  157. +#include "ProcessList.h"
  158. +#include "CRT.h"
  159. +
  160. +#include <stdio.h>
  161. +#include <stdlib.h>
  162. +#include <string.h>
  163. +#include <limits.h>
  164. +
  165. +/*{
  166. +#include "Meter.h"
  167. +}*/
  168. +
  169. +int TemperatureMeter_attributes[] = {
  170. + TEMPERATURE_COOL,
  171. + TEMPERATURE_MEDIUM,
  172. + TEMPERATURE_HOT,
  173. +};
  174. +
  175. +static void TemperatureMeter_setValues(Meter* this, char* buffer, int len) {
  176. + ProcessList* pl = this->pl;
  177. + this->total = pl->totalTasks;
  178. + this->values[0] = pl->runningTasks;
  179. + snprintf(buffer, len, "%d/%d", (int) this->values[0], (int) this->total);
  180. +}
  181. +
  182. +static void TemperatureMeter_display(Object* cast, RichString* out) {
  183. + FILE *p;
  184. + p = popen("sensors", "r");
  185. + if(p == NULL) return 1;
  186. +
  187. + int textColor = CRT_colors[METER_TEXT];
  188. + int coolColor = CRT_colors[TEMPERATURE_COOL];
  189. + int mediumColor = CRT_colors[TEMPERATURE_MEDIUM];
  190. + int hotColor = CRT_colors[TEMPERATURE_HOT];
  191. +
  192. + size_t read, len;
  193. + char *line = NULL;
  194. + char *entry = NULL;
  195. + char *tstart = NULL, *tend = NULL;
  196. + int temperature;
  197. + while ((read = getline(&line, &len, p)) != -1) {
  198. + // contains this line a core-temperature?
  199. + entry = strstr(line, "Core ");
  200. + if (entry == NULL) continue;
  201. +
  202. + // find the begin of the temperature value
  203. + tstart = strchr(entry, '+'); // no negative temperatures expected :)
  204. + if (tstart == NULL) continue;
  205. + tstart++; // jump over the '+'
  206. +
  207. + // find the end of the temperature. Remember, it can be above 99°C ;)
  208. + tend = strchr(tstart, '.'); // just the integer
  209. + if (tend == NULL) continue;
  210. +
  211. + // convert the string into an integer, this is necessary for further steps
  212. + temperature = strtol(tstart, &tend, 10);
  213. + if (temperature == LONG_MAX || temperature == LONG_MIN) continue;
  214. + if (tstart == tend) continue;
  215. +
  216. + // choose the color for the temperature
  217. + int tempColor;
  218. + if (temperature < 60) tempColor = coolColor;
  219. + else if (temperature >= 60 && temperature < 70) tempColor = mediumColor;
  220. + else tempColor = hotColor;
  221. +
  222. + // output the temperature
  223. + char buffer[20];
  224. + sprintf(buffer, "%d", temperature);
  225. + RichString_append(out, tempColor, buffer);
  226. + RichString_append(out, textColor, "°C ");
  227. + }
  228. +
  229. + free(line);
  230. + pclose(p);
  231. +}
  232. +
  233. +MeterClass TemperatureMeter_class = {
  234. + .super = {
  235. + .extends = Class(Meter),
  236. + .display = TemperatureMeter_display,
  237. + .delete = Meter_delete,
  238. + },
  239. + .updateValues = TemperatureMeter_setValues,
  240. + .defaultMode = TEXT_METERMODE,
  241. + .total = 100.0,
  242. + .attributes = TemperatureMeter_attributes,
  243. + .name = "Temperature",
  244. + .uiName = "Temperature Sensors",
  245. + .caption = "Temperature: "
  246. +};
  247. diff --git a/TemperatureMeter.h b/TemperatureMeter.h
  248. index e69de29..b86ddd8 100644
  249. --- a/TemperatureMeter.h
  250. +++ b/TemperatureMeter.h
  251. @@ -0,0 +1,19 @@
  252. +/* Do not edit this file. It was automatically generated. */
  253. +
  254. +#ifndef HEADER_TemperatureMeter
  255. +#define HEADER_TemperatureMeter
  256. +/*
  257. +htop - TemperatureMeter.h
  258. +(C) 2013 Ralf Stemmer
  259. +(C) 2014 Blair Bonnett
  260. +Released under the GNU GPL, see the COPYING file
  261. +in the source distribution for its full text.
  262. +*/
  263. +
  264. +#include "Meter.h"
  265. +
  266. +extern int TemperatureMeter_attributes[];
  267. +
  268. +extern MeterClass TemperatureMeter_class;
  269. +
  270. +#endif
  271. diff --git a/linux/Platform.c b/linux/Platform.c
  272. index 04360ca..d256c94 100644
  273. --- a/linux/Platform.c
  274. +++ b/linux/Platform.c
  275. @@ -22,6 +22,7 @@ in the source distribution for its full text.
  276. #include "ClockMeter.h"
  277. #include "HostnameMeter.h"
  278. #include "LinuxProcess.h"
  279. +#include "TemperatureMeter.h"
  280.  
  281. #include <math.h>
  282. #include <assert.h>
  283. @@ -116,6 +117,7 @@ MeterClass* Platform_meterTypes[] = {
  284. &MemoryMeter_class,
  285. &SwapMeter_class,
  286. &TasksMeter_class,
  287. + &TemperatureMeter_class,
  288. &UptimeMeter_class,
  289. &BatteryMeter_class,
  290. &HostnameMeter_class,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement