2195 lines
66 KiB
C++
Raw Normal View History

2024-11-25 17:15:44 +08:00
#include "gamedisplaypage.h"
#include "ui_gamedisplaypage.h"
#include "mainwindowpagecontrol.h"
#include <QPropertyAnimation>
#include <QButtonGroup>
#include <QDebug>
#include <QPaintEvent>
#include <QPainter>
#include <QMessageBox>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonParseError>
#include "currentuserdata.h"
//#include "paramtipsdialog.h"
#include "gamecontrol.h"
#include "languagemanager.h"
#include "icemodule.h"
#include "fescontroldialog.h"
#include "icemodule.h"
#include "ccommunicateapi.h"
#include "paramtipsdialog.h"
#define SpeedMax 100
#define SleepTime 500
GameDisplayPage::GameDisplayPage(QWidget *parent) :
QWidget(parent),
ui(new Ui::GameDisplayPage),
m_openState(true),
upDirection(1),
downDirection(1),
m_spasmTipsDialog(NULL),
heartTimer(NULL),
countDownTimer(NULL),
m_spasmTimes(0),
m_currentMode(0),
m_AP_mode(1),//默认为主动
m_reportDialog(NULL),
m_quitDialog(NULL),
m_emergencyDialog(NULL),
heartCount(0),
E_gameState(STOP),
m_increasingSpeed(false),
m_decreasingSpeed(false),
m_decreasingForce(false),
m_increasingForce(false),
m_quitBySpeedDialog(NULL),
gameState(0)
{
ui->setupUi(this);
this->setWindowFlags(Qt::FramelessWindowHint); //设置无边框
setAttribute(Qt::WA_TranslucentBackground,true); //设置透明
initGameSocket();
m_leftAnimation = new QPropertyAnimation(ui->leftPage_GroupBox,"pos");
m_rightAnimation = new QPropertyAnimation(ui->rightPage_GroupBox,"pos");
m_leftAnimation->setDuration(1000);
m_rightAnimation->setDuration(1000);
QButtonGroup *upLimpGroup = new QButtonGroup(this);
upLimpGroup->addButton(ui->forward_Btn);
upLimpGroup->addButton(ui->backward_Btn);
m_channelBList.append(ui->channelB1_Label);
m_channelBList.append(ui->channelB2_Label);
m_channelBList.append(ui->channelB3_Label);
m_channelBList.append(ui->channelB4_Label);
m_channelBList.append(ui->channelB5_Label);
m_channelBList.append(ui->channelB6_Label);
m_channelBList.append(ui->channelB7_Label);
m_channelBList.append(ui->channelB8_Label);
ui->stop_Btn->setVisible(false);
ui->pause_Btn->setVisible(false);
ui->signal_Label->setVisible(false);
ui->signal_Label_2->setVisible(false);
ui->wifiSignal_Label->move(1620,25);
E_LANGUAGE language = LanguageManager::getInstance()->getCurrentLanguage();
if(language == English_E)
ui->warnTips_Label->move(1000,20);
else
ui->warnTips_Label->move(1090,20);
m_spasmTipsDialog = new SpasmTipsDialog();
m_emergencyDialog = new EmergencyStopDialog();
setTitle();
connect(IceModule::getInstance(),SIGNAL(signalSetFesAParam(int*,int)),this,SLOT(slotSetChannelAData(int*,int)));
connect(IceModule::getInstance(),SIGNAL(signalSetFesBParam(int*,int)),this,SLOT(slotSetChannelBData(int*,int)));
connect(IceModule::getInstance(),SIGNAL(signalSetBicycleParam(ST_BicycleParam)),this,SLOT(slotSetBicycleParam(ST_BicycleParam)));
connect(CCommunicateAPI::getInstance(),SIGNAL(signalReadyRead(QByteArray)),this,SLOT(slotReceiveData(QByteArray)));
heartTimer = new QTimer();
connect(heartTimer,SIGNAL(timeout()),this,SLOT(slotHeartTimer()));
heartTimer->setInterval(1000);
#ifdef HEARTBEAT
heartTimer->start();
#endif
#ifndef OXYGEN
ui->heart_GroupBox->setVisible(false);
#endif
countDownTimer = new QTimer();
countDownTimer->setInterval(1000);
connect(countDownTimer,SIGNAL(timeout()),this,SLOT(slotCountDownTimer()));
paramPressTimer = new QTimer();
connect(paramPressTimer, &QTimer::timeout, this, &GameDisplayPage::pressedAdjustSpeed);
paramPressForceTimer = new QTimer();
connect(paramPressForceTimer, &QTimer::timeout, this, &GameDisplayPage::pressAdjustForce);
m_reportDialog = new TrainReport();
m_trainReportTwoTwo = new TrainReportTwoTwo();
m_trainReportTwoThree = new TrainReportTwoThree();
m_trainReportThreeTwo = new TrainReportThreeTwo();
m_quitDialog = new QuitGameDialog();
connect(ui->back1_Btn,SIGNAL(clicked()),this,SLOT(slotBackClicked()));
connect(ui->back2_Btn,SIGNAL(clicked()),this,SLOT(slotBackClicked()));
ui->warnTips_Label->setVisible(false);
st_trainReport.passiveTime = 0;
st_trainReport.activeTime = 0;
ui->debug_GroupBox->setVisible(false);
#ifdef NORMALEXE
ui->groupBox_6->setVisible(false);
#endif
// ui->currentMode_label->setFont(QFont("黑体",8));
m_soundDialog = new SoundDialog();
m_quitBySpeedDialog = new QuitBySpeedDialog();
connect(m_quitBySpeedDialog,SIGNAL(signalClosed()),this,SLOT(slotSpeedDialogClosed()));
// 游戏自运行测试
}
GameDisplayPage::~GameDisplayPage()
{
if(m_leftAnimation)
delete m_leftAnimation;
if(m_rightAnimation)
delete m_rightAnimation;
if(heartTimer)
delete heartTimer;
if(countDownTimer)
delete countDownTimer;
if(m_reportDialog)
delete m_reportDialog;
if(m_quitDialog)
delete m_quitDialog;
if(m_emergencyDialog)
delete m_emergencyDialog;
if(m_trainReportTwoTwo)
delete m_trainReportTwoTwo;
if(m_trainReportThreeTwo)
delete m_trainReportThreeTwo;
if(m_trainReportTwoThree)
delete m_trainReportTwoThree;
if(m_gameSocket)
delete m_gameSocket;
if(m_soundDialog)
{
delete m_soundDialog;
}
if(m_quitBySpeedDialog)
delete m_quitBySpeedDialog;
if(paramPressTimer)
delete paramPressTimer;
if(paramPressForceTimer)
delete paramPressForceTimer;
delete ui;
}
void GameDisplayPage::initGameSocket()
{
m_gameSocket = new QUdpSocket();
int16_t port = 2100;
if(m_gameSocket->bind(QHostAddress("127.0.0.1"),port))
{
qDebug()<<(QString("游戏服务端口%1").arg(port));
}
else {
qDebug()<<(QString("游戏服务端口%1绑定失败").arg(port));
}
connect(m_gameSocket,&QUdpSocket::readyRead,this,&GameDisplayPage::slotReceiveGameData);
}
void GameDisplayPage::setUser(const ST_PatientMsg &st_patientMsg)
{
ui->user_Btn->setText(st_patientMsg.name);
}
void GameDisplayPage::setTitle()
{
//设置title效果
ui->user_Btn->setIcon(QIcon(":/DependFile/Source/User/user1.png"));
ui->user_Btn->setIconSize(QSize(40,40));
}
void GameDisplayPage::setTrainPart(int type)
{
m_bodyPart = type;
switch(type)
{
case 0:
ui->upLimp_GroupBox->move(20,135);
ui->heart_GroupBox->move(20,320);
ui->upLimp_GroupBox->setVisible(true);
ui->downLimp_GroupBox->setVisible(false);
ui->title_Label->setText(tr("上肢训练"));
break;
case 1:
ui->downLimp_GroupBox->move(20,135);
ui->heart_GroupBox->move(20,320);
ui->upLimp_GroupBox->setVisible(false);
ui->downLimp_GroupBox->setVisible(true);
ui->title_Label->setText(tr("下肢训练"));
break;
case 2:
ui->upLimp_GroupBox->move(20,135);
ui->downLimp_GroupBox->move(20,320);
ui->heart_GroupBox->move(20,505);
ui->upLimp_GroupBox->setVisible(true);
ui->downLimp_GroupBox->setVisible(true);
ui->title_Label->setText(tr("上下肢训练"));
break;
case 3:
ui->upLimp_GroupBox->move(20,135);
ui->heart_GroupBox->move(20,320);
ui->upLimp_GroupBox->setVisible(true);
ui->downLimp_GroupBox->setVisible(false);
ui->title_Label->setText(tr("上肢训练"));
break;
}
}
//实时数据填充
void GameDisplayPage::setSlaveParam(ST_DeviceParam &st_deviceParam)
{
// qDebug()<<"hello";
ST_GameControlParam st_gameControlParam;
//qDebug()<<"单车速度:"<<st_deviceParam.upLimpSpeed<<st_deviceParam.downLimpSpeed;
//qDebug() <<"设备的左平衡、右平衡:"<<st_deviceParam.upBalance << st_deviceParam.downBalance;
switch(m_bodyPart)
{
case 0: //上肢
{
if(st_deviceParam.upLimpSpeed > SpeedMax)
st_deviceParam.upLimpSpeed = SpeedMax;
ui->upRealSpeed_Label->setText(QString::number(st_deviceParam.upLimpSpeed));
ui->upRealPower_Label->setText(QString::number(st_deviceParam.upPower));
m_currentSpeed = st_deviceParam.upLimpSpeed;
if(m_st_bicycleParam.trainMode == 7 || m_st_bicycleParam.trainMode == 10)
setActivePassiveSwitchMode(st_deviceParam.currentMode);
//运动距离怎么计算
ui->length_Label->setText(QString::number(st_deviceParam.upLimpCircle*0.6,'f',1) + "m");
st_gameControlParam.speed = st_deviceParam.upLimpSpeed;
st_gameControlParam.forceLeft = st_deviceParam.upBalance;
st_gameControlParam.forceRight = 100 - st_deviceParam.upBalance;
st_gameControlParam.angle = st_deviceParam.leftHandPosition;
}
break;
case 1: //下肢
{
if(st_deviceParam.downLimpSpeed > SpeedMax)
st_deviceParam.downLimpSpeed = SpeedMax;
ui->downRealSpeed_Label->setText(QString::number(st_deviceParam.downLimpSpeed));
m_currentSpeed = st_deviceParam.downLimpSpeed;
// qDebug() <<"实时功率"<<st_deviceParam.downPower;
ui->downRealPower_Label->setText(QString::number(st_deviceParam.downPower));
if(m_st_bicycleParam.trainMode == 7 || m_st_bicycleParam.trainMode == 10)
setActivePassiveSwitchMode(st_deviceParam.currentMode);
ui->length_Label->setText(QString::number(st_deviceParam.downLimpCircle*0.6,'f',1) + "m");
st_gameControlParam.speed = st_deviceParam.downLimpSpeed;
st_gameControlParam.forceLeft = 100 - st_deviceParam.downBalance;
st_gameControlParam.forceRight = st_deviceParam.downBalance;
}
break;
case 2: //上下肢
{
if(st_deviceParam.upLimpSpeed > SpeedMax)
st_deviceParam.upLimpSpeed = SpeedMax;
ui->upRealSpeed_Label->setText(QString::number(st_deviceParam.upLimpSpeed));
ui->upRealPower_Label->setText(QString::number(st_deviceParam.upPower));
if(st_deviceParam.downLimpSpeed > SpeedMax)
st_deviceParam.downLimpSpeed = SpeedMax;
m_currentSpeed = SpeedMax;
if(m_spasmTipsDialog->isVisible())
{
ui->downRealSpeed_Label->setText(QString::number(0));
ui->downRealPower_Label->setText(QString::number(0));
st_deviceParam.downLimpSpeed = 0;
//gameState = 2; //不再接收游戏
}
else
{ ui->downRealSpeed_Label->setText(QString::number(st_deviceParam.downLimpSpeed));
ui->downRealPower_Label->setText(QString::number(st_deviceParam.downPower));
//gameState = 1; //接收数据
}
if(m_st_bicycleParam.trainMode == 7 || m_st_bicycleParam.trainMode == 10)
setActivePassiveSwitchMode(st_deviceParam.currentMode);
ui->length_Label->setText(QString::number(st_deviceParam.upLimpCircle*0.6,'f',1) + "m");
if(st_deviceParam.upLimpSpeed >= st_deviceParam.downLimpSpeed)
{
st_gameControlParam.forceLeft = st_deviceParam.upBalance;
st_gameControlParam.forceRight = 100 - st_deviceParam.upBalance;
}
else
{
st_gameControlParam.forceLeft = 100 - st_deviceParam.downBalance;
st_gameControlParam.forceRight = st_deviceParam.downBalance;
}
st_gameControlParam.speed = st_deviceParam.upLimpSpeed > st_deviceParam.downLimpSpeed?st_deviceParam.upLimpSpeed:st_deviceParam.downLimpSpeed;
}
break;
case 3: //垂直上肢
{
if(st_deviceParam.upLimpSpeed > SpeedMax)
st_deviceParam.upLimpSpeed = SpeedMax;
ui->upRealSpeed_Label->setText(QString::number(st_deviceParam.upLimpSpeed));
ui->upRealPower_Label->setText(QString::number(st_deviceParam.upPower));
m_currentSpeed = st_deviceParam.upLimpSpeed;
if(m_st_bicycleParam.trainMode == 7 || m_st_bicycleParam.trainMode == 10)
setActivePassiveSwitchMode(st_deviceParam.currentMode);
//运动距离怎么计算
ui->length_Label->setText(QString::number(st_deviceParam.upLimpCircle*0.6,'f',1) + "m");
st_gameControlParam.speed = st_deviceParam.upLimpSpeed;
st_gameControlParam.forceLeft = st_deviceParam.upBalance;
st_gameControlParam.forceRight = 100 - st_deviceParam.upBalance;
st_gameControlParam.angle = st_deviceParam.leftHandPosition;
//qDebug()<<"左手位置:"<<st_deviceParam.leftHandPosition;
//左手距离和打鱼游戏同步角度差了150度游戏会多出来150度
// qDebug() <<"角度"<< st_gameControlParam.angle;
/*
if(st_deviceParam.leftHandPosition >= 180)
{
st_deviceParam.leftHandPosition -= 180;
}
else
{
st_deviceParam.leftHandPosition = st_deviceParam.leftHandPosition + 180;
}
*/
st_gameControlParam.angle = st_deviceParam.leftHandPosition;
}
break;
}
//设置当前模式
m_currentMode = st_deviceParam.currentMode;
st_trainReport.upLimpLength = st_deviceParam.upLimpCircle*0.6;
st_trainReport.downLimpLength = st_deviceParam.downLimpCircle*0.6;
ui->leftHandAngle_label->setText(QString::number(st_deviceParam.leftHandPosition));
ui->leftFootAngle_label->setText(QString::number(st_deviceParam.leftFootPosition));
//此处显示的是左右平衡,但是下位机上传的是上下肢平衡
//qDebug() <<"st_gameControlParam.forceLeft"<< st_gameControlParam.forceLeft << gameState;
if(!gameState) //游戏未开始设置作用平衡为50
{
st_gameControlParam.forceLeft = 50;
st_gameControlParam.forceRight = 50;
}
if(m_bodyPart != 3 && gameState) //不是垂直上肢改变平衡度,同时游戏开始才改变平衡度
{
ui->leftBalance_Label->setText(QString::number(st_gameControlParam.forceLeft) +"%");
ui->rightBalance_Label->setText(QString::number(st_gameControlParam.forceRight)+"%");
}
//采集平衡数据
static int skipNum = 0;
++skipNum;
if(skipNum > 20)
{
QPair<int,int> balancePair;
balancePair.first = st_deviceParam.upBalance;
balancePair.second = st_deviceParam.downBalance;
//左右平衡计数
balanceList.append(balancePair);
//填充上肢或者下肢最大速度
int tempSpeed = qMax(st_deviceParam.upLimpSpeed,st_deviceParam.downLimpSpeed);
speedList.append(tempSpeed);
}
#if 1 //触发急停(必须放在痉挛前,原因暂时未找到)
if( 1 == st_deviceParam.emergencyState)
{
//痉挛设置速度为0
//st_deviceParam.downLimpSpeed = 0;
//st_deviceParam.downPower = 0;
IceModule::getInstance()->setEmergencyState(true);
if(m_emergencyDialog->isVisible())
return;
//训练界面未开始训练
if(m_st_bicycleParam.controlState == 0 )
{
if(this->isVisible())
{
//退出游戏
sendStopCmd();
//显示急停弹框
m_emergencyDialog->show();
//切到主界面关闭当前页显示关闭游戏container
// emit signalGameStateChanged(0);
}
else
{
m_emergencyDialog->show();
}
}
//训练界面已开始训练
else
{
if(m_spasmTipsDialog->isVisible())
{
m_spasmTipsDialog->stopPlayBell();
m_spasmTipsDialog->close();
}
//退出游戏
sendStopCmd();
//显示急停弹框
m_emergencyDialog->show();
//关闭倒计时
countDownTimer->stop();
//切换界面
//emit signalGameStateChanged(0);
st_trainReport.passiveTime = 0;
st_trainReport.activeTime = 0;
//切换为未训练状态
m_st_bicycleParam.controlState = 0;
}
}
else
{
IceModule::getInstance()->setEmergencyState(false);
if(m_emergencyDialog->isVisible())
{
m_emergencyDialog->close();
}
//非急停状态下发送数据驱动游戏
st_gameControlParam.speed *= 0.3;
if(st_gameControlParam.speed < 1.1 && st_gameControlParam.speed > 0)
st_gameControlParam.speed = 1.1;
sendGameControlParam(st_gameControlParam);
}
#endif
//触发痉挛
if(1 == st_deviceParam.spasmState )
{
if(m_spasmTipsDialog->isVisible())
return;
m_spasmTimes++;
//痉挛次数用于报告
st_trainReport.spasmTimes = m_spasmTimes;
switch(m_currentDirection)
{
case 0: //逆向
{
m_spasmTipsDialog->setSpasmCompletedDirection(1),
ui->direction_Label->setText(tr("正向"));
}
break;
case 1: //正向
{
m_spasmTipsDialog->setSpasmCompletedDirection(0),
ui->direction_Label->setText(tr("逆向"));
}
break;
}
m_spasmTipsDialog->setSpasmDialogVisible(true,m_spasmTimes);
if(m_currentDirection)
m_currentDirection = 0;
else
m_currentDirection = 1;
if(1 == m_currentDirection)
{
ui->forward_Btn->setChecked(true);
ui->backward_Btn->setChecked(false);
}
//逆向
else if(0 == m_currentDirection)
{
ui->forward_Btn->setChecked(false);
ui->backward_Btn->setChecked(true);
}
if(m_spasmTimes >= 3)
{
m_spasmTimes = 0;
//大于3次痉挛退出训练
on_stop_Btn_clicked();
}
}
//FES踏车时 发送电刺激参数
if(IceModule::getInstance()->getGameType() == 2)
{
ST_FESRealTimeParam st_FesRealTimeParam;
st_FesRealTimeParam.currentUpAngle = st_deviceParam.leftHandPosition;
st_FesRealTimeParam.currentDownAngle = st_deviceParam.leftFootPosition;
st_FesRealTimeParam.direction = st_deviceParam.direction;
st_FesRealTimeParam.upSpeed = st_deviceParam.upLimpSpeed;
st_FesRealTimeParam.downSpeed = st_deviceParam.downLimpSpeed;
sendRealTimeFesParam(st_FesRealTimeParam);
}
}
void GameDisplayPage::open_Btn_clicked()
{
m_leftAnimation->setStartValue(QPoint(-430,120));
m_leftAnimation->setEndValue(QPoint(0,120));
m_rightAnimation->setStartValue(QPoint(1920,120));
m_rightAnimation->setEndValue(QPoint(1490,120));
m_leftAnimation->start(QAbstractAnimation::KeepWhenStopped);
m_rightAnimation->start(QAbstractAnimation::KeepWhenStopped);
}
void GameDisplayPage::close_Btn_clicked()
{
m_leftAnimation->setStartValue(QPoint(0,120));
m_leftAnimation->setEndValue(QPoint(-430,120));
m_rightAnimation->setStartValue(QPoint(1490,120));
m_rightAnimation->setEndValue(QPoint(1920,120));
m_leftAnimation->start(QAbstractAnimation::KeepWhenStopped);
m_rightAnimation->start(QAbstractAnimation::KeepWhenStopped);
}
void GameDisplayPage::mouseDoubleClickEvent(QMouseEvent *event)
{
Q_UNUSED(event)
if(event->pos().x() > 434 && event->pos().x() < 1482)
{
if(m_openState)
close_Btn_clicked();
else
open_Btn_clicked();
m_openState = !m_openState;
}
}
void GameDisplayPage::on_upSpeedMinus_Btn_clicked()
{
int speed = ui->upSpeed_Label->text().toInt();
if(speed > 2)
{
--speed;
ui->upSpeed_Label->setText(QString::number(speed));
setTrainSpeed(speed);
m_st_bicycleParam.speed = speed;
}
}
void GameDisplayPage::on_upSpeedPlus_Btn_clicked()
{
int speed = ui->upSpeed_Label->text().toInt();
if(speed < 55)
{
++speed;
if((E_gameState != START) && (speed > 30))
{
ParamTipsDialog tipDialog;
tipDialog.setParamTipsMsg(tr("设定速度已超30r/min确认使用该速度训练吗"));
tipDialog.exec();
if(0 == tipDialog.getResult())
{
ui->upSpeed_Label->setText("30");
return;
}
}
ui->upSpeed_Label->setText(QString::number(speed));
setTrainSpeed(speed);
m_st_bicycleParam.speed = speed;
}
}
void GameDisplayPage::on_upForceMinus_Btn_clicked()
{
int force = ui->upForce_Label->text().toInt();
if(force > 1)
{
--force;
ui->upForce_Label->setText(QString::number(force));
setTrainFore(force);
m_st_bicycleParam.resistance = force;
}
}
void GameDisplayPage::on_upForcePlus_Btn_clicked()
{
int force = ui->upForce_Label->text().toInt();
if(force < 20)
{
++force;
ui->upForce_Label->setText(QString::number(force));
setTrainFore(force);
m_st_bicycleParam.resistance = force;
}
}
void GameDisplayPage::slotSetChannelAData(int *data,int size)
{
if(size <= 8 )
for(int i = 0;i <size;i++)
if(data[i] != 0)
m_channelAList.at(i)->setText(QString::number(data[i]));
}
void GameDisplayPage::slotSetChannelBData(int *data,int size)
{
if(size <= 8 )
for(int i = 0;i <size;i++)
if(data[i] != 0)
m_channelBList.at(i)->setText(QString::number(data[i]));
}
/*******踏车设置参数,根据参数设置界面来填充数据*******/
void GameDisplayPage::slotSetBicycleParam(ST_BicycleParam st_setBicycleParam)
{
//设置初始方向
if(st_setBicycleParam.direction == 1)
ui->direction_Label->setText(tr("正向"));
else if(st_setBicycleParam.direction == 0)
ui->direction_Label->setText(tr("逆向"));
m_st_bicycleParam = st_setBicycleParam;
m_startNum = m_st_bicycleParam.trainTime * 60;
m_spasmTipsDialog->setSpasmCompletedDirection(st_setBicycleParam.spasmType);
//训练模式
setTrainMode(m_st_bicycleParam.trainMode);
//主被动模式按钮状态切换
switchButtonState(m_st_bicycleParam.trainMode);
//设置训练部位
setTrainPart(st_setBicycleParam.bodyPart);
//上肢+垂直下肢
if(0 == st_setBicycleParam.bodyPart || 3 == st_setBicycleParam.bodyPart|| 2 == st_setBicycleParam.bodyPart)
{
//主动训练速度设置成0
if(1 == m_st_bicycleParam.trainMode)
st_setBicycleParam.speed = 0;
ui->upSpeed_Label->setText(QString::number(st_setBicycleParam.speed));
ui->upForce_Label->setText(QString::number(st_setBicycleParam.resistance));
ui->upRemainTime_Label->setText(QString::number(m_st_bicycleParam.trainTime));
//正向
if(1 == st_setBicycleParam.direction)
{
ui->forward_Btn->setChecked(true);
ui->backward_Btn->setChecked(false);
}
//逆向
else if(3 == st_setBicycleParam.direction)
{
ui->forward_Btn->setChecked(false);
ui->backward_Btn->setChecked(true);
}
}
//下肢
if(1 == st_setBicycleParam.bodyPart || 2 == st_setBicycleParam.bodyPart)
{
//主动训练速度设置成0
if(1 == m_st_bicycleParam.trainMode)
st_setBicycleParam.speed = 0;
ui->upSpeed_Label->setText(QString::number(st_setBicycleParam.speed));
ui->upForce_Label->setText(QString::number(st_setBicycleParam.resistance));
ui->downRemainTime_Label->setText(QString::number(m_st_bicycleParam.trainTime));
//正向
if(1 == st_setBicycleParam.direction)
{
ui->forward_Btn->setChecked(true);
ui->backward_Btn->setChecked(false);
}
//逆向
else if(0 == st_setBicycleParam.direction)
{
ui->forward_Btn->setChecked(false);
ui->backward_Btn->setChecked(true);
}
}
//垂直上肢隐藏平衡
if(3 == st_setBicycleParam.bodyPart)
{
ui->leftBalance_Label->hide();
ui->leftBalanceText_Label->hide();
ui->rightBalance_Label->hide();
ui->rightBalanceText_Label->hide();
}
else
{
ui->leftBalance_Label->show();
ui->leftBalanceText_Label->show();
ui->rightBalance_Label->show();
ui->rightBalanceText_Label->show();
}
//获取当前方向
m_currentDirection = st_setBicycleParam.direction;
st_patientMsg = CurrentUserData::getInstace()->getCurrentPatientMsg();
//填充报告内容
//患者基础信息
st_trainReport.ID = st_patientMsg.ID;
st_trainReport.name = st_patientMsg.name;
st_trainReport.sex = st_patientMsg.sex;
st_trainReport.phone = st_patientMsg.phone;
st_trainReport.age = st_patientMsg.age;
st_trainReport.markMsg = st_patientMsg.markMsg;
//训练设置参数
st_trainReport.trainMode = m_st_bicycleParam.trainMode;
st_trainReport.bodyIndex = m_st_bicycleParam.bodyPart;
st_trainReport.trainTime = m_st_bicycleParam.trainTime;
//初始化平衡值
st_trainReport.leftBalance = 0;
st_trainReport.rightBalance = 0;
}
void GameDisplayPage::getEmergecyState(ST_DeviceParam &st_deviceParam)
{
#if 1 //触发急停(必须放在痉挛前,原因暂时未找到)
2024-11-29 17:47:45 +08:00
qDebug() <<"急停状态:"<<st_deviceParam.emergencyState;
2024-11-25 17:15:44 +08:00
if( 1 == st_deviceParam.emergencyState)
{
IceModule::getInstance()->setEmergencyState(true);
if(m_emergencyDialog->isVisible())
return;
//训练界面未开始训练
if(m_st_bicycleParam.controlState == 0 )
{
if(this->isVisible())
{
//退出游戏
sendStopCmd();
//显示急停弹框
m_emergencyDialog->show();
//切到主界面关闭当前页显示关闭游戏container
// emit signalGameStateChanged(0);
qDebug() <<"---------------------------------------1";
}
else
{
m_emergencyDialog->show();
qDebug() <<"---------------------------------------2";
}
}
//训练界面已开始训练
else
{
if(m_spasmTipsDialog->isVisible())
{
m_spasmTipsDialog->stopPlayBell();
m_spasmTipsDialog->close();
qDebug() <<"---------------------------------------3";
}
//退出游戏
sendStopCmd();
//显示急停弹框
m_emergencyDialog->show();
//关闭倒计时
countDownTimer->stop();
//切换界面
//emit signalGameStateChanged(0);
st_trainReport.passiveTime = 0;
st_trainReport.activeTime = 0;
//切换为未训练状态
m_st_bicycleParam.controlState = 0;
}
}
else
{
IceModule::getInstance()->setEmergencyState(false);
if(m_emergencyDialog->isVisible())
{
m_emergencyDialog->close();
qDebug() <<"---------------------------------------4";
}
//非急停状态下发送数据驱动游戏
//st_gameControlParam.speed *= 0.3;
//if(st_gameControlParam.speed < 1.1 && st_gameControlParam.speed > 0)
// st_gameControlParam.speed = 1.1;
//sendGameControlParam(st_gameControlParam);
}
#endif
}
//接收下位机数据
void GameDisplayPage::slotReceiveData(QByteArray array)
{
// qDebug() <<"收到:"<<array.toHex();
switch(array[2])
{
case BRFORE_START_CMD: //启动前
case AFTER_START_CMD: //启动后
{
ST_DeviceParam st_deviceParam;
memcpy(&st_deviceParam,array.data() + 3,sizeof(ST_DeviceParam));
if(gameState ==1) //游戏开始之后炒菜接受数据,1开始2暂停不接受
{
setSlaveParam(st_deviceParam);//////////////////////////////
// qDebug() <<"游戏、急停:" << gameState<< st_deviceParam.emergencyState;
//qDebug() <<"急停状态:" << st_deviceParam.emergencyState;
}
else if(array.size() >= 30) //接手的是非实时参数的数据
{
//qDebug() <<"游戏、急停:" << gameState<< st_deviceParam.emergencyState;
// qDebug() <<"急停状态:" << st_deviceParam.emergencyState;
getEmergecyState(st_deviceParam);
}
int speed = st_deviceParam.downLimpSpeed >= st_deviceParam.upLimpSpeed ? st_deviceParam.downLimpSpeed:st_deviceParam.upLimpSpeed;
static int overTimes = 0;
//speed = 100;
//速度提示
if(speed > 99)
{
overTimes++;
if(overTimes > 40 && !m_quitBySpeedDialog->isVisible())
{
m_quitBySpeedDialog->startTimer();
overTimes = 0;
}
}
else
{
m_quitBySpeedDialog->stopTimer();
overTimes = 0;
}
}
break;
case RECE_HEARTBEAT_CMD:
++heartCount;
// qDebug()<<"接收下位机心跳";
break;
case GET_VERSION_CMD: //软件版本号
{
QString version;
version.append(array.mid(3,4));
IceModule::getInstance()->setVersion(version);
}
break;
}
}
void GameDisplayPage::slotHeartTimer()
{
// qDebug()<<"上位机发送心跳";
CCommunicateAPI::getInstance()->sendHeartBeat();
static int num = 0;
++num;
if(num > 3)
{
num = 0;
QPixmap pixmap;
if(heartCount < 1)
{
IceModule::getInstance()->setBicycleDeviceState(false);
pixmap.load(":/DependFile/Source/signal/deviceDisconnected.png");
}
else
{
IceModule::getInstance()->setBicycleDeviceState(true);
pixmap.load(":/DependFile/Source/signal/deviceConnected.png");
}
if(heartCount >= 3)
{
heartCount = 0;
}
ui->wifiSignal_Label->setPixmap(pixmap);
}
}
void GameDisplayPage::slotCountDownTimer()
{
--m_startNum;
if(m_startNum < 0)
{
countDownTimer->stop();
return;
}
int minNum = m_startNum/60;//分钟数
int secNum = m_startNum%60;//秒数
//训练时间计时
++st_trainReport.trainTime;
qDebug()<<"计时:"<<st_trainReport.trainTime;
//计算主被动时间
switch(m_currentMode)
{
case 0: //被动
++st_trainReport.passiveTime;
break;
case 1://主动
++st_trainReport.activeTime;
break;
case 2:
{
if(m_currentSpeed > ui->upSpeed_Label->text().toInt())
++st_trainReport.activeTime;
else
st_trainReport.passiveTime++;
};
break;
case 9://单独主动
st_trainReport.passiveTime+=1;
break;
case 10://被动可切主动
st_trainReport.activeTime += 1;
break;
case 11:
case 12:
++st_trainReport.passiveTime;
++st_trainReport.activeTime;
break;
}
//填入阻力值
resistentList<<ui->upForce_Label->text().toInt();
if(minNum == 0 && secNum == 0)
{
m_startNum = 0;
//关闭定时器
countDownTimer->stop();
ui->upRemainTime_Label->setText("0");
ui->downRemainTime_Label->setText("0");
//告知下位机停止训练
m_st_bicycleParam.controlState = 0;
CCommunicateAPI::getInstance()->sendBicycleParam(m_st_bicycleParam);
//弹出报告
//计算结果数据(平衡度、距离等)
calculateResultData();
//弹出训练报告
m_reportDialog->setReportData(st_trainReport,1);
//开窗
if(!m_openState)
{
open_Btn_clicked();
m_openState = !m_openState;
}
st_trainReport.passiveTime = 0;
st_trainReport.activeTime = 0;
st_trainReport.trainTime = 0;
//停止游戏
sendStopCmd();
}
else
{
ui->upRemainTime_Label->setText(QString::number(minNum+1));
ui->downRemainTime_Label->setText(QString::number(minNum+1));
}
}
void GameDisplayPage::slotStopTraining()
{
m_st_bicycleParam.controlState = 0;
CCommunicateAPI::getInstance()->sendBicycleParam(m_st_bicycleParam);
}
void GameDisplayPage::slotReceiveGameData()
{
while(m_gameSocket->hasPendingDatagrams())
{
QByteArray buf;
buf.resize(m_gameSocket->pendingDatagramSize());
m_gameSocket->readDatagram(buf.data(),buf.size());
parseGameMsg(buf);
}
}
void GameDisplayPage::slotBackClicked()
{
//首先停止运动
m_st_bicycleParam.controlState = 0;
CCommunicateAPI::getInstance()->sendBicycleParam(m_st_bicycleParam);
m_quitDialog->exec();
if(m_quitDialog->getResult() == 1)
{
//开窗
if(!m_openState)
{
open_Btn_clicked();
m_openState = !m_openState;
}
quitTrain();
//emit signalGameStateChanged(0);
}
else
{
if(E_gameState == PAUSE || E_gameState == STOP)
return;
m_st_bicycleParam.controlState = 1;
CCommunicateAPI::getInstance()->sendBicycleParam(m_st_bicycleParam);
}
}
void GameDisplayPage::quitTrain()
{
//关闭定时器
countDownTimer->stop();
//退出游戏
sendStopCmd();
}
void GameDisplayPage::changeModeTips(QString str)
{
m_tipStr = str;
ui->warnTips_Label->setVisible(true);
if(m_switchTimes > 0 )
ui->warnTips_Label->setText(tr("模式切换中"));
else
ui->warnTips_Label->setText(tr("被动"));
QTimer::singleShot(2500,this,[this](){
ui->warnTips_Label->setText(m_tipStr);
});
//|| m_currentSpeed > ui->upSpeed_Label->text().toInt()
//qDebug()<<"比较速度"<<m_currentSpeed << ui->upSpeed_Label->text().toInt();
++m_switchTimes;
}
void GameDisplayPage::switchButtonState(int8_t mode)
{
switch(mode)
{
case 0://被动不设置阻力
//上肢速度
setSpeedState(true);
//上肢阻力
setForceState(false);
setDirectionState(true);
break;
case 1://主动
//上肢速度
setSpeedState(false);
if(m_st_bicycleParam.bodyPart == 3)
setDirectionState(false); //垂直上至的主动模式
else
setDirectionState(true);
// qDebug() <<"主动、部位1"<<m_bodyPart ;
//上肢阻力
setForceState(true);
break;
case 3://等速
//上肢速度
setSpeedState(true);
//上肢阻力
setForceState(false);
setDirectionState(true);
break;
case 4:
setSpeedState(true);
setForceState(false);
setDirectionState(true);
break;
default:
setSpeedState(true);
setForceState(true);
setDirectionState(true);
break;
}
}
void GameDisplayPage::setbackBtVisible(bool isShow)
{
ui->back1_Btn->setVisible(isShow);
ui->back2_Btn->setVisible(isShow);
}
//发送实时电刺激相关参数
void GameDisplayPage::sendRealTimeFesParam(ST_FESRealTimeParam st_fesRealTimeParam)
{
for(int i = 0;i <= 4;++i)
{
//if(FesControlDialog::getInstance()->getDeviceStateByNo(i))
if(FesControlDialog::getInstance()->getMuscleDeviceStateByNo(i))
{
FesControlDialog::getInstance()->setRealTimeParam(i,st_fesRealTimeParam);
}
}
}
void GameDisplayPage::testTipsDialog()
{
/*
static int overTimes = 0;
int speed = 100;
//速度提示
if(speed > 99)
{
overTimes++;
if(overTimes > 40 && !m_quitBySpeedDialog->isVisible())
{
m_quitBySpeedDialog->startTimer();
overTimes = 0;
}
}
else
{
m_quitBySpeedDialog->stopTimer();
overTimes = 0;
}
*/
QByteArray data = QByteArray::fromHex("AB040107100001CD");
slotReceiveData(data);
}
//解析游戏数据
void GameDisplayPage::parseGameMsg(QByteArray jsonArray)
{
QJsonParseError jsonError;
QJsonDocument doucment = QJsonDocument::fromJson(jsonArray, &jsonError); // 转化为 JSON 文档
if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError))
{
if(doucment.isObject())
{
QJsonObject object = doucment.object(); // 转化为对象
if(object.contains("MsgID"))
{
QString str = object.value("MsgID").toString();
int msgID = str.toInt();
switch(msgID)
{
case 3: //开始游戏
emit signalGameStateChanged(1);
m_gameRebackState = 1;
break;
case 4: //退出游戏
{
m_gameRebackState = 0;
QTimer::singleShot(200,this,[this](){
emit signalGameStateChanged(0);
});
}
break;
}
}
}
}
else
qDebug()<<"jsonError.error"<<jsonError.error;
// qDebug()<<"m_gameRebackState"<<m_gameRebackState;
}
void GameDisplayPage::sendGameControlParam(ST_GameControlParam st_gameControlParam)
{
st_gameControlParam.MsgId = 1;
QJsonObject object;
//当为蹬单车(1或者2)的游戏时固定最大偏斜调度为60优化极端偏倒
int tempGameID = GameControl::getInstance()->getCurrentGameID();
object.insert("MsgID",st_gameControlParam.MsgId);
object.insert("userName",st_gameControlParam.userName);
object.insert("ID",st_gameControlParam.ID);
object.insert("speed",st_gameControlParam.speed);
if(tempGameID ==1 || tempGameID ==2)
{
object.insert("forceLeft",st_gameControlParam.forceLeft*0.7 >= 60 ? 60 : st_gameControlParam.forceLeft*0.7);
object.insert("forceRight",st_gameControlParam.forceRight*0.7 >= 60 ? 60 : st_gameControlParam.forceRight*0.7);
}
else
{
object.insert("forceLeft",st_gameControlParam.forceLeft*0.7);
object.insert("forceRight",st_gameControlParam.forceRight*0.7);
}
object.insert("steps",30);
object.insert("calories",5);
object.insert("angle",st_gameControlParam.angle);
//左右平衡度数据,angle:1-359;可能跳变333;停了一会;
QJsonDocument document;
document.setObject(object);
QByteArray sendArray = document.toJson(QJsonDocument::Compact);
QString ip("127.0.0.1");
int16_t port = 12000;
m_gameSocket->writeDatagram(sendArray,QHostAddress(ip),port);
}
void GameDisplayPage::sendStopCmd()
{
QJsonObject object;
object.insert("MsgID",2);
object.insert("GameState",0);
QJsonDocument document;
document.setObject(object);
QByteArray sendArray = document.toJson(QJsonDocument::Compact);
QString ip("127.0.0.1");
int16_t port = 12000;
m_gameSocket->writeDatagram(sendArray,QHostAddress(ip),port);
QTimer::singleShot(100,this,[this](){
if(m_gameRebackState)
{ //再次发送关闭指令
qDebug()<<"再次发送关闭指令";
sendStopCmd();
}
});
}
//开始游戏
void GameDisplayPage::startGameCmd()
{
QJsonObject object;
object.insert("MsgID",2);
object.insert("GameState",1);
QJsonDocument document;
document.setObject(object);
QByteArray sendArray = document.toJson(QJsonDocument::Compact);
QString ip("127.0.0.1");
int16_t port = 12000;
m_gameSocket->writeDatagram(sendArray,QHostAddress(ip),port);
//test
}
//暂停游戏
void GameDisplayPage::pauseGameCmd()
{
QJsonObject object;
object.insert("MsgID",2);
object.insert("GameState",2);
QJsonDocument document;
document.setObject(object);
QByteArray sendArray = document.toJson(QJsonDocument::Compact);
QString ip("127.0.0.1");
int16_t port = 12000;
m_gameSocket->writeDatagram(sendArray,QHostAddress(ip),port);
}
void GameDisplayPage::sendStopCmdThreeTimes()
{
sendStopCmd();
QTimer::singleShot(400,this,[this](){
sendStopCmd();
});
}
void GameDisplayPage::calculateResultData()
{
//计算平衡度
int upBalance = 0,downBalance = 0;
int upSum = 0,downSum = 0;
for(int i = 0;i < balanceList.size();i++)
{
upSum += balanceList.at(i).first;
downSum += balanceList.at(i).second;
}
upBalance = ((float)upSum)/balanceList.size();
downBalance = ((float)downSum)/balanceList.size();
//报告中的平衡度
switch(m_bodyPart)
{
case 0: //上肢
st_trainReport.leftBalance = upBalance;
st_trainReport.rightBalance = 100 - upBalance;
break;
case 1: //下肢
st_trainReport.leftBalance = downBalance;
st_trainReport.rightBalance = 100 - downBalance;
break;
case 2: //上下肢
st_trainReport.leftBalance = upBalance;
st_trainReport.rightBalance = 100 - upBalance;
break;
case 3: //垂直上肢
st_trainReport.leftBalance = 50;
st_trainReport.rightBalance = 50;
break;
}
//计算阻力值
int maxResistent = 0,minResistent = 200,sumResistent = 0,aveResistent = 0;
if(!resistentList.empty())
{
for(int i = 0;i < resistentList.size();i++)
{
if(maxResistent < resistentList.at(i))
maxResistent = resistentList.at(i);
if(minResistent > resistentList.at(i))
minResistent = resistentList.at(i);
sumResistent += resistentList.at(i);
}
if(resistentList.size() > 0)
aveResistent = sumResistent/resistentList.size();
st_trainReport.minResistance = minResistent;
st_trainReport.maxResistance = maxResistent;
st_trainReport.averangeResistance = aveResistent;
}
else
{
int tempResistance = ui->upForce_Label->text().toInt();
st_trainReport.minResistance = tempResistance;
st_trainReport.maxResistance = tempResistance;
st_trainReport.averangeResistance = tempResistance;
}
//计算速度
int maxSpeed = 0,sumSpeed = 0,aveSpeed = 0;
if(!speedList.empty())
{
for(int i = 0;i < speedList.size();i++)
{
if(maxSpeed < speedList.at(i))
maxSpeed = speedList.at(i);
sumSpeed += speedList.at(i);
}
if(speedList.size() > 0)
aveSpeed = sumSpeed/speedList.size();
// st_trainReport.minResistance = minResistent;
st_trainReport.maxSpeed = maxSpeed;
st_trainReport.averageSpeed = aveSpeed;
}
else
{
int tempSpeed = ui->upSpeed_Label->text().toInt(); //需要修改
st_trainReport.maxSpeed = tempSpeed;
st_trainReport.averageSpeed = tempSpeed;
}
}
void GameDisplayPage::initButton()
{
ui->stop_Btn->setVisible(false);
ui->pause_Btn->setVisible(false);
ui->start_Btn->setVisible(true);
ui->length_Label->setText("0.00m");
qDebug()<<"0.0m";
ui->leftBalance_Label->setText("50%");
ui->rightBalance_Label->setText("50%");
}
void GameDisplayPage::setTrainSpeed(int speed, qint8 type)
{
if(0 == type)
CCommunicateAPI::getInstance()->sendRealTimeParam(PASSIVE_SPEED,speed);
else if(1 == type)
CCommunicateAPI::getInstance()->sendRealTimeParam(EQUAL_SPEED,speed);
}
void GameDisplayPage::setTrainFore(int force, qint8 type)
{
Q_UNUSED(type)
CCommunicateAPI::getInstance()->sendRealTimeParam(RESISTANCE_CMD,force);
}
void GameDisplayPage::setTrainDirection(qint8 direction, qint8 type)
{
//direction 默认为1
Q_UNUSED(type)
CCommunicateAPI::getInstance()->sendRealTimeParam(SWITCH_DIRECTION,direction);
}
void GameDisplayPage::switchFes(qint8 channel, bool ok)
{
Q_UNUSED(channel)
Q_UNUSED(ok)
}
void GameDisplayPage::on_start_Btn_clicked()
{
for(int i=0 ;i<100; i++)
{
testTipsDialog();
}
if(0 == gameState)///
{
//训练起始时间
st_trainReport.startTimeStr = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
st_trainReport.trainTime = 0;
st_trainReport.activeTime = 0;
st_trainReport.passiveTime = 0;
}
E_LANGUAGE language = LanguageManager::getInstance()->getCurrentLanguage();
if (language == Chinese_E)
{
GameControl::getInstance()->playTipMusic("./DependFile/Music/startTraining.mp3");
}
else if (language == English_E) //初始化英文暂停和结束
{
GameControl::getInstance()->playTipMusic("./DependFile/Music/startTraining_En.mp3");
}
//已开始
gameState = 1;
E_gameState = START;////
setbackBtVisible(false);
ui->start_Btn->setVisible(false);
ui->stop_Btn->setVisible(true);
ui->pause_Btn->setVisible(true);
//配置功率
m_st_bicycleParam.configPower = IceModule::getInstance()->getPower();
//告知下位机开始运动
if(m_st_bicycleParam.controlState == 2)
m_st_bicycleParam.controlState = 3;
else
m_st_bicycleParam.controlState = 1;
//if(m_st_bicycleParam.bodyPart == 3)
// m_st_bicycleParam.bodyPart = 0;
qDebug() <<"部位:"<< m_st_bicycleParam.bodyPart;
CCommunicateAPI::getInstance()->sendBicycleParam(m_st_bicycleParam);
//开始时间计时器
countDownTimer->start();
startGameCmd();
//停止游戏运动
/*
ST_GameControlParam st_gameControlParam;
st_gameControlParam.speed = 30;
st_gameControlParam.forceLeft = 50;
st_gameControlParam.forceRight = 50;
bool increaseDir = true,decreaseDir=true,speedDir=true;
for(int i=0; i<100000; i++)
{
Sleep(100);
if(st_gameControlParam.angle >0 && speedDir)
st_gameControlParam.angle += 3;
else if(st_gameControlParam.angle < 180 && !speedDir)
st_gameControlParam.angle -= 3;
if(st_gameControlParam.angle == 0 || st_gameControlParam.angle == 180)
speedDir = !speedDir;
if(st_gameControlParam.forceRight >0 && increaseDir)
st_gameControlParam.forceRight ++;
else if(st_gameControlParam.forceRight < 180 && !increaseDir)
st_gameControlParam.forceRight --;
if(st_gameControlParam.forceRight == 0 || st_gameControlParam.forceRight == 180)
increaseDir = !increaseDir;
if(st_gameControlParam.forceLeft >0 && decreaseDir)
st_gameControlParam.forceLeft ++;
else if(st_gameControlParam.forceLeft < 180 && !decreaseDir)
st_gameControlParam.forceLeft --;
if(st_gameControlParam.forceLeft == 0 || st_gameControlParam.forceLeft == 180)
decreaseDir = !decreaseDir;
sendGameControlParam(st_gameControlParam);
}
*/
}
void GameDisplayPage::on_stop_Btn_clicked()
{
//更新玩游戏的三个处方参数
ST_TrainParam st_trainParam = GameControl::getInstance()->getTrainParam();
if(ui->direction_Label->text() == tr("正向"))
st_trainParam.trainDirection = 1;
else
st_trainParam.trainDirection = 0;
st_trainParam.trainSpeed = ui->upSpeed_Label->text().toInt();
st_trainParam.trainResistance = ui->upForce_Label->text().toInt();
GameControl::getInstance()->setTrainParam(st_trainParam);
E_gameState = STOP;
ui->start_Btn->setVisible(false);
ui->stop_Btn->setVisible(false);
ui->pause_Btn->setVisible(false);
E_LANGUAGE language = LanguageManager::getInstance()->getCurrentLanguage();
if (language == Chinese_E)
{
GameControl::getInstance()->playTipMusic("./DependFile/Music/stopTraining.mp3");
}
else if (language == English_E) //初始化英文暂停和结束
{
GameControl::getInstance()->playTipMusic("./DependFile/Music/stopTraining_En.mp3");
}
//告知下位机停止训练
m_st_bicycleParam.controlState = 0;
CCommunicateAPI::getInstance()->sendBicycleParam(m_st_bicycleParam);
//关闭定时器
countDownTimer->stop();
// sendStopCmd();
//停止游戏运动
ST_GameControlParam st_gameControlParam;
st_gameControlParam.speed = 0;
st_gameControlParam.forceLeft = 50;
st_gameControlParam.forceRight = 50;
sendGameControlParam(st_gameControlParam);
//计算结果数据(平衡度、距离等)
calculateResultData();
//弹出训练报告
int chooseReport = 0; //增加了垂直上肢等速、
if(st_trainReport.bodyIndex==3 && ( st_trainReport.trainMode==0 || st_trainReport.trainMode==3))
{
chooseReport = 1; //2*2=原来:(垂直上肢的助力模式和被动模式),现在 (垂直上肢的助力模式、被动模式、等速)
}
else if(st_trainReport.bodyIndex==3 && (st_trainReport.trainMode==2 || st_trainReport.trainMode == 1 || st_trainReport.trainMode==10))
{
chooseReport = 2; //3*2=原来:(垂直上肢的主动模式、等速模式和主被动),现在(垂直上肢的主动模式、主被动)
}
else if((st_trainReport.bodyIndex==0 || st_trainReport.bodyIndex== 2|| st_trainReport.bodyIndex==1)
&& (st_trainReport.trainMode==0 || st_trainReport.trainMode==4)
|| (st_trainReport.bodyIndex==0 ||st_trainReport.bodyIndex == 1) && st_trainReport.trainMode==3)
{
chooseReport = 3;//2*3=原来水平上肢、上下肢和下肢的被动和助力现在水平上肢、上下肢和下肢的被动、水平上肢和下肢的等速模式上下肢被动模式是4不是0
}
//qDebug()<<"chooseReport:"<<"st_trainReport.bodyIndex:"<<"st_trainReport.trainMode:"<<chooseReport<<st_trainReport.bodyIndex<<st_trainReport.trainMode;
if(chooseReport == 0) //显示3行3图片
m_reportDialog->setReportData(st_trainReport,1);
else if(chooseReport == 1)
m_trainReportTwoTwo->setReportData(st_trainReport,1);
else if(chooseReport == 2)
m_trainReportThreeTwo->setReportData(st_trainReport,1);
else if(chooseReport == 3)
m_trainReportTwoThree->setReportData(st_trainReport,1);
//开窗
if(!m_openState)
{
open_Btn_clicked();
m_openState = !m_openState;
}
st_trainReport.activeTime = 0;
st_trainReport.passiveTime = 0;
//退出游戏
sendStopCmd();
// Sleep(SleepTime);
// emit signalGameStateChanged(0);
//只修改页面索引,不发送槽函数
//MainWindowPageControl::getInstance()->setPageIndex(MainPage_E);
}
void GameDisplayPage::on_pause_Btn_clicked()
{
E_gameState = PAUSE;
gameState = 2; //设置游戏状态为2启动的时候再开启
E_LANGUAGE language = LanguageManager::getInstance()->getCurrentLanguage();
if (language == Chinese_E)
{
GameControl::getInstance()->playTipMusic("./DependFile/Music/pauseTraining.mp3");
}
else if (language == English_E) //初始化英文暂停和结束
{
GameControl::getInstance()->playTipMusic("./DependFile/Music/pauseTraining_En.mp3");
}
pauseGameCmd();
//关闭定时器
countDownTimer->stop();
// **************一行代码;
//qDebug()<<"暂停时间:"<<st_trainReport.trainTime;
m_st_bicycleParam.direction = m_currentDirection;
m_st_bicycleParam.controlState = 2;
CCommunicateAPI::getInstance()->sendBicycleParam(m_st_bicycleParam);
ui->start_Btn->setVisible(true);
ui->stop_Btn->setVisible(false);
ui->pause_Btn->setVisible(false);
ui->upRealPower_Label->setText("0");
ui->upRealSpeed_Label->setText("0");
ui->downRealPower_Label->setText("0");
ui->downRealSpeed_Label->setText("0");
/*
if(m_st_bicycleParam.trainMode == 7 || m_st_bicycleParam.trainMode == 10)
{
ui->upCurrentStage_Label->setText(tr("主动模式"));
//将当前模式切成主动
m_currentMode = 1;
}
*/
}
void GameDisplayPage::on_switchAFes_Btn_clicked()
{
QMessageBox::warning(NULL,tr("提示"),tr("未检测到电刺激设备"));
return;
}
void GameDisplayPage::setTrainMode(int8_t mode)
{
QString modeName;
switch(mode)
{
case 0:
modeName = tr("被动");
break;
case 1:
modeName = tr("主动");
break;
case 2:
modeName = tr("助力");
break;
case 3:
modeName = tr("等速");
break;
case 4: //四肢被动
modeName = tr("被动");
break;
case 5:
modeName = tr("上肢带下肢");
break;
case 6:
modeName = tr("下肢带上肢");
break;
case 7:
modeName = tr("主被动");
break;
case 8:
modeName = tr("FES");
break;
case 9:
modeName = tr("主动");
break;
case 10:
modeName = tr("主被动");
break;
case 11:
ui->upCurrentStage_Label->setText(tr("主动"));
break;
case 12:
ui->upCurrentStage_Label->setText(tr("被动"));
break;
}
ui->upCurrentStage_Label->setText(modeName);
}
//设置主被动切换的模式(实时填充)
void GameDisplayPage::setActivePassiveSwitchMode(int8_t mode)
{
if(m_AP_mode == mode)
return;
if(m_AP_mode != mode)
{
QString modeName;
switch(mode)
{
case 0:
modeName = tr("被动");
break;
case 1:
modeName = tr("主动");
break;
case 7:
modeName = tr("主被动");
break;
case 9:
modeName = tr("主动");
break;
case 10:
modeName = tr("主被动");
break;
case 11:
//ui->upCurrentStage_Label->setText(tr("主动"));
break;
case 12:
//ui->upCurrentStage_Label->setText(tr("被动"));
break;
}
ui->warnTips_Label->setText(modeName);
if(m_st_bicycleParam.trainMode == 7 || m_st_bicycleParam.trainMode == 10)
{
changeModeTips(modeName);
}
m_AP_mode = mode;
}
}
//填充设置参数
void GameDisplayPage::fillSetParam(int updown,int speed,int resistance,int direction)
{
//上肢
upDirection = direction;
if(upDirection == 1)
on_forward_Btn_clicked();
else if(upDirection == 0)
on_backward_Btn_clicked();
ui->upSpeed_Label->setText(QString::number(speed));
ui->upForce_Label->setText(QString::number(resistance));
}
void GameDisplayPage::setPulseOxygen(const ST_PulseOxygen& pulseOxygen)
{
// ui->pulse_Label->setText(QString::number(pulseOxygen.pulse));
// ui->oxygen_Label->setText(QString::number(pulseOxygen.oxygen));
}
void GameDisplayPage::setCenterParam(int left, int right, int length)
{
ui->leftBalance_Label->setText(QString::number(left) + "%");
ui->leftBalance_Label->setText(QString::number(right) + "%");
ui->leftBalance_Label->setText(QString::number(length) + "m");
}
void GameDisplayPage::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)
QPainter painter(this);
painter.fillRect(rect(),QColor(0,0,0,10));
}
void GameDisplayPage::showEvent(QShowEvent *event)
{
Q_UNUSED(event)
initButton();//初始化
gameState = 0;//未开始
m_spasmTimes = 0;
st_trainReport.spasmTimes = 0;
st_trainReport.upLimpLength =0;
st_trainReport.downLimpLength = 0;
ui->upRealPower_Label->setText("0");
ui->upRealSpeed_Label->setText("0");
ui->downRealPower_Label->setText("0");
ui->downRealSpeed_Label->setText("0");
balanceList.clear();
resistentList.clear();
speedList.clear(); //清空
//设置当前用户
setUser(CurrentUserData::getInstace()->getCurrentPatientMsg());
setbackBtVisible(true);
m_AP_mode = 1;
ui->warnTips_Label->setVisible(false);
E_gameState = STOP;
m_switchTimes = 0;
int8_t type = IceModule::getInstance()->getGameType();
switch (type) {
case 1: //单独踏车
ui->groupBox_6->setVisible(false);
break;
case 2: //FES踏车
ui->groupBox_6->setVisible(true);
break;
}
E_LANGUAGE language = LanguageManager::getInstance()->getCurrentLanguage();
if (language == English_E) //初始化英文暂停和结束
{
ui->stop_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/stop_E.png);");
ui->pause_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/pause_E.png);");
ui->warnTips_Label->move(1290,20);
ui->upCurrentStage_Label->setStyleSheet("color:white;width: 58px;height: 29px;font-size: 23px;font-weight: 500;color: #FFFFFF;line-height: 44px;");
ui->currentMode_label->setStyleSheet("color:white;width: 58px;height: 29px;font-size: 23px;font-weight: 500;color: #FFFFFF;line-height: 44px;");
}
}
void GameDisplayPage::on_forward_Btn_clicked()
{
/*
setTrainDirection(1);
m_st_bicycleParam.direction = 1;
m_currentDirection = 1;
*/
if(m_currentDirection == 0)
{
setTrainDirection(1);
m_st_bicycleParam.direction = 1;
m_currentDirection = 1;
ui->direction_Label->setText(tr("正向"));
}
else
{
setTrainDirection(0);
m_st_bicycleParam.direction = 0;
m_currentDirection = 0;
ui->direction_Label->setText(tr("逆向"));
}
}
void GameDisplayPage::on_backward_Btn_clicked()
{
/*
setTrainDirection(0);
m_st_bicycleParam.direction = 0;
m_currentDirection = 0;
*/
if(m_currentDirection == 0)
{
setTrainDirection(1);
m_st_bicycleParam.direction = 1;
m_currentDirection = 1;
ui->direction_Label->setText(tr("正向"));
}
else
{
setTrainDirection(0);
m_st_bicycleParam.direction = 0;
m_currentDirection = 0;
ui->direction_Label->setText(tr("逆向"));
}
}
void GameDisplayPage::on_switchFes_Btn_clicked()
{
QString fesA("border-image: url(:/DependFile/Source/gamePage/checkA.png);");
QString fesB("border-image: url(:/DependFile/Source/gamePage/checkB.png);");
// if(ui->switchFes_Btn->styleSheet() == fesA)
// {
// ui->switchFes_Btn->setStyleSheet(fesB);
// }
// else if(ui->switchFes_Btn->styleSheet() == fesB)
// {
// ui->switchFes_Btn->setStyleSheet(fesA);
// }
}
void GameDisplayPage::changeEvent(QEvent* event)
{
switch (event->type())
{
case QEvent::LanguageChange:
{
//qDebug() <<"改变语言";
E_LANGUAGE language = LanguageManager::getInstance()->getCurrentLanguage();
switch(language)
{
case Chinese_E:
ui->stop_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/stop.png);");
ui->pause_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/pause.png);");
//调节样式
ui->currentMode_label->setStyleSheet("color:white;width: 58px;height: 29px;font-size: 29px;font-weight: 500;color: #FFFFFF;line-height: 44px;");
ui->upCurrentStage_Label->setStyleSheet("color:white;width: 58px;height: 29px;font-size: 29px;font-weight: 500;color: #FFFFFF;line-height: 44px;");
ui->upLimb_label->setFont(QFont("黑体",29));
ui->downLimb_label->setFont(QFont("黑体",29));
ui->directionText_label->setFont(QFont("黑体",29));
ui->speedText_label->setFont(QFont("黑体",29));
ui->resistText_label->setFont(QFont("黑体",29));
ui->directionText_label->move(110,10);
ui->speedText_label->move(100,10);
ui->resistText_label->move(100,10);
ui->warnTips_Label->move(1090,20); //主被动模式下的主动和被动提示
break;
case English_E:
ui->stop_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/stop_E.png);");
ui->pause_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/pause_E.png);");
//调节样式
ui->currentMode_label->setStyleSheet("color:white;width: 58px;height: 29px;font-size: 23px;font-weight: 500;color: #FFFFFF;line-height: 44px;");
ui->upCurrentStage_Label->setStyleSheet("color:white;width: 58px;height: 29px;font-size: 23px;font-weight: 500;color: #FFFFFF;line-height: 44px;");
ui->upLimb_label->setFont(QFont("黑体",15));
ui->downLimb_label->setFont(QFont("黑体",15));
ui->directionText_label->setFont(QFont("黑体",15));
ui->speedText_label->setFont(QFont("黑体",15));
ui->resistText_label->setFont(QFont("黑体",15));
ui->directionText_label->move(108,10);
ui->speedText_label->move(95,10);
ui->resistText_label->move(105,10);
ui->warnTips_Label->move(1290,20);
break;
}
ui->retranslateUi(this);
}
break;
default:
QWidget::changeEvent(event);
break;
}
}
//设置速度使能状态
void GameDisplayPage::setSpeedState(bool enabled)
{
ui->upSpeedMinus_Btn->setEnabled(enabled);
ui->upSpeedPlus_Btn->setEnabled(enabled);
ui->speed_GroupBox->setEnabled(enabled);
if(enabled)
{
ui->upSpeedMinus_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/decreaseValue.png);");
ui->upSpeedPlus_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/plusValue.png);");
ui->speed_GroupBox->setStyleSheet("#speed_GroupBox{border-image: url(:/DependFile/Source/gamePage/parameBackground.png);}");
}
else
{
ui->upSpeedMinus_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/valuePlusOffChange.png);");
ui->upSpeedPlus_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/valueOffChange.png);");
ui->speed_GroupBox->setStyleSheet("#speed_GroupBox{border-image: url(:/DependFile/Source/gamePage/parameBackground.png);}");
}
}
//设置阻力使能状态
void GameDisplayPage::setDirectionState(bool enabled)
{
ui->forward_Btn->setEnabled(enabled);
ui->backward_Btn->setEnabled(enabled);
ui->groupBox_3->setEnabled(enabled);
if(enabled)
{
ui->backward_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/decreaseValue.png);");
ui->forward_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/plusValue.png);");
ui->groupBox_3->setStyleSheet("#groupBox_3{border-image: url(:/DependFile/Source/gamePage/parameBackground.png);}");
}
else
{
ui->backward_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/valuePlusOffChange.png);");
ui->forward_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/valueOffChange.png);");
ui->groupBox_3->setStyleSheet("#groupBox_3{border-image: url(:/DependFile/Source/gamePage/parameBackground.png);}");
}
}
//设置阻力使能状态
void GameDisplayPage::setForceState(bool enabled)
{
ui->upForceMinus_Btn->setEnabled(enabled);
ui->upForcePlus_Btn->setEnabled(enabled);
ui->force_GroupBox->setEnabled(enabled);
if(enabled)
{
ui->upForceMinus_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/decreaseValue.png);");
ui->upForcePlus_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/plusValue.png);");
ui->force_GroupBox->setStyleSheet("#force_GroupBox{border-image: url(:/DependFile/Source/gamePage/parameBackground.png);}");
}
else
{
ui->upForceMinus_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/valuePlusOffChange.png);");
ui->upForcePlus_Btn->setStyleSheet("border-image: url(:/DependFile/Source/gamePage/valueOffChange.png);");
ui->force_GroupBox->setStyleSheet("#force_GroupBox{border-image: url(:/DependFile/Source/gamePage/parameBackground.png);}");
}
}
void GameDisplayPage::pressedAdjustSpeed()
{
int speed = ui->upSpeed_Label->text().toInt();
if(m_increasingSpeed && speed < 55)
{
++speed;
if((E_gameState != START) && (speed > 30))
{
ParamTipsDialog tipDialog;
tipDialog.setParamTipsMsg(tr("设定速度已超30r/min确认使用该速度训练吗"));
tipDialog.exec();
if(0 == tipDialog.getResult())
{
ui->upSpeed_Label->setText("30");
return;
}
}
ui->upSpeed_Label->setText(QString::number(speed));
setTrainSpeed(speed);
m_st_bicycleParam.speed = speed;
}
else if(m_decreasingSpeed && speed > 2)
{
--speed;
ui->upSpeed_Label->setText(QString::number(speed));
setTrainSpeed(speed);
m_st_bicycleParam.speed = speed;
}
if(!m_decreasingSpeed && !m_increasingSpeed)
{
paramPressTimer->stop();
}
}
void GameDisplayPage::pressAdjustForce()
{
int force = ui->upForce_Label->text().toInt();
if(m_increasingForce && force < 20)
{
++force;
ui->upForce_Label->setText(QString::number(force));
setTrainFore(force);
m_st_bicycleParam.resistance = force;
}
else if(m_decreasingForce && force > 1)
{
--force;
ui->upForce_Label->setText(QString::number(force));
setTrainFore(force);
m_st_bicycleParam.resistance = force;
}
if(!m_decreasingForce && !m_increasingForce)
{
paramPressForceTimer->stop();
}
}
void GameDisplayPage::on_sound_Button_clicked()
{
m_soundDialog->show();
}
void GameDisplayPage::on_upSpeedPlus_Btn_pressed()
{
paramPressTimer->start(200);
m_increasingSpeed = true;
}
void GameDisplayPage::on_upSpeedMinus_Btn_pressed()
{
paramPressTimer->start(200);
m_decreasingSpeed = true;
}
void GameDisplayPage::on_upSpeedPlus_Btn_released()
{
m_increasingSpeed = false;
}
void GameDisplayPage::on_upSpeedMinus_Btn_released()
{
m_decreasingSpeed = false;
}
void GameDisplayPage::on_upForcePlus_Btn_pressed()
{
m_increasingForce = true;
paramPressForceTimer->start(200);
}
void GameDisplayPage::on_upForceMinus_Btn_pressed()
{
m_decreasingForce = true;
paramPressForceTimer->start(200);
}
void GameDisplayPage::on_upForcePlus_Btn_released()
{
m_increasingForce = false;
}
void GameDisplayPage::on_upForceMinus_Btn_released()
{
m_decreasingForce = false;
}
void GameDisplayPage::slotSpeedDialogClosed()
{
on_stop_Btn_clicked(); //速到超过5s终止训练
}
void GameDisplayPage::slotSimulateData()
{
static int angle = 0;
ST_GameControlParam st_gameControlParam;
st_gameControlParam.speed = 10;
st_gameControlParam.forceLeft = 50;
st_gameControlParam.forceRight = 50;
st_gameControlParam.angle = angle;
sendGameControlParam(st_gameControlParam);
angle++;
if(angle >= 360)
angle = 0;
}