| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596 |
- /* P5_Automation_can-dev
- * 2020-06 testing communications CAN for integrate further with Procesy5
- * A.Binder
- * Uses:
- * LCD1602 - big 2x16 character display
- * TFT_ILI9163C 128x128 lcd display
- * MCP_2515 - can port controller
- * //#define HAS_I2C_driver_Adafruit_PWMServoDriver
- * controls
- * Slave ports via:
- * I2C
- * PCA9685 - 16port 12bit PWM driver - can controll 16 eg. LEDs which can be 0....12V dimmed=]
- * todo 74HC595 - Serial to Parallel Shifting-Out - from 8 ports to many if connected in paraller
- * based on https://www.arduino.cc/en/tutorial/ShiftOut
- * or 16 servos
- * - can have addressed many of PCA9685 on I2C bus - so can controll over 64 ports
- * to be added another devices tested
- * todo Rottary Swich { GND, +, SW, DT, CLK } - to provide LCD menu access
- * TODO structure of port is in _Slave_Ports.h
- * _Slave_Port _Slave_Ports[] = {
- {"CAN", 0x102, 0x80, 0x00, 0, 0x00, 0x00 },
- {"CAN", - Base port origin protocol
- 0x102, - Base port origin protocol address
- 0x80, - int PortTypes; 0xFF = 1111 1111
- 0x01 = 0000 0001 = PWM port
- {
- bit 1 - PWM port
- bit 2 - not allocated
- bit 3 - not allocated
- bit 4 - not allocated
- bit 2 - not allocated
- bit 5 - not allocated
- bit 6 - not allocated
- bit 7 - not allocated
- bit 8 - not allocated
- },
- 0x00, int Address - local address on e.g. I2C bus - 0x40 etc
- 0x00, - int LocalPort - local port number when used e.g. I2C extension
- 0x01 - Exp_state - 0xFF = 1111 1111
- 0x00 = 0000 0000 = OFF = 0V
- 0x01 = 0000 0001 = ON = PWM max
- {
- bit 1 - OFF = 0V
- bit 2 - ON = PWM max
- bit 3 - not allocated
- bit 4 - not allocated
- bit 2 - not allocated
- bit 5 - not allocated
- bit 6 - not allocated
- bit 7 - not allocated
- bit 8 - not allocated
- },
- 0x6d - testowy ttl - 10 sekund do przedawnienia stanu portu w tablicy i koniecznosci odswiezenia tablicy
- }
- };
- - to be optimalized for inegration
- - to allow of subscribe ports
- - to allow of concurent routing
- - to allow new port detectioj
- - to allow creating ports dependencies e.g. IF
- - port has value
- - port AND port
- THEN
- - set port
- - probably should be avilable creations of virtual ports which would describe
- - state of port AND port etc...
- * TO BE INTEGRATED WITH p5
- * - interface and WFST
- * TO BE INGEGRATED WITH MARLIN 3D PRINTERS - machine and automation purpose
- * - controll remote ports via g-code
- * - allows interrupts
- * TO ALLOW OF NEXT PACKETS TYPES WITH DIFFERENT MEANINGS
- * - dimming
- * logic
- */
- //#define HAS_DEBUG_ACTION_TRIG
- //#define DEBUG_I2C //to debug _Slave_Ports_I2C_POP etc
- //#define HAS_TFT_ILI9163C
- //#define HAS_TFT_ILI9163C__ROTATED
- //#define HAS_LCD1602
- //#define HAS_LCD1602_I2C
- //#define LCD1602_DISPLAY_PHYSICAL_X_CHARS_A
- //#define LCD1602_DISPLAY_PHYSICAL_Y_CHARS_A
- //#define HAS_ROTTARY_SW
- #define ROTTARY_ENCODER_ACTION_MILLIS_MIN 250
- //#define HAS_CAN
- //#define DEBUG_I2C_driver_Adafruit_PWMServoDriver
- //#define DEBUG_CAN
- //#define DEBUG_QUEUE
- //#define DEBUG_QUEUE_ASSERT
- //#define DEBUG_QUEUE_WAIT 500
- //#define DEBUG_STRUCT_INIT
- //#define DEBUG_STORAGE_QUEUE_TEST
- //#define DEBUG_ARDUINO_ATTR_ARRAY_S__commit_added_element_QUEUE
- //#define DEBUG_ARDUINO_ARRAY_INDEX_NEXT_LOCK
- //#define HAS__PCINT_setup //to allow interrupts
- //#define DEBUG_TASK_TYPE_T_Slave_Ports_broadcast____
- //#define DEBUG_TASK_TYPE_T_DISPLAY_queue_pop________
- //#define DEBUG_TASK_TYPE_T_Slave_Ports_set_I2C______
- //#define DEBUG_QUEUE_ASSERT todo not working
- //#define DEBUG_LAST_ACTION_TRIG_ENABLE
- #define DISABLE_DISPLAY__add_record
- #define DISPLAY_array16_T_is_DISPLAY_string_T
- #define ENABLE_DISPLAY_MENU
- #define USE_DISPLAY_string_T
- //#define USE_DISPLAY_char_PA //dev testing pointer to display
- //#define DISABLE_ANY_PRINT //when uno ?
- //#define DEBUG 3
- //#define DISABLE_LOOP
- #define DISABLE_QUEUE_REASSIGN
- //#define DEBUG_LATENCY_MARKER
- //ports assign config
- #define PortA1 A1 //for rottary pro mini SW
- #define PortA2 A2 //for rottary pro mini SW DT
- #define PortA3 A3 //for rottary pro mini SW CLK
- #define PortA7 A7 //
- #define PortA8 A8 //for rottary sw
- #define PortA9 A9 //for rottary sw dt
- #define PortA10 A10 //for rottary sw clk
- #define Port7 7 //for TFT_ILI9163C_CSpin 7
- #define Port8 8 //for TFT_ILI9163C_DCpin 8
- #define Port9 9 //for TFT_ILI9163C__RSTpin 9
- #define Port10 10 // CAN_INTpin 10
- #define Port11 11 // todo PIR LOCAL
- #define Port12 12 // todo change CAN to 12 from 53
- #define Port53 53 // #define CAN_CSpin 53 //todo change can be 12?
- #define Sprintln(a) (Serial.println(a))
- /*
- Then instead of
- Serial.println(F("Hello world!"));
- write
- Sprintln(F("Hello world!"));
- etc. To deactivate the Serial printing, define the macro empty:
- #define Sprintln(a)
- */
- const int DISPLAY_MENU_A__PROGMEM_CONSOLE_PRINT = 3 ;
- #include "progmem.h"
- #include "___CONFIG/config_Active_Controller_EEPROM.h" //there kleep id of device
- #include "___CONFIG/config_Active_ControllerID.h" //there kleep id of device
- //config active should once update id
- //EEPROM_Active_ControllerID_read_T EEPROM_Active_ControllerID_read_A = EEPROM_Active_ControllerID_read();
- #define HAS__jm_Scheduler //to allow planned actions blink etc
- #if defined(HAS__jm_Scheduler)
- #include "jm_Scheduler.h"
- #endif
- //Debug level
- //#define DEBUG 5
- //#define DISABLE_LOOP //To debug and disable any output
- #include "__main_struct.h" //lite #include "___main/__main_struct.h"
- //#include "automation_driven.submodule.struct.write.h"
- #include "__main_trigger_struct.h" //lite #include "___main/__main_trigger_struct.h"
- #include "__main_struct_funct.h" //lite #include "___main/__main_struct_funct.h"
- #include "__main_struct_limits.h" //lite ___main/
- #include "_time_struct.h"
- #include "_DRIVER_STATUS_struct.h" //lite
- #include "__main_I2C_struc.h" //lite ___main/
- #include "__main_static.h" //lite ___main/
- #include "__main_auto.h" //lite ___main/
- #include "__main_register.h" //lite ___main/
- #include "__main_extern.h" //lite ___main/
- #include "___template/__STORAGE_ARRAY_func.h" //testing
- //#define _ControllerID 0x11
- //#define _Slave1_ID 0x13
- //#include "Active_ControllerID_0x103.h"
- //#define Active_ControllerID _ControllerID
- //#define Active_ControllerID _Slave1_ID
- //#include "config_Slave_Ports_LOCAL_0x101_init.h" //there kleep config of this id device
- #define print_SEP_RT "]"
- #include "config_Slave_Ports_LOCAL_config.h" //lite
- #if defined(HAS_TFT_ILI9163C)
- #include "_TFT_ILI9163C_config.h"
- #endif
- #include "_DISPLAY_struct.h" //lite
- #include "_Port_ID_sruct.h"
- #include "_TASK_TYPES_struct.h"
- #include "_Slave_Ports_Status_QUEUE_struct.h"
- //#include "Slave_Ports_Status_QUEUE.h"
- #include "_I2C_driver_Adafruit_PWMServoDriver_struct.h" //lite
- #include "_CAN_config.h" //lite _CAN/
- #if defined(HAS_ROTTARY_SW)
- #include "_ROTTARY_SW_config.h" //_ROTTARY_SW/
- #endif
- #if defined(HAS_I2C_driver_Adafruit_PWMServoDriver)
- #include "_I2C_driver_Adafruit_PWMServoDriver_config.h" //lite _I2C_driver_Adafruit_PWMServoDriver/
- #endif
- #if defined(HAS_ROTTARY_SW)
- #include "_ROTTARY_SW_struct.h" //lite _ROTTARY_SW/
- #endif
- #include "Queue.h"
- //#include "TPQ.h"
- Queue<int> _Slave_Ports_queue = Queue<int>(ARDUINO_ARRAY_INDEX_LIMIT_QUEUE);
- Queue<int> TEST_QUEUE = Queue<int>(ARDUINO_ARRAY_INDEX_LIMIT_QUEUE);
- /*#if Active_ControllerID == _ControllerID
- String lcdPattern = "s" ;
-
- #endif
- #if Active_ControllerID == _Slave1_ID
- String lcdPattern = "." ;
- #endif
- */
- //BEGIN 1602
- #if defined(HAS_LCD1602) or defined(HAS_LCD1602_I2C)
-
- // initialize the library with the numbers of the interface pins
- //LiquidCrystal lcd(4, 6, 10, 11, 12, 13);
- //LiquidCrystal lcd(4, 6, 53, 51, 50, 52 );
- #include "_LCD1602_struct.h"
- #endif
- #if defined(HAS_TFT_ILI9163C)
- #include "_TFT_ILI9163C_struct.h"
- #endif
- #if defined(HAS__PCINT_setup)
- #include "_PCINT_struct.h" //pins MYPIN1 MYPIN2 MYPIN3
- #endif
- //BEGIN CAN
- #include "_CAN_init.h" //lite #include "_CAN/_CAN_init.h"
- //EOF CAN
- //REMOTE PORTS DEFINITIONS
- #include "_PortTypes_struct.h"
- #include "_PortStates_struct.h"
- #include "_Port_Exp_state_ttl_struct.h"
- #include "_Port_Broadcast_state_struct.h"
- #include "_Port_I2C_driver_struct.h"
- #include "_Slave_Ports_Status_struct.h"
- #include "_Slave_Ports_Protocol_CAN_struct.h" //lite _CAN/
- #include "_Slave_Ports_Protocol_CAN_func.h"
- #include "automation_driven.submodule.struct.write.h"
-
-
- #if defined(HAS_TFT_ILI9163C)
- #include "_TFT_ILI9163C_func.h"
- #endif
- #include "_DISPLAY_DEV.h"
- #if defined(HAS_SERIAL_PROXY)
- #include "SERIAL_PROXY__struct.h"
- #endif
- #if defined(HAS_I2C_driver_Adafruit_PWMServoDriver)
- #include "_I2C_driver_Adafruit_PWMServoDriver_func.h" //lite _I2C_driver_Adafruit_PWMServoDriver/
- #endif
- #include "_TASK_TYPES_func.h"
- #include "_Slave_Ports_Status_QUEUE_add_func.h"
- #include "_DISPLAY_add_record_func.h"
- #include "_DISPLAY_func.h"
- #if defined(HAS_LCD1602) or defined(HAS_LCD1602_I2C)
- #include "_LCD1602_init.h"
- #endif
- #if defined(HAS_LCD1602) or defined(HAS_LCD1602_I2C)
- #include "_LCD1602_func.h"
- //#include "_LCD1602_init.h"
- #endif
- #if defined(HAS_ROTTARY_SW)
- #include "_ROTTARY_SW_func.h" //lite _ROTTARY_SW/
- #endif
- #include "_time_func.h"
- #include "_Slave_Ports_ttl_decrement_func.h"
- #include "_Slave_Ports_broadcast_func.h"
- #include "TASK_TYPE_T_Set_Port_Smooth_forward__.h"
- #include "_Slave_Ports_I2C_func.h"
- #include "_Slave_Ports_action_func.h"
- #include "_DISPLAY_queue_pop_func.h"
- #include "_Slave_Ports_Status_QUEUE_func.h"
- #include "TASK_TYPE_T_Get_Ports_Status_INPUT_A___.h"
- #include "_Slave_Ports_Status_func.h"
- #include "Slave_Ports_Status__DISPLAY_TARGET.h"
- #include "TASK_TYPE_T_Set_Ports_Status_LIMITS_A__.h"
- #include "TASK_TYPE_T_Set_Ports_Status_ASSOC.h"
-
- #include "_CAN_func.h" //lite _CAN/
- //EOF SERIAL ##############//EOF SERIAL ##############//EOF SERIAL ##############
- #include "SERIAL__init.h"
- #if defined(HAS_SERIAL_PROXY_SoftwareSerial)
- #include <SoftwareSerial.h>
- //SoftwareSerial SERIAL_PROXY_DEVICE(SERIAL_PROXY_SoftwareSerial_rx_pin, SERIAL_PROXY_SoftwareSerial_tx_pin); // RX, TX
- #include "SERIAL_PROXY__init.h"
- #if defined(SERIAL_PROXY_DEVICE)
- #errior when set HAS_SERIAL_PROXY_SoftwareSerial - cannot be set both hardware SERIAL_PROXY_DEVICE
- #endif
- #endif
- #if defined(HAS_SERIAL_PROXY)
- #include "SERIAL__struct.h"
- // #include "SERIAL__func.h"
- #endif
- #if defined(HAS_SERIAL_PROXY_DISPLAY_SLAVE)
- #define SoftwareSerial_SLAVE SoftwareSerial
- #include "SERIAL_PROXY_DISPLAY_SLAVE__init.h"
- #include "SERIAL_PROXY_DISPLAY_SLAVE__func.h"
- #endif
- #if defined(HAS_SERIAL_PROXY_DISPLAY_MASTER)
- #define SoftwareSerial_MASTER SoftwareSerial
- #include "SERIAL_PROXY_DISPLAY_MASTER__init.h"
- #include "SERIAL_PROXY_DISPLAY_MASTER__func.h"
- #endif
- #if defined(HAS_SERIAL_PROXY)
- // #define SoftwareSerial_PROXY SoftwareSerial
- // #include "SERIAL__struct.h"
- #include "SERIAL_PROXY__func.h"
- #include "SERIAL__func.h"
- #endif
- //EOF SERIAL ##############//EOF SERIAL ##############//EOF SERIAL ##############
- // #include "_Slave_Ports_ttl_decrement_POP.h"
- // #define _CAN_P_0x102_PWM0x00_0 { _Slave1_ID , "PWM", 0x00, 0 }
- //#define _CAN_P_0x102_PWMServoDriver0x40
-
- // #define Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver();
- // Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x40);
- // #define __CSpin 53 // 10 // chip select
-
-
-
- #if defined(HAS_TFT_ILI9163C)
- #include "_TFT_ILI9163C_init.h"
- #endif
-
- #include "_DISPLAY_init.h"
- #if defined(HAS_SERIAL_PROXY)
- #include "automation_driven.submodule.struct.read__communication_generated.h"
- #endif
- #if defined(HAS__PCINT_setup)
- #include "_PCINT_init.h"
- #endif
- #include "config_Slave_Ports_LOCAL_init.h"
- #if defined(HAS_I2C_driver_Adafruit_PWMServoDriver)
- #include "_I2C_driver_Adafruit_PWMServoDriver_init.h" //lite _I2C_driver_Adafruit_PWMServoDriver/
- #endif
- #include "__main_init.h" //lite ___main/
- #ifdef DISABLE_LOOP
- #include "___DEBUG/___DEBUG_DISABLE_INIT.h"
- #endif
- #include "scan.h"
- //test driven lcd_display
- #include "automation_driven_main.submodule.struct.write.lcd_menu.h"
- void setup() { //REMEMBER NOT INITIALIZE ANY VARIABLES OR ARRAYS
- Serial.begin(115200);
- Wire.begin();
-
-
-
-
- scan_h();
- ARDUINO_SETUP_DEF_T HAS_I2C_driver_Adafruit_PWMServoDriver_A = false;
- #if defined(DEBUG) || defined(DEBUG_QUEUE)
- Serial.println("#329 Serial.begin(115200)");
- #endif
- ARDUINO_SETUP_DEF_T HAS_ROTTARY_SW_A = false;
- //#include "___CONFIG/0x11/setup_Active_ControllerID_0x11.h"
- //#include "___CONFIG/0x13/setup_Active_ControllerID_0x13.h"
- //todo PCINT service
- #if defined(DISABLE_LOOP) || defined(DEBUG)
- Serial.println("#375 will include ___main/__main_I2C_setup.h");
- #endif
- #include "__main_I2C_setup.h" //lite ___main/
- #if defined(HAS__PCINT_setup)
- #include "_PCINT_setup.h" //empty
- #endif
- #if defined(HAS_ROTTARY_SW)
- #include "_ROTTARY_SW_setup.h" //Attach interrupts //lite _ROTTARY_SW/
- #endif
- #if defined(HAS_SERIAL_PROXY_SoftwareSerial)
- SERIAL_PROXY_DEVICE.println("<text,99,12.34,77>");
- pinMode(SERIAL_PROXY_SoftwareSerial_rx_pin, INPUT);
- pinMode(SERIAL_PROXY_SoftwareSerial_rx_pin, OUTPUT);
- SERIAL_PROXY_DEVICE.begin(SERIAL_PROXY_SPEED);
- #endif
- #if defined(HAS_SERIAL_PROXY)
- #include "SERIAL_PROXY__setup.h"
- #endif
-
-
- #if defined(HAS_I2C_driver_Adafruit_PWMServoDriver)
- #if defined(DISABLE_LOOP) || defined(DEBUG) || defined(DEBUG_I2C_driver_Adafruit_PWMServoDriver)
- Serial.println("#401 will include /_I2C_driver_Adafruit_PWMServoDriver_setup.h");
- #endif
-
- #include "_I2C_driver_Adafruit_PWMServoDriver_setup.h" //not any changes //lite _I2C_driver_Adafruit_PWMServoDriver/
- #endif
-
- // put your setup code here, to run once:
- ARDUINO_SETUP_DEF_T HAS_LCD1602_A = false; //todo
- #if defined(HAS_LCD1602) or defined(HAS_LCD1602_I2C)
- #include "_LCD1602_setup.h"
- #endif
- ARDUINO_SETUP_DEF_T HAS_TFT_ILI9163C_A = false ; //todo
- #if defined(HAS_TFT_ILI9163C)
- #include "_TFT_ILI9163C_setup.h"
-
- #endif
-
- //BEGIN CAN
-
-
- #include "_CAN_setup.h" //lite _CAN/
-
- #if defined(HAS_LCD1602) or defined(HAS_LCD1602_I2C)
- /* todo
- LCDarray1 = "loop.... ";
- LCDarray2 = "....";
- LCD_print(LCDarray1, LCDarray2, LCDtim/10);
- */
- #endif
- #ifndef DISABLE_LOOP
- #include "__main_setup.h" //lite ___main/
- #endif
- #ifdef DISABLE_LOOP
- #include "___DEBUG/___DEBUG_DISABLE_SETUP.h"
- #endif
- }
- //#if Active_ControllerID == _ControllerID
- // byte data[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
- //#endif
- //String LCDarray1 ;
- //String LCDarray2 ;
- unsigned long time;
- #include "_LOOP_LATENCY_COUNTER.h" //lite ___loop/
- void loop() {
- register long time;
- time = millis();
- #include "___loop_init.h" //lite ___loop/
-
- #if defined(HAS_ROTTARY_SW)
- #include "_ROTTARY_SW_loop.h" //lite _ROTTARY_SW/
- #endif
- #ifdef DISABLE_LOOP
- #include "___DEBUG/___DEBUG_DISABLE_LOOP.h"
- #endif
- #include "__main_loop_top.h" //lite ___loop/
-
- #include "_SlaveID_loop1.h" //todo PCINT //lite ___loop/
- #include "_ControllerID_loop1.h" //todo make default //lite ___loop/
- #include "__main_loop_end.h" //lite ___loop/
- #if defined(HAS_SERIAL_PROXY)
- #include "SERIAL_PROXY__loop.h"
- #endif
- if(DEBUG_ACTION_TRIG != DEBUG_LAST_ACTION_TRIG) {
- #if defined(DEBUG_LAST_ACTION_TRIG_ENABLE)
- Serial.print(F("#534 DEBUG_ACTION_TRIG["));Serial.print(DEBUG_ACTION_TRIG);Serial.print(F("] ")); Serial.print(F("] LAST_DEBUG_ACTION_TRIG["));Serial.print(DEBUG_LAST_ACTION_TRIG);Serial.println(F("] "));
- #endif
- // Serial.print("] COUNTER__MAIN_A["); Serial.print(ARDUINO_LOOP_LATENCY_COUNTER__MAIN_A);
- // Serial.print("] COUNTER__MAIN_END_A["); Serial.print(ARDUINO_LOOP_LATENCY_COUNTER__MAIN_END_A);
- }
- DEBUG_LAST_ACTION_TRIG = DEBUG_ACTION_TRIG ;
- }
- #include "_PCINT_func_loop.h" //todo empty implement display etc
- #include "_Slave_Ports_func_loop.h" //todo implement
|