remove some bugs
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include<string.h>
|
||||
#include "gpio.h"
|
||||
|
||||
#define BASEPATH "/sys/class/gpio/"
|
||||
#define GPIO_FOLDER "gpio%s/"
|
||||
|
||||
void writeFile(char *filename, char *buffer, size_t count)
|
||||
{
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
#ifndef GPIO_H_
|
||||
#define GPIO_H_
|
||||
|
||||
#define BASEPATH "/sys/class/gpio/"
|
||||
#define GPIO_FOLDER "gpio%s/"
|
||||
|
||||
void writeFile(char *filename, char *buffer, size_t count);
|
||||
void registerPin(char *pin);
|
||||
void freePin(char *pin);
|
||||
|
||||
@@ -14,29 +14,27 @@
|
||||
#define MOTOR_ON 1
|
||||
#define MOTOR_OFF 0
|
||||
|
||||
bool motor_rechts_forward_on = false;
|
||||
bool motor_rechts_reverse_on = false;
|
||||
bool motor_links_forward_on = false;
|
||||
bool motor_links_reverse_on = false;
|
||||
bool motor_rechts_on = false;
|
||||
bool motor_links_on = false;
|
||||
|
||||
void forward(int motorNumber)
|
||||
{
|
||||
if(motorNumber == 1)
|
||||
{
|
||||
writeOutput(PIN_MOTOR_RECHTS_FORWARD, MOTOR_ON);
|
||||
motor_rechts_forward_on = true;
|
||||
motor_rechts_on = true;
|
||||
}
|
||||
else if(motorNumber == 2)
|
||||
{
|
||||
writeOutput(PIN_MOTOR_LINKS_FORWARD, MOTOR_ON);
|
||||
motor_links_forward_on = true;
|
||||
motor_links_on = true;
|
||||
}
|
||||
else if(motorNumber == 3)
|
||||
{
|
||||
writeOutput(PIN_MOTOR_RECHTS_FORWARD, MOTOR_ON);
|
||||
writeOutput(PIN_MOTOR_LINKS_FORWARD, MOTOR_ON);
|
||||
motor_rechts_forward_on = true;
|
||||
motor_links_forward_on = true;
|
||||
motor_rechts_on = true;
|
||||
motor_links_on = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,44 +43,36 @@ void reverse(int motorNumber)
|
||||
if(motorNumber == 1)
|
||||
{
|
||||
writeOutput(PIN_MOTOR_RECHTS_REVERSE, MOTOR_ON);
|
||||
motor_rechts_reverse_on = true;
|
||||
motor_rechts_on = true;
|
||||
}
|
||||
else if(motorNumber == 2)
|
||||
{
|
||||
writeOutput(PIN_MOTOR_LINKS_REVERSE, MOTOR_ON);
|
||||
motor_links_reverse_on = true;
|
||||
motor_links_on = true;
|
||||
}
|
||||
else if(motorNumber == 3)
|
||||
{
|
||||
writeOutput(PIN_MOTOR_RECHTS_REVERSE, MOTOR_ON);
|
||||
writeOutput(PIN_MOTOR_LINKS_REVERSE, MOTOR_ON);
|
||||
motor_rechts_reverse_on = true;
|
||||
motor_links_reverse_on = true;
|
||||
motor_rechts_on = true;
|
||||
motor_links_on = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void stopMotor(int motorNumber)
|
||||
{
|
||||
if(motorNumber == 1 && motor_rechts_forward_on)
|
||||
if(motorNumber == 1 && motor_rechts_on)
|
||||
{
|
||||
writeOutput(PIN_MOTOR_RECHTS_FORWARD, MOTOR_OFF);
|
||||
motor_rechts_forward_on = false;
|
||||
writeOutput(PIN_MOTOR_RECHTS_REVERSE, MOTOR_OFF);
|
||||
motor_rechts_on = false;
|
||||
}
|
||||
else if(motorNumber == 2 && motor_links_forward_on)
|
||||
else if(motorNumber == 2 && motor_links_on)
|
||||
{
|
||||
writeOutput(PIN_MOTOR_LINKS_FORWARD, MOTOR_OFF);
|
||||
motor_links_forward_on = false;
|
||||
}
|
||||
else if(motorNumber == 3 && motor_rechts_reverse_on)
|
||||
{
|
||||
writeOutput(PIN_MOTOR_RECHTS_REVERSE, MOTOR_OFF);
|
||||
motor_rechts_reverse_on = false;
|
||||
}
|
||||
else if(motorNumber == 4 && motor_links_reverse_on)
|
||||
{
|
||||
writeOutput(PIN_MOTOR_LINKS_REVERSE, MOTOR_OFF);
|
||||
motor_links_reverse_on = false;
|
||||
motor_links_on = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -132,16 +122,6 @@ int main(int argc, char* argv[])
|
||||
//motor_links_forward stop
|
||||
stopMotor(2);
|
||||
}
|
||||
else if(strcmp(argv[1],"8")==0)
|
||||
{
|
||||
//motor_rechts_reverse stop
|
||||
stopMotor(3);
|
||||
}
|
||||
else if(strcmp(argv[1],"9")==0)
|
||||
{
|
||||
//motor_links_reverse stop
|
||||
stopMotor(4);
|
||||
}
|
||||
else if(strcmp(argv[1],"0")==0)
|
||||
{
|
||||
freePin(PIN_MOTOR_RECHTS_FORWARD);
|
||||
|
||||
Reference in New Issue
Block a user