_ControllerID_loop1.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // send data: ID = 0x100, Standard CAN Frame, Data length = 8 bytes, 'data' = array of data bytes to send
  2. //byte sndStat = CAN0.sendMsgBuf(0x100, 0, 8, data);
  3. Serial.println("For tesing init remote ports");
  4. /* for (String v: _Slave_Ports) {
  5. Serial.print("Port: ");
  6. Serial.println(v);
  7. // for (auto i: v) {
  8. // do something with i
  9. //}
  10. }
  11. const char * const _Protocol;
  12. int _Slave_ID;
  13. int PortTypes; //0xFF = 1111 1111 { PWM, .....} = 0x80
  14. // byte has_Address;
  15. int Address ;
  16. // byte has_Local_Port;
  17. int LocalPort;
  18. int Exp_state;
  19. int Exp_state_ttl; // 0x00 = odswiezyc
  20. */
  21. for (auto element: _Slave_Ports) {
  22. Serial.print(" Prot:");
  23. Serial.print(element._Protocol);
  24. Serial.print(" , ID:");
  25. Serial.print(element._Slave_ID);
  26. Serial.print(" , PortTypes:");
  27. Serial.print(element.PortTypes);
  28. Serial.print(" , Addr:");
  29. Serial.print(element.Address);
  30. Serial.print(" , Local:");
  31. Serial.print(element.LocalPort);
  32. Serial.print(" , Exp state:");
  33. Serial.print(element.Exp_state);
  34. Serial.print(" , Exp_state_ttl");
  35. Serial.println(element.Exp_state_ttl);
  36. if(element._Protocol == "CAN") {
  37. // if(element.PortTypes == 0x80) {
  38. Serial.println(" Prepared data");
  39. #if defined(HAS_LCD1602)
  40. delay(LCDtim);
  41. String LCDarray1 = "P[";
  42. LCDarray1.concat(element._Protocol);
  43. LCDarray1.concat("] ID[");
  44. LCDarray1.concat(String(element._Slave_ID, HEX));
  45. LCDarray1.concat("] T[");
  46. LCDarray1.concat(String(element.PortTypes, HEX));
  47. LCDarray1.concat(" "); //1234567890ABCDEFGHIJKLMNOPQRTSWabcdefghijklmnopqrstwquwz
  48. // lcd.print(LCDarray1);
  49. unsigned char LCDarray1buf[15];
  50. Serial.print(" LCDarray1 Strlen:::[");
  51. Serial.print(LCDarray1);
  52. Serial.println(" ]:::");
  53. //char LCDarray11[] = {String(LCDarray1)};
  54. LCDarray1.toCharArray(LCDarray1buf, 15);
  55. Serial.print(" LCDarray1BStrlen:::[");
  56. Serial.print(LCDarray1);
  57. Serial.println(" ]:::");
  58. String LCDarray2 = " >";
  59. LCDarray2.concat(String(element.Address, HEX));
  60. LCDarray2.concat( "< {");
  61. LCDarray2.concat( String(element.LocalPort, HEX));
  62. LCDarray2.concat( "} =[" );
  63. LCDarray2.concat(String(element.Exp_state, HEX) );
  64. LCDarray2.concat("] ?[" ) ;
  65. LCDarray2.concat(String(element.Exp_state_ttl, HEX)) ;
  66. LCDarray2.concat("] ") ;
  67. unsigned char LCDarray2buf[16];
  68. Serial.print(" LCDarray2 Strlen:::[");
  69. Serial.print(LCDarray2);
  70. Serial.println(" ]:::");
  71. LCDarray2.toCharArray(LCDarray2buf, 15);
  72. Serial.print(" LCDarray2B`Strlen:::[");
  73. Serial.print(LCDarray2);
  74. Serial.println(" ]:::");
  75. lcd.setCursor(15,0);
  76. for ( int positionCounter1 = 15;
  77. positionCounter1 < 24; positionCounter1++)
  78. {
  79. lcd.scrollDisplayLeft(); //Scrolls the contents of the display one space to the left.
  80. lcd.print(LCDarray1[positionCounter1]); // Print a message to the LCD.
  81. delay(LCDtim); //wait for 250 microseconds
  82. }
  83. lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner.
  84. lcd.setCursor(15,1);
  85. for ( int positionCounter2 = 15;
  86. positionCounter2 < 24; positionCounter2++)
  87. {
  88. lcd.scrollDisplayLeft(); //Scrolls the contents of the display one space to the left.
  89. lcd.print(LCDarray2[positionCounter2]); // Print a message to the LCD.
  90. delay(LCDtim); //wait for 250 microseconds
  91. }
  92. delay(LCDtim * 5); //wait for 250 microseconds
  93. lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner.
  94. /* lcd.print("P[");
  95. lcd.print(element._Protocol);
  96. lcd.print("]ID[");
  97. lcd.print(element._Slave_ID);
  98. lcd.print("]T[");
  99. lcd.print(element.PortTypes);
  100. */
  101. // lcd.setCursor(0,1);
  102. // lcd.print(LCDarray2);
  103. /* lcd.print("]@[");
  104. lcd.print(element.Address);
  105. lcd.print("]|[");
  106. lcd.print(element.LocalPort);
  107. lcd.print("]=[");
  108. lcd.print(element.Exp_state);
  109. lcd.print("]?[");
  110. lcd.println(element.Exp_state_ttl);
  111. */
  112. /*
  113. lcdPos = 14;
  114. delay(LCDtim * 5);
  115. lcd.setCursor(0,0);
  116. lcd.print(LCDarray2);
  117. lcd.setCursor(0,1);
  118. lcd.print(" ");
  119. //copy cursor to up
  120. */
  121. #endif
  122. byte data[8] = {element.Address, element.LocalPort, element.PortTypes, element.LocalPort, element.Exp_state, element.Exp_state_ttl, 0x06, 0x07};
  123. // }
  124. byte sndStat = CAN0.sendMsgBuf(element._Slave_ID, 0, 8, data);
  125. if(sndStat == CAN_OK){
  126. Serial.println("Message Sent Successfully!");
  127. String LCDarray1 = "Message Sent";
  128. String LCDarray2 = "Successfully";
  129. } else {
  130. Serial.println("Error Sending Message...");
  131. String LCDarray1 = "Error Sending";
  132. String LCDarray2 = "Message...";
  133. }
  134. }
  135. #if defined(HAS_LCD1602)
  136. delay(LCDtim);
  137. //lcd.setCursor(0,1);
  138. lcd.print(lcdPattern);
  139. //lcd.print(lcdPos % 10);
  140. if(lcdPos >= 16) {
  141. //lcd.print("N");
  142. lcd.setCursor(0,1);
  143. lcdPos = 0;
  144. if(lcdPattern=="s") lcdPattern = "S" ;
  145. else lcdPattern = "s" ;
  146. }
  147. lcdPos ++;
  148. #endif
  149. #if defined(HAS_TFT_ILI9163C)
  150. delay(LCDtim);
  151. display.setCursor(0,60);
  152. display.print(LCDarray1); display.print(" "); display.print(LCDarray2);
  153. #endif
  154. delay(5000); // send data per 100ms
  155. }
  156. // byte sndStat = CAN0.sendMsgBuf(_Slave1_ID, 0, 8, data);