Im Simu-Mode Bedienung über Tastatur
This commit is contained in:
54
io/io.c
54
io/io.c
@@ -2,17 +2,22 @@
|
||||
#include "main.h"
|
||||
#include "io.h"
|
||||
#include <can/can_client.h>
|
||||
#include <settings/settings.h>
|
||||
#include <mqtt/mqtt_client.h>
|
||||
|
||||
struct GPIO_KEY_DATA gpioKeyStop;
|
||||
struct GPIO_KEY_DATA gpioKeyPwrUp;
|
||||
struct GPIO_KEY_DATA gpioKeyPwrDown;
|
||||
|
||||
char nInitialized = 0;
|
||||
int iPowerSupplyOn = 0;
|
||||
|
||||
/// @brief Initialize the io pins
|
||||
/// @return
|
||||
int IO_Init()
|
||||
{
|
||||
iPowerSupplyOn = 0;
|
||||
|
||||
if (wiringPiSetupPinType(WPI_PIN_BCM))
|
||||
{
|
||||
mylog(LOG_ERR, "IO: Set up wiringPi failed!");
|
||||
@@ -179,46 +184,57 @@ void IO_DoCyclic()
|
||||
ReadKey(&gpioKeyPwrUp);
|
||||
ReadKey(&gpioKeyPwrDown);
|
||||
|
||||
if (gpioKeyStop.iKeyValue)
|
||||
if (gpioKeyStop.iKeyValue || atomic_load(&abKeyStop))
|
||||
{
|
||||
// stop key is pressed
|
||||
if (gpioKeyStop.iKeyRisingEdge)
|
||||
if (gpioKeyStop.iKeyRisingEdge || atomic_load(&abKeyStop))
|
||||
{
|
||||
mylog(LOG_INFO, "IO: KEY-Stop: Stop motor.");
|
||||
Can_SetMotorGear(0, 0);
|
||||
}
|
||||
}
|
||||
else if (motctrl[0].nDriveReady) // plus and minus keys only when drive is ready
|
||||
|
||||
if (gpioKeyPwrUp.iKeyRisingEdge || atomic_load(&abKeyPlus))
|
||||
{
|
||||
if (gpioKeyPwrUp.iKeyRisingEdge)
|
||||
if (motctrl[0].nDriveReady)
|
||||
{
|
||||
// plus key is pressed -> increase power
|
||||
// when drive is ready to run: plus key is pressed -> increase power
|
||||
if (motctrl[0].iMotorGear == MOTOR_GEAR_NEUTRAL)
|
||||
{
|
||||
mylog(LOG_INFO, "IO: KEY-Plus: Start motor.");
|
||||
Can_SetMotorGear(0, 1);
|
||||
Can_SetMotorPower(0, 1);
|
||||
}
|
||||
else
|
||||
else if (motctrl[0].iMotorPowerSteps < settings.iMotorPwrStepCount)
|
||||
{
|
||||
mylog(LOG_INFO, "IO: KEY-Plus: Increase power.");
|
||||
Can_SetMotorPower(0, motctrl[0].iMotorPowerSteps + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (gpioKeyPwrDown.iKeyRisingEdge)
|
||||
else if (settings.iShellySupplyCount > 0)
|
||||
{
|
||||
// minus key is pressed -> decrease power
|
||||
if (motctrl[0].iMotorPowerSteps > 1)
|
||||
{
|
||||
mylog(LOG_INFO, "IO: KEY-Minus: Decrease power.");
|
||||
Can_SetMotorPower(0, motctrl[0].iMotorPowerSteps - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
mylog(LOG_INFO, "IO: KEY-Minus: Stop motor.");
|
||||
Can_SetMotorGear(0, 0);
|
||||
}
|
||||
// when drive is not ready and we have to switch the supply
|
||||
MqttClient_SwitchPowerSupply(1);
|
||||
iPowerSupplyOn = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (gpioKeyPwrDown.iKeyRisingEdge || atomic_load(&abKeyMinus))
|
||||
{
|
||||
// minus key is pressed -> decrease power
|
||||
if (motctrl[0].iMotorPowerSteps > 1)
|
||||
{
|
||||
mylog(LOG_INFO, "IO: KEY-Minus: Decrease power.");
|
||||
Can_SetMotorPower(0, motctrl[0].iMotorPowerSteps - 1);
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// mylog(LOG_INFO, "IO: KEY-Minus: Stop motor.");
|
||||
// Can_SetMotorGear(0, 0);
|
||||
// }
|
||||
}
|
||||
|
||||
atomic_store(&abKeyPlus, false);
|
||||
atomic_store(&abKeyMinus, false);
|
||||
atomic_store(&abKeyStop, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user