1
/* $Id: plugin_w1retap.c
3
* plugin to perform simple file operations for w1retap
5
* Copyright (C) 2007 Jonathan Hudson <jh+w1retap@daria.co.uk>
6
* Copyright (C) 2006 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
8
* This file is part of LCD4Linux.
10
* LCD4Linux is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2, or (at your option)
15
* LCD4Linux is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
* This module returns a specific value associated with a key from a
28
* file containing one or more lines formatted as KEY=VALUE.
30
* It is intended for use with the w1retap weather station logging
31
* software <http://www.daria.co.uk/wx/tech.html>, but is applicable
32
* to any similarly formatted file.
38
* int plugin_init_file (void)
39
* adds various functions
58
/* function 'my_readkey' */
59
/* takes two arguments, file name and key */
60
/* returns value associated with key, trimmed to suitable dec places */
62
static void my_readkey(RESULT * result, RESULT * arg1, RESULT * arg2)
64
char value[80], val2[80];
73
fp = fopen(R2S(arg1), "r");
76
error("w1retap couldn't open file '%s'", R2S(arg1));
79
size = strlen(reqkey);
80
while (!feof(fp) && pval == value) {
81
fgets(val2, sizeof(val2), fp);
82
if (*(val2 + size) == '=') {
83
if (strncmp(val2, reqkey, size) == 0) {
87
p = index(val2, '\n');
92
pval = val2 + size + 1;
96
d = strtod(pval, &ep);
97
if (ep != pval && (*ep == 0 || isspace(*ep))) {
99
sprintf(val2, "%.0f", d);
101
sprintf(val2, "%.1f", d);
113
SetResult(&result, R_STRING, pval);
117
/* plugin initialization */
118
/* MUST NOT be declared 'static'! */
119
int plugin_init_w1retap(void)
122
/* register all our cool functions */
123
/* the second parameter is the number of arguments */
124
/* -1 stands for variable argument list */
125
AddFunction("w1retap::readkey", 2, my_readkey);
130
void plugin_exit_w1retap(void)
132
/* free any allocated memory */
133
/* close filedescriptors */
139
#Sample configuration for w1retap
140
#================================
157
Foreground '000000ff'
158
Background '00000033'
168
expression h=strftime('%H', time()); x=file::readline('/tmp/.lcd',1)+0; b=(h > 5 | h < 23) + x ; LCD::backlight(b)
174
expression w1retap::readkey(file, 'OTMP0')
183
expression w1retap::readkey(file, 'GHT')
192
expression w1retap::readkey(file, 'OTMP1')
200
expression w1retap::readkey(file, 'OTMP2')
208
expression w1retap::readkey(file, 'STMP1')
216
expression w1retap::readkey(file, 'OPRS')
225
expression w1retap::readkey(file1, 'RAIN')
256
file '/tmp/.w1retap.dat'
257
file1 '/tmp/.w1rain.txt'