-
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.
- Loading branch information
1 parent
c2b326f
commit 929faad
Showing
19 changed files
with
110 additions
and
478 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "stepper.h" | ||
#include <unistd.h> | ||
|
||
int main(int argc, char *argv[]) { | ||
|
||
// create an instance of the stepper class with suitable pins set up | ||
struct Stepper_t* stepper = stepper_create(); | ||
|
||
// configure the stepper motor speed in RPM | ||
setSpeed(stepper, 10); | ||
|
||
// move the motor the number of steps indicated by val | ||
int16_t val = 42; | ||
move_clockwise(stepper, val); | ||
|
||
// wait for the stepper motor to finish moving | ||
while(isRunning(stepper)) { | ||
sleep(1); | ||
} | ||
|
||
} | ||
|
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
set(SRC_LIB_NAME src) | ||
set(SOURCES sample.c) | ||
set(SOURCES | ||
stepper.h | ||
stepper.c) | ||
add_library(${SRC_LIB_NAME} ${SOURCES}) | ||
target_sources(${SRC_LIB_NAME} PRIVATE ${SOURCES}) | ||
target_include_directories(${SRC_LIB_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,35 @@ | ||
#include "stepper.h" | ||
|
||
#include <stdlib.h> | ||
|
||
struct Stepper_t *stepper_create() { | ||
int8_t pin1 = 8; | ||
int8_t pin2 = 9; | ||
int8_t pin3 = 10; | ||
int8_t pin4 = 1; | ||
return stepper_create_with_pins(pin1, pin2, pin3, pin4); | ||
} | ||
|
||
struct Stepper_t * stepper_create_with_pins(const int8_t pin1, const int8_t pin2, const int8_t pin3, const int8_t pin4) { | ||
struct Stepper_t* stepper = malloc(sizeof(*stepper)); | ||
// logic related to the pins is omitted in this exercise | ||
stepper->speed = 10; | ||
return stepper; | ||
} | ||
|
||
void setSpeed(struct Stepper_t *stepper, int8_t speed) { | ||
stepper->speed = speed; | ||
} | ||
|
||
void move_clockwise(struct Stepper_t *stepper, int16_t steps) { | ||
// logic to activate the relevant pins is omitted in this exercise | ||
} | ||
|
||
void move_anticlockwise(struct Stepper_t *stepper, int16_t steps) { | ||
// logic to activate the relevant pins is omitted in this exercise | ||
} | ||
|
||
bool isRunning(struct Stepper_t *stepper) { | ||
// logic to read the pins and determine this omitted in this exercise | ||
return false; | ||
} |
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,40 @@ | ||
#ifndef STEPPER_H | ||
#define STEPPER_H | ||
|
||
#include <stdbool.h> | ||
#include <unistd.h> | ||
|
||
// the number of steps to rotate a complete circle of 360 degrees | ||
#define STEPS 2048 | ||
|
||
// the maximum speed of the motor in RPM | ||
#define MAX_SPEED 15 | ||
|
||
/* | ||
* This struct is a placeholder for a real object that would be able to | ||
* control an electric stepper motor. | ||
*/ | ||
struct Stepper_t { | ||
int8_t speed; | ||
}; | ||
|
||
struct Stepper_t *stepper_create_with_pins( | ||
int8_t pin1, | ||
int8_t pin2, | ||
int8_t pin3, | ||
int8_t pin4); | ||
|
||
struct Stepper_t *stepper_create(); | ||
|
||
// Set the speed of the motor in RPM. Maximum is defined above. | ||
void setSpeed(struct Stepper_t* stepper, int8_t speed); | ||
|
||
// Move the indicated number of steps. The size of a step is defined above. | ||
void move_clockwise(struct Stepper_t* stepper, int16_t steps); | ||
void move_anticlockwise(struct Stepper_t* stepper, int16_t steps); | ||
|
||
// Whether the motor is currently moving. | ||
// Motors that are moving should not be given new instructions. | ||
bool isRunning(struct Stepper_t* stepper); | ||
|
||
#endif //STEPPER_H |
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 |
---|---|---|
|
@@ -42,5 +42,3 @@ endfunction() | |
|
||
|
||
add_subdirectory(simple_test) | ||
add_subdirectory(sample_test) | ||
add_subdirectory(uptime) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.