Skip to content

Commit

Permalink
Added stepper abstraction draft (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
climategadgets committed Apr 16, 2020
1 parent 48c0717 commit 355b4a9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
idf_component_register(SRCS "app_main.cpp"
INCLUDE_DIRS ".")
INCLUDE_DIRS "." "include")
2 changes: 2 additions & 0 deletions main/app_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

#include "cJSON.h"

#include "stepper_api.h"

#if !(CONFIG_HCC_ESP32_ONE_WIRE_ENABLE || CONFIG_HCC_ESP32_A4988_ENABLE)
#error "No components enabled, configuration doesn't make sense. Run 'idf.py menuconfig' to enable."
#endif
Expand Down
57 changes: 57 additions & 0 deletions main/include/stepper_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef _HCC_ESP32_STEPPER_API_H_
#define _HCC_ESP32_STEPPER_API_H_

#ifdef __cplusplus
extern "C" {
#endif

namespace stepper {

enum class Direction {
down = -1,
up = 1
};

class Stepper {
public:

virtual ~Stepper() = 0;

/**
* Move the stepper in the specified direction, and return the current position.
*/
virtual int step(Direction d) = 0;

/**
* Returns max supported microstepping divider, or 0 if microstepping is not supported.
*/
virtual int getMaxMicrostep() = 0;

/**
* Returns currently used microstepping divider.
*
* NOTE: if microstepping is not supported, return value is 1, as a syntax sugar.
*/
virtual int getMicrostep() = 0;

/**
* Set microstepping to the specified divider.
*
* Returns the provided value if set successfully, 0 if microstepping is not enabled by configuration,
* -1 if microstepping not supported, and -2 if the given value is not supported.
*/
virtual int setMicrostep(int divider) = 0;

/**
* Put the controller to sleep with {@code true}, wake up with {@code false}.
*
* Returns {@code true} if the controller supports this operation.
*/
virtual bool powerSave(bool enable) = 0;
};
}
#ifdef __cplusplus
}
#endif //__cplusplus

#endif

0 comments on commit 355b4a9

Please sign in to comment.