forked from MarlinFirmware/Marlin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
U e optical surface probe: MVP (MarlinFirmware#9)
* WIP * bump stm32 targets to c++17 * add more methods, add type safety enums, fix syntax * add WIP config and source file * more aggressive cpp version bump * improve type aliasing and namespacing * add pin initialization, implement simple analog reader * fix missing semicolon * add optical surface probe pin assignments * add instansiation and Mcode for reading sensor value * add interval reporting option * add comments, change scope of variables used for parsing * add position to probe interval report
- Loading branch information
arades79
authored
Dec 6, 2021
1 parent
8920266
commit f102185
Showing
8 changed files
with
188 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "../inc/MarlinConfig.h" | ||
|
||
#if ENABLED(OPTICAL_SURFACE_PROBE) | ||
#include "optical_surface_probe.h" | ||
#include "../gcode/gcode.h" | ||
#include "../gcode/parser.h" | ||
|
||
static OpticalSurfaceProbe probe; | ||
|
||
void GcodeSuite::M1100() | ||
{ | ||
const auto val = probe.get_distance(); | ||
SERIAL_ECHOLNPAIR("Probe raw reading: ", val); | ||
|
||
const auto ms = parser.intval('P', 0); | ||
probe.interval_report(ms); | ||
} | ||
|
||
#endif // OPTICAL_SURFACE_PROBE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
#pragma once | ||
|
||
#include "../inc/MarlinConfig.h" | ||
|
||
#include "../module/planner.h" | ||
|
||
#include <string_view> | ||
// using namespace std::string_view_literals; | ||
|
||
struct OpticalSurfaceProbe | ||
{ | ||
OpticalSurfaceProbe() | ||
{ | ||
SET_INPUT(OPT_SURF_IN_PIN); | ||
SET_INPUT(OPT_SURF_ERR_PIN); | ||
SET_OUTPUT(OPT_SURF_MFI_PIN); | ||
OUT_WRITE(OPT_SURF_LED_ON_PIN, HIGH); | ||
} | ||
|
||
void init(); | ||
|
||
const auto get_distance() const | ||
{ | ||
return analogRead(OPT_SURF_IN_PIN); | ||
} | ||
|
||
/** | ||
* @brief reports analog sensor reading at a set interval | ||
* using a hardware timer based interrupt | ||
* | ||
* @param ms milliseconds between reports | ||
*/ | ||
void interval_report(const int ms) | ||
{ | ||
// requires static lifetime for interrupts to trigger, | ||
// and to ensure we can stop the timer later. | ||
static HardwareTimer timer{TIM12}; | ||
timer.pause(); | ||
if (ms <= 0) | ||
return; | ||
|
||
timer.setOverflow(ms * 1000, TimerFormat_t::MICROSEC_FORMAT); | ||
timer.attachInterrupt([this] | ||
{ | ||
const auto position = planner.get_axis_positions_mm(); | ||
SERIAL_ECHOLNPAIR("prb:", get_distance(), ",X:", position.x, ",Y:", position.y, ",Z:", position.z); | ||
}); | ||
timer.resume(); | ||
} | ||
|
||
/** | ||
* @brief TODO: unimplemented, intended to alter sensor angle | ||
* | ||
*/ | ||
void deploy() {} | ||
|
||
/** | ||
* @brief TODO: unimplemented, intended to alter sensor angle | ||
* | ||
*/ | ||
void retract() {} | ||
|
||
private: | ||
constexpr static size_t READ_BUFFER_SIZE{255}; | ||
|
||
/** | ||
* @brief Private inner struct for holding serial communication | ||
* protocols and other sensor specific implementation details | ||
* | ||
*/ | ||
struct | ||
{ | ||
using str = std::string_view; | ||
|
||
void begin() { serial.begin(115200); } | ||
|
||
// user functions | ||
enum class User | ||
{ | ||
User, | ||
Professional | ||
}; | ||
void login(const User, const str); | ||
void set_password(const str); | ||
const User get_user() const; | ||
void set_default_user(const User); | ||
|
||
enum class Trigger | ||
{ | ||
None, | ||
Pulse, | ||
Edge, | ||
Software | ||
}; | ||
void set_trigger(const Trigger); | ||
|
||
enum class MFILevel | ||
{ | ||
High, | ||
Low | ||
}; | ||
void set_mfi_level(const MFILevel); | ||
|
||
enum class OutputMode | ||
{ | ||
None, | ||
Uart, | ||
Analog | ||
}; | ||
void set_output_mode(const OutputMode); | ||
|
||
void set_analog_scale_default(); | ||
void set_analog_scale(const float min, const float max); | ||
|
||
void get_info() const; | ||
void get_all_settings() const { serial.println("PRINT"); } | ||
void set_all_factory_defaults(); | ||
|
||
private: | ||
HardwareSerial &serial{OPT_SURF_HW_SERIAL}; | ||
|
||
void read_response() | ||
{ | ||
char read_buf[READ_BUFFER_SIZE] = {0}; // zero initialized buffer | ||
serial.readBytesUntil('>', read_buf, READ_BUFFER_SIZE); | ||
str parse_string{read_buf, READ_BUFFER_SIZE}; | ||
} | ||
|
||
} protocol; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters