p5_automation_lite.ino 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /*
  2. 2021-01 abinder - moving to libs, and cleanup
  3. */
  4. #define DISPLAY_CURSOR_Y_CHARS_DEBUG_DEF 5 //todo proportional
  5. #define ARDUINO_ARRAY_INDEX_LIMIT_QUEUE_DEF 4
  6. #define ARDUINO_ARRAY_INDEX_LIMIT_I2C_ARRAY_DRIVER_DEF 2//1
  7. #define ARDUINO_ARRAY_INDEX_LIMIT_DISPLAY_DEF 2 // 3 //todo debug
  8. #define ARDUINO_ARRAY_INDEX_LIMIT_DISPLAY_MENU_DEF 2 //todo test
  9. #define ARDUINO_ARRAY_INDEX_LIMIT_DISPLAY_MENU_ITEM_A_DEF 10 //todo debug
  10. #define ARDUINO_ARRAY_INDEX_LIMIT_PORTS_DEF 6//4//3 //todo debug lite
  11. #define ARDUINO_ARRAY_INDEX_LIMIT_PORTS_I2C_DEF 2//2 //todo debug lite
  12. //#define HAS_DEBUG_ACTION_TRIG
  13. //#define DEBUG_I2C //to debug _Slave_Ports_I2C_POP etc
  14. //#define HAS_TFT_ILI9163C
  15. //#define HAS_TFT_ILI9163C__ROTATED
  16. //#define HAS_LCD1602
  17. //#define HAS_LCD1602_I2C
  18. //#define LCD1602_DISPLAY_PHYSICAL_X_CHARS_A
  19. //#define LCD1602_DISPLAY_PHYSICAL_Y_CHARS_A
  20. //#define HAS_ROTTARY_SW
  21. #define ROTTARY_ENCODER_ACTION_MILLIS_MIN 250
  22. //#define HAS_CAN
  23. //#define DEBUG_I2C_driver_Adafruit_PWMServoDriver
  24. //#define DEBUG_CAN
  25. //#define DEBUG_QUEUE
  26. //#define DEBUG_QUEUE_ASSERT
  27. //#define DEBUG_QUEUE_WAIT 500
  28. //#define DEBUG_STRUCT_INIT
  29. //#define DEBUG_STORAGE_QUEUE_TEST
  30. //#define DEBUG_ARDUINO_ATTR_ARRAY_S__commit_added_element_QUEUE
  31. //#define DEBUG_ARDUINO_ARRAY_INDEX_NEXT_LOCK
  32. //#define HAS__PCINT_setup //to allow interrupts
  33. //#define DEBUG_TASK_TYPE_T_Slave_Ports_broadcast____
  34. //#define DEBUG_TASK_TYPE_T_DISPLAY_queue_pop________
  35. //#define DEBUG_TASK_TYPE_T_Slave_Ports_set_I2C______
  36. //#define DEBUG_QUEUE_ASSERT todo not working
  37. //#define DEBUG_LAST_ACTION_TRIG_ENABLE
  38. #define DISABLE_DISPLAY__add_record
  39. #define DISPLAY_array16_T_is_DISPLAY_string_T
  40. #define ENABLE_DISPLAY_MENU
  41. #define USE_DISPLAY_string_T
  42. //#define USE_DISPLAY_char_PA //dev testing pointer to display
  43. //#define DISABLE_ANY_PRINT //when uno ?
  44. //#define DEBUG 3
  45. //#define DISABLE_LOOP
  46. #define DISABLE_QUEUE_REASSIGN
  47. //#define DEBUG_LATENCY_MARKER
  48. //ports assign config
  49. #define PortA0 A0 //for rottary pro mini SW
  50. #define PortA1 A1 //for rottary pro mini SW DT
  51. #define PortA2 A2 //for rottary pro mini SW CLK
  52. #define PortA3 A3
  53. #define PortA7 A7 //
  54. #define PortA8 A8 //for rottary sw
  55. #define PortA9 A9 //for rottary sw dt
  56. #define PortA10 A10 //for rottary sw clk
  57. #define Port7 7 //for TFT_ILI9163C_CSpin 7
  58. #define Port8 8 //for TFT_ILI9163C_DCpin 8
  59. #define Port9 9 //for TFT_ILI9163C__RSTpin 9
  60. #define Port10 10 // CAN_INTpin 10
  61. #define Port11 11 // todo PIR LOCAL
  62. #define Port12 12 // todo change CAN to 12 from 53
  63. #define Port53 53 // #define CAN_CSpin 53 //todo change can be 12?
  64. #include "Wire.h"
  65. #include "progmem.h"
  66. #include "___CONFIG/config_Active_ControllerID.h" //there kleep id of device
  67. //config active should once update id
  68. //EEPROM_Active_ControllerID_read_T EEPROM_Active_ControllerID_read_A = EEPROM_Active_ControllerID_read();
  69. //#define DEBUG 5
  70. //#define DISABLE_LOOP //To debug and disable any output
  71. #include "__main_struct.h" //lite #include "___main/__main_struct.h"
  72. #include "__main_trigger_struct.h" //lite #include "___main/__main_trigger_struct.h"
  73. #include "__main_struct_funct.h" //lite #include "___main/__main_struct_funct.h"
  74. #include "__main_struct_limits.h" /lite ___main/
  75. #include "_time_struct.h"
  76. //lite wyglada na niepotrzebne
  77. #include "_DRIVER_STATUS_struct.h" //lite
  78. #include "__main_I2C_struc.h" //lite ___main/
  79. #include "__main_static.h" //lite ___main/
  80. #include "__main_auto.h" //lite ___main/
  81. #include "__main_register.h" //lite ___main/
  82. #include "__main_extern.h" //lite ___main/
  83. #include "config_Slave_Ports_LOCAL_config.h" //lite
  84. #include "_DISPLAY_struct__lite.h" //lite
  85. #include "_Port_ID_sruct.h"
  86. #include "_TASK_TYPES_struct.h"
  87. #include "_Slave_Ports_Status_QUEUE_struct.h"
  88. //#include "Slave_Ports_Status_QUEUE.h"
  89. #include "_I2C_driver_Adafruit_PWMServoDriver_struct.h" //lite
  90. #include "_CAN_config.h" //lite _CAN/
  91. #if defined(HAS_ROTTARY_SW)
  92. #include "_ROTTARY_SW_config.h" //lite _ROTTARY_SW/
  93. #endif
  94. #if defined(HAS_ROTTARY_SW)
  95. #include "_ROTTARY_SW_struct.h" //lite _ROTTARY_SW/
  96. #endif
  97. #if defined(HAS_TFT_ILI9163C)
  98. //L#include "_TFT_ILI9163C_struct.h"
  99. #endif
  100. #if defined(HAS_u8g2)
  101. //L #include "u8g2_struct.h" //too much ram
  102. #endif
  103. #if defined(HAS_u8x8)
  104. #include "u8x8_struct.h"
  105. #endif
  106. #if defined(HAS__PCINT_setup)
  107. #include "_PCINT/_PCINT_struct.h" //pins MYPIN1 MYPIN2 MYPIN3
  108. #endif
  109. #include "_CAN_init.h" //lite #include "_CAN/_CAN_init.h"
  110. //REMOTE PORTS DEFINITIONS
  111. #include "_PortTypes_struct.h"
  112. #include "_PortStates_struct.h"
  113. #include "_Port_Exp_state_ttl_struct.h"
  114. #include "_Port_Broadcast_state_struct.h"
  115. #include "_Port_I2C_driver_struct.h"
  116. //#include "_Slave_Ports_Status_struct_lite.h" // lite
  117. #include "_Slave_Ports_Status_struct.h"
  118. // #include "_Slave_Ports_Protocol_CAN_2020_struct.h"
  119. #include "_Slave_Ports_Protocol_CAN_struct.h" //lite _CAN/
  120. #include "_Slave_Ports_Protocol_CAN_func.h"
  121. #include "automation_driven.submodule.struct.write.h"
  122. #if defined(HAS_TFT_ILI9163C)
  123. #include "_TFT_ILI9163C_func.h"
  124. #endif
  125. #if defined(HAS_u8g2) //lite too much ram
  126. //L #include <math.h>
  127. //L #include "u8g2.h"
  128. //L U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
  129. #endif
  130. #if defined(HAS_u8x8)
  131. #include "u8x8_func.h"
  132. #include "u8x8_init.h"
  133. #endif
  134. #include "_DISPLAY_DEV.h"
  135. #include "_TASK_TYPES_func.h"
  136. #include "_Slave_Ports_Status_QUEUE_add_func.h"
  137. #include "_DISPLAY_add_record_func.h"
  138. //#include "_DISPLAY_func.h"
  139. #include "_DISPLAY_func_lite.h"
  140. #if defined(HAS_LCD1602)
  141. //L#include "_LCD1602_init.h"
  142. #endif
  143. #if defined(HAS_LCD1602)
  144. //L#include "_LCD1602_func.h"
  145. //#include "_LCD1602_init.h"
  146. #endif
  147. void DISPLAY_MENU_SELECTOR( DISPLAY_PHYSICAL_CHAR_T &DISPLAY_PHYSICAL_CHAR_A,
  148. Slave_Ports_Status_T* Slave_Ports_Status_A ,
  149. Slave_Ports_Status_T_ARDUINO_ATTR_ARRAY_T &Slave_Ports_Status_T_ARDUINO_ATTR_ARRAY_A,
  150. // DISPLAY_MENU_ITEM_INDEX_T DISPLAY_MENU_ITEM_INDEX_A ,
  151. time_seq_id_T time_seq_id_A ,
  152. time_min_run_T time_min_run_A ,
  153. //DISPLAY_MENU_SELECTOR_STATUS_T DISPLAY_MENU_SELECTOR_STATUS_A , //; //which mode
  154. DISPLAY_MENU_SELECTOR_SWITCH_T DISPLAY_MENU_SELECTOR_SWITCH_A,
  155. DISPLAY_MENU_SELECTOR_oldEncPos_T DISPLAY_MENU_SELECTOR_oldEncPos_A , //; //values
  156. DISPLAY_MENU_SELECTOR_encoderPos_T DISPLAY_MENU_SELECTOR_encoderPos_A,
  157. DISPLAY_MENU_SELECTOR_triggerCountOld_T DISPLAY_MENU_SELECTOR_triggerCountOld_A,
  158. DISPLAY_MENU_SELECTOR_triggerCount_T DISPLAY_MENU_SELECTOR_triggerCount_A) {
  159. }
  160. #if defined(HAS_ROTTARY_SW)
  161. #include "_ROTTARY_SW_func.h" //_ROTTARY_SW/
  162. #endif
  163. #include "_time_func.h"
  164. #include "_Slave_Ports_ttl_decrement_func.h"
  165. #include "_Slave_Ports_broadcast_func.h"
  166. #include "TASK_TYPE_T_Set_Port_Smooth_forward__.h"
  167. #include "_Slave_Ports_I2C_func.h"
  168. #include "_Slave_Ports_action_func.h"
  169. #include "_DISPLAY_queue_pop_func.h"
  170. #include "_Slave_Ports_Status_QUEUE_func.h"
  171. #include "TASK_TYPE_T_Get_Ports_Status_INPUT_A___.h"
  172. #include "_Slave_Ports_Status_func.h"
  173. #include "Slave_Ports_Status__DISPLAY_TARGET.h"
  174. #include "TASK_TYPE_T_Set_Ports_Status_LIMITS_A__.h"
  175. #include "TASK_TYPE_T_Set_Ports_Status_ASSOC.h"
  176. #include "_CAN_func.h" //lite _CAN/
  177. #include "DISPLAY_ELEMENT_TO_REFRESH.h"
  178. //L #include "_CAN_func.h" //lite _CAN/
  179. //EOF SERIAL ##############//EOF SERIAL ##############//EOF SERIAL ##############
  180. #include "SERIAL__init.h"
  181. #if defined(HAS_SERIAL_PROXY_SoftwareSerial)
  182. #include <SoftwareSerial.h>
  183. //SoftwareSerial SERIAL_PROXY_DEVICE(SERIAL_PROXY_SoftwareSerial_rx_pin, SERIAL_PROXY_SoftwareSerial_tx_pin); // RX, TX
  184. #include "SERIAL_PROXY__init.h"
  185. #if defined(SERIAL_PROXY_DEVICE)
  186. #errior when set HAS_SERIAL_PROXY_SoftwareSerial - cannot be set both hardware SERIAL_PROXY_DEVICE
  187. #endif
  188. #endif
  189. #if defined(HAS_SERIAL_PROXY)
  190. #include "SERIAL__struct.h"
  191. // #include "SERIAL__func.h"
  192. #endif
  193. #if defined(HAS_SERIAL_PROXY_DISPLAY_SLAVE)
  194. #define SoftwareSerial_SLAVE SoftwareSerial
  195. #include "SERIAL_PROXY_DISPLAY_SLAVE__init.h"
  196. #include "SERIAL_PROXY_DISPLAY_SLAVE__func.h"
  197. #endif
  198. #if defined(HAS_SERIAL_PROXY_DISPLAY_MASTER)
  199. #define SoftwareSerial_MASTER SoftwareSerial
  200. #include "SERIAL_PROXY_DISPLAY_MASTER__init.h"
  201. #include "SERIAL_PROXY_DISPLAY_MASTER__func.h"
  202. #endif
  203. #if defined(HAS_SERIAL_PROXY)
  204. // #define SoftwareSerial_PROXY SoftwareSerial
  205. // #include "SERIAL__struct.h"
  206. #include "SERIAL_PROXY__func.h"
  207. #include "SERIAL__func.h"
  208. #endif
  209. //EOF SERIAL ##############//EOF SERIAL ##############//EOF SERIAL ##############
  210. #if defined(HAS_TFT_ILI9163C)
  211. #include "_TFT_ILI9163C_init.h"
  212. #endif
  213. #include "_DISPLAY_init.h"
  214. #if defined(HAS_SERIAL_PROXY)
  215. #include "automation_driven.submodule.struct.read__communication_generated.h"
  216. #endif
  217. #include "config_Slave_Ports_LOCAL_init.h"
  218. #include "__main_init.h" //lite ___main/
  219. void setup() { //REMEMBER NOT INITIALIZE ANY VARIABLES OR ARRAYS
  220. Serial.begin(115200);
  221. //Wire.begin();
  222. // scan_h();
  223. SPFT(begin);
  224. #if defined(HAS_u8g2)
  225. //L #include "u8g2__setup.h"
  226. #endif
  227. #if defined(HAS_u8x8)
  228. #include "u8x8__setup.h"
  229. #endif
  230. #if defined(HAS_SERIAL_PROXY_SoftwareSerial)
  231. pinMode(SERIAL_PROXY_SoftwareSerial_rx_pin, INPUT);
  232. pinMode(SERIAL_PROXY_SoftwareSerial_rx_pin, OUTPUT);
  233. SERIAL_PROXY_DEVICE.begin(SERIAL_PROXY_SPEED);
  234. #endif
  235. #if defined(HAS_SERIAL_PROXY)
  236. #include "SERIAL_PROXY__setup.h"
  237. #endif
  238. }
  239. unsigned long time;
  240. unsigned long t_timestamp = 0;
  241. #include "_LOOP_LATENCY_COUNTER.h" //lite ___loop/
  242. void loop() {
  243. register long time;
  244. time = millis();
  245. if( t_timestamp < millis() ) {
  246. t_timestamp = millis() + 4000 ;
  247. Serial.print(F("D"));
  248. //Serial.print(String(DISPLAY_PHYSICAL_CHAR_A___DISPLAY_textsize_x_A_struct(DISPLAY_PHYSICAL_CHAR_INDEX_DEFAULT_A).Data_Level2_Value_A));
  249. }
  250. #include "___loop_init.h" //lite ___loop/
  251. #if defined(HAS_ROTTARY_SW)
  252. #include "_ROTTARY_SW_loop.h" //lite _ROTTARY_SW/
  253. #endif
  254. #include "__main_loop_top.h" //lite ___loop/
  255. // #include "__main_loop_end.h" //lite ___loop/
  256. _Slave_Ports_queue__POP(
  257. Slave_Ports_Status_QUEUE_A,
  258. Slave_Ports_Status_QUEUE_T_ARDUINO_ATTR_ARRAY_A ,
  259. LCDtim,
  260. Slave_Ports_Status_A ,
  261. Slave_Ports_Status_T_ARDUINO_ATTR_ARRAY_A ,
  262. Slave_Ports_Status_T_ARDUINO_ARRAY_INDEX_TABLE_A,
  263. Slave_Ports_Status_T_ARDUINO_ARRAY_INDEX_T_TO_DELETE_A,
  264. Slave_Ports_Status_T_ARDUINO_ARRAY_ASSOC_TABLE_S_Port_ID_A,
  265. // DISPLAY_PHYSICAL_CHAR_A,
  266. //lite removed Adafruit_PWMServoDriver_A,
  267. 0 //time
  268. );
  269. #if defined(HAS_SERIAL_PROXY)
  270. #include "SERIAL_PROXY__loop.h"
  271. #endif
  272. #if defined(HAS_SERIAL_PROXY_DISPLAY_MASTER)
  273. #endif
  274. }