p5_automation_lite_display.ino 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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 0//1
  7. #define ARDUINO_ARRAY_INDEX_LIMIT_DISPLAY_DEF 0 // 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 0//4//3 //todo debug lite
  11. #define ARDUINO_ARRAY_INDEX_LIMIT_PORTS_I2C_DEF 0//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. #if defined(HAS_ROTTARY_SW)
  89. #include "_ROTTARY_SW_config.h" //lite _ROTTARY_SW/
  90. #endif
  91. #if defined(HAS_ROTTARY_SW)
  92. #include "_ROTTARY_SW_struct.h" //lite _ROTTARY_SW/
  93. #endif
  94. #if defined(HAS_TFT_ILI9163C)
  95. //L#include "_TFT_ILI9163C_struct.h"
  96. #endif
  97. #if defined(HAS_u8g2)
  98. //L #include "u8g2_struct.h" //too much ram
  99. #endif
  100. #if defined(HAS_u8x8)
  101. #include "u8x8_struct.h"
  102. #endif
  103. #if defined(HAS__PCINT_setup)
  104. #include "_PCINT/_PCINT_struct.h" //pins MYPIN1 MYPIN2 MYPIN3
  105. #endif
  106. //REMOTE PORTS DEFINITIONS
  107. #include "_PortTypes_struct.h"
  108. #include "_PortStates_struct.h"
  109. #include "_Port_Exp_state_ttl_struct.h"
  110. #include "_Port_Broadcast_state_struct.h"
  111. #include "_Port_I2C_driver_struct.h"
  112. //#include "_Slave_Ports_Status_struct_lite.h" // lite
  113. #include "_Slave_Ports_Status_struct.h"
  114. #include "_Slave_Ports_Protocol_CAN_struct.h" //lite _CAN/
  115. //#include "_Slave_Ports_Protocol_CAN_2020_struct.h"
  116. #include "automation_driven.submodule.struct.write.h"
  117. #if defined(HAS_TFT_ILI9163C)
  118. #include "_TFT_ILI9163C_func.h"
  119. #endif
  120. #if defined(HAS_u8g2) //lite too much ram
  121. //L #include <math.h>
  122. //L #include "u8g2.h"
  123. //L U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
  124. #endif
  125. #if defined(HAS_u8x8)
  126. #include "u8x8_func.h"
  127. #include "u8x8_init.h"
  128. #endif
  129. #include "_DISPLAY_DEV.h"
  130. #include "_TASK_TYPES_func.h"
  131. #include "_Slave_Ports_Status_QUEUE_add_func.h"
  132. #include "_DISPLAY_add_record_func.h"
  133. //#include "_DISPLAY_func.h"
  134. #include "_DISPLAY_func_lite.h"
  135. #if defined(HAS_LCD1602)
  136. //L#include "_LCD1602_init.h"
  137. #endif
  138. #if defined(HAS_LCD1602)
  139. //L#include "_LCD1602_func.h"
  140. //#include "_LCD1602_init.h"
  141. #endif
  142. void DISPLAY_MENU_SELECTOR( DISPLAY_PHYSICAL_CHAR_T &DISPLAY_PHYSICAL_CHAR_A,
  143. Slave_Ports_Status_T* Slave_Ports_Status_A ,
  144. Slave_Ports_Status_T_ARDUINO_ATTR_ARRAY_T &Slave_Ports_Status_T_ARDUINO_ATTR_ARRAY_A,
  145. // DISPLAY_MENU_ITEM_INDEX_T DISPLAY_MENU_ITEM_INDEX_A ,
  146. time_seq_id_T time_seq_id_A ,
  147. time_min_run_T time_min_run_A ,
  148. //DISPLAY_MENU_SELECTOR_STATUS_T DISPLAY_MENU_SELECTOR_STATUS_A , //; //which mode
  149. DISPLAY_MENU_SELECTOR_SWITCH_T DISPLAY_MENU_SELECTOR_SWITCH_A,
  150. DISPLAY_MENU_SELECTOR_oldEncPos_T DISPLAY_MENU_SELECTOR_oldEncPos_A , //; //values
  151. DISPLAY_MENU_SELECTOR_encoderPos_T DISPLAY_MENU_SELECTOR_encoderPos_A,
  152. DISPLAY_MENU_SELECTOR_triggerCountOld_T DISPLAY_MENU_SELECTOR_triggerCountOld_A,
  153. DISPLAY_MENU_SELECTOR_triggerCount_T DISPLAY_MENU_SELECTOR_triggerCount_A) {
  154. }
  155. #if defined(HAS_ROTTARY_SW)
  156. #include "_ROTTARY_SW_func.h" //_ROTTARY_SW/
  157. #endif
  158. #include "_time_func.h"
  159. #include "DISPLAY_ELEMENT_TO_REFRESH.h"
  160. #include "Slave_Ports_Status__DISPLAY_TARGET.h"
  161. #include "TASK_TYPE_T_Set_Ports_Status_LIMITS_A__.h"
  162. #include "TASK_TYPE_T_Set_Ports_Status_ASSOC.h"
  163. //L #include "_CAN_func.h" //lite _CAN/
  164. //EOF SERIAL ##############//EOF SERIAL ##############//EOF SERIAL ##############
  165. #include "SERIAL__init.h"
  166. #if defined(HAS_SERIAL_PROXY_SoftwareSerial)
  167. #include <SoftwareSerial.h>
  168. //SoftwareSerial SERIAL_PROXY_DEVICE(SERIAL_PROXY_SoftwareSerial_rx_pin, SERIAL_PROXY_SoftwareSerial_tx_pin); // RX, TX
  169. #include "SERIAL_PROXY__init.h"
  170. #if defined(SERIAL_PROXY_DEVICE)
  171. #errior when set HAS_SERIAL_PROXY_SoftwareSerial - cannot be set both hardware SERIAL_PROXY_DEVICE
  172. #endif
  173. #endif
  174. #if defined(HAS_SERIAL_PROXY)
  175. #include "SERIAL__struct.h"
  176. // #include "SERIAL__func.h"
  177. #endif
  178. #if defined(HAS_SERIAL_PROXY_DISPLAY_SLAVE)
  179. #define SoftwareSerial_SLAVE SoftwareSerial
  180. #include "SERIAL_PROXY_DISPLAY_SLAVE__init.h"
  181. #include "SERIAL_PROXY_DISPLAY_SLAVE__func.h"
  182. #endif
  183. #if defined(HAS_SERIAL_PROXY_DISPLAY_MASTER)
  184. #define SoftwareSerial_MASTER SoftwareSerial
  185. #include "SERIAL_PROXY_DISPLAY_MASTER__init.h"
  186. #include "SERIAL_PROXY_DISPLAY_MASTER__func.h"
  187. #endif
  188. #if defined(HAS_SERIAL_PROXY)
  189. // #define SoftwareSerial_PROXY SoftwareSerial
  190. // #include "SERIAL__struct.h"
  191. #include "SERIAL_PROXY__func.h"
  192. #include "SERIAL__func.h"
  193. #endif
  194. //EOF SERIAL ##############//EOF SERIAL ##############//EOF SERIAL ##############
  195. #if defined(HAS_TFT_ILI9163C)
  196. #include "_TFT_ILI9163C_init.h"
  197. #endif
  198. #include "_DISPLAY_init.h"
  199. #if defined(HAS_SERIAL_PROXY)
  200. #include "automation_driven.submodule.struct.read__communication_generated.h"
  201. #endif
  202. void setup() { //REMEMBER NOT INITIALIZE ANY VARIABLES OR ARRAYS
  203. Serial.begin(115200);
  204. //Wire.begin();
  205. // scan_h();
  206. SPFTFT(setup,init);
  207. #if defined(HAS_ROTTARY_SW)
  208. #include "_ROTTARY_SW_setup.h" //Attach interrupts //lite _ROTTARY_SW/
  209. #endif
  210. #if defined(HAS_u8g2)
  211. #include "u8g2__setup.h"
  212. #endif
  213. #if defined(HAS_u8x8)
  214. #include "u8x8__setup.h"
  215. #if defined(HAS_SERIAL_PROXY_DISPLAY_SLAVE)
  216. u8x8.setCursor(0,1); //DISPLAY_DEV_setCursor(0,1);
  217. u8x8.print(" connect rx to"); u8x8.print(SERIAL_PROXY_SoftwareSerial_rx_pin); //DISPLAY_DEV_print(" connect rx to"); u8x8.print(SERIAL_PROXY_SoftwareSerial_rx_pin);
  218. u8x8.setCursor(0,2); //DISPLAY_DEV_setCursor(0,2);
  219. u8x8.print(" connect tx to");u8x8.print(SERIAL_PROXY_SoftwareSerial_tx_pin);
  220. u8x8.setCursor(0,3);
  221. u8x8.print(" . ");
  222. u8x8.setCursor(0,4);
  223. #endif
  224. #endif
  225. #if defined(HAS_SERIAL_PROXY_SoftwareSerial)
  226. pinMode(SERIAL_PROXY_SoftwareSerial_rx_pin, INPUT);
  227. pinMode(SERIAL_PROXY_SoftwareSerial_rx_pin, OUTPUT);
  228. SERIAL_PROXY_DEVICE.begin(SERIAL_PROXY_SPEED);
  229. #endif
  230. #if defined(HAS_SERIAL_PROXY)
  231. #include "SERIAL_PROXY__setup.h"
  232. #endif
  233. }
  234. unsigned long time = 0;
  235. #include "_LOOP_LATENCY_COUNTER.h" //lite ___loop/
  236. unsigned long t_timestamp = 0;
  237. void loop() {
  238. register long time;
  239. time = millis();
  240. #if defined(HAS_ROTTARY_SW)
  241. #include "_ROTTARY_SW_loop.h" //lite _ROTTARY_SW/
  242. #endif
  243. #ifdef DISABLE_LOOP
  244. #include "___DEBUG/___DEBUG_DISABLE_LOOP.h"
  245. #endif
  246. if( t_timestamp < millis() ) {
  247. t_timestamp = millis() + 4000 ;
  248. //u8x8.print("S"); //DISPLAY_DEV_print("S");
  249. //Serial.print(F("D"));
  250. Slave_Ports_Protocol_CAN_message_prototype_T__SERIAL_PROXY_DEVICE__send_ack() ;
  251. Slave_Ports_Status__DISPLAY_TARGET(
  252. Slave_Ports_Status_A ,
  253. Slave_Ports_Status_T_ARDUINO_ATTR_ARRAY_A,
  254. 0 ,
  255. // DISPLAY_PHYSICAL_CHAR_A,
  256. time,
  257. time + ARDUINO_time_seq_id_A_INCREMENT //ARDUINO_LOOP_LATENCY_DISPLAY_MENU
  258. //queue
  259. ,Slave_Ports_Status_QUEUE_A, Slave_Ports_Status_QUEUE_T_ARDUINO_ATTR_ARRAY_A ,
  260. TASK_TYPE_T__EMPTY__JUST_PASSED_ARG__,
  261. TASK_PORT_ASSOC_EMPTY
  262. //,DISPLAY_PHYSICAL_CHAR_A
  263. );
  264. DISPLAY__print_menu(
  265. //lite removed DISPLAY_A ,
  266. //lite removed DISPLAY_T_ARDUINO_ATTR_ARRAY_A ,
  267. // DISPLAY_PHYSICAL_CHAR_A,
  268. DISPLAY_MENU_INDEX_DEFAULT_A, //DISPLAY_MENU_ITEM_INDEX_T DISPLAY_MENU_ITEM_INDEX_A
  269. time,time + ARDUINO_LOOP_LATENCY_DISPLAY_MENU//time_seq_id_A, (time_seq_id_A + 5000)
  270. ,Slave_Ports_Status_A
  271. );
  272. }
  273. #if defined(HAS_SERIAL_PROXY)
  274. #include "SERIAL_PROXY__loop.h"
  275. #endif
  276. }