p5_automation_lite.ino 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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 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 3 //todo debug
  10. #define ARDUINO_ARRAY_INDEX_LIMIT_PORTS_DEF 3//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. #if defined(HAS_I2C_driver_Adafruit_PWMServoDriver)
  89. #include "_I2C_driver_Adafruit_PWMServoDriver_struct.h" //lite - too much ram 4% //reorganize
  90. #endif
  91. #include "_CAN_config.h" //lite _CAN/
  92. #if defined(HAS_ROTTARY_SW)
  93. #include "_ROTTARY_SW_config.h" //lite _ROTTARY_SW/
  94. #endif
  95. #if defined(HAS_I2C_driver_Adafruit_PWMServoDriver)
  96. #include "_I2C_driver_Adafruit_PWMServoDriver_config.h" //lite _I2C_driver_Adafruit_PWMServoDriver/
  97. #endif
  98. #if defined(HAS_ROTTARY_SW)
  99. #include "_ROTTARY_SW_struct.h" //lite _ROTTARY_SW/
  100. #endif
  101. #if defined(HAS_TFT_ILI9163C)
  102. //L#include "_TFT_ILI9163C_struct.h"
  103. #endif
  104. #if defined(HAS_u8g2)
  105. //L #include "u8g2_struct.h" //too much ram
  106. #endif
  107. #if defined(HAS_u8x8)
  108. #include "u8x8_struct.h"
  109. #endif
  110. #if defined(HAS__PCINT_setup)
  111. #include "_PCINT/_PCINT_struct.h" //pins MYPIN1 MYPIN2 MYPIN3
  112. #endif
  113. //BEGIN CAN
  114. #include "_CAN_init.h" //lite #include "_CAN/_CAN_init.h"
  115. //EOF CAN
  116. //REMOTE PORTS DEFINITIONS
  117. #include "_PortTypes_struct.h"
  118. #include "_PortStates_struct.h"
  119. #include "_Port_Exp_state_ttl_struct.h"
  120. #include "_Port_Broadcast_state_struct.h"
  121. #include "_Port_I2C_driver_struct.h"
  122. #include "_Slave_Ports_Status_struct_lite.h" // lite #include "_Slave_Ports_Status_struct.h"
  123. #include "_Slave_Ports_Protocol_CAN_struct.h" //lite _CAN/
  124. #if defined(HAS_TFT_ILI9163C)
  125. #include "_TFT_ILI9163C_func.h"
  126. #endif
  127. #if defined(HAS_u8g2) //lite too much ram
  128. //L #include <math.h>
  129. //L #include "u8g2.h"
  130. //L U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
  131. #endif
  132. #if defined(HAS_u8x8)
  133. #include "u8x8_func.h"
  134. #endif
  135. #include "_DISPLAY_DEV.h"
  136. #if defined(HAS_I2C_driver_Adafruit_PWMServoDriver)
  137. #include "_I2C_driver_Adafruit_PWMServoDriver_func.h" //lite _I2C_driver_Adafruit_PWMServoDriver/
  138. #endif
  139. #include "_TASK_TYPES_func.h"
  140. #include "_Slave_Ports_Status_QUEUE_add_func.h"
  141. #include "_DISPLAY_add_record_func.h"
  142. //#include "_DISPLAY_func.h"
  143. #include "_DISPLAY_func_lite.h"
  144. #if defined(HAS_LCD1602)
  145. //L#include "_LCD1602_init.h"
  146. #endif
  147. #if defined(HAS_LCD1602)
  148. //L#include "_LCD1602_func.h"
  149. //#include "_LCD1602_init.h"
  150. #endif
  151. #if defined(HAS_ROTTARY_SW)
  152. #include "_ROTTARY_SW_func.h" //_ROTTARY_SW/
  153. #endif
  154. #include "_time_func.h"
  155. #include "DISPLAY_ELEMENT_TO_REFRESH.h"
  156. #include "_Slave_Ports_ttl_decrement_func.h"
  157. #include "_Slave_Ports_broadcast_func.h"
  158. #include "TASK_TYPE_T_Set_Port_Smooth_forward__.h"
  159. #include "_Slave_Ports_I2C_func.h"
  160. #include "_Slave_Ports_action_func.h"
  161. #include "_DISPLAY_queue_pop_func.h"
  162. #include "_Slave_Ports_Status_QUEUE_func.h"
  163. #include "_Slave_Ports_Protocol_CAN_func.h"
  164. #include "TASK_TYPE_T_Get_Ports_Status_INPUT_A___.h"
  165. #include "_Slave_Ports_Status_func.h"
  166. #include "Slave_Ports_Status__DISPLAY_TARGET.h"
  167. #include "TASK_TYPE_T_Set_Ports_Status_LIMITS_A__.h"
  168. //L #include "_CAN_func.h" //lite _CAN/
  169. //L #include "_Slave_Ports.h"
  170. // #include "_Slave_Ports_ttl_decrement_POP.h"
  171. // #define _CAN_P_0x102_PWM0x00_0 { _Slave1_ID , "PWM", 0x00, 0 }
  172. //#define _CAN_P_0x102_PWMServoDriver0x40
  173. // #define Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver();
  174. // Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40);
  175. // #define __CSpin 53 // 10 // chip select
  176. #if defined(HAS_TFT_ILI9163C)
  177. #include "_TFT_ILI9163C_init.h"
  178. #endif
  179. #include "_DISPLAY_init.h"
  180. #include "config_Slave_Ports_LOCAL_init.h" //lite
  181. #if defined(HAS_I2C_driver_Adafruit_PWMServoDriver)
  182. //L #include "_I2C_driver_Adafruit_PWMServoDriver_init.h" //lite _I2C_driver_Adafruit_PWMServoDriver/
  183. #endif
  184. #include "__main_init.h"
  185. #ifdef DISABLE_LOOP
  186. //L #include "___DEBUG/___DEBUG_DISABLE_INIT.h"
  187. #endif
  188. //#include "scan.h"
  189. void setup() { //REMEMBER NOT INITIALIZE ANY VARIABLES OR ARRAYS
  190. Serial.begin(115200);
  191. //Wire.begin();
  192. // scan_h();
  193. #if defined(HAS_u8g2)
  194. //L #include "u8g2__setup.h"
  195. #endif
  196. #if defined(HAS_u8x8)
  197. #include "u8x8__setup.h"
  198. #endif
  199. }
  200. unsigned long time;
  201. #include "_LOOP_LATENCY_COUNTER.h" //lite ___loop/
  202. void loop() {
  203. register long time;
  204. time = millis();
  205. #include "___loop_init.h" //lite ___loop/
  206. #if defined(HAS_ROTTARY_SW)
  207. #include "_ROTTARY_SW_loop.h" //lite _ROTTARY_SW/
  208. #endif
  209. #include "__main_loop_top.h" //lite ___loop/
  210. #include "__main_loop_end.h" //lite ___loop/
  211. }