P5_Automation_can-dev.ino 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* P5_Automation_can-dev
  2. */
  3. #define _ControllerID 0x101
  4. #define _Slave1_ID 0x103
  5. #define Active_ControllerID _ControllerID
  6. //#define Active_ControllerID _Slave1_ID
  7. #include "Slave_Ports_Status.h"
  8. Slave_Ports_Status Slave_Ports_Status_C;
  9. //#include "Slave_Ports_QUEUE.h"
  10. //#include "_Slave_Ports_queue_task_type_LIST.h"
  11. //#include "_Slave_Ports_Protocol.h"
  12. //BEGIN CAN
  13. /*
  14. #include <mcp_can.h>
  15. #include <SPI.h>
  16. long unsigned int CANrxId;
  17. unsigned char CANlen = 0;
  18. unsigned char CANrxBuf[8];
  19. const int CAN_CSpin = 53 , CAN_INTpin = 10 ;
  20. MCP_CAN CAN0(CAN_CSpin); // Set CS to pin 10
  21. //EOF CAN
  22. */
  23. //REMOTE PORTS DEFINITIONS
  24. // #include "_Slave_Ports.h"
  25. /*
  26. #if defined(HAS_ROTTARY_SW)
  27. #include "_ROTTARY_SW.h"
  28. #endif
  29. // include the library code
  30. //EOF BEGIN 1602
  31. #include "_PCINT.h"
  32. #include "_PCINT_loop.h"
  33. */
  34. int Slave_Ports_Status_C_ports_defined = 0;
  35. void setup() {
  36. Serial.begin(57600);
  37. // Slave_Ports_QUEUE Slave_Ports_QUEUE_C;
  38. //#include "_Slave_Ports_LOCAL_LIST.h"
  39. /*AAA
  40. #if defined(HAS_LCD1602)
  41. lcd.begin(16, 2);
  42. #endif
  43. */
  44. //Slave_Ports_Status_T _add[] = { 1, Active_ControllerID, 0x01, 0x00, 1, 0x01, 0x01, 0x01 };
  45. Serial.println("UUWWW adding ports");
  46. //todo PCINT service
  47. //#include "_PCINT_setup.h"
  48. /*
  49. #if defined(HAS_ROTTARY_SW)
  50. #include "_ROTTARY_SW_setup.h"
  51. #endif
  52. */
  53. Serial.println("CCCAA");
  54. /*
  55. if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK) {
  56. Serial.println("#303 MCP2515 Init Okay");
  57. CAN0.setMode(MCP_NORMAL); // Change to normal mode to allow messages to be transmitted
  58. pinMode(CAN_INTpin, INPUT); // Setting pin 2 for /INT input
  59. Serial.println("#362 set MCP_NORMAL");
  60. } else {
  61. Serial.println("#322 MCP2515 Init Failed");
  62. }
  63. //EOF CAN
  64. */
  65. Serial.println("WWWF _Slave_Ports_queue__list");
  66. }
  67. //#if Active_ControllerID == _ControllerID
  68. // byte data[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  69. //#endif
  70. //String LCDarray1 ;
  71. //String LCDarray2 ;
  72. //unsigned long time;
  73. int loop_id = 0;
  74. void loop() {
  75. Serial.println("BBCC :loop " );
  76. delay(1000);
  77. loop_id ++;
  78. // time = millis();
  79. if( Slave_Ports_Status_C_ports_defined == 0) {
  80. Serial.println("AAXX Slave_Ports_Status_C_ports_defined = 0" );
  81. Slave_Ports_Status_C_ports_defined = 1;
  82. 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)
  83. int _count_get = Slave_Ports_Status_C._count_get();
  84. Serial.print("AVVV S_count_get: " ); Serial.println(_count_get );
  85. // 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)
  86. //_count_get = Slave_Ports_Status_C._count_get();
  87. //_count_get = Slave_Ports_Status_C._count_get();
  88. // 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)
  89. // _count_get = Slave_Ports_Status_C._count_get();
  90. } else {
  91. Serial.println("GGHH : Slave_Ports_Status_C_ports_defined =1" );
  92. }
  93. Serial.write("Loop " );
  94. Serial.println(loop_id );
  95. delay(5000);
  96. //_LCD_print_buffors_list(_LCD_print_buffors) ;
  97. //_LCD_print_screens_list(_LCD_print_screens);
  98. }