From c46b97ec2dfba4845c78bfb98075744e23de7dc7 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Fri, 25 Feb 2022 08:20:24 +0100 Subject: [PATCH] Add base code for PAT9125_sensor --- Firmware/Filament_sensor.cpp | 2 ++ Firmware/Filament_sensor.h | 53 ++++++++++++++++++++++++++++++++++++ Firmware/pat9125.cpp | 4 +++ 3 files changed, 59 insertions(+) diff --git a/Firmware/Filament_sensor.cpp b/Firmware/Filament_sensor.cpp index b7a1fb9d3..ec8045eb0 100644 --- a/Firmware/Filament_sensor.cpp +++ b/Firmware/Filament_sensor.cpp @@ -5,5 +5,7 @@ IR_sensor fsensor; #elif FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG IR_sensor_analog fsensor; +#elif FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125 +PAT9125_sensor fsensor; #endif #endif //FILAMENT_SENSOR diff --git a/Firmware/Filament_sensor.h b/Firmware/Filament_sensor.h index 8718725b7..7eba962e3 100644 --- a/Firmware/Filament_sensor.h +++ b/Firmware/Filament_sensor.h @@ -16,6 +16,7 @@ #include "fastio.h" #include "adc.h" #include "Timer.h" +#include "pat9125.h" #define FSENSOR_IR 1 #define FSENSOR_IR_ANALOG 2 @@ -438,10 +439,62 @@ private: #endif //(FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG) #endif //(FILAMENT_SENSOR_TYPE == FSENSOR_IR) || (FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG) +#if (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125) +class PAT9125_sensor: public Filament_sensor { +public: + void init() { + if (state == State::error) { + deinit(); //deinit first if there was an error. + } + puts_P(PSTR("fsensor::init()")); + ;// + settings_init(); //also sets the state to State::initializing + } + + void deinit() { + puts_P(PSTR("fsensor::deinit()")); + ;// + state = State::disabled; + } + + bool update() { + switch (state) { + case State::initializing: + // state = State::ready; //the IR sensor gets ready instantly as it's just a gpio read operation. + oldFilamentPresent = getFilamentPresent(); //initialize the current filament state so that we don't create a switching event right after the sensor is ready. + // fallthru + case State::ready: { + postponedLoadEvent = false; + bool event = checkFilamentEvents(); + + ;// + + return event; + } break; + case State::disabled: + case State::error: + default: + return false; + } + } + + bool getFilamentPresent() { + return false;/// + } + + void settings_init() { + Filament_sensor::settings_init(); + } +protected: +}; +#endif //(FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125) + #if FILAMENT_SENSOR_TYPE == FSENSOR_IR extern IR_sensor fsensor; #elif FILAMENT_SENSOR_TYPE == FSENSOR_IR_ANALOG extern IR_sensor_analog fsensor; +#elif FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125 +extern PAT9125_sensor fsensor; #endif #endif //FILAMENT_SENSOR diff --git a/Firmware/pat9125.cpp b/Firmware/pat9125.cpp index 819d70710..18cf7c1ae 100644 --- a/Firmware/pat9125.cpp +++ b/Firmware/pat9125.cpp @@ -4,7 +4,9 @@ #include #include "config.h" #include +#include "Configuration_prusa.h" +#if defined(FILAMENT_SENSOR) && (FILAMENT_SENSOR_TYPE == FSENSOR_PAT9125) //PAT9125 registers #define PAT9125_PID1 0x00 @@ -305,3 +307,5 @@ static uint8_t pat9125_wr_seq(const uint8_t* seq) } return 1; } + +#endif