添加遥控器功能

This commit is contained in:
hm
2021-04-29 09:54:21 +08:00
parent a98244d7ff
commit bc8040e2e6
13 changed files with 743 additions and 63 deletions
+12 -1
View File
@@ -27,7 +27,18 @@ void JoyStick::setValue(uint16_t ch, uint16_t value)//
if((value > m_max[ch])||(value < m_min[ch]))
{
emit error(Rate_Error);
return;
//return;
if(value > m_max[ch])
{
value = m_max[ch];
}
if(value < m_min[ch])
{
value = m_min[ch];
}
}
m_channel[ch] = value;
@@ -11,10 +11,16 @@ RemoteControl::RemoteControl(QWidget *parent) :
AUX8Switch(new Switch(this))
{
this->setTop(true);
resize(600,400);
setMinimumSize(600,400);
timer = new QTimer();
timer->setInterval(100);
connect(timer,&QTimer::timeout,
this,&RemoteControl::timerout);
joystick_left->setGeometry(0,
this->height()/2 - joystick_left->height()/2,
joystick_left->width(),
@@ -198,6 +204,13 @@ RemoteControl::~RemoteControl()
{
delete joystick_left;
delete joystick_right;
if(timer)
{
timer->stop();
delete timer;
timer = nullptr;
}
}
@@ -260,16 +273,23 @@ void RemoteControl::PowerSwitchUpdate(uint16_t value)
if(value <= 1300)
{
isActive = 0;
isActive = 2;
timer->start();
}
else if(value <= 1600)
{
isActive = 1;
timer->stop();
}
else
{
isActive = 2;
isActive = 0;
timer->stop();
}
//qDebug() << isActive << value;
update();
emit RemoteActive(isActive);
}
@@ -289,6 +309,15 @@ void RemoteControl::stateChanged(void)
rc.append(channel[7]);
rc.append(channel[8]);
rc.append(channel[9]);
rc.append(channel[10]);
rc.append(channel[11]);
rc.append(channel[12]);
rc.append(channel[13]);
rc.append(channel[14]);
rc.append(channel[15]);
rc.append(channel[16]);
rc.append(channel[17]);
rc.append(channel[18]);
if(isActive == 2)
@@ -361,6 +390,11 @@ void RemoteControl::setChannelOveride(QList<uint16_t> rc)
{
if(isActive == 1)
{
for(int i = 1;i <= 18;i++)
{
channel[i] = rc.at(i);
}
if(mode == RightHand)//右手油门
{
joystick_right->setValue(0,rc.at(1));
@@ -386,7 +420,12 @@ void RemoteControl::setChannelOveride(QList<uint16_t> rc)
.arg(rc[0],5).arg(rc[1],4).arg(rc[2],4)\
.arg(rc[3],4).arg(rc[4],4).arg(rc[5],4)\
.arg(rc[6],4).arg(rc[7],4).arg(rc[8],4).arg(rc[9],4));
update();
}
}
void RemoteControl::timerout(void)
{
stateChanged();
}
+12
View File
@@ -7,6 +7,8 @@
#include "QLabel"
#include "ToolsUI/ToolsWidget.h"
#include "QTimer"
class RemoteControl : public ToolsWidget
{
Q_OBJECT
@@ -31,6 +33,8 @@ public:
signals:
void RemoteActive(uint32_t);
void RemoteControlUpdate(QList<uint16_t>);
@@ -56,6 +60,11 @@ protected:
void stateChanged(void);
private slots:
void timerout(void);
private:
QLabel *remotelabel;
@@ -88,6 +97,9 @@ private:
//开关
uint32_t isActive= 0;
QTimer *timer = nullptr;
};
#endif // REMOTECONTROL_H