| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345 |
- /* 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
- *
- * 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_TFT_ILI9163C
- //#define HAS_LCD1602
- //#define HAS_ROTTARY_SW
- #define HAS__PCINT_setup //to allow interrupts
- #define DEBUG 5 //Debug level
- #include "__main_struct.h"
- #include "__main_struct_funct.h"
- #include "__main_struct_limits.h"
- #include "_time_struct.h"
- #define _ControllerID 0x101
- #define _Slave1_ID 0x103
- #include "config_Active_ControllerID.h"
- #if defined(HAS_TFT_ILI9163C)
- #include "_TFT_ILI9163C_config.h"
- #endif
- //#include "Active_ControllerID_0x103.h"
- //#define Active_ControllerID _ControllerID
- //#define Active_ControllerID _Slave1_ID
- // #define HAS_I2C_driver_Adafruit_PWMServoDriver
- #include "_DISPLAY_struct.h"
- #include "_Port_ID_sruct.h"
- #include "_I2C_driver_Adafruit_PWMServoDriver_struct.h"
- #include "_TASK_TYPES_struct.h"
- #include "_Slave_Ports_Status_QUEUE_struct.h"
- //#include "Slave_Ports_Status_QUEUE.h"
- #include "Queue.h"
-
- Queue<int> _Slave_Ports_queue = Queue<int>(10);
-
- #if Active_ControllerID == _ControllerID
- String lcdPattern = "s" ;
-
- #endif
- #if Active_ControllerID == _Slave1_ID
- String lcdPattern = "." ;
-
- #endif
- //BEGIN 1602
- #if defined(HAS_LCD1602)
- #include <LiquidCrystal.h>
- // 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"
- // #include "_LCD1602_init.h"
- #endif
- #if defined(HAS_TFT_ILI9163C)
- #include "_TFT_ILI9163C_struct.h"
- #endif
- #if defined(HAS__PCINT_setup)
- #include "_PCINT_struct.h"
- #endif
- //BEGIN CAN
- #include "_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"
-
- #if defined(HAS_TFT_ILI9163C)
- #include "_TFT_ILI9163C_func.h"
- #endif
-
- #include "_DISPLAY_func.h"
- #if defined(HAS_LCD1602)
- #include "_LCD1602_func.h"
- //#include "_LCD1602_init.h"
- #endif
- #if defined(HAS_ROTTARY_SW)
- #include "_ROTTARY_SW_func.h"
- #endif
- #include "_TASK_TYPES_func.h"
- #include "_Slave_Ports_Status_QUEUE_func.h"
- #include "_Slave_Ports_Protocol_CAN_func.h"
- #include "_Slave_Ports_Status_func.h"
- #include "_Slave_Ports_broadcast_func.h"
- #include "_Slave_Ports_ttl_decrement_func.h"
- #include "_Slave_Ports.h"
- // #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_LCD1602)
- #include "_LCD1602_init.h"
- #endif
- #if defined(HAS_TFT_ILI9163C)
- #include "_TFT_ILI9163C_init.h"
- #endif
-
- #include "_DISPLAY_init.h"
-
- #if defined(HAS_ROTTARY_SW)
- #include "_ROTTARY_SW_init.h"
- #endif
- #if defined(HAS_I2C_driver_Adafruit_PWMServoDriver)
- #include "_I2C_driver_Adafruit_PWMServoDriver_init.h"
- #endif
- #if defined(HAS__PCINT_setup)
- #include "_PCINT_init.h"
- #endif
- #include "config_Slave_Ports_LOCAL_init.h"
- ARDUINO_FUNCT_INIT_RESULT_T ARDUINO_FUNCT_INIT_RESULT__Slave_Ports_LOCAL_init =
- _Slave_Ports_LOCAL_init(
- Slave_Ports_Status_A ,
- Slave_Ports_Status_T_ARDUINO_ATTR_ARRAY_A,
- DISPLAY_A , DISPLAY_T_ARDUINO_ATTR_ARRAY_A
- //, DISPLAY_PHYSICAL_CHAR_A
- );
- void setup() {
- Serial.begin(115200);
- // Serial.println("#233 setup" );
- // _LCD_print_queue.push(1);
- // _LCD_print_queue.push(2);
- // _LCD_print_queue.push(3);
- //String character = "Geas";
- //char b = abc.charAt(0);
- //int b_ascii_value = b;
- // LCD_print_background_add( _LCD_print_buffors, 0, 0, 0, "W", 5000, 6000);
- // LCD_print_background_add( _LCD_print_buffors, 1, 0, 0, "H", 5000, 6000);
- // LCD_print_background_add( _LCD_print_buffors, 2, 0, 0, "W", 5000, 6000);
- // LCD_print_background_add( _LCD_print_buffors, 3, 0, 0, "K", 5000, 6000);
-
- //todo PCINT service
- #include "_PCINT_setup.h"
- #if defined(HAS_ROTTARY_SW)
- #include "_ROTTARY_SW_setup.h"
- #endif
- String LCDarray1="CAN_1602_LCD "; //the string to print onthe LCD
- String LCDarray2="Testing id "; //the string to print onthe LCD
- LCDarray2.concat(String(Active_ControllerID, HEX) ) ;
-
-
- // put your setup code here, to run once:
- #if defined(HAS_LCD1602)
- #include "_LCD1602_setup.h"
- #endif
- #if defined(HAS_TFT_ILI9163C)
- #include "_TFT_ILI9163C_setup.h"
- #endif
-
- //BEGIN CAN
- #include "_CAN_setup.h"
-
- #if defined(HAS_LCD1602)
- LCDarray1 = "loop.... ";
- LCDarray2 = "....";
- LCD_print(LCDarray1, LCDarray2, LCDtim/10);
-
- #endif
- #include "__main_setup.h"
- }
- //#if Active_ControllerID == _ControllerID
- // byte data[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
- //#endif
- //String LCDarray1 ;
- //String LCDarray2 ;
- unsigned long time;
-
- void loop() {
-
- #include "_PCINT_loop.h"
- time = millis();
- Serial.println("Time: " );
- // Serial.println(time);
- #include "_SlaveID_loop1.h" //todo PCINT
- #include "_ControllerID_loop1.h" //todo make default
-
- #include "__main_loop_end.h"
- // DISPLAY_DEV.setCursor(10,10);
- // DISPLAY_DEV.print(" Test307");
-
- DISPLAY__print_ANY(
- DISPLAY_T_ARDUINO_ATTR_ARRAY_A ,
- DISPLAY_PHYSICAL_CHAR_A,
- DISPLAY_pos_seq_A_NEXT,
- "123456789012345678901234567890"
- );
- delay(5000);
-
- }
- #include "_PCINT_func_loop.h" //todo empty implement display etc
- #include "_Slave_Ports_func_loop.h" //todo implement
|