Fix start MMU with filament blocking the selector
parent
2640e9d899
commit
ffd8924d8c
48
src/main.cpp
48
src/main.cpp
|
|
@ -50,49 +50,6 @@ logic::CommandBase *currentCommand = &logic::noCommand;
|
||||||
/// will look like "X0 F" until a command (T, L, U ...) has been issued.
|
/// will look like "X0 F" until a command (T, L, U ...) has been issued.
|
||||||
mp::RequestMsg currentCommandRq(mp::RequestMsgCodes::Reset, 0);
|
mp::RequestMsg currentCommandRq(mp::RequestMsgCodes::Reset, 0);
|
||||||
|
|
||||||
// examples and test code shall be located here
|
|
||||||
void TmpPlayground() {
|
|
||||||
using namespace hal;
|
|
||||||
|
|
||||||
// SPI example
|
|
||||||
// gpio::Init(gpio::GPIO_pin(GPIOC, 6), gpio::GPIO_InitTypeDef(gpio::Mode::output, gpio::Level::high));
|
|
||||||
// uint8_t dat[5];
|
|
||||||
// gpio::WritePin(gpio::GPIO_pin(GPIOC, 6), gpio::Level::low);
|
|
||||||
// spi::TxRx(SPI0, 0x01);
|
|
||||||
// spi::TxRx(SPI0, 0x00);
|
|
||||||
// spi::TxRx(SPI0, 0x00);
|
|
||||||
// spi::TxRx(SPI0, 0x00);
|
|
||||||
// spi::TxRx(SPI0, 0x00);
|
|
||||||
// gpio::WritePin(gpio::GPIO_pin(GPIOC, 6), gpio::Level::high);
|
|
||||||
// gpio::WritePin(gpio::GPIO_pin(GPIOC, 6), gpio::Level::low);
|
|
||||||
// dat[0] = spi::TxRx(SPI0, 0x00);
|
|
||||||
// dat[1] = spi::TxRx(SPI0, 0x00);
|
|
||||||
// dat[2] = spi::TxRx(SPI0, 0x00);
|
|
||||||
// dat[3] = spi::TxRx(SPI0, 0x00);
|
|
||||||
// dat[4] = spi::TxRx(SPI0, 0x00);
|
|
||||||
// gpio::WritePin(gpio::GPIO_pin(GPIOC, 6), gpio::Level::high);
|
|
||||||
// (void)dat;
|
|
||||||
|
|
||||||
// using namespace hal::gpio;
|
|
||||||
// WritePin(GPIO_pin(GPIOB, 5), Level::low);
|
|
||||||
// TogglePin(GPIO_pin(GPIOB, 6));
|
|
||||||
// if (hal::gpio::ReadPin(GPIO_pin(GPIOB, 7)) == hal::gpio::Level::low)
|
|
||||||
// break;
|
|
||||||
|
|
||||||
sei();
|
|
||||||
hu::usart1.puts("1234567890\n");
|
|
||||||
hu::usart1.puts("1234567890\n");
|
|
||||||
hu::usart1.puts("1234567890\n");
|
|
||||||
hu::usart1.puts("1234567890\n");
|
|
||||||
hu::usart1.puts("1234567890\n");
|
|
||||||
hu::usart1.puts("1234567890\n");
|
|
||||||
hu::usart1.puts("1234567890\n");
|
|
||||||
hu::usart1.puts("1234567890\n");
|
|
||||||
hu::usart1.puts("1234567890\n");
|
|
||||||
hu::usart1.puts("1234567890\n");
|
|
||||||
hu::usart1.puts("1234567890\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One-time setup of HW and SW components
|
/// One-time setup of HW and SW components
|
||||||
/// Called before entering the loop() function
|
/// Called before entering the loop() function
|
||||||
/// Green LEDs signalize the progress of initialization. If anything goes wrong we shall turn on a red LED
|
/// Green LEDs signalize the progress of initialization. If anything goes wrong we shall turn on a red LED
|
||||||
|
|
@ -145,10 +102,7 @@ void setup() {
|
||||||
|
|
||||||
mu::cdc.Init();
|
mu::cdc.Init();
|
||||||
|
|
||||||
if (mg::globals.FilamentLoaded() < mg::FilamentLoadState::InFSensor) {
|
ms::selector.Init(); // selector decides if homing is possible
|
||||||
// home the Selector only in case we don't have filament loaded (or at least we think we don't)
|
|
||||||
ms::selector.Home();
|
|
||||||
}
|
|
||||||
mi::idler.Home(); // home Idler every time
|
mi::idler.Home(); // home Idler every time
|
||||||
|
|
||||||
_delay_ms(100);
|
_delay_ms(100);
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,9 @@ namespace globals {
|
||||||
Globals globals;
|
Globals globals;
|
||||||
|
|
||||||
void Globals::Init() {
|
void Globals::Init() {
|
||||||
mps::FilamentLoaded::get(activeSlot); //@@TODO check for errors
|
if (!mps::FilamentLoaded::get(activeSlot)) {
|
||||||
|
activeSlot = config::toolCount;
|
||||||
|
}
|
||||||
|
|
||||||
if (activeSlot < config::toolCount) {
|
if (activeSlot < config::toolCount) {
|
||||||
// some valid slot has been recorded in EEPROM - we have some filament loaded in the selector or even in the nozzle
|
// some valid slot has been recorded in EEPROM - we have some filament loaded in the selector or even in the nozzle
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include "motion.h"
|
#include "motion.h"
|
||||||
#include "permanent_storage.h"
|
#include "permanent_storage.h"
|
||||||
#include "../debug.h"
|
#include "../debug.h"
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
namespace modules {
|
namespace modules {
|
||||||
namespace selector {
|
namespace selector {
|
||||||
|
|
@ -72,5 +73,15 @@ bool Selector::Step() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Selector::Init() {
|
||||||
|
if (mg::globals.FilamentLoaded() < mg::FilamentLoadState::InFSensor) {
|
||||||
|
// home the Selector only in case we don't have filament loaded (or at least we think we don't)
|
||||||
|
Home();
|
||||||
|
} else {
|
||||||
|
// otherwise set selector's position according to know slot positions (and pretend it is correct)
|
||||||
|
mm::motion.SetPosition(mm::Selector, SlotPosition(mg::globals.ActiveSlot()).v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace selector
|
} // namespace selector
|
||||||
} // namespace modules
|
} // namespace modules
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,12 @@ public:
|
||||||
/// @returns the index of idle position of the selector, usually 5 in case of 0-4 valid indices of filament slots
|
/// @returns the index of idle position of the selector, usually 5 in case of 0-4 valid indices of filament slots
|
||||||
inline static constexpr uint8_t IdleSlotIndex() { return config::toolCount; }
|
inline static constexpr uint8_t IdleSlotIndex() { return config::toolCount; }
|
||||||
|
|
||||||
|
/// Initializes the selector after restart/cold boot
|
||||||
|
/// Reads the active slot from the EEPROM and decides if the selector is free or blocked by a piece of filament
|
||||||
|
/// - free -> home the selector
|
||||||
|
/// - blocked -> set selector's position according to the active filament slot
|
||||||
|
void Init();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void PrepareMoveToPlannedSlot() override;
|
virtual void PrepareMoveToPlannedSlot() override;
|
||||||
virtual void PlanHomingMove() override;
|
virtual void PlanHomingMove() override;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,22 @@ bool VerifyEnvironmentState(mg::FilamentLoadState fls, uint8_t idlerSlotIndex, u
|
||||||
CHECKED_ELSE(mg::globals.FilamentLoaded() & fls) { // beware - abusing the values as bit masks to detect multiple situations at once
|
CHECKED_ELSE(mg::globals.FilamentLoaded() & fls) { // beware - abusing the values as bit masks to detect multiple situations at once
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if( mg::globals.FilamentLoaded() >= mg::FilamentLoadState::InSelector ){
|
||||||
|
// check eeprom content - filament blocking the selector
|
||||||
|
uint8_t eeSlot = 0xff;
|
||||||
|
CHECKED_ELSE(mps::FilamentLoaded::get(eeSlot)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
CHECKED_ELSE(eeSlot == selectorSlotIndex){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// check eeprom content - filament blocking the selector
|
||||||
|
uint8_t eeSlot = 0xff;
|
||||||
|
CHECKED_ELSE(mps::FilamentLoaded::get(eeSlot) == false){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
CHECKED_ELSE(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(idlerSlotIndex).v) {
|
CHECKED_ELSE(mm::axes[mm::Idler].pos == mi::Idler::SlotPosition(idlerSlotIndex).v) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "main_loop_stub.h"
|
#include "main_loop_stub.h"
|
||||||
|
|
||||||
#include "../../modules/stubs/stub_adc.h"
|
#include "../../modules/stubs/stub_adc.h"
|
||||||
|
#include "../../modules/stubs/stub_eeprom.h"
|
||||||
#include "../../modules/stubs/stub_timebase.h"
|
#include "../../modules/stubs/stub_timebase.h"
|
||||||
|
|
||||||
#include "../../../../src/modules/buttons.h"
|
#include "../../../../src/modules/buttons.h"
|
||||||
|
|
@ -52,6 +53,8 @@ void ForceReinitAllAutomata() {
|
||||||
new (&ms::selector) ms::Selector();
|
new (&ms::selector) ms::Selector();
|
||||||
new (&mm::motion) mm::Motion();
|
new (&mm::motion) mm::Motion();
|
||||||
|
|
||||||
|
hal::eeprom::ClearEEPROM();
|
||||||
|
|
||||||
// no buttons involved ;)
|
// no buttons involved ;)
|
||||||
hal::adc::ReinitADC(config::buttonsADCIndex, hal::adc::TADCData({ 1023 }), 1);
|
hal::adc::ReinitADC(config::buttonsADCIndex, hal::adc::TADCData({ 1023 }), 1);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#include "catch2/catch.hpp"
|
#include "catch2/catch.hpp"
|
||||||
|
|
||||||
#include "../../../../src/hal/eeprom.h"
|
#include "../../../../src/hal/eeprom.h"
|
||||||
|
#include "stub_eeprom.h"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
@ -14,6 +15,10 @@ EEPROM eeprom;
|
||||||
constexpr uint16_t eepromSize = 2048U;
|
constexpr uint16_t eepromSize = 2048U;
|
||||||
static std::array<uint8_t, eepromSize> EE;
|
static std::array<uint8_t, eepromSize> EE;
|
||||||
|
|
||||||
|
void ClearEEPROM() {
|
||||||
|
std::fill(EE.begin(), EE.end(), 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
/// EEPROM interface
|
/// EEPROM interface
|
||||||
void EEPROM::WriteByte(EEPROM::addr_t offset, uint8_t value) {
|
void EEPROM::WriteByte(EEPROM::addr_t offset, uint8_t value) {
|
||||||
REQUIRE(offset < EE.size());
|
REQUIRE(offset < EE.size());
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
namespace hal {
|
||||||
|
namespace eeprom {
|
||||||
|
|
||||||
|
void ClearEEPROM();
|
||||||
|
|
||||||
|
} // namespace eeprom
|
||||||
|
} // namespace hal
|
||||||
Loading…
Reference in New Issue