20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
21 *****************************************************************************/ |
21 *****************************************************************************/ |
22 |
22 |
23 #include "lock.h" |
23 #include "lock.h" |
24 #include "rdconfig.h" |
24 #include "rdconfig.h" |
25 #include "devices.h" |
|
26 #include "server.h" |
25 #include "server.h" |
27 #include "thermferm.h" |
26 #include "thermferm.h" |
|
27 #include "devices.h" |
28 #include "delay.h" |
28 #include "delay.h" |
29 #include "simulator.h" |
29 #include "simulator.h" |
30 #include "lcd-pcf8574.h" |
30 #include "lcd-pcf8574.h" |
31 #include "lcd-buffer.h" |
31 #include "lcd-buffer.h" |
32 #include "slcd.h" |
32 #include "slcd.h" |
33 #include "panel.h" |
33 #include "panel.h" |
|
34 #include "one-wire.h" |
34 #include "futil.h" |
35 #include "futil.h" |
35 #include "xutil.h" |
36 #include "xutil.h" |
36 #include "pid.h" |
37 #include "pid.h" |
37 #include "mqtt.h" |
38 #include "mqtt.h" |
38 |
39 |
49 extern int slcdHandle; |
50 extern int slcdHandle; |
50 extern int my_devices_state; |
51 extern int my_devices_state; |
51 extern int my_panel_state; |
52 extern int my_panel_state; |
52 extern int my_server_state; |
53 extern int my_server_state; |
53 extern int my_simulator_state; |
54 extern int my_simulator_state; |
|
55 extern int my_one_wire_state; |
54 int setupmenu = MENU_NONE; |
56 int setupmenu = MENU_NONE; |
55 units_list *current_unit = NULL; /* In panel editor this points to the current unit. */ |
57 units_list *current_unit = NULL; /* In panel editor this points to the current unit. */ |
56 float temp_temp = 20.0; |
58 float temp_temp = 20.0; |
57 |
59 |
58 pthread_t threads[5]; |
60 pthread_t threads[5]; |
1058 |
1060 |
1059 rc = pthread_create(&threads[t], NULL, my_panel_loop, (void *)t ); |
1061 rc = pthread_create(&threads[t], NULL, my_panel_loop, (void *)t ); |
1060 if (rc) { |
1062 if (rc) { |
1061 fprintf(stderr, "my_panel_loop thread didn't start rc=%d\n", rc); |
1063 fprintf(stderr, "my_panel_loop thread didn't start rc=%d\n", rc); |
1062 syslog(LOG_NOTICE, "my_panel_loop thread didn't start rc=%d", rc); |
1064 syslog(LOG_NOTICE, "my_panel_loop thread didn't start rc=%d", rc); |
|
1065 } else { |
|
1066 t++; |
|
1067 } |
|
1068 |
|
1069 rc = pthread_create(&threads[t], NULL, my_one_wire_loop, (void *)t ); |
|
1070 if (rc) { |
|
1071 fprintf(stderr, "my_one_wire_loop thread didn't start rc=%d\n", rc); |
|
1072 syslog(LOG_NOTICE, "my_one_wire_loop thread didn't start rc=%d", rc); |
1063 } else { |
1073 } else { |
1064 t++; |
1074 t++; |
1065 } |
1075 } |
1066 |
1076 |
1067 #ifdef USE_SIMULATOR |
1077 #ifdef USE_SIMULATOR |
1913 } |
1923 } |
1914 syslog(LOG_NOTICE, "Out of loop"); |
1924 syslog(LOG_NOTICE, "Out of loop"); |
1915 |
1925 |
1916 /* |
1926 /* |
1917 * Note that we don't care if the command server is stopped, this one |
1927 * Note that we don't care if the command server is stopped, this one |
1918 * does almost certain keep running but tat doesn't harm. |
1928 * does almost certain keep running but that doesn't harm. |
1919 */ |
1929 */ |
1920 while ((my_devices_state + my_panel_state + my_simulator_state) > 0) { sleep(1); }; |
1930 while ((my_devices_state + my_panel_state + my_simulator_state + my_one_wire_state) > 0) { sleep(1); }; |
1921 mqtt_disconnect(); |
1931 mqtt_disconnect(); |
1922 |
1932 |
1923 stopLCD(); |
1933 stopLCD(); |
1924 if (sock != -1) { |
1934 if (sock != -1) { |
1925 if (shutdown(sock, SHUT_RDWR)) { |
1935 if (shutdown(sock, SHUT_RDWR)) { |