a.binder преди 5 години
родител
ревизия
fcbb2103bb

+ 38 - 359
SE/stuff/P5_Automation_can-dev/P5_Automation_can-dev.ino

@@ -1,135 +1,17 @@
 /* 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
- */
-
-#include "Queue.h"
+*/
  
- Queue<int> _Slave_Ports_queue = Queue<int>(10);
- 
- 
- 
-#define  _ControllerID   0x101 
+#define  _ControllerID    0x101 
 #define  _Slave1_ID   0x103 
 
 #define Active_ControllerID _ControllerID 
 //#define Active_ControllerID _Slave1_ID 
  
 #include "Slave_Ports_Status.h"
-#include "Slave_Ports_QUEUE.h"  
+//#include "Slave_Ports_QUEUE.h"  
     
-#include "_Slave_Ports_queue_task_type_LIST.h"
-#include "_Slave_Ports_Protocol.h"
-
-
-
-
- #if Active_ControllerID == _ControllerID 
-    String lcdPattern = "s" ;
-   // #define HAS_LCD1602 
-   //  #define HAS_TFT_ILI9163C 
-   #define HAS_ROTTARY_SW
- #endif
- #if Active_ControllerID == _Slave1_ID 
-    String lcdPattern = "." ;
-    #define HAS_TFT_ILI9163C 
-   // #define HAS_LCD1602 
- #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  );
-  const int LCD1602rs=12, LCD1602en=11, LCD1602db4=5, LCD1602db5=4, LCD1602db6=3, LCD1602db7=2; // lcd keypad shield pins
-  LiquidCrystal lcd(LCD1602rs, LCD1602en, LCD1602db4, LCD1602db5, LCD1602db6, LCD1602db7);
-  int lcdPos = 0 ;
-  
-  #include "LCD1602.h"
-#endif
-
-
-#if defined(HAS_TFT_ILI9163C)
-
-  #include <SPI.h>
-  #include <Adafruit_GFX.h>
-  #include <TFT_ILI9163C.h>
-  #include "TFT_ILI9163C.h"
-
-#endif
+//#include "_Slave_Ports_queue_task_type_LIST.h"
+//#include "_Slave_Ports_Protocol.h"
 
 
 
@@ -152,26 +34,7 @@ MCP_CAN CAN0(CAN_CSpin);                          // Set CS to pin 10
 
  //REMOTE PORTS DEFINITIONS
 
-  #include "_Slave_Ports.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
- 
- 
- 
- int LCDtim = 250;  //the value of delay time
-
-
-
-
-
-
-
+ // #include "_Slave_Ports.h"
   
 
 #if defined(HAS_ROTTARY_SW)
@@ -184,77 +47,27 @@ MCP_CAN CAN0(CAN_CSpin);                          // Set CS to pin 10
 
 #include "_PCINT.h"
    
-
-
+ int Slave_Ports_Status_C_ports_defined = 0;
+  Slave_Ports_Status  Slave_Ports_Status_C;
 
 void setup() {
 
  Serial.begin(115200);
  
-   Slave_Ports_Status  Slave_Ports_Status_C;
-   Slave_Ports_QUEUE Slave_Ports_QUEUE_C;
+ 
+   
+ //  Slave_Ports_QUEUE Slave_Ports_QUEUE_C;
  
  #include "_Slave_Ports_LOCAL_LIST.h"
+  /*AAA
   #if defined(HAS_LCD1602)
     lcd.begin(16, 2);
   #endif
+  */
  //Slave_Ports_Status_T _add[] = { 1, Active_ControllerID, 0x01, 0x00, 1, 0x01, 0x01, 0x01 };
  
 
      Serial.println("#200 adding ports");
-     
-Slave_Ports_Status_C.add_port(
-             1, // int  Port_ID,
-            Active_ControllerID,  //  int  _Slave_ID,
-                0x01, //  int  PortTypes,
-                     0x00, //  int  Address,
-                      1, // int  LocalPort,
-                       0x01, //   int  Exp_state,
-                       0x01, // int  Exp_state_ttl,
-                       0x01, //  int  Broadcast_state,
-                       0x01, // int I2C_port,
-                      I2C_driver_NOT_USED_ ); //  int I2C_driver
-
-Slave_Ports_Status_C.add_port( 2, Active_ControllerID, 0x01, 0x00, 1, 0x01, 0x01, 0x01, 0x01, I2C_driver_NOT_USED_); // Slave_Ports_Status_C.I2C_driver_F(Adafruit_PWMServoDriver)
-
-Slave_Ports_Status_C.add_port( 3, Active_ControllerID, 0x01, 0x00, 1, 0x01, 0x01, 0x01, 0x01, I2C_driver_Adafruit_PWMServoDriver ); // Slave_Ports_Status_C.I2C_driver_F(Adafruit_PWMServoDriver)
-
-Slave_Ports_Status_C.add_port( 4, _Slave1_ID, 0x01, 0x00, 1, 0x01, 0x01, 0x01, 0x01, I2C_driver_Adafruit_PWMServoDriver ); // Slave_Ports_Status_C.I2C_driver_F(Adafruit_PWMServoDriver)
-
-
-
-
-
-
- //Slave_Ports_Status_C.list_ports();
-
-//Slave_Ports_Status_C.add_empty();
-//Queue<int> _Slave_Ports_queue = Queue<int>(10);
-//  LiquidCrystal lcd(LCD1602rs, LCD1602en, LCD1602db4, LCD1602db5, LCD1602db6, LCD1602db7);
-
-
- //Slave_Ports_Status_T
-//struct Slave_Ports_Status_S _add;
-
-
-
-
-
-
-// _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);
- Serial.println("#221");
-
  
 //todo PCINT service
 #include "_PCINT_setup.h"
@@ -265,146 +78,29 @@ Slave_Ports_Status_C.add_port( 4, _Slave1_ID, 0x01, 0x00, 1, 0x01, 0x01, 0x01, 0
  #include "_ROTTARY_SW_setup.h"
 #endif
  Serial.println("#231");
- 
 
 
- 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) ) ;
- 
-delay(1000);
-  
-  // put your setup code here, to run once:
-  #if defined(HAS_LCD1602)
-  
-     LCD_print(LCDarray1, LCDarray2, LCDtim/5);
-  #endif
-
-  #if defined(HAS_TFT_ILI9163C)
-
-  
-  TFT_ILI9163C display = TFT_ILI9163C(TFT_ILI9163C_CSpin, TFT_ILI9163C_DCpin, TFT_ILI9163C__RSTpin);
-  float p = 3.1415926;
-     display.begin();
-     display.clearScreen();
-     display.setCursor(0,0);
-     display.print(LCDarray1);
-     display.setCursor(0,10);
-     display.print(LCDarray2);
-     delay(LCDtim); 
-  #endif
-
-  //BEGIN CAN
- 
-  //if(CAN0.begin(MCP_STDEXT, CAN_500KBPS, MCP_16MHZ) == CAN_OK) {
   if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK) {
-     //LCDarray1="MCP2515 Init Okay";
-     //LCDarray2="500KBPS 16MHZ";
+ 
     Serial.println("#303 MCP2515 Init Okay");
-    /*
-    #if defined(HAS_LCD1602)
-      LCD_print(LCDarray1, LCDarray2, LCDtim/5);
-    #endif
-    #if defined(HAS_TFT_ILI9163C)
-      delay(LCDtim);  
-      display.setCursor(0,20); 
-      display.print("MCP2515 Init Okay!!\r\n");
-      delay(LCDtim); 
-    #endif
-    */
-  } else { 
-     /* LCDarray1 = "MCP2515 Init Failed";
-     LCDarray2 = "CAN_CSpin: "; 
-     LCDarray2.concat(CAN_CSpin);  
-     LCDarray2.concat("CAN_INTpin: ");
-     LCDarray2.concat(CAN_INTpin);    
-     */
-    Serial.println("#322 MCP2515 Init Failed");
-      /*
-      #if defined(HAS_LCD1602)
-          LCD_print(LCDarray1, LCDarray2, LCDtim / 2 ) ;
-      #endif
-      #if defined(HAS_TFT_ILI9163C)
-        delay(LCDtim);  
-        display.setCursor(0,20); 
-        display.print(LCDarray1);
-        delay(LCDtim); 
-         display.setCursor(0,50); 
-         display.print(LCDarray2);
-         delay(LCDtim); 
-      #endif
-      */
-  }
-
-        /*AAA
-       #if Active_ControllerID == _Slave1_ID 
-        #include "_SlaveID_setup.h"
-       #elif Active_ControllerID == _ControllerID
-          LCDarray1 = "Master Module       ";
-          LCDarray2 = "enabling remotes        ";
-       #endif
-        Serial.println("");
-         #if defined(HAS_LCD1602)
-          LCD_print(LCDarray1, LCDarray2, LCDtim / 5 ) ;
-          delay(LCDtim * 10); 
-         #endif
-         #if defined(HAS_TFT_ILI9163C)
-          delay(LCDtim);  
-          display.setCursor(0,30); 
-          display.print(LCDarray1); display.print(" ");
-          display.print(LCDarray2);
-
-          delay(LCDtim); 
-         #endif
-         */
+    
         CAN0.setMode(MCP_NORMAL);                // Change to normal mode to allow messages to be transmitted
         pinMode(CAN_INTpin, INPUT);                       // Setting pin 2 for /INT input
        Serial.println("#362 set MCP_NORMAL");
+    
+ 
+  } else { 
+ 
+    Serial.println("#322 MCP2515 Init Failed");
+ 
+  }
+       
   //EOF CAN
   
-    /*AA
-    #if defined(HAS_LCD1602) 
-      LCDarray1 = "#323 loop.... ";
-      //LCDarray2 = "....";
-     LCD_print1(LCDarray1, LCDtim/10);
-     
-    #endif
-    */
-    
-//_Slave_Ports_queue.push(_LCD_print_queue.peek() + 1);
+ 
  Serial.println("#298 _Slave_Ports_queue__list");
- //AA _Slave_Ports_queue__INIT(_Slave_Ports_queue_tasks_LIST);
-//AA _Slave_Ports_queue__list(_Slave_Ports_queue_tasks_LIST);
-//AA  int _Slave_Ports_queue_peek =  _Slave_Ports_queue.peek() ;
-//  int _Slave_Ports_queue_push = _Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1) ; 
-  //int _Slave_Ports_queue_peek_new = _Slave_Ports_queue.peek() ; _Slave_Ports_queue__add(  *_Slave_Ports_queue_tasks_LIST, 0x01 ,0x00 ,100, 5000 ) ;  // _Slave_Ports_queue_peek, _Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1), _Slave_Ports_queue.peek());
-//void _Slave_Ports_queue__add( _Slave_Ports_queue_tasksT* _Slave_Ports_queue_tasks_LIST,int _Slave_Ports_queue_task_type,int _Slave_Port_link,long time_seq_id, long time_min_run //, 
-//A_Slave_Ports_queue__add(     _Slave_Ports_queue_tasks_LIST,  int(0x04) ,0x00 ,100, 5000 ) ;  //        "_Slave_Ports_broadcast", //4
-int Slave_Ports_QUEUE_C_queue_id_current_broadcast = Slave_Ports_QUEUE_C.queue__add( TASK_TYPE_T_Slave_Ports_broadcast____,100, 5000 ) ;  //        "_Slave_Ports_broadcast", //4
-//_Slave_Ports_queue__add(  _Slave_Ports_queue_tasks_LIST, 0x05 ,0x00 ,100, 5000 ) ;  //"_Slave_Ports_set_I2C" //5  - to set ports associated on PW
-int Slave_Ports_QUEUE_C_queue_id_current_set_I2C = Slave_Ports_QUEUE_C.queue__add( TASK_TYPE_T_Slave_Ports_set_I2C______,100, 5000 ) ;  //        "_Slave_Ports_broadcast", //4
-
-delay(10000);
-
- //  _Slave_Ports_queue_peek =  _Slave_Ports_queue.peek() ; 
-   //_Slave_Ports_queue_push =  _Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1) ;  
-   //_Slave_Ports_queue_peek_new = _Slave_Ports_queue.peek() ; 
-//_Slave_Ports_queue__add(  _Slave_Ports_queue_tasks_LIST, 0x02 ,0x00 ,100, 5000, _Slave_Ports_queue_peek, _Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1), _Slave_Ports_queue.peek());
-//   _Slave_Ports_queue_peek =  _Slave_Ports_queue.peek() ; 
-   //_Slave_Ports_queue_push =  _Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1) ; 
-  // _Slave_Ports_queue_peek_new = _Slave_Ports_queue.peek() ; 
-//_Slave_Ports_queue__add(  _Slave_Ports_queue_tasks_LIST, 0x03 ,0x00 ,100, 5000, _Slave_Ports_queue_peek, 
-//_Slave_Ports_queue.push(_Slave_Ports_queue.peek() + 1),
-//_Slave_Ports_queue.peek());
-
- Serial.println("#301 _Slave_Ports_queue__list");
-_Slave_Ports_queue__list(_Slave_Ports_queue_tasks_LIST);
-Serial.print("#304 _Slave_Ports_queue.count(), "); Serial.println(_Slave_Ports_queue.count());
+ 
   
-   
- //  _Slave_Ports_queue__add(  _Slave_Ports_queue_tasks_LIST, 0x03 ,0x00 ,100, 5000 ) ;  
- //Serial.println("#323 _Slave_Ports_queue__list"); _Slave_Ports_queue__list(_Slave_Ports_queue_tasks_LIST);
-// Serial.print("#324 _Slave_Ports_queue.count(), "); Serial.println(_Slave_Ports_queue.count());
 
 }
 
@@ -418,42 +114,25 @@ Serial.print("#304 _Slave_Ports_queue.count(), "); Serial.println(_Slave_Ports_q
 
   unsigned long time;
   
-
+ #include "_PCINT_loop.h"
 
 void loop() {
- 
-  #include "_PCINT_loop.h"
+ Serial.println("#120 :loop " );
+ delay(1000);
 
+  
+  if( Slave_Ports_Status_C_ports_defined == 0) {
+   Serial.println("#431 : Slave_Ports_Status_C_ports_defined = 0" );
+   Slave_Ports_Status_C_ports_defined = 1;
+        Slave_Ports_Status_C.add_port( 1, 0x102, 0x01, 0x00, 1, 0x01, 0x01, 0x01, 0x01, 0x00); // Slave_Ports_Status_C.I2C_driver_F(Adafruit_PWMServoDriver)
+        Slave_Ports_Status_C.add_port( 2, 0x102, 0x01, 0x00, 1, 0x01, 0x01, 0x01, 0x01, 0x00); // Slave_Ports_Status_C.I2C_driver_F(Adafruit_PWMServoDriver)
+    //    Slave_Ports_Status_C.add_port( 3, 0x102, 0x01, 0x00, 1, 0x01, 0x01, 0x01, 0x01, 0x00); // Slave_Ports_Status_C.I2C_driver_F(Adafruit_PWMServoDriver)
+} else {
+    Serial.println("#438 : Slave_Ports_Status_C_ports_defined =1" );
+}
 
 
-  time = millis();
-  Serial.print("Time: " );
-  Serial.println(time);
-  // put your main code here, to run repeatedly:
-  //BEGIN CAN
-   
-   #if Active_ControllerID == _Slave1_ID
-      #include "_SlaveID_loop1.h"
-    #elif Active_ControllerID == _ControllerID
-         #include "_ControllerID_loop1.h"
-         
-    #endif
   
-  
-  _Slave_Ports_queue__list(_Slave_Ports_queue_tasks_LIST) ;
-  int _Slave_Ports_queue_count = _Slave_Ports_queue.count();
-  int _Slave_Ports_queue_front = _Slave_Ports_queue.front();
-  int _Slave_Ports_queue_back =  _Slave_Ports_queue.back();
-  int _Slave_Ports_queue_peek = _Slave_Ports_queue.peek();
-  int _Slave_Ports_queue_pop = _Slave_Ports_queue.pop();
- _Slave_Ports_queue__POP( _Slave_Ports_queue_tasks_LIST, 
- _Slave_Ports_queue_count, 
- _Slave_Ports_queue_pop, 
- _Slave_Ports_queue_front, 
- _Slave_Ports_queue_back,
- _Slave_Ports_queue_peek,
- LCDtim, _Slave_Ports);
-
  delay(5000);
   //_LCD_print_buffors_list(_LCD_print_buffors) ;
   //_LCD_print_screens_list(_LCD_print_screens);

+ 16 - 14
SE/stuff/P5_Automation_can-dev/Slave_Ports_QUEUE.cpp

@@ -21,14 +21,14 @@ int Slave_Ports_QUEUE::queue__add_A( Slave_Ports_Status_QUEUE_T QUEUE_A ) {
     if(_queue_count == 0) {
     
      }
-     Slave_Ports_Status_QUEUE_A[_queue_count + 1]._queue_id = _queue_id_current + 1 ;
-     Slave_Ports_Status_QUEUE_A[_queue_count + 1].TASK_TYPE_A = QUEUE_A.TASK_TYPE_A ;
+     this->Slave_Ports_Status_QUEUE_A[_queue_count + 1]._queue_id = _queue_id_current + 1 ;
+     this->Slave_Ports_Status_QUEUE_A[_queue_count + 1].TASK_TYPE_A = QUEUE_A.TASK_TYPE_A ;
      if(QUEUE_A.time_seq_id > 0) { 
-        Slave_Ports_Status_QUEUE_A[_queue_count + 1].time_seq_id = QUEUE_A.time_seq_id ;
+       this->Slave_Ports_Status_QUEUE_A[_queue_count + 1].time_seq_id = QUEUE_A.time_seq_id ;
      } else {
-        Slave_Ports_Status_QUEUE_A[_queue_count + 1].time_seq_id =  millis();
+        this->Slave_Ports_Status_QUEUE_A[_queue_count + 1].time_seq_id =  millis();
      }
-      Slave_Ports_Status_QUEUE_A[_queue_count + 1].time_min_run = QUEUE_A.time_min_run ;
+      this->Slave_Ports_Status_QUEUE_A[_queue_count + 1].time_min_run = QUEUE_A.time_min_run ;
          Serial.print("#261:queue__add A");
 
 }
@@ -38,18 +38,20 @@ int Slave_Ports_QUEUE::queue__add_A( Slave_Ports_Status_QUEUE_T QUEUE_A ) {
 int Slave_Ports_QUEUE::queue__add(  int TASK_TYPE_A, long time_seq_id, long time_min_run ) {
  
     
-     Slave_Ports_Status_QUEUE_A[_queue_count + 1]._queue_id = _queue_id_current + 1 ;
-     Slave_Ports_Status_QUEUE_A[_queue_count + 1].TASK_TYPE_A = TASK_TYPE_A ;
+     this->Slave_Ports_Status_QUEUE_A[_queue_count + 1]._queue_id = _queue_id_current + 1 ;
+     this->Slave_Ports_Status_QUEUE_A[_queue_count + 1].TASK_TYPE_A = TASK_TYPE_A ;
      if(time_seq_id > 0) { 
-        Slave_Ports_Status_QUEUE_A[_queue_count + 1].time_seq_id = time_seq_id ;
+        this->Slave_Ports_Status_QUEUE_A[_queue_count + 1].time_seq_id = time_seq_id ;
      } else {
-        Slave_Ports_Status_QUEUE_A[_queue_count + 1].time_seq_id =  millis();
+        this->Slave_Ports_Status_QUEUE_A[_queue_count + 1].time_seq_id =  millis();
      }
-      Slave_Ports_Status_QUEUE_A[_queue_count + 1].time_min_run = time_min_run ;
-         Serial.print("#285:queue__add");
-      _queue_count++;
-      _queue_id_current++;
-      return _queue_id_current;
+      this->Slave_Ports_Status_QUEUE_A[_queue_count + 1].time_min_run = time_min_run ;
+         Serial.print("#285:queue__add  new _queue_count[");
+      this->_queue_count++;
+      this->_queue_id_current++;
+      Serial.print(this->_queue_count); Serial.print("]  _queue_id_current[");
+      Serial.print(this->_queue_id_current); Serial.println("]  ");
+      return this->_queue_id_current;
       
 }
 

+ 0 - 245
SE/stuff/P5_Automation_can-dev/Slave_Ports_Status.cpp

@@ -1,245 +0,0 @@
-#include "Slave_Ports_Status.h"
-
-/*Slave_Ports_Status::Slave_Ports_Status(Client& client) : m_client(client) {
-    m_accountName = NULL;
-    m_appKeyName = NULL;
-    m_appKeyValue = NULL;
-    m_path = NULL;
-    m_nextChar = NULL;
-    m_nextState = END;
-}
-*/
-
-/*
-Slave_Ports_Status::Slave_Ports_Status(Client& client) : m_client(client) {
-    m_accountName = NULL;
-    m_appKeyName = NULL;
-    m_appKeyValue = NULL;
-    m_path = NULL;
-    m_nextChar = NULL;
-    m_nextState = END;
-}
-*/
-/*
-
-void Slave_Ports_Status::push() { //
-
-
-}
-*/
-
-
-
-Slave_Ports_Status::Slave_Ports_Status(){
-    Serial.print("#35 Slave_Ports_Status::Slave_Ports_Status():");
-    _count = 0 ;
-   Slave_Ports_Status_T Slave_Ports_Status_A[10];
-   // Slave_Ports_Status_QUEUE_T Slave_Ports_Status_QUEUE_A[10] ;
-    //_queue_id_current = 0 ;
-    //_queue_count = 0;
-}
-
-
-
-/*
-inline int Slave_Ports_Status::add(Slave_Ports_Status_T item)
-{
-  
-  Serial.print("Add item...  _count["); Serial.print(item.Port_ID);
-  
-   Serial.print("] 0 ["); Serial.print(item.Port_ID);
-   Serial.print("1 ["); Serial.print(item._Slave_ID);
-   Serial.print("2 ["); Serial.print(item.PortTypes);
-   Serial.print("3 ["); Serial.print(item.Address);
-   Serial.print("4 ["); Serial.print(item.LocalPort);
-   Serial.print("5 ["); Serial.print(item.Exp_state);
-   Serial.print("6 ["); Serial.print(item.Exp_state_ttl);
-   Serial.print("7 ["); Serial.print(item.Broadcast_state);
-   Serial.println("]"); 
-   
-   return 1 ;
-}
-*/
-
-
- 
-/*
-  void Slave_Ports_Status::I2C_driver_FS(int  I2C_driver) { //char*
-  
-   
-    // Serial.print("I2C_driver_FS[");
-     //Serial.print(I2C_driver_F(_NOT_USED_));
-     if(I2C_driver_NOT_USED_  == I2C_driver) {
-       Serial.println("_NOT_USED_");
-                       
-      // I2C_driver_FT =  "_NOT_USED______________";
-       //return  "_NOT_USED______________";
-     }
-       else if( I2C_driver_Adafruit_PWMServoDriver == I2C_driver) {
-       Serial.println("Adafruit_PWMServoDriver");
-                       //12345678901234567890134
-     //   I2C_driver_FT = "Adafruit_PWMServoDriver";
-      // return  "Adafruit_PWMServoDriver";
-     } else {
-        Serial.print("_UNKNOWN_");
-       //  I2C_driver_FT = "_UNKNOWN_______________";
-      //  return  "_UNKNOWN_______________";
-     }
-   
-     
- // sprintf(I2C_driver_FT, "%02d", 1);
- // return I2C_driver_FT;
- }
- 
-*/
-
-
- void Slave_Ports_Status::add_port(
-                int  Port_ID,
-                int  _Slave_ID,
-                int  PortTypes,
-                int  Address,
-                int  LocalPort,
-                int  Exp_state,
-                int  Exp_state_ttl,
-                int  Broadcast_state,
-                int I2C_port,
-                //int I2C_driver
-                int I2C_driver
-                )
-{
-  
-  Serial.print("add_port   _count["); Serial.print(_count);
-   Serial.print("]  _count + 1["); Serial.print(_count + 1);
-   Serial.print("] Port_ID["); Serial.print(Port_ID);
-   Serial.print("] _Slave_ID[0x"); Serial.print( _Slave_ID);
-   Serial.print("] PortTypes["); Serial.print(PortTypes);
-   Serial.print("] Address["); Serial.print(Address);
-   Serial.print("] LocalPort["); Serial.print(LocalPort);
-   Serial.print("] Exp_state["); Serial.print(Exp_state);
-//   Serial.print("] Exp_state_ttl["); Serial.print(Exp_state_ttl);
-//   Serial.print("] Broadcast_state["); Serial.print(Broadcast_state);
-//   Serial.print("] I2C_port["); Serial.print(I2C_port);
- //  Serial.print("] I2C_driver["); I2C_driver_FS(I2C_driver);
-   //Serial.print("] I2C_driver_Rev["); 
-      //unsigned char LCDarray1buf[24];
-      //LCDarray1.toCharArray(LCDarray1buf, 24);
-  //  I2C_driver_FT[24]  =   I2C_driver_FS(I2C_driver_F(I2C_driver)) ;
-   Serial.println("]"); 
-    //Slave_Ports_Status_A[_count + 1].Port_ID = Port_ID ;
-    
-    if(_count == 0) {
-    
-     this->Slave_Ports_Status_A[_count ].Port_ID=0x00;
-     this->Slave_Ports_Status_A[_count ]._Slave_ID=0x00;
-     this->Slave_Ports_Status_A[_count ].PortTypes=0x00;
-     this->Slave_Ports_Status_A[_count ].Address=0x00;
-     this->Slave_Ports_Status_A[_count ].LocalPort=0x00;
-     this->Slave_Ports_Status_A[_count ].Exp_state=0x00;
-     this->Slave_Ports_Status_A[_count ].Exp_state_ttl=0x00;
-     this->Slave_Ports_Status_A[_count ].Broadcast_state=0x00;
-     this->Slave_Ports_Status_A[_count ].I2C_port=0x00;
-     this->Slave_Ports_Status_A[_count ].I2C_driver=0x00;
-     //_count ++;
-     
-     this->_count ++;
-    /* Slave_Ports_Status::add_port(
-                  Port_ID,
-                  _Slave_ID,
-                  PortTypes,
-                  Address,
-                  LocalPort,
-                  Exp_state,
-                  Exp_state_ttl,
-                  Broadcast_state,
-                 I2C_port,
-                 I2C_driver
-                );
-     */
-    }
-    
-    this->Slave_Ports_Status_A[_count + 1].Port_ID = Port_ID ;
-    this->Slave_Ports_Status_A[_count + 1]._Slave_ID = _Slave_ID ;
-    this->Slave_Ports_Status_A[_count + 1].PortTypes = PortTypes ;
-    this->Slave_Ports_Status_A[_count + 1].Address = Address ;
-    this->Slave_Ports_Status_A[_count + 1].LocalPort = LocalPort ;
-    this->Slave_Ports_Status_A[_count + 1].Exp_state = Exp_state ;
-    this->Slave_Ports_Status_A[_count + 1].Exp_state_ttl = Exp_state_ttl ;
-    this->Slave_Ports_Status_A[_count + 1].Broadcast_state = Broadcast_state ;
-    this->Slave_Ports_Status_A[_count + 1].I2C_port = I2C_port ;
-    this->Slave_Ports_Status_A[_count + 1].I2C_driver = I2C_driver ;
-//    Slave_Ports_Status_A[_count + 1].I2C_driver = I2C_driver_F(I2C_driver) ;
-    this->_count ++;
-  
-}
-
-
-bool Slave_Ports_Status::add_empty()
-{
-  Serial.println("add_empty");
-}
-
-
-void Slave_Ports_Status::list_ports()
-{
-  Serial.print("print_ports#154   _count["); Serial.print(_count); Serial.println("] ");
-    int i;
-    for(i=2;i<=_count;i++) {
- 
-         Serial.print(" #IND["); Serial.print(i); 
-         Serial.print("] Port_ID["); Serial.print(Slave_Ports_Status_A[i].Port_ID, HEX);
-         Serial.print("] _Slave_ID[0x"); Serial.print( Slave_Ports_Status_A[i]._Slave_ID, HEX );
-         Serial.print("] PortTypes["); Serial.print(Slave_Ports_Status_A[i].PortTypes, HEX);
-      //   Serial.println("] Address [");
-         Serial.print("] Address["); //Serial.print(Slave_Ports_Status_A[i].Address, HEX);
-         Serial.print("] LocalPort["); Serial.print(Slave_Ports_Status_A[i].LocalPort);
-         Serial.print("] Exp_state["); Serial.print(Slave_Ports_Status_A[i].Exp_state, HEX);
-        Serial.print("] Exp_state_ttl["); Serial.print(Slave_Ports_Status_A[i].Exp_state_ttl, HEX);
-         Serial.print("] Broadcast_state["); Serial.print(Slave_Ports_Status_A[i].Broadcast_state, HEX);
-         Serial.print("] I2C_port["); Serial.print(Slave_Ports_Status_A[i].I2C_port, HEX);
-      //   Serial.print("] I2C_driver[");   Serial.print(Slave_Ports_Status_A[i].I2C_driver.CNF1);
-         
-          // I2C_driver_FT[24]  = I2C_driver_FS(Slave_Ports_Status_A[i].I2C_driver);
-          //  Serial.print(I2C_driver_FT[24]);
-         Serial.println("]"); 
-         
-         
-   }
-   
-   
-}
-
-/*
-
-Slave_Ports_Status_S Slave_Ports_Status::get_port(int  Port_ID)
-{
- // Serial.print("list_ports#154   _count["); Serial.print(_count); Serial.println("] ");
-    //int i;
-    //for(i=2;i<=_count;i++) {
-        return Slave_Ports_Status_A[Port_ID];         
-         
-  // }
-   //return Slave_Ports_Status_A;
-}
-
-
-*/
-
-Slave_Ports_Status::~Slave_Ports_Status(){
-     delete[] Slave_Ports_Status_A;
-    //Serial.print("#40 free ~Slave_Ports_Status");
-}
-
-/*
-int Slave_Ports_Status::get_count()
-    {
-            return _count;         
-    }
-
-*/
-
-/*
- byte Slave_Ports_Status::_Slave_Ports_Protocol_CAN_broadcast_F() {
-}
-*/
-

+ 0 - 200
SE/stuff/P5_Automation_can-dev/Slave_Ports_Status.h

@@ -1,200 +0,0 @@
-
-#ifndef SLAVE_PORTS_STATUS_H
-#define SLAVE_PORTS_STATUS_H
-
-
-
-
-
- #define    I2C_driver_NOT_USED_  0x00
- #define    I2C_driver_Adafruit_PWMServoDriver    0x01
-
-
-
-#include <Arduino.h>
-
-
-            
-            #ifndef voidfuncptr_t
-            #define voidfuncptr_t voidfuncptr_t
-            typedef void (*voidfuncptr_t)(void); // void function pointer typedef
-            #endif
-            
-            
-            
-            #ifndef vfp_vpu32b_t
-            #define vfp_vpu32b_t vfp_vpu32b_t
-            typedef void (*vfp_vpu32b_t)(void*, uint32_t, bool);
-            #endif
-
-
-typedef struct
-{
-  uint8_t CNF1;
-} I2C_driver_T;
-
-
-static I2C_driver_T constexpr _NOT_USED_  = {0x00};
-static I2C_driver_T constexpr Adafruit_PWMServoDriver  = {0x01};
-
-/*
-typedef struct  {
-   char I2C_driver_TA[32];
-} I2C_driver_TS ;
-*/
-//typedef struct I2C_driver_TS I2C_driver_TT;
-
-
-//I2C_driver_TS I2C_driver_AA = { "_NOT_USED_" };
-                                
-//I2C_driver_AA[0] =  "_NOT_USED_" ;
-//I2C_driver_AA[0x01] =  "Adafruit_PWMServoDriver" ; 
-
-
-
- struct Slave_Ports_Status_S {
-  int  Port_ID ; //global id for device //const char * const _Protocol;
-  int  _Slave_ID; //Device which orginated port   //remote id - use FF for broadcast
-  int  PortTypes;  //0xFF  =  1111 1111 s
-                                          /*
-                                          {
-                                      bit 1 - PWM port
-                                      bit 2 - on I2C managed port
-                                      bit 3 - expanded port with LocalPort address
-                                      bit 4 - not allocated
-                                      bit 2 - not allocated
-                                      bit 5 - not allocated
-                                      bit 6 - not allocated
-                                      bit 7 - not allocated
-                                      bit 8 - not allocated
-                                    } 
-                                           */
- // byte has_Address;
-  int  Address ;
- // byte has_Local_Port;
-  int  LocalPort;
-  int  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
-                                    }*/
-  int  Exp_state_ttl;  // 0x00 = odswiezyc
-  int  Broadcast_state; //0x00 - not broadcast; 0x01
-  int I2C_port ; //0x01 - default port, 0x00 - not I2C connected
-  int I2C_driver; //0x00 - not driver, 0x01 Adafruit_PWMServoDriver.h
- // int IS_Local; // Define if port is local or remote added
-  
-} ;
-
-typedef struct Slave_Ports_Status_S Slave_Ports_Status_T;
-
-/*
-enum class Mode : uint8_t
-{
-  Normal     = 0x00,
-  Sleep      = 0x20,
-  Loopback   = 0x40,
-  ListenOnly = 0x60,
-  Config     = 0x80
-};
-
-
-*/
-
-
-  //char I2C_driver_FT[32] ;
- static char I2C_driver_FT[24];
-
-
-
-
-
-#include "Slave_Ports_Status_QUEUE.h"
-
-
-
-
-
-class Slave_Ports_Status
-{
-
-
-private:
-    
-  
-  
-    
-//public:
-  //  static Slave_Ports_Status *first;
-    //static Slave_Ports_Status *_data;
-public:
-        int _count;
-        
-        
-         //   int _queue_id_current  ;
-         //   int _queue_count ;
-            
-            
-         Slave_Ports_Status_T *Slave_Ports_Status_A;
-         //Slave_Ports_Status_QUEUE_T *Slave_Ports_Status_QUEUE_A ;
-       
-       
-        //  void push(Slave_Ports_Status_S const &item);
-          //void push();
-          //Slave_Ports_Status();
-          //  bool setMode();
-          //voidfuncptr_t func;					// address of coroutine function
-          Slave_Ports_Status();
-          
-          
-         
-          
-         /* inline int add(
-            Slave_Ports_Status_LIST_T Slave_Ports_Status_LIST_A , 
-            Slave_Ports_Status_T Slave_Ports_Status_A
-            ) {
-            };
-            */
-          void add_port(
-                int  Port_ID,
-                int  _Slave_ID,
-                int  PortTypes,
-                int  Address,
-                int  LocalPort,
-                int  Exp_state,
-                int  Exp_state_ttl,
-                int  Broadcast_state,
-                int I2C_port,
-                int I2C_driver
-                //I2C_driver_T I2C_driver
-                );
-          bool add_empty();
-          void print_ports();
-          void list_ports();
-        //  Slave_Ports_Status_S get_port(int Port_ID);
-        //  int get_count();
-           
-           
-          // void I2C_driver_FS(int  I2C_driver) ;//char*
-           
-           // byte _Slave_Ports_Protocol_CAN_broadcast_F();
-           
-          ~Slave_Ports_Status();
-                    
-          
-       //   int queue__add_A(Slave_Ports_Status_QUEUE_T QUEUE_A);
-       //   int queue__add(TASK_TYPE_T, long int, long int);
-
-};
-
-
-#endif

+ 2 - 2
SE/stuff/P5_Automation_can-dev/_Slave_Ports.h

@@ -487,12 +487,12 @@ int _Slave_Ports_queue_task_type, int _Slave_Port_link, long time_seq_id, long t
                     */
                         if( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type == 0x01 ) {
                            Serial.print("#224 running _Slave_Ports_ttl_decrement = ");     Serial.println( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type);
-                            #include "_Slave_Ports_ttl_decrement.h"
+                            
                            _Slave_Ports_ttl_decrement_POP(_Slave_Ports_queue_tasks_LIST, _Slave_Ports_queue_pop ,  _Slave_Ports ) ; 
                            
                         } else if( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type == 0x04 ) {
                            Serial.print("#337 running _Slave_Ports_broadcast = ");     Serial.println( _Slave_Ports_queue_tasks_LIST[_Slave_Ports_queue_pop]._Slave_Ports_queue_task_type);
-                            #include "_Slave_Ports_ttl_decrement.h"
+                           
                            _Slave_Ports_broadcast_POP(_Slave_Ports_queue_tasks_LIST, _Slave_Ports_queue_pop ,  _Slave_Ports, LCDtim ) ; 
                            
                         }  else {