55 extern int my_devices_shutdown; |
56 extern int my_devices_shutdown; |
56 extern int my_panel_state; |
57 extern int my_panel_state; |
57 extern int my_panel_shutdown; |
58 extern int my_panel_shutdown; |
58 extern int my_server_state; |
59 extern int my_server_state; |
59 extern int my_server_shutdown; |
60 extern int my_server_shutdown; |
|
61 extern int my_ws_state; |
|
62 extern int my_ws_shutdown; |
60 extern int my_simulator_state; |
63 extern int my_simulator_state; |
61 #ifdef USE_SIMULATOR |
64 #ifdef USE_SIMULATOR |
62 extern int my_simulator_shutdown; |
65 extern int my_simulator_shutdown; |
63 #endif |
66 #endif |
64 extern int my_one_wire_state; |
67 extern int my_one_wire_state; |
69 |
72 |
70 pthread_t my_one_wire_thread; |
73 pthread_t my_one_wire_thread; |
71 pthread_t my_devices_thread; |
74 pthread_t my_devices_thread; |
72 pthread_t my_panel_thread; |
75 pthread_t my_panel_thread; |
73 pthread_t my_server_thread; |
76 pthread_t my_server_thread; |
|
77 pthread_t my_ws_thread; |
74 #ifdef USE_SIMULATOR |
78 #ifdef USE_SIMULATOR |
75 pthread_t my_simulator_thread; |
79 pthread_t my_simulator_thread; |
76 #endif |
80 #endif |
77 |
81 |
78 pthread_mutex_t mutexes[5]; |
82 pthread_mutex_t mutexes[5]; |
1877 slcdCharDef(slcdHandle, 4, RevCoolONOFF); |
1883 slcdCharDef(slcdHandle, 4, RevCoolONOFF); |
1878 slcdCharDef(slcdHandle, 5, HeatONOFF); |
1884 slcdCharDef(slcdHandle, 5, HeatONOFF); |
1879 slcdCharDef(slcdHandle, 6, RevHeatONOFF); |
1885 slcdCharDef(slcdHandle, 6, RevHeatONOFF); |
1880 |
1886 |
1881 my_shutdown = my_reboot = FALSE; |
1887 my_shutdown = my_reboot = FALSE; |
1882 my_devices_shutdown = my_panel_shutdown = my_server_shutdown = my_one_wire_shutdown = 0; |
1888 my_devices_shutdown = my_panel_shutdown = my_server_shutdown = my_ws_shutdown = my_one_wire_shutdown = 0; |
1883 my_devices_state = my_panel_state = my_server_state = my_one_wire_state = 0; |
1889 my_devices_state = my_panel_state = my_server_state = my_ws_state = my_one_wire_state = 0; |
1884 my_simulator_state = 0; |
1890 my_simulator_state = 0; |
1885 #ifdef USE_SIMULATOR |
1891 #ifdef USE_SIMULATOR |
1886 my_simulator_shutdown = 0; |
1892 my_simulator_shutdown = 0; |
1887 #endif |
1893 #endif |
1888 if (lockprog((char *)"thermferm")) { |
1894 if (lockprog((char *)"thermferm")) { |
1890 return 1; |
1896 return 1; |
1891 } |
1897 } |
1892 mqtt_connect(); |
1898 mqtt_connect(); |
1893 |
1899 |
1894 /* |
1900 /* |
1895 * First scan the one-wire bus |
1901 * Start websockets first. |
|
1902 */ |
|
1903 rc = pthread_create(&my_ws_thread, NULL, my_ws_loop, (void *)t ); |
|
1904 if (rc) { |
|
1905 fprintf(stderr, "my_ws_loop thread didn't start rc=%d\n", rc); |
|
1906 syslog(LOG_NOTICE, "my_ws_loop thread didn't start rc=%d", rc); |
|
1907 } else { |
|
1908 t++; |
|
1909 } |
|
1910 |
|
1911 /* |
|
1912 * Next scan the one-wire bus |
1896 */ |
1913 */ |
1897 rc = pthread_create(&my_one_wire_thread, NULL, my_one_wire_loop, (void *)t ); |
1914 rc = pthread_create(&my_one_wire_thread, NULL, my_one_wire_loop, (void *)t ); |
1898 if (rc) { |
1915 if (rc) { |
1899 fprintf(stderr, "my_one_wire_loop thread didn't start rc=%d\n", rc); |
1916 fprintf(stderr, "my_one_wire_loop thread didn't start rc=%d\n", rc); |
1900 syslog(LOG_NOTICE, "my_one_wire_loop thread didn't start rc=%d", rc); |
1917 syslog(LOG_NOTICE, "my_one_wire_loop thread didn't start rc=%d", rc); |
2050 |
2067 |
2051 my_devices_shutdown = 1; |
2068 my_devices_shutdown = 1; |
2052 while (my_devices_state) { mDelay(50); }; |
2069 while (my_devices_state) { mDelay(50); }; |
2053 my_one_wire_shutdown = 1; |
2070 my_one_wire_shutdown = 1; |
2054 while (my_one_wire_state) { mDelay(50); }; |
2071 while (my_one_wire_state) { mDelay(50); }; |
2055 |
2072 my_ws_shutdown = 1; |
|
2073 while (my_ws_state) { mDelay(50); }; |
2056 mqtt_disconnect(); |
2074 mqtt_disconnect(); |
2057 |
2075 |
2058 stopLCD(); |
2076 stopLCD(); |
2059 if (sock != -1) { |
2077 if (sock != -1) { |
2060 if (shutdown(sock, SHUT_RDWR)) { |
2078 if (shutdown(sock, SHUT_RDWR)) { |