Added support of BCM2835 which is mostly used by the raspberry pi3
authorJean-Philippe Orsini <jeanfi@gmail.com>
Sun, 5 Feb 2017 22:16:32 +0000 (23:16 +0100)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Sun, 5 Feb 2017 22:16:32 +0000 (23:16 +0100)
NEWS
NEWS.html
README.html
po/POTFILES.in
po/psensor.pot
src/lib/Makefile.am
src/lib/bcm2835.c [new file with mode: 0644]
src/lib/bcm2835.h [new file with mode: 0644]
src/lib/psensor.h
src/main.c

diff --git a/NEWS b/NEWS
index 4eca30d..0a6a2d1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,7 +4,9 @@
 v1.2.1
 ------
 
-* documentation files are generated with asciidoctor instead of asciidoc.
+* documentation files are generated with asciidoctor instead of
+  asciidoc.
+* added support of BCM2835 which is mostly used in the Raspberry PI3.
 
 v1.2.0
 ------
index 377300d..37f3da4 100644 (file)
--- a/NEWS.html
+++ b/NEWS.html
@@ -423,6 +423,22 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
 </div>
 <div id="content">
 <div class="sect1">
+<h2 id="_v1_2_1">v1.2.1</h2>
+<div class="sectionbody">
+<div class="ulist">
+<ul>
+<li>
+<p>documentation files are generated with asciidoctor instead of
+asciidoc.</p>
+</li>
+<li>
+<p>added support of BCM2835 which is mostly used in the Raspberry PI3.</p>
+</li>
+</ul>
+</div>
+</div>
+</div>
+<div class="sect1">
 <h2 id="_v1_2_0">v1.2.0</h2>
 <div class="sectionbody">
 <div class="ulist">
@@ -2376,7 +2392,7 @@ Initial release</pre>
 </div>
 <div id="footer">
 <div id="footer-text">
-Last updated 2016-12-20 00:39:54 CET
+Last updated 2017-02-05 23:15:39 CET
 </div>
 </div>
 </body>
index b1f3a7c..842369f 100644 (file)
@@ -637,7 +637,7 @@ modern GNU/Linux distribution.</p>
 <p>help2man (optional, required to produce the manpage)</p>
 </li>
 <li>
-<p>asciidoc (optional, required to produce the html version of the
+<p>asciidoctor (optional, required to produce the html version of the
 faq)</p>
 </li>
 <li>
@@ -748,7 +748,7 @@ have extracted the ATI ADL SDK. Other steps are indentical.</p>
 </div>
 <div id="footer">
 <div id="footer-text">
-Last updated 2017-02-04 23:24:02 CET
+Last updated 2017-02-04 23:26:13 CET
 </div>
 </div>
 </body>
index 8b527b9..77d2763 100644 (file)
@@ -5,6 +5,7 @@ src/glade/psensor-pref.glade
 src/glade/sensor-edit.glade
 src/graph.c
 src/lib/amd.c
+src/lib/bcm2835.c
 src/lib/hdd_atasmart.c
 src/lib/hdd_hddtemp.c
 src/lib/lmsensor.c
index 2f9efd0..657f897 100644 (file)
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: jeanfi@gmail.com\n"
-"POT-Creation-Date: 2017-01-22 15:41+0100\n"
+"POT-Creation-Date: 2017-02-05 23:13+0100\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -443,7 +443,17 @@ msgstr ""
 msgid "Number of active AMD/ATI adapters: %d"
 msgstr ""
 
-#: src/lib/hdd_atasmart.c:70 src/lib/hdd_hddtemp.c:125
+#: src/lib/bcm2835.c:85
+msgid "The BCM2835 (probably a Raspberry PI3) has been detected"
+msgstr ""
+
+#: src/lib/bcm2835.c:122
+#, c-format
+msgid "Failed to get content of file %s."
+msgstr ""
+
+#: src/lib/hdd_atasmart.c:70 src/lib/hdd_hddtemp.c:125 src/lib/pudisks2.c:193
+#: src/lib/pudisks2.c:194
 msgid "Disk"
 msgstr ""
 
@@ -561,6 +571,15 @@ msgstr ""
 msgid "%"
 msgstr ""
 
+#: src/lib/pudisks2.c:62 src/ui_notify.c:48
+msgid "gettimeofday failed."
+msgstr ""
+
+#: src/lib/pudisks2.c:142
+#, c-format
+msgid "%s: cannot get the udisks2 client"
+msgstr ""
+
 #: src/lib/slog.c:87
 msgid "HOME variable not set."
 msgstr ""
@@ -582,7 +601,7 @@ msgstr ""
 msgid "Sensor log not open, cannot close."
 msgstr ""
 
-#: src/main.c:61 src/server/server.c:88
+#: src/main.c:62 src/server/server.c:88
 #, c-format
 msgid ""
 "Copyright (C) %s jeanfi@gmail.com\n"
@@ -592,69 +611,69 @@ msgid ""
 "There is NO WARRANTY, to the extent permitted by law.\n"
 msgstr ""
 
-#: src/main.c:72 src/server/server.c:98
+#: src/main.c:73 src/server/server.c:98
 #, c-format
 msgid "Usage: %s [OPTION]...\n"
 msgstr ""
 
-#: src/main.c:74
+#: src/main.c:75
 msgid ""
 "Psensor is a GTK+ application for monitoring hardware sensors, including "
 "temperatures and fan speeds."
 msgstr ""
 
-#: src/main.c:78
+#: src/main.c:79
 msgid "Options:"
 msgstr ""
 
-#: src/main.c:79
+#: src/main.c:80
 msgid ""
 "  -h, --help          display this help and exit\n"
 "  -v, --version       display version information and exit"
 msgstr ""
 
-#: src/main.c:85
+#: src/main.c:86
 msgid ""
 "  -u, --url=URL       the URL of the psensor-server,\n"
 "                      example: http://hostname:3131"
 msgstr ""
 
-#: src/main.c:88
+#: src/main.c:89
 msgid "  -n, --new-instance  force the creation of a new Psensor application"
 msgstr ""
 
-#: src/main.c:91
+#: src/main.c:92
 msgid "  -d, --debug=LEVEL   set the debug level, integer between 0 and 3"
 msgstr ""
 
-#: src/main.c:96 src/server/server.c:121
+#: src/main.c:97 src/server/server.c:121
 #, c-format
 msgid "Report bugs to: %s\n"
 msgstr ""
 
-#: src/main.c:98 src/server/server.c:123
+#: src/main.c:99 src/server/server.c:123
 #, c-format
 msgid "%s home page: <%s>\n"
 msgstr ""
 
-#: src/main.c:390
+#: src/main.c:392
 msgid "Psensor has not been compiled with remote sensor support."
 msgstr ""
 
-#: src/main.c:460
+#: src/main.c:464
 msgid "Enables debug mode."
 msgstr ""
 
-#: src/main.c:472 src/server/server.c:422
+#: src/main.c:476 src/server/server.c:422
 #, c-format
 msgid "Try `%s --help' for more information.\n"
 msgstr ""
 
-#: src/main.c:485
+#: src/main.c:489
 msgid "A Psensor instance already exists."
 msgstr ""
 
-#: src/main.c:527
+#: src/main.c:531
 msgid "Failed to create thread for monitoring sensors"
 msgstr ""
 
@@ -804,10 +823,6 @@ msgstr ""
 msgid "Failed to load glade file %s: %s"
 msgstr ""
 
-#: src/ui_notify.c:48
-msgid "gettimeofday failed."
-msgstr ""
-
 #: src/ui_notify.c:77
 msgid "Temperature alert"
 msgstr ""
index 6c4dd7c..b426715 100644 (file)
@@ -2,6 +2,7 @@ noinst_LIBRARIES = libpsensor.a
 
 libpsensor_a_SOURCES = \
        amd.h\
+       bcm2835.c bcm2835.h\
        bool.h\
        color.h color.c\
        hdd.h hdd_hddtemp.c\
diff --git a/src/lib/bcm2835.c b/src/lib/bcm2835.c
new file mode 100644 (file)
index 0000000..efc8854
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2017 jeanfi@gmail.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#include <locale.h>
+#include <libintl.h>
+#define _(str) gettext(str)
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <bool.h>
+#include <pio.h>
+#include <bcm2835.h>
+
+/* Support of the BCM2835 chip which is mostly used by by the
+ * Raspberry PI3 and provides the temperature of the chip. */
+static const char *PROVIDER_NAME = "BCM2835";
+
+/*
+ * If this file exists and contains bcm2835_thermal it can be assumed
+ * that a BCM2835 chip is present.
+ */
+static const char *SYS_THERMAL_TYPE = "/sys/class/thermal/thermal_zone0/type";
+static const char *BCM2835_TYPE = "bcm2835_thermal";
+/* this file contains the temperature of the chip in celcius * 1000 */
+static char *SYS_THERMAL_TEMP = "/sys/class/thermal/thermal_zone0/temp";
+
+static void log_provider_info(const char *str)
+{
+       log_info("%s: %s", PROVIDER_NAME, str);
+}
+
+static bool is_bcm2835_present(void)
+{
+       bool ret;
+       char *str;
+
+       ret = is_file(SYS_THERMAL_TYPE);
+
+       if (!ret) {
+               log_debug("%s: %s does not exist.",
+                         PROVIDER_NAME,
+                         SYS_THERMAL_TYPE);
+               return false;
+       }
+
+       str = file_get_content(SYS_THERMAL_TYPE);
+
+       if (!str || strncmp(str, BCM2835_TYPE, strlen(BCM2835_TYPE) - 1)) {
+               log_debug("%s: type: %s.", PROVIDER_NAME, str);
+               ret = false;
+       } else {
+               ret = true;
+       }
+
+       if (str)
+               free(str);
+
+       return ret;
+}
+
+void bcm2835_psensor_list_append(struct psensor ***sensors, int vl)
+{
+       struct psensor *p;
+
+       log_fct_enter();
+
+       if (is_bcm2835_present()) {
+               log_provider_info(_("The BCM2835 (probably a Raspberry PI3) "
+                                   "has been detected"));
+
+               p = psensor_create(strdup(PROVIDER_NAME),
+                                  strdup(PROVIDER_NAME),
+                                  strdup(PROVIDER_NAME),
+                                  SENSOR_TYPE_BCM2835 | SENSOR_TYPE_TEMP,
+                                  vl);
+
+               psensor_list_append(sensors, p);
+       } else {
+               log_provider_info("The BCM2835 has not been detected.");
+       }
+
+       log_fct_exit();
+}
+
+static double bcm2835_update_temp(struct psensor *s)
+{
+       char *str, *end;
+       long l;
+       
+       log_fct_enter();
+
+       str = file_get_content(SYS_THERMAL_TEMP);
+
+       if (str[strlen(str) - 1] == '\n')
+               str[strlen(str) - 1] = '\0';
+
+       if (str) {
+               l = strtol(str, &end, 10);
+               if (*end != '\0')
+                       log_debug("%s: found invalid value: A%sB %d.", PROVIDER_NAME, str, strlen(str));
+               else
+                       psensor_set_current_value(s, l / 1000);
+               free(str);
+       } else {
+               log_err(_("Failed to get content of file %s."), SYS_THERMAL_TEMP);
+       }
+               
+       log_fct_exit();
+
+       return 0;
+}
+
+void bcm2835_psensor_list_update(struct psensor **sensors)
+{
+       struct psensor *s;
+       
+       log_fct_enter();
+
+       for (; *sensors; sensors++) {
+               s = *sensors;
+
+               if (s->type & SENSOR_TYPE_REMOTE)
+                       continue;
+
+               if (s->type & SENSOR_TYPE_BCM2835) {
+                       bcm2835_update_temp(s);
+                       break; /* only one possible sensor */
+               }
+       }
+       
+       log_fct_exit();
+}
diff --git a/src/lib/bcm2835.h b/src/lib/bcm2835.h
new file mode 100644 (file)
index 0000000..84c1f2d
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2017 jeanfi@gmail.com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+/*
+ * Retrieve temperature from the chip BCM2835 which is mostly
+ * used by the Raspberry PI3 and not support by lmsensor.
+ */
+#ifndef _PSENSOR_BCM2835_H_
+#define _PSENSOR_BCM2835_H_
+
+#include <bool.h>
+#include <psensor.h>
+
+static inline bool bcm2835_is_supported(void) { return true; }
+
+void bcm2835_psensor_list_update(struct psensor **);
+void bcm2835_psensor_list_append(struct psensor ***, int);
+void bcm2835_cleanup(void);
+
+#endif
index 111976b..8f9e7f7 100644 (file)
@@ -42,6 +42,7 @@ enum psensor_type {
        SENSOR_TYPE_ATASMART = 0x01000,
        SENSOR_TYPE_HDDTEMP = 0x02000,
        SENSOR_TYPE_UDISKS2 = 0x800000,
+       SENSOR_TYPE_BCM2835 = 0x1000000,
 
        /* Type of HW component */
        SENSOR_TYPE_HDD = 0x04000,
index 5686f5b..a24c636 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2016 jeanfi@gmail.com
+ * Copyright (C) 2010-2017 jeanfi@gmail.com
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
@@ -31,6 +31,7 @@
 #include <config.h>
 
 #include <amd.h>
+#include <bcm2835.h>
 #include <cfg.h>
 #include <graph.h>
 #include <hdd.h>
@@ -144,6 +145,7 @@ static void *update_measures(void *data)
                gtop2_psensor_list_update(sensors);
                atasmart_psensor_list_update(sensors);
                hddtemp_psensor_list_update(sensors);
+               bcm2835_psensor_list_update(sensors);
 
                psensor_log_measures(sensors);
 
@@ -415,6 +417,8 @@ static struct psensor **create_sensors_list(const char *url)
 
                if (config_is_udisks2_enabled())
                        udisks2_psensor_list_append(&sensors, 600);
+
+               bcm2835_psensor_list_append(&sensors, 600);
        }
 
        associate_preferences(sensors);