arkadiusz binder 5 yıl önce
ebeveyn
işleme
80f27363fd

+ 43 - 8
SE/stuff/P5_Automation_can-dev-res-working-1930/___SUBMODULES___/P5_automation_can_arduino_i2c_submodule/P5_automation_can_arduino_i2c_submodule.ino

@@ -163,7 +163,11 @@ const TASK_TYPE_T TASK_TYPE_T_Broadcast_child_CHANGE___ = 0x12 ; //todo to repor
 #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  50
+#define HX711_Broadcast_child_CHANGE__TIME_MIN  100
+
+#define HX711_Broadcast_child_CHANGE__TIME_RETRY_LAST  500
+
+
 
 #define HX711_Broadcast_child_CHANGE__DELTA_MIN  5000
 #define HX711_Broadcast_child_CHANGE__LEVEL_MIN  20000
@@ -173,7 +177,8 @@ const TASK_TYPE_T TASK_TYPE_T_Broadcast_child_CHANGE___ = 0x12 ; //todo to repor
 
 float HX711_last_Broadcast_child_CHANGE = 0;
 int HX711_last_Broadcast_child_CHANGE_ratio = 0;
-
+int HX711_Broadcast_child_CHANGE__TIME_RETRY_LAST_FLAG = 0 ;  //to force last level after some time
+ 
 
 #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
 
@@ -213,9 +218,13 @@ void setup() {
 }
 
 
-
+  unsigned long time;
+unsigned long HX711_last_Broadcast_child_CHANGE_time ;
+int DTime ;
 
 void loop() {
+ // register long time;
+  time = millis();
  delay(HX711_Broadcast_child_CHANGE__TIME_MIN);
 // delay(500);
 
@@ -227,15 +236,41 @@ void loop() {
  
   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) {
+     HX711_last_Broadcast_child_CHANGE_time = time ;
+   } else if((abs(HX711_last_Broadcast_child_CHANGE - HX711_current) > HX711_Broadcast_child_CHANGE__DELTA_MIN)
+    or (HX711_Broadcast_child_CHANGE__TIME_RETRY_LAST_FLAG == 1 and (time - HX711_last_Broadcast_child_CHANGE_time) > HX711_Broadcast_child_CHANGE__TIME_RETRY_LAST)
+            ) {
      Serial.print(" TODO CAN SEND:  ");
+     
+       Serial.print(" ; Time  ");
+     Serial.print(time);
+     
+      Serial.print(" ; LTime  ");
+     Serial.print(HX711_last_Broadcast_child_CHANGE_time);
+    if((time - HX711_last_Broadcast_child_CHANGE_time) > HX711_Broadcast_child_CHANGE__TIME_RETRY_LAST) {
+            DTime = int(time) - int(HX711_last_Broadcast_child_CHANGE_time) ;
+              Serial.print(" ; DTime > TIME_RETRY_LAST  ");
+                  Serial.print(DTime, HEX);
+                   HX711_Broadcast_child_CHANGE__TIME_RETRY_LAST_FLAG = 0; 
+                     Serial.print(" --[" ); 
+             } else {
+                    HX711_Broadcast_child_CHANGE__TIME_RETRY_LAST_FLAG = 1; 
+                     Serial.print(" ++[" ); 
+
+             }
+              
+     Serial.print(HX711_Broadcast_child_CHANGE__TIME_RETRY_LAST_FLAG);             
+     Serial.print("]RETRY_LAST_FLAG;  " );             
+
      Serial.print(HX711_current);
      Serial.print(" ; %  ");
-        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 ))   ;
+        HX711_last_Broadcast_child_CHANGE_ratio = 255 * ( ( HX711_Broadcast_child_CHANGE__LEVEL_MIN -  HX711_current ) / ( HX711_Broadcast_child_CHANGE__LEVEL_MAX - HX711_Broadcast_child_CHANGE__LEVEL_MIN )) * - 1   ;
         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);
+        if(HX711_last_Broadcast_child_CHANGE_ratio < 10) HX711_last_Broadcast_child_CHANGE_ratio = 0 ;     Serial.println(HX711_last_Broadcast_child_CHANGE_ratio);
     
       HX711_last_Broadcast_child_CHANGE = HX711_current;
+      HX711_last_Broadcast_child_CHANGE_time = time ;
+     
       /*
       
  struct _Slave_Ports_Protocol_CAN_request_set_new_Exp_state_S {
@@ -257,7 +292,7 @@ void loop() {
       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__OUTPUT__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
          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
@@ -276,7 +311,7 @@ void loop() {
            Serial.println("Error Sending Message...");
          }
       
-   }
+   } 
  /* 
         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 ;