🎨 Laser Ammeter followup (#22079)

Followup to #21835
This commit is contained in:
Scott Lahteine 2021-06-08 07:51:28 -05:00 committed by Scott Lahteine
parent 2fd9971f41
commit 3f103c91f0
13 changed files with 90 additions and 116 deletions

View File

@ -3283,15 +3283,6 @@
//#define AIR_ASSIST_PIN 44 // Override the default Air Assist pin
#endif
//
// Laser I2C Ammeter (High precision INA226 low/high side module)
//
//#define I2C_AMMETER
#if ENABLED(I2C_AMMETER)
#define I2C_AMMETER_IMAX .1 // Calibration value for the expected current range in Amps (use float e.g. 1.0)
#define I2C_AMMETER_SHUNT_RESISTOR .1 // Calibration shunt resistor value in ohms
#endif
//#define SPINDLE_SERVO // A servo converting an angle to spindle power
#ifdef SPINDLE_SERVO
#define SPINDLE_SERVO_NR 0 // Index of servo used for spindle control
@ -3424,8 +3415,18 @@
#define SPINDLE_LASER_POWERDOWN_DELAY 50 // (ms) Delay to allow the spindle to stop
#endif
//
// Laser I2C Ammeter (High precision INA226 low/high side module)
//
//#define I2C_AMMETER
#if ENABLED(I2C_AMMETER)
#define I2C_AMMETER_IMAX 0.1 // (Amps) Calibration value for the expected current range
#define I2C_AMMETER_SHUNT_RESISTOR 0.1 // (Ohms) Calibration shunt resistor value
#endif
#endif
#endif // SPINDLE_FEATURE || LASER_FEATURE
/**
* Synchronous Laser Control with M106/M107

View File

@ -23,8 +23,13 @@
#include "../inc/MarlinConfig.h"
#if ENABLED(I2C_AMMETER)
#include "ammeter.h"
#ifndef I2C_AMMETER_IMAX
#define I2C_AMMETER_IMAX 0.500 // Calibration range 500 Milliamps
#endif
INA226 ina;
Ammeter ammeter;
@ -41,8 +46,8 @@
float Ammeter::read() {
scale = 1;
current = ina.readShuntCurrent();
if (current <= .0001) current = 0; // Cleanup lsb bit amplification errors
if (current < .1) scale = 1000;
if (current <= 0.0001f) current = 0; // Clean up least-significant-bit amplification errors
if (current < 0.1f) scale = 1000;
return current * scale;
}

View File

@ -26,10 +26,6 @@
#include <Wire.h>
#include <INA226.h>
#ifndef I2C_AMMETER_IMAX
#define I2C_AMMETER_IMAX .500 // Calibration range 500 Milli Amps
#endif
class Ammeter {
private:
static float scale;
@ -38,7 +34,6 @@ public:
static float current;
static void init();
static float read();
};
extern Ammeter ammeter;

View File

@ -81,7 +81,6 @@ void SpindleLaser::init() {
#if ENABLED(I2C_AMMETER)
ammeter.init(); // Init I2C Ammeter
#endif
}
#if ENABLED(SPINDLE_LASER_PWM)

View File

@ -405,6 +405,10 @@
#endif
#if EITHER(LCD_I2C_TYPE_MCP23017, LCD_I2C_TYPE_MCP23008) && DISABLED(NO_LCD_DETECT)
#define DETECT_I2C_LCD_DEVICE 1
#endif
#ifndef STD_ENCODER_PULSES_PER_STEP
#if ENABLED(TOUCH_SCREEN)
#define STD_ENCODER_PULSES_PER_STEP 2

View File

@ -68,11 +68,7 @@
#elif EITHER(LCD_I2C_TYPE_MCP23017, LCD_I2C_TYPE_MCP23008)
LCD_CLASS lcd(LCD_I2C_ADDRESS
#ifdef DETECT_DEVICE
, 1
#endif
);
LCD_CLASS lcd(LCD_I2C_ADDRESS OPTARG(DETECT_I2C_LCD_DEVICE, 1));
#elif ENABLED(LCD_I2C_TYPE_PCA8574)
@ -380,11 +376,7 @@ void MarlinUI::init_lcd() {
}
bool MarlinUI::detected() {
return (true
#if EITHER(LCD_I2C_TYPE_MCP23017, LCD_I2C_TYPE_MCP23008) && defined(DETECT_DEVICE)
&& lcd.LcdDetected() == 1
#endif
);
return TERN1(DETECT_I2C_LCD_DEVICE, lcd.LcdDetected() == 1);
}
#if HAS_SLOW_BUTTONS
@ -602,10 +594,11 @@ FORCE_INLINE void _draw_cooler_status(const char prefix, const bool blink) {
FORCE_INLINE void _draw_ammeter_status() {
lcd_put_u8str(" ");
ammeter.read();
if (ammeter.current <= .999) {
lcd_put_u8str(ftostr3ns(ammeter.current));
if (ammeter.current <= 0.999f) {
lcd_put_u8str(ui16tostr3rj(uint16_t(ammeter.current * 1000 + 0.5f)));
lcd_put_u8str("mA");
} else {
}
else {
lcd_put_u8str(ftostr12ns(ammeter.current));
lcd_put_wchar('A');
}
@ -847,15 +840,9 @@ void MarlinUI::draw_status_screen() {
#endif
#endif
#if HAS_COOLER
_draw_cooler_status('*', blink);
#endif
#if ENABLED(LASER_COOLANT_FLOW_METER)
_draw_flowmeter_status();
#endif
#if ENABLED(I2C_AMMETER)
_draw_ammeter_status();
#endif
TERN_(HAS_COOLER, _draw_cooler_status('*', blink));
TERN_(LASER_COOLANT_FLOW_METER, _draw_flowmeter_status());
TERN_(I2C_AMMETER, _draw_ammeter_status());
#endif // LCD_WIDTH >= 20

View File

@ -110,14 +110,13 @@
//
// Laser Ammeter
//
#if !STATUS_AMMETER_WIDTH && ENABLED(I2C_AMMETER)
#if ENABLED(I2C_AMMETER)
#if !STATUS_AMMETER_WIDTH
#include "status/ammeter.h"
#endif
#ifndef STATUS_AMMETER_WIDTH
#define STATUS_AMMETER_WIDTH 0
#endif
#ifndef STATUS_AMMETER_BYTEWIDTH
#define STATUS_AMMETER_BYTEWIDTH BW(STATUS_AMMETER_WIDTH)
#endif
//
@ -614,31 +613,30 @@
#endif
#endif
#if ENABLED(I2C_AMMETER)
#if STATUS_AMMETER_WIDTH
//
// I2C Laser Ammeter
//
#if ENABLED(I2C_AMMETER) && STATUS_AMMETER_WIDTH
#ifndef STATUS_AMMETER_BYTEWIDTH
#define STATUS_AMMETER_BYTEWIDTH BW(STATUS_AMMETER_WIDTH)
#endif
#ifndef STATUS_AMMETER_X
#define STATUS_AMMETER_X (LCD_PIXEL_WIDTH - (STATUS_AMMETER_BYTEWIDTH + STATUS_FLOWMETER_BYTEWIDTH + STATUS_FAN_BYTEWIDTH + STATUS_CUTTER_BYTEWIDTH + STATUS_COOLER_BYTEWIDTH) * 8)
#endif
#ifndef STATUS_AMMETER_HEIGHT
#define STATUS_AMMETER_HEIGHT(S) (sizeof(status_ammeter_bmp1) / (STATUS_AMMETER_BYTEWIDTH))
#endif
#ifndef STATUS_AMMETER_Y
#define STATUS_AMMETER_Y(S) (18 - STATUS_AMMETER_HEIGHT(S))
#endif
#ifndef STATUS_AMMETER_TEXT_X
#define STATUS_AMMETER_TEXT_X (STATUS_AMMETER_X + 7)
#endif
static_assert(
sizeof(status_ammeter_bmp1) == (STATUS_AMMETER_BYTEWIDTH) * STATUS_AMMETER_HEIGHT(0),
"Status ammeter bitmap (status_ammeter_bmp1) dimensions don't match data."
);
#endif
#endif
//
// Bed Bitmap Properties

View File

@ -1,6 +1,6 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
@ -24,7 +24,6 @@
//
// lcd/dogm/status/ammeter.h - Status Screen Laser Ammeter bitmaps
//
#if ENABLED(I2C_AMMETER)
#define STATUS_AMMETER_WIDTH 20
@ -67,5 +66,3 @@ const unsigned char status_ammeter_bmp_A[] PROGMEM = {
B00000011,B00000011,B00000000,
B00000000,B11111100,B00000000,
};
#endif

View File

@ -697,7 +697,7 @@ void MarlinUI::draw_status_screen() {
const uint8_t ammetery = STATUS_AMMETER_Y(status_ammeter_bmp_mA),
ammeterh = STATUS_AMMETER_HEIGHT(status_ammeter_bmp_mA);
if (PAGE_CONTAINS(ammetery, ammetery + ammeterh - 1))
u8g.drawBitmapP(STATUS_AMMETER_X, ammetery, STATUS_AMMETER_BYTEWIDTH, ammeterh, (ammeter.current < .1) ? status_ammeter_bmp_mA : status_ammeter_bmp_A);
u8g.drawBitmapP(STATUS_AMMETER_X, ammetery, STATUS_AMMETER_BYTEWIDTH, ammeterh, (ammeter.current < 0.1f) ? status_ammeter_bmp_mA : status_ammeter_bmp_A);
#endif
// Heated Bed

View File

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

View File

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

View File

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