Bladeren bron

🎨 Laser Ammeter followup (#22079)

Followup to #21835
Scott Lahteine 2 jaren geleden
bovenliggende
commit
d320545066
No account linked to committer's email address

+ 11
- 10
Marlin/Configuration_adv.h Bestand weergeven

@@ -3283,15 +3283,6 @@
3283 3283
     //#define AIR_ASSIST_PIN            44     // Override the default Air Assist pin
3284 3284
   #endif
3285 3285
 
3286
-  //
3287
-  // Laser I2C Ammeter (High precision INA226 low/high side module)
3288
-  //
3289
-  //#define I2C_AMMETER
3290
-  #if ENABLED(I2C_AMMETER)
3291
-    #define I2C_AMMETER_IMAX            .1     // Calibration value for the expected current range in Amps (use float e.g. 1.0)
3292
-    #define I2C_AMMETER_SHUNT_RESISTOR  .1     // Calibration shunt resistor value in ohms
3293
-  #endif
3294
-
3295 3286
   //#define SPINDLE_SERVO                      // A servo converting an angle to spindle power
3296 3287
   #ifdef SPINDLE_SERVO
3297 3288
     #define SPINDLE_SERVO_NR   0               // Index of servo used for spindle control
@@ -3424,8 +3415,18 @@
3424 3415
       #define SPINDLE_LASER_POWERDOWN_DELAY   50 // (ms) Delay to allow the spindle to stop
3425 3416
 
3426 3417
     #endif
3418
+
3419
+    //
3420
+    // Laser I2C Ammeter (High precision INA226 low/high side module)
3421
+    //
3422
+    //#define I2C_AMMETER
3423
+    #if ENABLED(I2C_AMMETER)
3424
+      #define I2C_AMMETER_IMAX            0.1    // (Amps) Calibration value for the expected current range
3425
+      #define I2C_AMMETER_SHUNT_RESISTOR  0.1    // (Ohms) Calibration shunt resistor value
3426
+    #endif
3427
+
3427 3428
   #endif
3428
-#endif
3429
+#endif // SPINDLE_FEATURE || LASER_FEATURE
3429 3430
 
3430 3431
 /**
3431 3432
  * Synchronous Laser Control with M106/M107

+ 1
- 1
Marlin/src/HAL/STM32/eeprom_flash.cpp Bestand weergeven

@@ -30,7 +30,7 @@
30 30
 
31 31
 // Better: "utility/stm32_eeprom.h", but only after updating stm32duino to 2.0.0
32 32
 // Use EEPROM.h for compatibility, for now.
33
-#include <EEPROM.h> 
33
+#include <EEPROM.h>
34 34
 
35 35
 /**
36 36
  * The STM32 HAL supports chips that deal with "pages" and some with "sectors" and some that

+ 24
- 19
Marlin/src/feature/ammeter.cpp Bestand weergeven

@@ -1,4 +1,4 @@
1
-  /**
1
+/**
2 2
  * Marlin 3D Printer Firmware
3 3
  * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4 4
  *
@@ -23,27 +23,32 @@
23 23
 #include "../inc/MarlinConfig.h"
24 24
 
25 25
 #if ENABLED(I2C_AMMETER)
26
-  #include "ammeter.h"
27 26
 
28
-  INA226 ina;
27
+#include "ammeter.h"
29 28
 
30
-  Ammeter ammeter;
29
+#ifndef I2C_AMMETER_IMAX
30
+  #define I2C_AMMETER_IMAX     0.500  // Calibration range 500 Milliamps
31
+#endif
31 32
 
32
-  float Ammeter::scale;
33
-  float Ammeter::current;
33
+INA226 ina;
34 34
 
35
-  void Ammeter::init() {
36
-    ina.begin();
37
-    ina.configure(INA226_AVERAGES_16, INA226_BUS_CONV_TIME_1100US, INA226_SHUNT_CONV_TIME_1100US, INA226_MODE_SHUNT_BUS_CONT);
38
-    ina.calibrate(I2C_AMMETER_SHUNT_RESISTOR,I2C_AMMETER_IMAX);
39
-  }
35
+Ammeter ammeter;
40 36
 
41
-  float Ammeter::read() {
42
-      scale = 1;
43
-      current = ina.readShuntCurrent();
44
-      if (current <= .0001) current = 0;  // Cleanup lsb bit amplification errors
45
-      if (current < .1) scale = 1000; 
46
-      return current * scale;
47
-  }
37
+float Ammeter::scale;
38
+float Ammeter::current;
48 39
 
49
-#endif //I2C_AMMETER
40
+void Ammeter::init() {
41
+  ina.begin();
42
+  ina.configure(INA226_AVERAGES_16, INA226_BUS_CONV_TIME_1100US, INA226_SHUNT_CONV_TIME_1100US, INA226_MODE_SHUNT_BUS_CONT);
43
+  ina.calibrate(I2C_AMMETER_SHUNT_RESISTOR, I2C_AMMETER_IMAX);
44
+}
45
+
46
+float Ammeter::read() {
47
+  scale = 1;
48
+  current = ina.readShuntCurrent();
49
+  if (current <= 0.0001f) current = 0;  // Clean up least-significant-bit amplification errors
50
+  if (current < 0.1f) scale = 1000;
51
+  return current * scale;
52
+}
53
+
54
+#endif // I2C_AMMETER

+ 4
- 9
Marlin/src/feature/ammeter.h Bestand weergeven

@@ -26,19 +26,14 @@
26 26
 #include <Wire.h>
27 27
 #include <INA226.h>
28 28
 
29
-#ifndef I2C_AMMETER_IMAX    
30
-  #define I2C_AMMETER_IMAX      .500 // Calibration range 500 Milli Amps
31
-#endif
32
-
33 29
 class Ammeter {
34 30
 private:
35
-    static float scale;
31
+  static float scale;
36 32
 
37 33
 public:
38
-    static float current;
39
-    static void init();
40
-    static float read();
41
- 
34
+  static float current;
35
+  static void init();
36
+  static float read();
42 37
 };
43 38
 
44 39
 extern Ammeter ammeter;

+ 1
- 2
Marlin/src/feature/spindle_laser.cpp Bestand weergeven

@@ -79,9 +79,8 @@ void SpindleLaser::init() {
79 79
     OUT_WRITE(AIR_ASSIST_PIN, !AIR_ASSIST_ACTIVE);                    // Init Air Assist OFF
80 80
   #endif
81 81
   #if ENABLED(I2C_AMMETER)
82
-    ammeter.init();                    // Init I2C Ammeter
82
+    ammeter.init();                                                   // Init I2C Ammeter
83 83
   #endif
84
-  
85 84
 }
86 85
 
87 86
 #if ENABLED(SPINDLE_LASER_PWM)

+ 4
- 0
Marlin/src/inc/Conditionals_LCD.h Bestand weergeven

@@ -405,6 +405,10 @@
405 405
 
406 406
 #endif
407 407
 
408
+#if EITHER(LCD_I2C_TYPE_MCP23017, LCD_I2C_TYPE_MCP23008) && DISABLED(NO_LCD_DETECT)
409
+  #define DETECT_I2C_LCD_DEVICE 1
410
+#endif
411
+
408 412
 #ifndef STD_ENCODER_PULSES_PER_STEP
409 413
   #if ENABLED(TOUCH_SCREEN)
410 414
     #define STD_ENCODER_PULSES_PER_STEP 2

+ 9
- 22
Marlin/src/lcd/HD44780/marlinui_HD44780.cpp Bestand weergeven

@@ -68,11 +68,7 @@
68 68
 
69 69
 #elif EITHER(LCD_I2C_TYPE_MCP23017, LCD_I2C_TYPE_MCP23008)
70 70
 
71
-  LCD_CLASS lcd(LCD_I2C_ADDRESS
72
-    #ifdef DETECT_DEVICE
73
-      , 1
74
-    #endif
75
-  );
71
+  LCD_CLASS lcd(LCD_I2C_ADDRESS OPTARG(DETECT_I2C_LCD_DEVICE, 1));
76 72
 
77 73
 #elif ENABLED(LCD_I2C_TYPE_PCA8574)
78 74
 
@@ -380,11 +376,7 @@ void MarlinUI::init_lcd() {
380 376
 }
381 377
 
382 378
 bool MarlinUI::detected() {
383
-  return (true
384
-    #if EITHER(LCD_I2C_TYPE_MCP23017, LCD_I2C_TYPE_MCP23008) && defined(DETECT_DEVICE)
385
-      && lcd.LcdDetected() == 1
386
-    #endif
387
-  );
379
+  return TERN1(DETECT_I2C_LCD_DEVICE, lcd.LcdDetected() == 1);
388 380
 }
389 381
 
390 382
 #if HAS_SLOW_BUTTONS
@@ -602,10 +594,11 @@ FORCE_INLINE void _draw_cooler_status(const char prefix, const bool blink) {
602 594
   FORCE_INLINE void _draw_ammeter_status() {
603 595
     lcd_put_u8str(" ");
604 596
     ammeter.read();
605
-    if (ammeter.current <= .999) {
606
-      lcd_put_u8str(ftostr3ns(ammeter.current));
597
+    if (ammeter.current <= 0.999f) {
598
+      lcd_put_u8str(ui16tostr3rj(uint16_t(ammeter.current * 1000 + 0.5f)));
607 599
       lcd_put_u8str("mA");
608
-    } else {
600
+    }
601
+    else {
609 602
       lcd_put_u8str(ftostr12ns(ammeter.current));
610 603
       lcd_put_wchar('A');
611 604
     }
@@ -847,15 +840,9 @@ void MarlinUI::draw_status_screen() {
847 840
         #endif
848 841
       #endif
849 842
 
850
-      #if HAS_COOLER
851
-        _draw_cooler_status('*', blink);
852
-      #endif
853
-      #if ENABLED(LASER_COOLANT_FLOW_METER)
854
-        _draw_flowmeter_status();
855
-      #endif
856
-      #if ENABLED(I2C_AMMETER)
857
-        _draw_ammeter_status();
858
-      #endif
843
+      TERN_(HAS_COOLER, _draw_cooler_status('*', blink));
844
+      TERN_(LASER_COOLANT_FLOW_METER, _draw_flowmeter_status());
845
+      TERN_(I2C_AMMETER, _draw_ammeter_status());
859 846
 
860 847
     #endif // LCD_WIDTH >= 20
861 848
 

+ 29
- 31
Marlin/src/lcd/dogm/dogm_Statusscreen.h Bestand weergeven

@@ -110,14 +110,13 @@
110 110
 //
111 111
 // Laser Ammeter
112 112
 //
113
-#if !STATUS_AMMETER_WIDTH && ENABLED(I2C_AMMETER)
114
-  #include "status/ammeter.h"
115
-#endif
116
-#ifndef STATUS_AMMETER_WIDTH
117
-  #define STATUS_AMMETER_WIDTH 0
118
-#endif
119
-#ifndef STATUS_AMMETER_BYTEWIDTH
120
-  #define STATUS_AMMETER_BYTEWIDTH BW(STATUS_AMMETER_WIDTH)
113
+#if ENABLED(I2C_AMMETER)
114
+  #if !STATUS_AMMETER_WIDTH
115
+    #include "status/ammeter.h"
116
+  #endif
117
+  #ifndef STATUS_AMMETER_WIDTH
118
+    #define STATUS_AMMETER_WIDTH 0
119
+  #endif
121 120
 #endif
122 121
 
123 122
 //
@@ -614,30 +613,29 @@
614 613
   #endif
615 614
 #endif
616 615
 
617
-#if ENABLED(I2C_AMMETER)
618
-  #if STATUS_AMMETER_WIDTH
619
-
620
-    #ifndef STATUS_AMMETER_X
621
-      #define STATUS_AMMETER_X (LCD_PIXEL_WIDTH - (STATUS_AMMETER_BYTEWIDTH + STATUS_FLOWMETER_BYTEWIDTH + STATUS_FAN_BYTEWIDTH + STATUS_CUTTER_BYTEWIDTH + STATUS_COOLER_BYTEWIDTH) * 8)
622
-    #endif
623
-
624
-    #ifndef STATUS_AMMETER_HEIGHT
625
-      #define STATUS_AMMETER_HEIGHT(S) (sizeof(status_ammeter_bmp1) / (STATUS_AMMETER_BYTEWIDTH))
626
-    #endif
627
-
628
-    #ifndef STATUS_AMMETER_Y
629
-      #define STATUS_AMMETER_Y(S) (18 - STATUS_AMMETER_HEIGHT(S))
630
-    #endif
631
-
632
-    #ifndef STATUS_AMMETER_TEXT_X
633
-      #define STATUS_AMMETER_TEXT_X (STATUS_AMMETER_X + 7)
634
-    #endif
635
-
636
-    static_assert(
637
-      sizeof(status_ammeter_bmp1) == (STATUS_AMMETER_BYTEWIDTH) * STATUS_AMMETER_HEIGHT(0),
638
-      "Status ammeter bitmap (status_ammeter_bmp1) dimensions don't match data."
639
-    );
616
+//
617
+// I2C Laser Ammeter
618
+//
619
+#if ENABLED(I2C_AMMETER) && STATUS_AMMETER_WIDTH
620
+  #ifndef STATUS_AMMETER_BYTEWIDTH
621
+    #define STATUS_AMMETER_BYTEWIDTH BW(STATUS_AMMETER_WIDTH)
640 622
   #endif
623
+  #ifndef STATUS_AMMETER_X
624
+    #define STATUS_AMMETER_X (LCD_PIXEL_WIDTH - (STATUS_AMMETER_BYTEWIDTH + STATUS_FLOWMETER_BYTEWIDTH + STATUS_FAN_BYTEWIDTH + STATUS_CUTTER_BYTEWIDTH + STATUS_COOLER_BYTEWIDTH) * 8)
625
+  #endif
626
+  #ifndef STATUS_AMMETER_HEIGHT
627
+    #define STATUS_AMMETER_HEIGHT(S) (sizeof(status_ammeter_bmp1) / (STATUS_AMMETER_BYTEWIDTH))
628
+  #endif
629
+  #ifndef STATUS_AMMETER_Y
630
+    #define STATUS_AMMETER_Y(S) (18 - STATUS_AMMETER_HEIGHT(S))
631
+  #endif
632
+  #ifndef STATUS_AMMETER_TEXT_X
633
+    #define STATUS_AMMETER_TEXT_X (STATUS_AMMETER_X + 7)
634
+  #endif
635
+  static_assert(
636
+    sizeof(status_ammeter_bmp1) == (STATUS_AMMETER_BYTEWIDTH) * STATUS_AMMETER_HEIGHT(0),
637
+    "Status ammeter bitmap (status_ammeter_bmp1) dimensions don't match data."
638
+  );
641 639
 #endif
642 640
 
643 641
 //

+ 4
- 7
Marlin/src/lcd/dogm/status/ammeter.h Bestand weergeven

@@ -1,6 +1,6 @@
1 1
 /**
2 2
  * Marlin 3D Printer Firmware
3
- * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
3
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4 4
  *
5 5
  * Based on Sprinter and grbl.
6 6
  * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
@@ -24,11 +24,10 @@
24 24
 //
25 25
 // lcd/dogm/status/ammeter.h - Status Screen Laser Ammeter bitmaps
26 26
 //
27
-#if ENABLED(I2C_AMMETER)
28 27
 
29
-  #define STATUS_AMMETER_WIDTH 20
28
+#define STATUS_AMMETER_WIDTH 20
30 29
 
31
-  const unsigned char status_ammeter_bmp_mA[] PROGMEM = {
30
+const unsigned char status_ammeter_bmp_mA[] PROGMEM = {
32 31
   B00000000,B11111100,B00000000,
33 32
   B00000011,B00000011,B00000000,
34 33
   B00000100,B00000000,B10000000,
@@ -46,7 +45,7 @@
46 45
   B00000100,B00000000,B10000000,
47 46
   B00000011,B00000011,B00000000,
48 47
   B00000000,B11111100,B00000000
49
-  };
48
+};
50 49
 
51 50
 const unsigned char status_ammeter_bmp_A[] PROGMEM = {
52 51
   B00000000,B11111100,B00000000,
@@ -67,5 +66,3 @@ const unsigned char status_ammeter_bmp_A[] PROGMEM = {
67 66
   B00000011,B00000011,B00000000,
68 67
   B00000000,B11111100,B00000000,
69 68
 };
70
-
71
-#endif

+ 2
- 2
Marlin/src/lcd/dogm/status_screen_DOGM.cpp Bestand weergeven

@@ -207,7 +207,7 @@ FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, co
207 207
 
208 208
 #if DO_DRAW_AMMETER
209 209
   FORCE_INLINE void _draw_centered_current(const float current, const uint8_t tx, const uint8_t ty) {
210
-    const char *str = ftostr31ns(current);           
210
+    const char *str = ftostr31ns(current);
211 211
     const uint8_t len = str[0] != ' ' ? 3 : str[1] != ' ' ? 2 : 1;
212 212
     lcd_put_u8str(tx - len * (INFO_FONT_WIDTH) / 2 + 1, ty, &str[3-len]);
213 213
   }
@@ -697,7 +697,7 @@ void MarlinUI::draw_status_screen() {
697 697
       const uint8_t ammetery = STATUS_AMMETER_Y(status_ammeter_bmp_mA),
698 698
                     ammeterh = STATUS_AMMETER_HEIGHT(status_ammeter_bmp_mA);
699 699
        if (PAGE_CONTAINS(ammetery, ammetery + ammeterh - 1))
700
-        u8g.drawBitmapP(STATUS_AMMETER_X, ammetery, STATUS_AMMETER_BYTEWIDTH, ammeterh, (ammeter.current < .1) ? status_ammeter_bmp_mA : status_ammeter_bmp_A);
700
+        u8g.drawBitmapP(STATUS_AMMETER_X, ammetery, STATUS_AMMETER_BYTEWIDTH, ammeterh, (ammeter.current < 0.1f) ? status_ammeter_bmp_mA : status_ammeter_bmp_A);
701 701
     #endif
702 702
 
703 703
     // Heated Bed

+ 0
- 9
Marlin/src/libs/numtostr.cpp Bestand weergeven

@@ -217,15 +217,6 @@ const char* ftostr41ns(const_float_t f) {
217 217
   return &conv[2];
218 218
 }
219 219
 
220
-// Convert unsigned float to string with 123 format
221
-const char* ftostr3ns(const_float_t f) {
222
-  const long i = UINTFLOAT(f, 3);
223
-  conv[4] = DIGIMOD(i, 100);
224
-  conv[5] = DIGIMOD(i, 10);
225
-  conv[6] = DIGIMOD(i, 1);
226
-  return &conv[4];
227
-}
228
-
229 220
 // Convert signed float to fixed-length string with 12.34 / _2.34 / -2.34 or -23.45 / 123.45 format
230 221
 const char* ftostr42_52(const_float_t f) {
231 222
   if (f <= -10 || f >= 100) return ftostr52(f); // -23.45 / 123.45

+ 0
- 3
Marlin/src/libs/numtostr.h Bestand weergeven

@@ -74,9 +74,6 @@ const char* ftostr31ns(const_float_t x);
74 74
 // Convert unsigned float to string with 123.4 format
75 75
 const char* ftostr41ns(const_float_t x);
76 76
 
77
-// Convert unsigned float to string with 123 format
78
-const char* ftostr3ns(const_float_t x);
79
-
80 77
 // Convert signed float to fixed-length string with 12.34 / _2.34 / -2.34 or -23.45 / 123.45 format
81 78
 const char* ftostr42_52(const_float_t x);
82 79
 

+ 1
- 1
buildroot/tests/mega2560 Bestand weergeven

@@ -193,7 +193,7 @@ opt_set MOTHERBOARD BOARD_RAMPS_14_EFB EXTRUDERS 0 LCD_LANGUAGE en TEMP_SENSOR_C
193 193
         MANUAL_FEEDRATE '{ 50*60, 50*60, 4*60 }' \
194 194
         AXIS_RELATIVE_MODES '{ false, false, false }'
195 195
 opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT EEPROM_SETTINGS EEPROM_BOOT_SILENT EEPROM_AUTO_INIT \
196
-           LASER_FEATURE AIR_EVACUATION AIR_EVACUATION_PIN AIR_ASSIST AIR_ASSIST_PIN LASER_COOLANT_FLOW_METER
196
+           LASER_FEATURE AIR_EVACUATION AIR_EVACUATION_PIN AIR_ASSIST AIR_ASSIST_PIN LASER_COOLANT_FLOW_METER I2C_AMMETER
197 197
 
198 198
 exec_test $1 $2 "REPRAP MEGA2560 RAMPS | Laser Feature | Air Evacuation | Air Assist | Cooler | Flowmeter | 44780 LCD " "$3"
199 199
 

Laden…
Annuleren
Opslaan