a.binder 3 years ago
parent
commit
5bd4f7c296

+ 154 - 0
SE/stuff/P5_Automation_can-dev-res-working-1930/___SUBMODULES___/MiniBalancer/MiniBalancer.ino

@@ -0,0 +1,154 @@
+
+#include "__main_struct.h" //lite #include "___main/__main_struct.h"
+#include "config_Active_ControllerID.h"
+
+#include "config_Slave_Ports_LOCAL_config.h" //lite
+
+//#include "automation_driven.submodule.struct.write_neuron_override.h"
+
+//#include "_Slave_Ports_Status_func_add_lite.h"
+
+
+
+
+#if defined(HAS_Adafruit_ST7789)
+    #include <Adafruit_GFX.h>    // Core graphics library
+    #include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
+    #include <SPI.h>  
+    // Initialize Adafruit ST7789 TFT library
+    //    Adafruit_ST7789 DISPLAY_DEV = Adafruit_ST7789(ST7789_CS, ST7789_DC, ST7789_RST);
+    Adafruit_ST7789 DISPLAY_DEV = Adafruit_ST7789(0, ST7789_DC, ST7789_RST);
+
+#endif
+
+
+
+#if defined(HAS_TFT_ILI9163C)
+   #include "_TFT_ILI9163C_config.h"
+//  #include "_TFT_ILI9163C_struct.h"
+
+   TFT_ILI9163C DISPLAY_DEV = TFT_ILI9163C(TFT_ILI9163C_CSpin, TFT_ILI9163C_DCpin, TFT_ILI9163C__RSTpin); //#include "_TFT_ILI9163C_func.h"
+   #elif defined(HAS_TFT_HX8357)
+   #include <TFT_HX8357.h>
+  // #error test
+   TFT_HX8357 DISPLAY_DEV = TFT_HX8357();       // Invoke custom library
+
+#endif
+
+int ErrPin = 7; //6 ;
+
+
+void setup() {
+  // initialize digital pin ledPin as an output.
+    #if defined(HAS_Adafruit_ST7789)
+ 
+        DISPLAY_DEV.init(240, 240, SPI_MODE2);    // Init ST7789 display 240x240 pixel
+        //DISPLAY_DEV.setRotation(2);
+        DISPLAY_DEV.fillScreen(ST77XX_BLACK);
+        DISPLAY_DEV.setCursor(0, 0);
+          DISPLAY_DEV.setTextColor(WHITE);
+          DISPLAY_DEV.setTextWrap(true);
+              DISPLAY_DEV.setTextSize(2);
+
+          DISPLAY_DEV.print(F("ACCU 12V 24A 24B"));
+
+    #endif
+   // digitalWrite(ErrPin,HIGH);
+    DISPLAY_DEV.fillRect(0, 20, DISPLAY_DEV.width(), 140, MAGENTA);
+
+}
+
+int ResistorDivisor = 28.8333 ;
+int FullLoad = 14 ;
+int OKLoad = 12 ;
+int WarnLoad = 11 ;
+
+int LastValue[5] = { -1,-1,-1,-1} ;
+
+bool PrintLevel(int PrintPort, int startY, int indexID ) {
+        
+        int VOltOffs = analogRead(PrintPort)/ ResistorDivisor ;
+        String messLoad = F("");
+        if(VOltOffs > FullLoad ) VOltOffs = FullLoad ;
+
+        if(LastValue[indexID] == analogRead(PrintPort)/ ResistorDivisor ) {
+            //same
+        } else {
+            LastValue[indexID] = analogRead(PrintPort)/ ResistorDivisor ;
+            uint16_hex SetCol   =  0x00F0 ; //0x0000  ;  
+            uint16_hex SetColFont   =  WHITE ; //0x0000  ;
+            
+            if(VOltOffs > OKLoad ) {
+                SetCol = GREEN ;
+                messLoad = String(analogRead(PrintPort)/ ResistorDivisor  *100 / FullLoad ) ;
+                messLoad.concat(" % ");
+                DISPLAY_DEV.setTextSize(4);
+            } else if(VOltOffs > WarnLoad ) {
+                SetCol = YELLOW ;
+                SetColFont   =  BLACK ; 
+                messLoad = String(VOltOffs  *100 / FullLoad ) ;
+                messLoad.concat(" % ");
+                DISPLAY_DEV.setTextSize(4);
+            } else if(VOltOffs == 0) {
+                SetCol = MAGENTA ;// 0xBBBB ;
+                SetColFont   =  BLACK ;
+                messLoad = F(" UNKNOWN %");
+                DISPLAY_DEV.setTextSize(3);
+            } else {
+                SetCol = RED ;
+                SetColFont   =  WHITE ; 
+                messLoad = String(VOltOffs  *100 / FullLoad ) ;
+                messLoad.concat(" % LOAD NOW ");
+                DISPLAY_DEV.setTextSize(3);
+            }
+            
+            if(VOltOffs > 0) { 
+               DISPLAY_DEV.fillRect(VOltOffs  *DISPLAY_DEV.width() / FullLoad , startY - 10 , DISPLAY_DEV.width(), 50, BLACK);
+               DISPLAY_DEV.fillRect(0, startY - 10 ,  VOltOffs  *DISPLAY_DEV.width() / FullLoad , 50, SetCol);
+                //140 * 11 / 12
+                DISPLAY_DEV.setCursor(3, startY);
+                DISPLAY_DEV.setTextColor(SetColFont);
+                DISPLAY_DEV.print( messLoad );
+             } else {
+                DISPLAY_DEV.fillRect(0, startY - 10 ,  DISPLAY_DEV.width()  , 50, SetCol);
+                DISPLAY_DEV.setCursor(3, startY);
+                DISPLAY_DEV.setTextColor(SetColFont);
+                DISPLAY_DEV.print( messLoad );
+             }      
+        }
+      
+}
+
+
+// the loop function runs over and over again forever
+void loop() {
+  //digitalWrite(ledPin, HIGH);   // turn the LED on (HIGH is the voltage level)
+  delay(100);                  // wait for a second
+    DISPLAY_DEV.setTextSize(4);
+   // DISPLAY_DEV.fillRect(0, 20, DISPLAY_DEV.width(), 140, MAGENTA);
+    
+    PrintLevel(A0, 40, 1);
+    PrintLevel(A1, 80, 2);
+    PrintLevel(A2, 120 , 3);
+
+        //int port = A0 ;
+        //int startY = 40 ;
+    //  if(analogRead(A0)/ ResistorDivisor > OKLoad ) {
+        //   DISPLAY_DEV.fillRect(0, 30,  analogRead(A0)/ ResistorDivisor  *DISPLAY_DEV.width() / FullLoad , 50, GREEN);
+                //140 * 11 / 12
+          //      DISPLAY_DEV.setCursor(0, 40);
+          //      DISPLAY_DEV.print( analogRead(A0)/ ResistorDivisor  *DISPLAY_DEV.width() / FullLoad    );
+      /*} else  if(analogRead(A0)/ ResistorDivisor > OKLoad ) { 
+        DISPLAY_DEV.setCursor(0, 40);
+        digitalWrite(ErrPin,HIGH);
+        DISPLAY_DEV.print(round( analogRead(A0)/ ResistorDivisor/FullLoad * DISPLAY_DEV.width() ));
+      } else { 
+        DISPLAY_DEV.setCursor(0, 40);
+        DISPLAY_DEV.print(round( analogRead(A0)/ ResistorDivisor/FullLoad * DISPLAY_DEV.width() ));
+      }
+      */
+    //  DISPLAY_DEV.setCursor(0, 80);
+   //   DISPLAY_DEV.print(analogRead(A1)/ ResistorDivisor);
+   //   DISPLAY_DEV.setCursor(0, 120);
+   //   DISPLAY_DEV.print(analogRead(A2)/ ResistorDivisor);
+}