Background: I am trying to make a remote control for a car controlled with Raspberry Pi. I’m using REST API from WebIOPI to do it.More info [nayarweb.com] (optional)
Problem: I have a class CarController (stripped version)
class CarController : public QObject
{
Q_OBJECT
Q_ENUMS(ACCELERATE_DIRECTION)
public:
enum ACCELERATE_DIRECTION {
FORWARD,
BACKWARD
};
explicit CarController(QObject *parent = 0);
Q_INVOKABLE void accelerate(ACCELERATE_DIRECTION direction, double power = 1);
void setGPIO(int no, int value);
};
#endif // CARCONTROLLER_H
void CarController::accelerate(CarController::ACCELERATE_DIRECTION direction, double power)
{
qDebug() << "direction" << direction;
if((direction == CarController::FORWARD) && (power > 0)){
qDebug() << "Forward";
setGPIO(forward_GPIO(),1);
setGPIO(backward_GPIO(),0);
}
else if ((direction == CarController::BACKWARD) && (power > 0)){
qDebug() << "Backward";
setGPIO(forward_GPIO(),0);
setGPIO(backward_GPIO(),1);
}
else{
setGPIO(forward_GPIO(),0);
setGPIO(backward_GPIO(),0);
}
}
I have the following QML
Button {
id: button1
x: 268
y: 158
width: 155
height: 73
text: qsTr("Forward")
onClicked: {
car.accelerate(car.FORWARD,1);
}
}
Button {
id: button4
x: 268
y: 308
width: 155
height: 23
text: qsTr("Reverse")
onClicked: {
car.accelerate(car.BACKWARD,1);
}
}
The first button works fine. But the “reverse” button is doing the same job as the “forward”. The direction is always being integer 0 in CarController::accelerate().
If i replace
car.accelerate(car.BACKWARD,1)
by
car.accelerate(1,1);
in the QML, it works fine then. Any guesses what is going wrong by calling car.BACKWARD?
↧










