Commit 4dc83784 authored by volker's avatar volker

new plugin raspi

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1195 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
parent 9b3ccb8e
......@@ -161,6 +161,7 @@ plugin_ppp.c \
plugin_proc_stat.c \
plugin_python.c \
plugin_qnaplog.c \
plugin_raspi.c \
plugin_sample.c \
plugin_seti.c \
plugin_statfs.c \
......
This diff is collapsed.
This diff is collapsed.
......@@ -61,9 +61,6 @@
/* Define to 1 if you have the `gettimeofday' function. */
#undef HAVE_GETTIMEOFDAY
/* Define if you have the iconv() function and it works. */
#undef HAVE_ICONV
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
......@@ -286,9 +283,6 @@
/* Define to 1 if you have the <X11/Xutil.h> header file. */
#undef HAVE_X11_XUTIL_H
/* Define as const if the declaration of iconv() needs const. */
#undef ICONV_CONST
/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
slash. */
#undef LSTAT_FOLLOWS_SLASHED_SYMLINK
......@@ -417,6 +411,9 @@
/* qnaplog plugin */
#undef PLUGIN_QNAPLOG
/* raspi plugin */
#undef PLUGIN_RASPI
/* sample plugin */
#undef PLUGIN_SAMPLE
......
This diff is collapsed.
......@@ -141,6 +141,9 @@ char *Plugins[] = {
#ifdef PLUGIN_PYTHON
"python",
#endif
#ifdef PLUGIN_RASPI
"raspi",
#endif
#ifdef PLUGIN_SAMPLE
"sample",
#endif
......@@ -241,6 +244,8 @@ int plugin_init_proc_stat(void);
void plugin_exit_proc_stat(void);
int plugin_init_python(void);
void plugin_exit_python(void);
int plugin_init_raspi(void);
void plugin_exit_raspi(void);
int plugin_init_sample(void);
void plugin_exit_sample(void);
int plugin_init_seti(void);
......@@ -373,6 +378,9 @@ int plugin_init(void)
#ifdef PLUGIN_PYTHON
plugin_init_python();
#endif
#ifdef PLUGIN_RASPI
plugin_init_raspi();
#endif
#ifdef PLUGIN_SAMPLE
plugin_init_sample();
#endif
......@@ -491,6 +499,9 @@ void plugin_exit(void)
#ifdef PLUGIN_PYTHON
plugin_exit_python();
#endif
#ifdef PLUGIN_RASPI
plugin_exit_raspi();
#endif
#ifdef PLUGIN_SAMPLE
plugin_exit_sample();
#endif
......
/* $Id$
* $URL$
*
* plugin raspi
*
* Copyright (C) 2003 Michael Reinelt <michael@reinelt.co.at>
* Copyright (C) 2013 Volker Gerng <v.gering@t-online.de>
* Copyright (C) 2004, 2005, 2006, 2007, 2008 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
*
* This file is part of LCD4Linux.
*
* LCD4Linux 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, or (at your option)
* any later version.
*
* LCD4Linux 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/*
* exported functions:
*
* int plugin_init_raspi (void)
* adds functions to get information about internal sensors of raspberry pi
*
*/
#include "config.h"
/* these should always be included */
#include "debug.h"
#include "plugin.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif
#define RASPI_FREQ_PATH "/sys/devices/system/cpu/cpu0/cpufreq/"
#define RASPI_FREQ_VALUE "cpuinfo_cur_freq"
#define RASPI_FREQ_IDFILE "scaling_driver"
#define RASPI_TEMP_PATH "/sys/class/thermal/thermal_zone0/"
#define RASPI_TEMP_VALUE "temp"
#define RASPI_TEMP_IDFILE "type"
#define RASPI_TEMP_ID "bcm2835_thermal"
#define _cat(a,b) (a##b)
#define strings(a, b) "_cat(a,b)"
char tmpstr[128];
/* Note: all local functions should be declared 'static' */
/* reading an positive integer value from path, -1 on error */
static int readValue(char *path) {
int value = -1;
FILE *fp;
fp = fopen(path, "r");
if (NULL != fp) {
fgets(tmpstr, sizeof(tmpstr), fp);
fclose(fp);
if (1 != sscanf(tmpstr, "%i", &value)) {
error("[raspi] error reading integer value from %s\n", path);
}
} else {
error("[raspi] error opening %s: %s\n", path, strerror(errno));
}
return value;
}
/* reads a string from path */
static char* readStr(char *path) {
FILE *fp;
memset(tmpstr, 0, sizeof(tmpstr));
fp = fopen(path, "r");
if (NULL != fp) {
fgets(tmpstr, sizeof(tmpstr), fp);
fclose(fp);
} else {
error("[raspi] error reading text value from %s: %s\n", path, strerror(errno));
}
return tmpstr;
}
/* reads the actual cpu frequency of the bcm2708 cpu */
static void my_cpufreq(RESULT * result)
{
snprintf(tmpstr, sizeof(tmpstr), "%s%s", RASPI_FREQ_PATH, RASPI_FREQ_VALUE);
double value = readValue(tmpstr) / 1000.0L;
info("[raspi] actual cpu frequency: %.2f MHz", value);
SetResult(&result, R_NUMBER, &value);
}
/* reads the actual cpu temperature in degree Celsius */
static void my_cputemp(RESULT * result)
{
snprintf(tmpstr, sizeof(tmpstr), "%s%s", RASPI_TEMP_PATH, RASPI_TEMP_VALUE);
double value = readValue(tmpstr) / 1000.0L;
info("[raspi] actual cpu temperature: %.1f C", value);
SetResult(&result, R_NUMBER, &value);
}
/* plugin initialization */
/* MUST NOT be declared 'static'! */
int plugin_init_raspi(void)
{
char checkFile[128];
AddFunction("raspi::cpufreq", 0, my_cpufreq);
AddFunction("raspi::cputemp", 0, my_cputemp);
snprintf(checkFile, sizeof(checkFile), "%s%s", RASPI_TEMP_PATH, RASPI_TEMP_IDFILE);
if (strncmp( readStr(checkFile), RASPI_TEMP_ID, strlen(RASPI_TEMP_ID) ) != 0) {
error("Warning: no raspberry pi thermal sensor found: value of '%s' is '%s', should be '%s'",
checkFile, readStr(checkFile), RASPI_TEMP_IDFILE);
}
return 0;
}
void plugin_exit_raspi(void)
{
/* free any allocated memory */
/* close filedescriptors */
}
......@@ -56,7 +56,7 @@ for plugin in $plugins; do
[ apm,asterisk,button_exec,cpuinfo,dbus,diskstats,dvb,exec,event,]
[ fifo,file,gps,hddtemp,huawei,i2c_sensors,iconv,imon,isdn,kvv,]
[ loadavg,meminfo,mpd,mpris_dbus,mysql,netdev,netinfo,pop3,ppp,]
[ proc_stat,python,qnaplog,sample,seti,statfs,uname,uptime,]
[ proc_stat,python,qnaplog,raspi,sample,seti,statfs,uname,uptime,]
[ w1retap,wireless,xmms])
AC_MSG_ERROR([run ./configure --with-plugins=...])
;;
......@@ -92,6 +92,7 @@ for plugin in $plugins; do
PLUGIN_PROC_STAT="yes"
PLUGIN_PYTHON=$with_python
PLUGIN_QNAPLOG="yes"
PLUGIN_RASPI="yes"
PLUGIN_SAMPLE="yes"
PLUGIN_SETI="yes"
PLUGIN_STATFS="yes"
......@@ -133,6 +134,7 @@ for plugin in $plugins; do
PLUGIN_PROC_STAT="no"
PLUGIN_PYTHON="no"
PLUGIN_QNAPLOG="no"
PLUGIN_RASPI="no"
PLUGIN_SAMPLE="no"
PLUGIN_SETI="no"
PLUGIN_STATFS="no"
......@@ -235,6 +237,9 @@ for plugin in $plugins; do
qnaplog)
PLUGIN_QNAPLOG=$val
;;
raspi)
PLUGIN_RASPI=$val
;;
sample)
PLUGIN_SAMPLE=$val
;;
......@@ -567,6 +572,12 @@ if test "$PLUGIN_QNAPLOG" = "yes"; then
fi
fi
# raspi (Raspberry PI)
if test "$PLUGIN_RASPI" = "yes"; then
PLUGINS="$PLUGINS plugin_raspi.o"
AC_DEFINE(PLUGIN_RASPI,1,[raspi plugin])
fi
# sample
if test "$PLUGIN_SAMPLE" = "yes"; then
PLUGINS="$PLUGINS plugin_sample.o"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment