1 #ifndef _MAIN_H |
1 #ifndef _MBSELIB_H |
2 #define _MAIN_H |
2 #define _MBSELIB_H |
3 |
3 |
4 |
4 |
5 #define TRUE 1 |
5 #define TRUE 1 |
6 #define FALSE 0 |
6 #define FALSE 0 |
7 |
7 |
|
8 #include "../config.h" |
|
9 |
|
10 #include <stdlib.h> |
|
11 #include <stdio.h> |
|
12 #include <stdint.h> |
|
13 #include <stdarg.h> |
|
14 #include <string.h> |
|
15 #include <ctype.h> |
|
16 #include <sys/types.h> |
|
17 #include <sys/stat.h> |
|
18 #include <sys/time.h> |
|
19 #include <time.h> |
|
20 #include <fcntl.h> |
|
21 #include <syslog.h> |
|
22 #include <unistd.h> |
|
23 #include <errno.h> |
|
24 #include <signal.h> |
|
25 #include <getopt.h> |
|
26 #include <limits.h> |
|
27 #include <sys/socket.h> |
|
28 #include <arpa/inet.h> |
|
29 #include <netdb.h> |
|
30 #include <poll.h> |
|
31 |
|
32 |
|
33 /* mosquitto */ |
|
34 #include <mosquitto.h> |
|
35 |
|
36 #ifdef HAVE_WIRINGPI_H |
|
37 /* wiringPi */ |
|
38 #include <wiringPi.h> |
|
39 #include <pcf8574.h> |
|
40 #include <lcd.h> |
|
41 |
|
42 #endif |
|
43 |
|
44 #define TRUE 1 |
|
45 #define FALSE 0 |
|
46 |
|
47 #define MBSE_SS(x) (x)?(x):"(null)" |
|
48 |
|
49 /* rdconfig.c */ |
|
50 typedef struct _key_list { |
|
51 char *key; |
|
52 int (*prc)(char **); |
|
53 char **dest; |
|
54 } key_list; |
|
55 |
|
56 typedef struct _w1_therm { |
|
57 struct _w1_therm *next; |
|
58 char *master; /* Master for this device */ |
|
59 int bus; /* Reserved for ds2482-800 */ |
|
60 char *name; /* Name of this device */ |
|
61 char *alias; /* Friendly name */ |
|
62 int present; /* 1=present, 0=absent */ |
|
63 int lastval; /* Last valid value */ |
|
64 int update; /* Value updated */ |
|
65 } w1_therm; |
|
66 |
|
67 typedef struct _rc_switch { |
|
68 struct _rc_switch *next; |
|
69 char *address; /* Address code */ |
|
70 char *alias; /* Friendly name */ |
|
71 } rc_switch; |
|
72 |
|
73 typedef struct _sys_config { |
|
74 char *name; /* Configuration name */ |
|
75 char *mosq_host; /* mosquitto server hostname */ |
|
76 int mosq_port; /* mosquitto server port */ |
|
77 int my_port; /* my client/server port */ |
|
78 w1_therm *w1therms; /* 1-wire temp sensors */ |
|
79 #ifdef HAVE_WIRINGPI_H |
|
80 int lcd_cols; /* LCD display columns */ |
|
81 int lcd_rows; /* LCD display rows */ |
|
82 int rx433; /* 433 MHz receiver pin */ |
|
83 int tx433; /* 433 MHz transmitter pin */ |
|
84 rc_switch *rcswitch; /* 433 MHz RC Power switches */ |
|
85 #endif |
|
86 } sys_config; |
|
87 |
|
88 |
|
89 void killconfig(void); |
|
90 int rdconfig(char *); |
|
91 |
|
92 |
|
93 /* lock.c */ |
|
94 int lockprog(char *); |
|
95 void ulockprog(char *); |
|
96 |
|
97 |
|
98 /* xutil.c */ |
|
99 char *xmalloc(size_t); |
|
100 char *xstrcpy(char *); |
|
101 char *xstrcat(char *, char *); |
|
102 |
|
103 |
|
104 #ifdef HAVE_WIRINGPI_H |
|
105 |
|
106 /* lcd-pcf8574.c */ |
|
107 // Defines for the pcf8574 Pi LCD interface board |
|
108 #define AF_BASE 100 |
|
109 |
|
110 #define AF_RS (AF_BASE + 0) |
|
111 #define AF_RW (AF_BASE + 1) |
|
112 #define AF_E (AF_BASE + 2) |
|
113 #define AF_BACKLIGHT (AF_BASE + 3) |
|
114 #define AF_DB4 (AF_BASE + 4) |
|
115 #define AF_DB5 (AF_BASE + 5) |
|
116 #define AF_DB6 (AF_BASE + 6) |
|
117 #define AF_DB7 (AF_BASE + 7) |
|
118 |
|
119 void setBacklight (int); |
|
120 int initLCD (int, int); |
|
121 void mb_lcdPutchar(const int, unsigned char); |
|
122 void mb_lcdPuts(const int, const char *); |
|
123 void mb_lcdClear(const int); |
|
124 |
|
125 |
|
126 /* logger.c */ |
|
127 void logger(char *, char *, char *); |
|
128 |
|
129 |
|
130 /* rc-switch.c */ |
|
131 int toggleSwitch(char *); |
|
132 int toggleTypeA(char *, char *, bool); |
|
133 int toggleTypeB(int, int, bool); |
|
134 int toggleTypeC(char, int, int, bool); |
|
135 int toggleTypeE(char, int, bool); |
|
136 |
|
137 void enableReceiveIRQ(int interrupt); |
|
138 void enableReceive(void); |
|
139 void disableReceive(void); |
|
140 bool available(void); |
|
141 void resetAvailable(void); |
|
142 |
|
143 unsigned long getReceivedValue(void); |
|
144 unsigned int getReceivedBitlength(void); |
|
145 unsigned int getReceivedDelay(void); |
|
146 unsigned int getReceivedProtocol(void); |
|
147 unsigned int *getReceivedRawdata(void); |
|
148 |
|
149 void enableTransmit(int); |
|
150 void disableTransmit(void); |
|
151 |
|
152 char *dec2binWzerofill(unsigned long, unsigned int); |
|
153 |
|
154 |
|
155 /* dht11.c */ |
|
156 void dht11Read(void); |
|
157 void dht11Init(int, int, int); |
|
158 |
|
159 PI_THREAD (my_sensors_loop); |
|
160 PI_THREAD (my_server_loop); |
|
161 |
|
162 #endif |
8 |
163 |
9 |
164 |
10 #endif |
165 #endif |
|
166 |