Power monitor and display (#17437)

This commit is contained in:
Scott Lahteine
2020-06-18 15:23:03 -05:00
committed by GitHub
parent c8e99d572c
commit 424569b4c4
32 changed files with 652 additions and 28 deletions

View File

@ -94,6 +94,10 @@
#include "../feature/powerloss.h"
#endif
#if ENABLED(POWER_MONITOR)
#include "../feature/power_monitor.h"
#endif
#include "../feature/pause.h"
#if ENABLED(BACKLASH_COMPENSATION)
@ -301,6 +305,11 @@ typedef struct SettingsDataStruct {
user_thermistor_t user_thermistor[USER_THERMISTORS]; // M305 P0 R4700 T100000 B3950
#endif
//
// Power monitor
//
uint8_t power_monitor_flags; // M430 I V W
//
// HAS_LCD_CONTRAST
//
@ -881,6 +890,19 @@ void MarlinSettings::postprocess() {
}
#endif
//
// Power monitor
//
{
#if HAS_POWER_MONITOR
const uint8_t &power_monitor_flags = power_monitor.flags;
#else
constexpr uint8_t power_monitor_flags = 0x00;
#endif
_FIELD_TEST(power_monitor_flags);
EEPROM_WRITE(power_monitor_flags);
}
//
// LCD Contrast
//
@ -1745,6 +1767,19 @@ void MarlinSettings::postprocess() {
}
#endif
//
// Power monitor
//
{
#if HAS_POWER_MONITOR
uint8_t &power_monitor_flags = power_monitor.flags;
#else
uint8_t power_monitor_flags;
#endif
_FIELD_TEST(power_monitor_flags);
EEPROM_READ(power_monitor_flags);
}
//
// LCD Contrast
//
@ -2604,6 +2639,11 @@ void MarlinSettings::reset() {
//
TERN_(HAS_USER_THERMISTORS, thermalManager.reset_user_thermistors());
//
// Power Monitor
//
TERN_(POWER_MONITOR, power_monitor.reset());
//
// LCD Contrast
//

View File

@ -84,6 +84,10 @@
#include "../feature/filwidth.h"
#endif
#if HAS_POWER_MONITOR
#include "../feature/power_monitor.h"
#endif
#if ENABLED(EMERGENCY_PARSER)
#include "../feature/e_parser.h"
#endif
@ -1529,11 +1533,13 @@ void Temperature::updateTemperaturesFromRawValues() {
#if HAS_HOTEND
HOTEND_LOOP() temp_hotend[e].celsius = analog_to_celsius_hotend(temp_hotend[e].raw, e);
#endif
TERN_(HAS_HEATED_BED, temp_bed.celsius = analog_to_celsius_bed(temp_bed.raw));
TERN_(HAS_TEMP_CHAMBER, temp_chamber.celsius = analog_to_celsius_chamber(temp_chamber.raw));
TERN_(HAS_TEMP_PROBE, temp_probe.celsius = analog_to_celsius_probe(temp_probe.raw));
TERN_(TEMP_SENSOR_1_AS_REDUNDANT, redundant_temperature = analog_to_celsius_hotend(redundant_temperature_raw, 1));
TERN_(FILAMENT_WIDTH_SENSOR, filwidth.update_measured_mm());
TERN_(HAS_POWER_MONITOR, power_monitor.capture_values());
// Reset the watchdog on good temperature measurement
watchdog_refresh();
@ -1740,6 +1746,12 @@ void Temperature::init() {
#if HAS_ADC_BUTTONS
HAL_ANALOG_SELECT(ADC_KEYPAD_PIN);
#endif
#if ENABLED(POWER_MONITOR_CURRENT)
HAL_ANALOG_SELECT(POWER_MONITOR_CURRENT_PIN);
#endif
#if ENABLED(POWER_MONITOR_VOLTAGE)
HAL_ANALOG_SELECT(POWER_MONITOR_VOLTAGE_PIN);
#endif
HAL_timer_start(TEMP_TIMER_NUM, TEMP_TIMER_FREQUENCY);
ENABLE_TEMPERATURE_INTERRUPT();
@ -2760,13 +2772,31 @@ void Temperature::tick() {
#if ENABLED(FILAMENT_WIDTH_SENSOR)
case Prepare_FILWIDTH: HAL_START_ADC(FILWIDTH_PIN); break;
case Measure_FILWIDTH:
if (!HAL_ADC_READY())
next_sensor_state = adc_sensor_state; // redo this state
else
filwidth.accumulate(HAL_READ_ADC());
if (!HAL_ADC_READY()) next_sensor_state = adc_sensor_state; // Redo this state
else filwidth.accumulate(HAL_READ_ADC());
break;
#endif
#if ENABLED(POWER_MONITOR_CURRENT)
case Prepare_POWER_MONITOR_CURRENT:
HAL_START_ADC(POWER_MONITOR_CURRENT_PIN);
break;
case Measure_POWER_MONITOR_CURRENT:
if (!HAL_ADC_READY()) next_sensor_state = adc_sensor_state; // Redo this state
else power_monitor.add_current_sample(HAL_READ_ADC());
break;
#endif
#if ENABLED(POWER_MONITOR_VOLTAGE)
case Prepare_POWER_MONITOR_VOLTAGE:
HAL_START_ADC(POWER_MONITOR_VOLTAGE_PIN);
break;
case Measure_POWER_MONITOR_VOLTAGE:
if (!HAL_ADC_READY()) next_sensor_state = adc_sensor_state; // Redo this state
else power_monitor.add_voltage_sample(HAL_READ_ADC());
break;
#endif
#if HAS_JOY_ADC_X
case PrepareJoy_X: HAL_START_ADC(JOY_X_PIN); break;
case MeasureJoy_X: ACCUMULATE_ADC(joystick.x); break;

View File

@ -148,6 +148,14 @@ enum ADCSensorState : char {
#if ENABLED(FILAMENT_WIDTH_SENSOR)
Prepare_FILWIDTH, Measure_FILWIDTH,
#endif
#if ENABLED(POWER_MONITOR_CURRENT)
Prepare_POWER_MONITOR_CURRENT,
Measure_POWER_MONITOR_CURRENT,
#endif
#if ENABLED(POWER_MONITOR_VOLTAGE)
Prepare_POWER_MONITOR_VOLTAGE,
Measure_POWER_MONITOR_VOLTAGE,
#endif
#if HAS_ADC_BUTTONS
Prepare_ADC_KEY, Measure_ADC_KEY,
#endif