Thu, 08 May 2014 22:36:51 +0200
Added library code to read DHT11 temperature/humidity sensor
7 | 1 | #ifndef _MBSELIB_H |
2 | #define _MBSELIB_H | |
3 | ||
4 | #include "../config.h" | |
5 | ||
6 | #include <stdlib.h> | |
7 | #include <stdio.h> | |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
8 | #include <stdint.h> |
7 | 9 | #include <string.h> |
10 | #include <ctype.h> | |
11 | #include <sys/types.h> | |
12 | 12 | #include <sys/stat.h> |
13 | #include <fcntl.h> | |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
14 | #include <syslog.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
15 | #include <unistd.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
16 | #include <errno.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
17 | #include <signal.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
18 | #include <getopt.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
19 | |
16
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
20 | /* mosquitto */ |
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
21 | #include <mosquitto.h> |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
22 | |
18
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
23 | #ifdef HAVE_WIRINGPI_H |
16
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
24 | /* wiringPi */ |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
25 | #include <wiringPi.h> |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
26 | #include <pcf8574.h> |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
27 | #include <lcd.h> |
7 | 28 | |
18
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
29 | #endif |
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
30 | |
7 | 31 | #define TRUE 1 |
32 | #define FALSE 0 | |
33 | ||
8
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
34 | #define MBSE_SS(x) (x)?(x):"(null)" |
e584bc0177df
Server communication seems ok, can handle server shutdowns too.
Michiel Broek <mbroek@mbse.eu>
parents:
7
diff
changeset
|
35 | |
7 | 36 | /* rdconfig.c */ |
37 | typedef struct _key_list { | |
38 | char *key; | |
39 | int (*prc)(char **); | |
40 | char **dest; | |
41 | } key_list; | |
42 | ||
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
43 | typedef struct _w1_therm { |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
44 | struct _w1_therm *next; |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
45 | char *master; /* Master for this device */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
46 | int bus; /* Reserved for ds2482-800 */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
47 | char *name; /* Name of this device */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
48 | char *alias; /* Friendly name */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
49 | int present; /* 1=present, 0=absent */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
50 | int lastval; /* Last valid value */ |
26
9322c619c525
Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
25
diff
changeset
|
51 | int update; /* Value updated */ |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
52 | } w1_therm; |
7 | 53 | |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
54 | typedef struct _rc_switch { |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
55 | struct _rc_switch *next; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
56 | char *address; /* Address code */ |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
57 | char *alias; /* Friendly name */ |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
58 | } rc_switch; |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
59 | |
7 | 60 | typedef struct _sys_config { |
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
61 | char *name; /* Configuration name */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
62 | char *mosq_host; /* mosquitto server hostname */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
63 | int mosq_port; /* mosquitto server port */ |
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
64 | w1_therm *w1therms; /* 1-wire temp sensors */ |
17
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
65 | #ifdef HAVE_WIRINGPI_H |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
66 | int lcd_cols; /* LCD display columns */ |
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
67 | int lcd_rows; /* LCD display rows */ |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
68 | int rx433; /* 433 MHz receiver pin */ |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
69 | int tx433; /* 433 MHz transmitter pin */ |
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
70 | rc_switch *rcswitch; /* 433 MHz RC Power switches */ |
17
b802305046dc
Tests for wiringPi are now not fatal
Michiel Broek <mbroek@mbse.eu>
parents:
16
diff
changeset
|
71 | #endif |
7 | 72 | } sys_config; |
73 | ||
74 | ||
9
91218bc77abc
Config now reads sensors configuration
Michiel Broek <mbroek@mbse.eu>
parents:
8
diff
changeset
|
75 | |
7 | 76 | void killconfig(void); |
24
873786a20a61
Read configuraion searches two system paths and users home path. Also the configuration filename must be passed to the rdconfig function
Michiel Broek <mbroek@mbse.eu>
parents:
22
diff
changeset
|
77 | int rdconfig(char *); |
7 | 78 | |
79 | ||
80 | /* xutil.c */ | |
81 | char *xmalloc(size_t); | |
82 | char *xstrcpy(char *); | |
83 | char *xstrcat(char *, char *); | |
84 | ||
16
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
85 | |
18
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
86 | #ifdef HAVE_WIRINGPI_H |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
87 | |
16
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
88 | /* lcd-pcf8574.c */ |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
89 | // Defines for the pcf8574 Pi LCD interface board |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
90 | #define AF_BASE 100 |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
91 | |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
92 | #define AF_RS (AF_BASE + 0) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
93 | #define AF_RW (AF_BASE + 1) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
94 | #define AF_E (AF_BASE + 2) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
95 | #define AF_BACKLIGHT (AF_BASE + 3) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
96 | #define AF_DB4 (AF_BASE + 4) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
97 | #define AF_DB5 (AF_BASE + 5) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
98 | #define AF_DB6 (AF_BASE + 6) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
99 | #define AF_DB7 (AF_BASE + 7) |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
100 | |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
101 | void setBacklight (int); |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
102 | int initLCD (int, int); |
f4cbe008da72
Version 0.0.2. Added LCD display using wiringPi library. The display is connected via a LCM1602 IIC board.
Michiel Broek <mbroek@mbse.eu>
parents:
12
diff
changeset
|
103 | |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
104 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
105 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
106 | /* rc-switch.c */ |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
107 | |
28
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
108 | int toggleSwitch(char *); |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
109 | int toggleTypeA(char *, char *, bool); |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
110 | int toggleTypeB(int, int, bool); |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
111 | int toggleTypeC(char, int, int, bool); |
32ed1ea4d0b6
Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents:
26
diff
changeset
|
112 | int toggleTypeE(char, int, bool); |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
113 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
114 | void enableReceiveIRQ(int interrupt); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
115 | void enableReceive(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
116 | void disableReceive(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
117 | bool available(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
118 | void resetAvailable(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
119 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
120 | unsigned long getReceivedValue(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
121 | unsigned int getReceivedBitlength(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
122 | unsigned int getReceivedDelay(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
123 | unsigned int getReceivedProtocol(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
124 | unsigned int *getReceivedRawdata(void); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
125 | |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
126 | void enableTransmit(int); |
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
127 | void disableTransmit(void); |
29
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
28
diff
changeset
|
128 | |
ac763b87ee25
Improved rc-switch library to be more flexible.
Michiel Broek <mbroek@mbse.eu>
parents:
28
diff
changeset
|
129 | char *dec2binWzerofill(unsigned long, unsigned int); |
20
f7f9463cdefd
Added 433 MHz transmitter and receiver library and demo programs
Michiel Broek <mbroek@mbse.eu>
parents:
18
diff
changeset
|
130 | |
31
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
131 | |
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
132 | /* dht11.c */ |
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
133 | void dht11Read(void); |
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
134 | void dht11Init(int, int, int); |
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
135 | |
89dd2b691701
Added library code to read DHT11 temperature/humidity sensor
Michiel Broek <mbroek@mbse.eu>
parents:
29
diff
changeset
|
136 | |
7 | 137 | #endif |
138 | ||
18
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
139 | |
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
140 | #endif |
3f4823083b9d
wirinPi code is now conditional
Michiel Broek <mbroek@mbse.eu>
parents:
17
diff
changeset
|
141 |