Im Simu-Mode Bedienung über Tastatur

This commit is contained in:
Bernhard
2026-01-24 18:56:30 +01:00
parent 4bde0cc888
commit 450e93982e
8 changed files with 167 additions and 42 deletions

54
io/io.c
View File

@@ -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);
}