浏览代码

todo - jakos dziala - do porzadkowNIA

arkadiusz binder 5 年之前
父节点
当前提交
ae1ba9a93e

+ 53 - 31
SE/stuff/P5_Automation_can-dev-res-working-1930/___SUBMODULES___/P5_automation_can_arduino_i2c_submodule/P5_automation_can_arduino_i2c_submodule.ino

@@ -154,22 +154,25 @@ const TASK_TYPE_T TASK_TYPE_T_Broadcast_child_CHANGE___ = 0x12 ; //todo to repor
 
 
 #define HX711_Broadcast_child_CHANGE__Port_ID  0x01
-#define HX711_Broadcast_child_CHANGE__PortTypes_T  PortTypes_INPUT //PortTypes_T  PortTypes;  //4 0xFF  =  1111 1111 s
+//#define HX711_Broadcast_child_CHANGE__PortTypes_T  PortTypes_INPUT //PortTypes_T  PortTypes;  //4 0xFF  =  1111 1111 s
+#define HX711_Broadcast_child_CHANGE__PortTypes_T  B00000111 //PortTypes_T  PortTypes;  //4 0xFF  =  1111 1111 s
+#define HX711_Broadcast_child_CHANGE__Exp_state_T  B00000100 //PortTypes_T  PortTypes;  //4 0xFF  =  1111 1111 s
+
+
 
- 
 #define HX711_Broadcast_child_CHANGE__OUTPUT__Slave_ID  0x11
 #define HX711_Broadcast_child_CHANGE__OUTPUT__Port_ID  5
 
-#define HX711_Broadcast_child_CHANGE__TIME_MIN  100
+#define HX711_Broadcast_child_CHANGE__TIME_MIN  50
 
-#define HX711_Broadcast_child_CHANGE__DELTA_MIN  10000
+#define HX711_Broadcast_child_CHANGE__DELTA_MIN  5000
 #define HX711_Broadcast_child_CHANGE__LEVEL_MIN  20000
 #define HX711_Broadcast_child_CHANGE__LEVEL_MAX 400000
 
 
 
 float HX711_last_Broadcast_child_CHANGE = 0;
-float HX711_last_Broadcast_child_CHANGE_ratio = 0;
+int HX711_last_Broadcast_child_CHANGE_ratio = 0;
 
 
 #define calibration_factor 2280 //This value is obtained using the SparkFun_HX711_Calibration sketch https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide?_ga=2.77038550.2126325781.1526891300-303225217.1493631967
@@ -214,27 +217,53 @@ void setup() {
 
 void loop() {
  delay(HX711_Broadcast_child_CHANGE__TIME_MIN);
- // Serial.println("DELAY 500");
+// delay(500);
+
+  //Serial.println("DELAY 500");
 
   float HX711_current = scale.get_units(); //scale.get_units() returns a float
+ 
+ 
+ 
   if(HX711_last_Broadcast_child_CHANGE == 0) {
      HX711_last_Broadcast_child_CHANGE = HX711_current;
    } else if(abs(HX711_last_Broadcast_child_CHANGE - HX711_current) > HX711_Broadcast_child_CHANGE__DELTA_MIN) {
      Serial.print(" TODO CAN SEND:  ");
      Serial.print(HX711_current);
      Serial.print(" ; %  ");
-     HX711_last_Broadcast_child_CHANGE_ratio = ( HX711_Broadcast_child_CHANGE__LEVEL_MIN -  HX711_current ) / ( HX711_Broadcast_child_CHANGE__LEVEL_MAX - HX711_Broadcast_child_CHANGE__LEVEL_MIN ) ;
-     Serial.println(HX711_last_Broadcast_child_CHANGE_ratio);
+        HX711_last_Broadcast_child_CHANGE_ratio = 255 * abs( ( HX711_Broadcast_child_CHANGE__LEVEL_MIN -  HX711_current ) / ( HX711_Broadcast_child_CHANGE__LEVEL_MAX - HX711_Broadcast_child_CHANGE__LEVEL_MIN ))   ;
+        if(HX711_last_Broadcast_child_CHANGE_ratio > 255) HX711_last_Broadcast_child_CHANGE_ratio = 255 ;
+        if(HX711_last_Broadcast_child_CHANGE_ratio < 0) HX711_last_Broadcast_child_CHANGE_ratio = 0 ;     Serial.println(HX711_last_Broadcast_child_CHANGE_ratio);
+    
       HX711_last_Broadcast_child_CHANGE = HX711_current;
+      /*
+      
+ struct _Slave_Ports_Protocol_CAN_request_set_new_Exp_state_S {
+  _CAN_REMOTE_ID_T  _CAN_REMOTE_ID ;   // 1remote id - use FF for broadcast
+  const _CAN_SENDER_ID_T  _CAN_SENDER_ID = EEPROM_Active_ControllerID_read_A ;//Active_ControllerID_HEX ; //2 sender //Device which orginated port 
+  int  Port_ID ; //3 global id for device //const char * const _Protocol;
+  PortTypes_T  PortTypes;  //4 0xFF  =  1111 1111 s
+  Exp_state_T  Exp_state;    //5
+  int  Exp_state_ttl;  //6
+  Exp_state_level_T  Exp_state_level_A;  //6
+  const int _CAN_8 = 0x03; // TASK_TYPE_T_request_set_new_Exp_state = 0x03 ; // _CAN_8_EMPTY; //0x07 ; //8 - nbot used
+} ;
+      
+      */
+      //  can0  011   [8]  11111111-remote; 00010001-sender=0x11 ; 00000010 - port id;  ; 00000111 exp state  ;11011111=exp ttl ;  11001000 - level? ;  00011110 00000100
+
       
-      byte data[8] = {0xFF,  //Remote
+      
+      byte data[8] = {
+      HX711_Broadcast_child_CHANGE__OUTPUT__Slave_ID, //0xFF,  //Remote
        Active_ControllerID_HEX, //sender
         HX711_Broadcast_child_CHANGE__Port_ID, //int  Port_ID ; //3 global id for device //const char * const _Protocol;
          HX711_Broadcast_child_CHANGE__PortTypes_T ,//PortTypes_T  PortTypes;  //4 0xFF  =  1111 1111 s
-         Exp_state_ON_USE_LEVEL ,//   Exp_state_T  Exp_state;    //5
-           Exp_state_ttl_FULL_FRESH, //   int  Exp_state_ttl;  //6
-           Broadcast_state_FULL_FRESH,// int  Broadcast_state;  //7
-            TASK_TYPE_T_Broadcast_child_CHANGE___};
+         HX711_Broadcast_child_CHANGE__Exp_state_T, //Exp_state_ON_USE_LEVEL ,//   Exp_state_T  Exp_state;    //5
+           Exp_state_ttl_TO_REFRESH, //Exp_state_ttl_FULL_FRESH, //   int  Exp_state_ttl;  //6
+          HX711_last_Broadcast_child_CHANGE_ratio ,// Broadcast_state_FULL_FRESH,// int  Broadcast_state;  //7
+            0x03 // TASK_TYPE_T_request_set_new_Exp_state = 0x03 
+            };
       
      // byte data[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
 
@@ -248,25 +277,18 @@ void loop() {
          }
       
    }
-   
-  //  Serial.print(HX711_current / 1000); //You can change this to lbs but you'll need to refactor the calibration_factor
-  //  Serial.print(" HX711_current;  "); //You can change this to lbs but you'll need to refactor the calibration_factor
-  //  Serial.print(HX711_last_Broadcast_child_CHANGE / 1000); //You can change this to lbs but you'll need to refactor the calibration_factor
-  //  Serial.println(" HX711_last  "); //You can change this to lbs but you'll need to refactor the calibration_factor
-
-
-/*
- byte data[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
-
-      //byte sndStat = CAN0.sendMsgBuf(Active_ControllerID, 0, 8, data);
-       byte sndStat = CAN0.sendMsgBuf(0x100, 0, 8, data);
+ /* 
+        HX711_last_Broadcast_child_CHANGE_ratio = 255 * abs( ( HX711_Broadcast_child_CHANGE__LEVEL_MIN -  HX711_current ) / ( HX711_Broadcast_child_CHANGE__LEVEL_MAX - HX711_Broadcast_child_CHANGE__LEVEL_MIN ))   ;
+        if(HX711_last_Broadcast_child_CHANGE_ratio > 255) HX711_last_Broadcast_child_CHANGE_ratio = 255 ;
+        if(HX711_last_Broadcast_child_CHANGE_ratio < 0) HX711_last_Broadcast_child_CHANGE_ratio = 0 ;
+     Serial.print(HX711_last_Broadcast_child_CHANGE_ratio);
+       Serial.print(" RATIO;    "); //You can change this to lbs but you'll need to refactor the calibration_factor
 
-         if(sndStat == CAN_OK){
-           Serial.println("Message 2 Sent Successfully!");
-         } else {
-           Serial.println("Error 2 Sending Message...");
-         }
-      
+   
+    Serial.print(HX711_current / 1000); //You can change this to lbs but you'll need to refactor the calibration_factor
+   Serial.println(" HX711_current;  "); //You can change this to lbs but you'll need to refactor the calibration_factor
+ //   Serial.print(HX711_last_Broadcast_child_CHANGE / 1000); //You can change this to lbs but you'll need to refactor the calibration_factor
+ //   Serial.println(" HX711_last  "); //You can change this to lbs but you'll need to refactor the calibration_factor
 */
 
 }