Reference + move funktioniert (Fehlerbehandlung muss implementiert werden)

This commit is contained in:
fewikay committed 2026-11-02 14:36:12 +01:00
1 parent 26b117b63f
commit 6a9a634df0
1 file changed
+100 -47
@@ -2,52 +2,6 @@
#include "LibL6474.h"
#include "main.h"
int StepperConsoleFunction( int argc, char** argv, void* ctx )
// --------------------------------------------------------------------------------------------------------------------
{
//possible commands are
//(stepper) step 100
(void)argc;
(void)argv;
(void)ctx;
L6474_Handle_t h = (L6474_Handle_t)ctx;
// first decode the subcommand and all arguments
if ( argc == 0 )
{
printf("invalid number of arguments\r\nFAIL");
return -1;
}
else if ( strcmp(argv[0], "step") == 0 )
{
if ( argc < 2 )
{
printf("missing step value for step command\r\nFAIL");
return -1;
}
L6474_StepIncremental(h, atoi(argv[1]));
printf("%d steps", (int)atoi(argv[1]));
}
else if ( strcmp(argv[0], "reset") == 0 )
{
reset_stepper(h);
}
else
{
printf("passed invalid sub command\r\nFAIL");
return -1;
}
// now back to console
return 0;
}
static void* StepLibraryMalloc( unsigned int size ){
return malloc(size);
@@ -145,6 +99,22 @@ void reset_stepper(L6474_Handle_t s){
void stepper_reference(L6474_Handle_t s, int flag){
//flag: 0 keiner, 1 -t, 2 -e, 3 -s
if(HAL_GPIO_ReadPin(REFERENCE_MARK_GPIO_Port, REFERENCE_MARK_Pin) == GPIO_PIN_RESET){
L6474_StepIncremental(s, 1000);
int button_pressed = 0;
while(!button_pressed){
L6474_StepIncremental(s, -1);
if(HAL_GPIO_ReadPin(REFERENCE_MARK_GPIO_Port, REFERENCE_MARK_Pin) == GPIO_PIN_RESET){
button_pressed=1;
}
}
}
if(flag == 3){
L6474_SetAbsolutePosition(s, 0);
return;
@@ -153,7 +123,7 @@ void stepper_reference(L6474_Handle_t s, int flag){
while(!button_pressed){
L6474_StepIncremental(s, -1);
if(HAL_GPIO_ReadPin(USR_BUTTON_GPIO_Port, USR_BUTTON_Pin) == GPIO_PIN_RESET){
if(HAL_GPIO_ReadPin(REFERENCE_MARK_GPIO_Port, REFERENCE_MARK_Pin) == GPIO_PIN_RESET){
button_pressed=1;
}
@@ -165,3 +135,86 @@ void stepper_reference(L6474_Handle_t s, int flag){
void stepper_softstart(L6474_Handle_t s, unsigned int duration){
}
void stepper_pos(L6474_Handle_t s){
int position = 0;
L6474_GetAbsolutePosition(s, &position);
printf("Stepper position: %d", position);
}
void stepper_move(L6474_Handle_t s, int pos){
int position = 0;
L6474_GetAbsolutePosition(s, &position);
int pos_diff = pos-position;
L6474_StepIncremental(s, pos_diff);
}
int StepperConsoleFunction( int argc, char** argv, void* ctx )
// --------------------------------------------------------------------------------------------------------------------
{
//possible commands are
//(stepper) step 100
(void)argc;
(void)argv;
(void)ctx;
L6474_Handle_t h = (L6474_Handle_t)ctx;
// first decode the subcommand and all arguments
if ( argc == 0 )
{
printf("invalid number of arguments\r\nFAIL");
return -1;
}
else if ( strcmp(argv[0], "step") == 0 )
{
if ( argc < 2 )
{
printf("missing step value for step command\r\nFAIL");
return -1;
}
L6474_StepIncremental(h, atoi(argv[1]));
printf("%d steps", (int)atoi(argv[1]));
}
else if ( strcmp(argv[0], "reset") == 0 )
{
reset_stepper(h);
}
else if ( strcmp(argv[0], "reference") == 0 )
{
stepper_reference(h, 0);
}
else if ( strcmp(argv[0], "pos") == 0 )
{
stepper_pos(h);
}
else if ( strcmp(argv[0], "move") == 0 )
{
if ( argc < 2 )
{
printf("missing step value for move command\r\nFAIL");
return -1;
}
stepper_move(h, atoi(argv[1]));
}
else
{
printf("passed invalid sub command\r\nFAIL");
return -1;
}
// now back to console
return 0;
}