今天这一篇我们主要讲如何把前面的GPIO/IIC/UART综合起来。
做成一个上位机。
前面的部分不用讲了,今天主要讲UI部分。
Qt我们使用的是拖拽控件的方式。
下面是实现的代码部分:
***.cpp
#include "tw_lightingui.h"
#include "ui_tw_lightingui.h"
#include "bsp_key.h"
#include "uart.h"
#include "jy901_Init.h"
#include "QMutex"
#include <QString>
//------------------------------Button define value set------------------------------------
#define SEL_FUN_HCALI 0 //option of LRTRAP
#define SEL_FUN_VCALI 1 //option of UDTRAP
#define SEL_FUN_ZROTA 2 //option of FRAMEROLL
#define SEL_FUN_DIGFOCUS 3 //option of UDSHIFT
#define SEL_FUN_UNIFOBRI 4 //option of LRSHIFT
#define SEL_FUN_HLINEAR 5 //option of LRLINEAR
#define SEL_FUN_VLINEAR 6 //option of UDLINEAR
#define SEL_OPT_CALILOCA 7 //option of LOCATE
#define SEL_OPT_RECTIFY 8 //option of RECTIFY
#define SEL_OPT_RESET 9 //option of RESET
#define SEL_OPT_LIGHRASPSW 10 //switch of SWITCH_FUNCTION
#define SEL_SW_HCALI 11 //switch of LTSW
#define SEL_SW_VCALI 12 //switch of UTSW
#define SEL_SW_ZROTA 13 //switch of FRSW
#define SEL_SW_DIGFO 14 //switch of SPSW
#define SEL_SW_UNIFOBRI 15 //switch of BRSW
#define SEL_SW_HLINEAR 16 //switch of LRSW
#define SEL_SW_VLINEAR 17 //switch of URSW
#define SEL_SW_FPCORR 18 //option of FPCORRSW
#define SEL_POINTA 19 //option of POINTA
#define SEL_POINTB 20 //option of POINTB
#define SEL_POINTC 21 //option of POINTC
#define SEL_POINTD 22 //option of POINTD
#define SEL_DFTVAL 23 //option of DFTVAL
#define SEL_RETVAL 24 //option of RETVAL
#define SEL_GYRO_OPT 25 //option of GYRO
extern float x_angle; // roll src data
extern float y_angle; // pitch src data
extern float z_angle; // yaw src data
//MODEL
//unsigned char hex_send[] = {0x55, 0xAA, 0x55, 0xAA, // head 4bytes [0-3]
// 0x01, // cmd 1byte [4]
// 0x45, // Func_val 1byte [5]
// 0xFF,0x9B, // X_val 2bytes [6-7]
// 0x00,0x7B, // Y_val 2bytes [8-9]
// 0xFF,0xAB, // Z_val 2bytes [10-11]
// 0x00,0x07}; // CRC 2bytes [12-13]
unsigned char hexData_send[14] = {0x55, 0xAA, 0x55, 0xAA}; //The whole string
static unsigned char opt_fun = 0; //value of button press option
static signed char value_hCali = 0;
static signed char value_vCali = 0;
static signed char value_zRota = 0;
static signed char value_digFo = 0;
static signed char value_unifoBri = 0;
static signed char value_hLinear = 0;
static signed char value_vLinear = 0;
static signed char value_PointAX = 0;
static signed char value_PointAY = 0;
static signed char value_PointBX = 0;
static signed char value_PointBY = 0;
static signed char value_PointCX = 0;
static signed char value_PointCY = 0;
static signed char value_PointDX = 0;
static signed char value_PointDY = 0;
bool ValOpt_Rectify = false; //flag to rectify
bool status_fpcorr = false; //flag to FPCorr
//reocrd ok position
signed short value_localx = 0;
signed short value_localy = 0;
signed short value_localz = 0;
//-----------------------------------------------------------------------------------------
TW_LightingUI::TW_LightingUI(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::TW_LightingUI)
{
ui->setupUi(this);
timer_gyro = new QTimer(this);
connect(timer_gyro, SIGNAL(timeout()), this, SLOT(on_GYRO_clicked()));
timer_gyro->start(40);
timer_senddata = new QTimer(this);
connect(timer_senddata, SIGNAL(timeout()), this, SLOT(tw_UIangleDisplay()));
timer_senddata->start(200);
}
TW_LightingUI::~TW_LightingUI()
{
delete ui;
}
/*
* brief: Get CRC value of all parameter sum. Then convert to hex
* param: data_tmp hexData_send except CRC bit
* return: value_crc
* notice: none
*/
static signed short tw_crcValueCalculate(unsigned char crc_tmp[])
{
//int i;
//signed short value_crc;
typedef struct tw_function
{
int head;
unsigned char cmd;
signed char func_val;
signed short x_val;
signed short y_val;
signed short z_val;
signed short crc;
};
tw_function tw_function_t;
tw_function_t.cmd = crc_tmp[4];
tw_function_t.func_val = crc_tmp[5];
tw_function_t.x_val = (crc_tmp[6] <<8 | crc_tmp[7]);
tw_function_t.y_val = (crc_tmp[8] <<8 | crc_tmp[9]);
tw_function_t.z_val = (crc_tmp[10]<<8 | crc_tmp[11]);
tw_function_t.crc = tw_function_t.cmd + tw_function_t.func_val + tw_function_t.x_val + tw_function_t.y_val + tw_function_t.z_val;
return tw_function_t.crc;
}
/*
* brief: Send whole string to uart.
* param: string
* return: 0 fialed 1 success
* notice: none
*/
static unsigned char tw_SendHexData(unsigned char str[])
{
int i;
for(i = 0; i < 14; i++)
{
serial_SendData(str[i]);
}
if(i == 13) //estimate string is integrity
return 1;
else
return 0;
}
/*
* brief: When press option button, select function
* param: none
* return: none
* notice: none
*/
void tw_optionSelected()
{
if(Key_PressCheck(SW5_OPTION) == 1)
{
opt_fun++;
if(opt_fun>24) //overflow to selected,return to 0
opt_fun = 0;
}
}
/*
* brief: update buttons color, default color is red.
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::tw_button_update()
{
ui->FUN_HCali->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->FUN_VCali->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->FUN_ZRota->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->FUN_DigFocus->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->FUN_UnifoBri->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->FUN_HLinear->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->FUN_VLinear->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->OPT_CaliLoca->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->OPT_Rectify->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->OPT_Reset->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->OPT_LighRaspSW->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->SW_HCali->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->SW_VCali->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->SW_ZRota->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->SW_DigFo->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->SW_UnifoBri->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->SW_HLinear->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->SW_VLinear->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->SW_FPCorr->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->POINT_A->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->POINT_B->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->POINT_C->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->POINT_D->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->DEFAULT_VALUE->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->RETURN_BEFORE_VALUE->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
ui->GYRO->setStyleSheet(
"QPushButton{background-color:pink}"
"QPushButton:checked{background-color:red}");
}
/*
* brief: Change selected button's color,if selected button color changed to yellow
* param: button value
* return: none
* notice: none
*/
void TW_LightingUI::tw_button_selected(unsigned char value_button)
{
switch(value_button)
{
case SEL_FUN_HCALI:
ui->FUN_HCali->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_FUN_VCALI:
ui->FUN_VCali->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_FUN_ZROTA:
ui->FUN_ZRota->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_FUN_DIGFOCUS:
ui->FUN_DigFocus->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_FUN_UNIFOBRI:
ui->FUN_UnifoBri->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_FUN_HLINEAR :
ui->FUN_HLinear->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_FUN_VLINEAR:
ui->FUN_VLinear->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_OPT_CALILOCA:
ui->OPT_CaliLoca->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_OPT_RECTIFY :
ui->OPT_Rectify->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_OPT_RESET:
ui->OPT_Reset->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_OPT_LIGHRASPSW:
ui->OPT_LighRaspSW->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_SW_HCALI:
ui->SW_HCali->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_SW_VCALI :
ui->SW_VCali->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_SW_ZROTA:
ui->SW_ZRota->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_SW_DIGFO:
ui->SW_DigFo->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_SW_UNIFOBRI:
ui->SW_UnifoBri->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_SW_HLINEAR:
ui->SW_HLinear->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_SW_VLINEAR:
ui->SW_VLinear->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_SW_FPCORR :
ui->SW_FPCorr->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_POINTA :
ui->POINT_A->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_POINTB:
ui->POINT_B->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_POINTC:
ui->POINT_C->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_POINTD:
ui->POINT_D->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_DFTVAL:
ui->DEFAULT_VALUE->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_RETVAL:
ui->RETURN_BEFORE_VALUE->setStyleSheet(
"QPushButton{background-color:yellow}"
"QPushButton:checked{background-color:red}");
break;
case SEL_GYRO_OPT:
break;
default:
break;
}
}
/*
* brief: Package button_update and button_selected function
* param: value of selected button
* return: none
* notice: none
*/
void TW_LightingUI::tw_button_funcSelected(unsigned char value_func)
{
tw_button_update();
tw_button_selected(value_func);
}
/*
* brief: First time record the xyz-axis value for projector map to wall or screen,
* then this xyz value is the base of projector move after.All data of xyz axis
* is relative to the base xyz data.
* there is four situation:
*
* 1. 0 =< start_angle <= 180, 0 =< end_angle <= 180
* 2. -180 =< start_angle <= 0, -180 =< end_angle <= 0
* 3. -180 =< start_angle <= 0, 0 =< end_angle <= 180
* 4. 0 =< start_angle <= 180, -180 =< end_angle <= 0
*
* param: start_angle is the base xyz data, also the location position as ok position
* end_angle is now position of projector xyz axis.
* return: relative data of xyz axis.
* notice: none
*/
static signed short Value_StartEndAngle_Caculate(signed short start_angle, signed short end_angle)
{
#define DELTA_LIMIT 0
signed short value_es;
// printf("start_angle = %d end_angle = %d\n", start_angle, end_angle);
if((start_angle>=0 && start_angle<=180) && (end_angle>=0 && end_angle<=180))
{
value_es = (end_angle - start_angle);
return value_es;
}
else if((start_angle<0 && start_angle>=-180) && (end_angle<=0 && end_angle>=-180))
{
value_es = (end_angle - start_angle);
return value_es;
}
else if((start_angle>=-180 && start_angle<=0) && (end_angle>=0 && end_angle<=180))
{
if(((end_angle - start_angle > DELTA_LIMIT) && (end_angle - start_angle < 180)) ||
(end_angle - start_angle < -180) ) // 规定旋转方向正
{
if((abs(start_angle)+abs(end_angle))>180)
{
value_es = 180 - (abs(start_angle)+abs(end_angle))%180;
return value_es;
}
else
{
value_es = abs(start_angle)+abs(end_angle);
return value_es;
}
}
if(((end_angle - start_angle < -DELTA_LIMIT) && (end_angle - start_angle > -180)) ||
(end_angle - start_angle > 180)) // 规定旋转方向负
{
if((abs(start_angle)+abs(end_angle))>180)
{
value_es = 180 - (abs(start_angle)+abs(end_angle))%180;
return -value_es;
}
else
{
value_es = abs(start_angle)+abs(end_angle);
return -value_es;
}
}
}
else if((start_angle>=0 && start_angle<180) && (end_angle<0 && end_angle>=-180))
{
if(((end_angle - start_angle > DELTA_LIMIT) && (end_angle - start_angle < 180)) ||
(end_angle - start_angle < -180) ) // 规定旋转方向正
{
if((abs(start_angle)+abs(end_angle))>180)
{
value_es = 180 - (abs(start_angle)+abs(end_angle))%180;
return value_es;
}
else
{
value_es = abs(start_angle)+abs(end_angle);
return value_es;
}
}
if(((end_angle - start_angle < -DELTA_LIMIT) && (end_angle - start_angle > -180)) ||
(end_angle - start_angle > 180)) // 规定旋转方向负
{
if((abs(start_angle)+abs(end_angle))>180)
{
value_es = 180 - (abs(start_angle)+abs(end_angle))%180;
return -value_es;
}
else
{
value_es = abs(start_angle)+abs(end_angle);
return -value_es;
}
}
}
}
/*
* brief: sample button clicked
* param: none
* return: none
* return: none
*/
void TW_LightingUI::tw_angleDisplay()
{
QString tempStr;
signed short tmp_crc = 0;
signed short x_rectify;
signed short y_rectify;
signed short z_rectify;
signed short x_delta;
signed short y_delta;
signed short z_delta;
if(!ValOpt_Rectify) //rectify switch is off, just display on UI, not send to t613
{
//dummy data
ui->GYRO_XVALUE->setText(tempStr.setNum((int)x_angle));
ui->GYRO_YVALUE->setText(tempStr.setNum((int)y_angle));
ui->GYRO_ZVALUE->setText(tempStr.setNum((int)z_angle));
}
else //need send delta xyz to t613, that's relative position to ok position
{
//for test data
// x_angle = 1;
// y_angle = 2;
// z_angle = 3;
//get now xyz position
x_rectify = (signed short)x_angle;
y_rectify = (signed short)y_angle;
z_rectify = (signed short)z_angle;
//get the relative value of xyz to ok position
x_delta = Value_StartEndAngle_Caculate(value_localx, x_rectify);
y_delta = Value_StartEndAngle_Caculate(value_localy, y_rectify);
z_delta = Value_StartEndAngle_Caculate(value_localz, z_rectify);
//display relative value on UI xyz
ui->GYRO_XVALUE->setText(tempStr.setNum((signed short)x_delta));
ui->GYRO_YVALUE->setText(tempStr.setNum((signed short)y_delta));
ui->GYRO_ZVALUE->setText(tempStr.setNum((signed short)z_delta));
//---------------------------------------send data to t613----------------------------------------
if(!status_fpcorr) //Do not send data, when FPCorr is open
{
hexData_send[4] = 0x0F; //CMD_Rectify_ON
hexData_send[5] = 0x00; //invalid data
hexData_send[6] = (x_delta & 0xFF00) >> 8;
hexData_send[7] = (x_delta & 0x00FF);
hexData_send[8] = (y_delta & 0xFF00) >> 8;
hexData_send[9] = (y_delta & 0x00FF);
hexData_send[10] = (z_delta & 0xFF00) >> 8;
hexData_send[11] = (z_delta & 0x00FF);
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
}
}
/*
* brief: Display sample xyz angle value,display on UI,the data not send to t613
* param: none
* return: none
* return: none
*/
void TW_LightingUI::tw_UIangleDisplay()
{
tw_angleDisplay();
}
/*
* brief: Display which option is selected and goto that button do it's task.
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_GYRO_clicked()
{
//Change button color
tw_optionSelected();
tw_button_funcSelected(opt_fun);
//Goto this button do task
switch(opt_fun)
{
//Function button
case SEL_FUN_HCALI:
on_FUN_HCali_clicked();
break;
case SEL_FUN_VCALI:
on_FUN_VCali_clicked();
break;
case SEL_FUN_ZROTA:
on_FUN_ZRota_clicked();
break;
case SEL_FUN_DIGFOCUS:
on_FUN_DigFocus_clicked();
break;
case SEL_FUN_UNIFOBRI:
on_FUN_UnifoBri_clicked();
break;
case SEL_FUN_HLINEAR:
on_FUN_HLinear_clicked();
break;
case SEL_FUN_VLINEAR:
on_FUN_VLinear_clicked();
break;
case SEL_OPT_CALILOCA:
on_OPT_CaliLoca_clicked();
break;
case SEL_OPT_RECTIFY:
on_OPT_Rectify_clicked();
break;
case SEL_OPT_RESET:
on_OPT_Reset_clicked();
break;
case SEL_OPT_LIGHRASPSW:
on_OPT_LighRaspSW_clicked();
break;
// case SEL_SW_HCALI:
// break;
// case SEL_SW_VCALI:
// break;
// case SEL_SW_ZROTA:
// break;
// case SEL_SW_DIGFO:
// break;
// case SEL_SW_UNIFOBRI:
// break;
// case SEL_SW_HLINEAR:
// break;
// case SEL_SW_VLINEAR:
// break;
case SEL_SW_FPCORR:
on_SW_FPCorr_clicked();
break;
case SEL_POINTA:
on_POINT_A_clicked();
break;
case SEL_POINTB:
on_POINT_B_clicked();
break;
case SEL_POINTC:
on_POINT_C_clicked();
break;
case SEL_POINTD:
on_POINT_D_clicked();
break;
case SEL_DFTVAL:
on_DEFAULT_VALUE_clicked();
break;
case SEL_RETVAL:
on_RETURN_BEFORE_VALUE_clicked();
break;
default:
break;
}
// tw_angleDisplay();
Bsp_Jy901_AngOut(); //call JY901 get XYZ value
}
/*
* brief: Get Axis X value
* param: none
* return: none
* notice: none
*/
static signed short tw_getAxisX_Value(void)
{
static signed short value_AxisX = 0;
return value_AxisX = (signed short)x_angle;
}
/*
* brief: Get Axis Y value
* param: none
* return: none
* notice: none
*/
static signed short tw_getAxisY_Value(void)
{
static signed short value_AxisY = 0;
return value_AxisY = (signed short)y_angle;
}
/*
* brief: Get Axis Z value
* param: none
* return: none
* notice: none
*/
static signed short tw_getAxisZ_Value(void)
{
static signed short value_AxisZ = 0;
return value_AxisZ = (signed short)z_angle;
}
/*
* brief: Two situation send two types data to T613
* param: none
* return: none
* notice: none
*/
static void tw_sendxyzToT613(void)
{
signed short tmp_x = 0;
signed short tmp_y = 0;
signed short tmp_z = 0;
signed short x_rectify;
signed short y_rectify;
signed short z_rectify;
signed short x_delta;
signed short y_delta;
signed short z_delta;
if(!ValOpt_Rectify) //when Rectify is off
{
//---------XYZ put into hexData_send--------
tmp_x = tw_getAxisX_Value();
//tmp_x = -1; //test
hexData_send[6] = (tmp_x & 0xFF00) >> 8;
hexData_send[7] = (tmp_x & 0x00FF);
tmp_y = tw_getAxisY_Value();
//tmp_y = 189; //test
hexData_send[8] = (tmp_y & 0xFF00) >> 8;
hexData_send[9] = (tmp_y & 0x00FF);
tmp_z = tw_getAxisZ_Value();
//tmp_z = -189; //test
hexData_send[10] = (tmp_z & 0xFF00) >> 8;
hexData_send[11] = (tmp_z & 0x00FF);
//------------------------------------------
}
else
{
//get now xyz position
x_rectify = (signed short)x_angle;
y_rectify = (signed short)y_angle;
z_rectify = (signed short)z_angle;
//get the relative value of xyz to ok position
x_delta = Value_StartEndAngle_Caculate(value_localx, x_rectify);
y_delta = Value_StartEndAngle_Caculate(value_localy, y_rectify);
z_delta = Value_StartEndAngle_Caculate(value_localz, z_rectify);
//---------------------------------------send data to t613----------------------------------------
if(!status_fpcorr) //Do not send data, when FPCorr is open
{
hexData_send[4] = 0x0F; //CMD_Rectify_ON
hexData_send[5] = 0x00; //invalid data
hexData_send[6] = (x_delta & 0xFF00) >> 8;
hexData_send[7] = (x_delta & 0x00FF);
hexData_send[8] = (y_delta & 0xFF00) >> 8;
hexData_send[9] = (y_delta & 0x00FF);
hexData_send[10] = (z_delta & 0xFF00) >> 8;
hexData_send[11] = (z_delta & 0x00FF);
}
}
}
/*
* brief: Change horizontal calibration value, then send real time data by uart to lighting
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_FUN_HCali_clicked()
{
signed short tmp_crc = 0;
hexData_send[4] = 0x00;
//---------XYZ put into hexData_send--------
tw_sendxyzToT613();
//------------------------------------------
if(Key_PressCheck(SW3_RIGHT) == 1)
{
if(value_hCali < 50)
value_hCali++;
else
value_hCali = 50;
//set cmd_value
hexData_send[5] = value_hCali;
timer_senddata->stop();
delay(50);
hexData_send[4] = 0x00;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
timer_senddata->start(200);
}
else if(Key_PressCheck(SW4_LEFT) == 1)
{
if(value_hCali > -50)
value_hCali--;
else
value_hCali = -50;
//set cmd_value
hexData_send[5] = value_hCali;
timer_senddata->stop();
delay(50);
hexData_send[4] = 0x00;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send);
timer_senddata->start(200);
}
// QString str = QString::number(value_hCali,10); //set ProgressBar display real time value
// ui->value_HPro->setText(str);
// ui->PBar_ValueHCali->setValue(value_hCali); //update progressBar
}
/*
* brief: Change vertical calibration value, then send real time data by uart to lighting
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_FUN_VCali_clicked()
{
signed short tmp_crc = 0;
hexData_send[4] = 0x02; //CMD_VCali_ON
//---------XYZ put into hexData_send--------
tw_sendxyzToT613();
//------------------------------------------
if(Key_PressCheck(SW3_RIGHT) == 1)
{
if(value_vCali < 50)
value_vCali++;
else
value_vCali = 50;
//set cmd_value
hexData_send[5] = value_vCali;
timer_senddata->stop();
delay(50);
hexData_send[4] = 0x02;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
timer_senddata->start(200);
}
else if(Key_PressCheck(SW4_LEFT) == 1)
{
if(value_vCali > -50)
value_vCali--;
else
value_vCali = -50;
//set cmd_value
hexData_send[5] = value_vCali;
timer_senddata->stop();
delay(50);
hexData_send[4] = 0x02;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send);
timer_senddata->start(200);
}
QString str = QString::number(value_vCali,10); //set ProgressBar display real time value
ui->value_VPro->setText(str);
ui->PBar_ValueVCali->setValue(value_vCali); //update progressBar
}
/*
* brief: Change Z Rotate value, then send real time data by uart to lighting
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_FUN_ZRota_clicked()
{
signed short tmp_crc = 0;
hexData_send[4] = 0x04; //CMD_ZRota_ON
//---------XYZ put into hexData_send--------
tw_sendxyzToT613();
//------------------------------------------
if(Key_PressCheck(SW3_RIGHT) == 1)
{
if(value_zRota < 50)
value_zRota++;
else
value_zRota = 50;
//set cmd_value
hexData_send[5] = value_zRota;
timer_senddata->stop();
delay(50);
hexData_send[4] = 0x04;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
timer_senddata->start(200);
}
else if(Key_PressCheck(SW4_LEFT) == 1)
{
if(value_zRota > -50)
value_zRota--;
else
value_zRota = -50;
//set cmd_value
hexData_send[5] = value_zRota;
timer_senddata->stop();
delay(50);
hexData_send[4] = 0x04;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send);
timer_senddata->start(200);
}
QString str = QString::number(value_zRota,10); //set ProgressBar display real time value
ui->value_ZPro->setText(str);
ui->PBar_ValueZRota->setValue(value_zRota); //update progressBar
}
/*
* brief: Change Digital Focus value, then send real time data by uart to lighting
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_FUN_DigFocus_clicked()
{
signed short tmp_crc = 0;
hexData_send[4] = 0xFF; //prevent err cmd parse,becasue if don't press ok,hexData_send[4] still is cmd ZRota
if(Key_PressCheck(SW2_OK) == 1)
{
timer_senddata->stop();
delay(50);
if(ui->SW_DigFo->text() == "ON")
{
ui->SW_DigFo->setText("OFF");
hexData_send[4] = 0x07; //CMD_DigFocus_OFF
}
else
{
ui->SW_DigFo->setText("ON");
hexData_send[4] = 0x06; //CMD_DigFocus_ON
}
hexData_send[5] = value_digFo;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
timer_senddata->start(200);
}
//---------XYZ put into hexData_send--------
tw_sendxyzToT613();
//------------------------------------------
if(Key_PressCheck(SW3_RIGHT) == 1)
{
timer_senddata->stop();
delay(50);
if(ui->SW_DigFo->text() == "ON")
{
hexData_send[4] = 0x06; //CMD_DigFocus_OFF
}
else
{
hexData_send[4] = 0x07; //CMD_DigFocus_ON
}
if(value_digFo < 50)
value_digFo++;
else
value_digFo = 50;
//set cmd_value
hexData_send[5] = value_digFo;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
timer_senddata->start(200);
}
else if(Key_PressCheck(SW4_LEFT) == 1)
{
timer_senddata->stop();
delay(50);
if(ui->SW_DigFo->text() == "ON")
{
hexData_send[4] = 0x06; //CMD_DigFocus_ON
}
else
{
hexData_send[4] = 0x07; //CMD_DigFocus_OFF
}
if(value_digFo > -50)
value_digFo--;
else
value_digFo = -50;
//set cmd_value
hexData_send[5] = value_digFo;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send);
timer_senddata->start(200);
}
QString str = QString::number(value_digFo,10); //set ProgressBar display real time value
ui->value_DgPro->setText(str);
ui->PBar_ValueDigFocus->setValue(value_digFo); //update progressBar
}
/*
* brief: Change Uniform brightness value, then send real time data by uart to lighting
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_FUN_UnifoBri_clicked()
{
signed short tmp_crc = 0;
hexData_send[4] = 0xFF; //prevent err cmd parse,becasue if don't press ok,hexData_send[4] still is cmd ZRota
//hexData_send[4] = 0x08; //CMD_UnifoBri_ON
if(Key_PressCheck(SW2_OK) == 1)
{
timer_senddata->stop();
delay(50);
if(ui->SW_UnifoBri->text() == "ON")
{
ui->SW_UnifoBri->setText("OFF");
hexData_send[4] = 0x09; //CMD_UnifoBri_OFF
}
else
{
ui->SW_UnifoBri->setText("ON");
hexData_send[4] = 0x08; //CMD_UnifoBri_ON
}
hexData_send[5] = value_unifoBri;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
timer_senddata->start(200);
}
//---------XYZ put into hexData_send--------
tw_sendxyzToT613();
//------------------------------------------
if(Key_PressCheck(SW3_RIGHT) == 1)
{
timer_senddata->stop();
delay(50);
if(ui->SW_UnifoBri->text() == "ON")
{
hexData_send[4] = 0x08;
}
else
{
hexData_send[4] = 0x09;
}
if(value_unifoBri < 50)
value_unifoBri++;
else
value_unifoBri = 50;
//set cmd_value
hexData_send[5] = value_unifoBri;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
timer_senddata->start(200);
}
else if(Key_PressCheck(SW4_LEFT) == 1)
{
timer_senddata->stop();
delay(50);
if(ui->SW_UnifoBri->text() == "ON")
{
hexData_send[4] = 0x08;
}
else
{
hexData_send[4] = 0x09;
}
if(value_unifoBri > -50)
value_unifoBri--;
else
value_unifoBri = -50;
//set cmd_value
hexData_send[5] = value_unifoBri;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send);
timer_senddata->start(200);
}
QString str = QString::number(value_unifoBri,10); //set ProgressBar display real time value
ui->value_VUbPro->setText(str);
ui->PBar_ValueUnifoBri->setValue(value_unifoBri); //update progressBar
}
/*
* brief: Change Horizontal value, then send real time data by uart to lighting
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_FUN_HLinear_clicked()
{
signed short tmp_crc = 0;
hexData_send[4] = 0xFF; //prevent err cmd parse,becasue if don't press ok,hexData_send[4] still is cmd ZRota
if(Key_PressCheck(SW2_OK) == 1)
{
timer_senddata->stop();
delay(50);
if(ui->SW_HLinear->text() == "ON")
{
ui->SW_HLinear->setText("OFF");
hexData_send[4] = 0x0B; //CMD_HLinear_OFF
}
else
{
ui->SW_HLinear->setText("ON");
hexData_send[4] = 0x0A; //CMD_HLinear_ON
}
hexData_send[5] = value_hLinear;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
timer_senddata->start(200);
}
//---------XYZ put into hexData_send--------
tw_sendxyzToT613();
//------------------------------------------
if(Key_PressCheck(SW3_RIGHT) == 1)
{
timer_senddata->stop();
delay(50);
if(ui->SW_HLinear->text() == "ON")
{
hexData_send[4] = 0x0A;
}
else
{
hexData_send[4] = 0x0B;
}
if(value_hLinear < 50)
value_hLinear++;
else
value_hLinear = 50;
//set cmd_value
hexData_send[5] = value_hLinear;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
timer_senddata->start(200);
}
else if(Key_PressCheck(SW4_LEFT) == 1)
{
timer_senddata->stop();
delay(50);
if(ui->SW_HLinear->text() == "ON")
{
hexData_send[4] = 0x0A;
}
else
{
hexData_send[4] = 0x0B;
}
if(value_hLinear > -50)
value_hLinear--;
else
value_hLinear = -50;
//set cmd_value
hexData_send[5] = value_hLinear;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send);
timer_senddata->start(200);
}
QString str = QString::number(value_hLinear,10); //set ProgressBar display real time value
ui->value_HLPro->setText(str);
ui->PBar_ValueHLinear->setValue(value_hLinear); //update progressBar
}
/*
* brief: Change Vertical value, then send real time data by uart to lighting
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_FUN_VLinear_clicked()
{
signed short tmp_crc = 0;
hexData_send[4] = 0xFF; //prevent err cmd parse,becasue if don't press ok,hexData_send[4] still is cmd ZRota
if(Key_PressCheck(SW2_OK) == 1)
{
timer_senddata->stop();
delay(50);
if(ui->SW_VLinear->text() == "ON")
{
ui->SW_VLinear->setText("OFF");
hexData_send[4] = 0x0D; //CMD_VLinear_OFF
}
else
{
ui->SW_VLinear->setText("ON");
hexData_send[4] = 0x0C; //CMD_VLinear_ON
}
hexData_send[5] = value_vLinear;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
timer_senddata->start(200);
}
//---------XYZ put into hexData_send--------
tw_sendxyzToT613();
//------------------------------------------
if(Key_PressCheck(SW3_RIGHT) == 1)
{
timer_senddata->stop();
delay(50);
if(ui->SW_VLinear->text() == "ON")
{
hexData_send[4] = 0x0C;
}
else
{
hexData_send[4] = 0x0D;
}
if(value_vLinear < 50)
value_vLinear++;
else
value_vLinear = 50;
//set cmd_value
hexData_send[5] = value_vLinear;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
timer_senddata->start(200);
}
else if(Key_PressCheck(SW4_LEFT) == 1)
{
timer_senddata->stop();
delay(50);
if(ui->SW_VLinear->text() == "ON")
{
hexData_send[4] = 0x0C;
}
else
{
hexData_send[4] = 0x0D;
}
if(value_vLinear > -50)
value_vLinear--;
else
value_vLinear = -50;
//set cmd_value
hexData_send[5] = value_vLinear;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send);
timer_senddata->start(200);
}
QString str = QString::number(value_vLinear,10); //set ProgressBar display real time value
ui->value_VLPro->setText(str);
ui->PBar_ValueVLinear->setValue(value_vLinear); //update progressBar
}
/*
* brief: Calibrate localtion, record ok position as base position.
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_OPT_CaliLoca_clicked()
{
signed short tmp_crc;
if(Key_PressCheck(SW2_OK) == 1)
{
value_localx = (signed short)x_angle; //base position of x axis
value_localy = (signed short)y_angle; //base position of y axis
value_localz = (signed short)z_angle; //base position of z axis
//for test
// value_localx = -4;
// value_localy = -6;
// value_localz = -8;
//set FPCorr default, this data is invalid
hexData_send[5] = 0;
hexData_send[6] = 0;
hexData_send[7] = 0;
hexData_send[8] = 0;
hexData_send[9] = 0;
hexData_send[10] = 0;
hexData_send[11] = 0;
hexData_send[4] = 0x0E; //CMD_CaliLoca
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
}
/*
* brief: If use auto rectify, when you move projector screen is rectify auto.
* or if not, move projector screen is not rectify.
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_OPT_Rectify_clicked()
{
signed short tmp_crc;
if(Key_PressCheck(SW2_OK) == 1)
{
if(ValOpt_Rectify)
{
ValOpt_Rectify = false;
}
else
{
ValOpt_Rectify = true;
}
if(ui->OPT_Rectify->text() == "Rectify_ON")
{
ui->OPT_Rectify->setText("Rectify_OFF");
hexData_send[4] = 0x10; //CMD_Rectify_OFF
}
else
{
ui->OPT_Rectify->setText("Rectify_ON");
hexData_send[4] = 0x0F; //CMD_Rectify_ON
}
//set FPCorr default, this data is invalid
hexData_send[5] = 0;
hexData_send[6] = 0;
hexData_send[7] = 0;
hexData_send[8] = 0;
hexData_send[9] = 0;
hexData_send[10] = 0;
hexData_send[11] = 0;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
}
/*
* brief: Four point correction switch
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_SW_FPCorr_clicked()
{
signed short tmp_crc;
//send FPCorr SW, this data is invalid
hexData_send[5] = 0;
hexData_send[6] = 0;
hexData_send[7] = 0;
hexData_send[8] = 0;
hexData_send[9] = 0;
hexData_send[10] = 0;
hexData_send[11] = 0;
if(Key_PressCheck(SW2_OK) == 1)
{
if(ui->SW_FPCorr->text() == "FPCORR_ON")
{
ui->SW_FPCorr->setText("FPCORR_OFF");
hexData_send[4] = 0x14;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
status_fpcorr = false;
}
else
{
ui->SW_FPCorr->setText("FPCORR_ON");
hexData_send[4] = 0x13;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
status_fpcorr = true;
}
}
}
/*
* brief: Point A correction 0=< PA(x) <=50
* 0=< PA(y) <=50
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_POINT_A_clicked()
{
signed short tmp_crc;
if(status_fpcorr) //when fpcorr open ,can do this operate
{
//send FPCorr SW, this data is invalid
hexData_send[6] = 0;
hexData_send[7] = 0;
hexData_send[8] = 0;
hexData_send[9] = 0;
hexData_send[10] = 0;
hexData_send[11] = 0;
//direction to left
if(Key_PressCheck(SW4_LEFT) == 1)
{
hexData_send[4] = 0x15; //CMD_CorrA_PX
value_PointAX--;
if(value_PointAX < 0)
value_PointAX = 0;
hexData_send[5] = value_PointAX;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
//direction to right
if(Key_PressCheck(SW3_RIGHT) == 1)
{
hexData_send[4] = 0x15; //CMD_CorrA_PX
value_PointAX++;
if(value_PointAX > 50)
value_PointAX = 50;
hexData_send[5] = value_PointAX;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
//direction to up
if(Key_PressCheck(SW6_UP) == 1)
{
hexData_send[4] = 0x16; //CMD_CorrA_PY
value_PointAY--;
if(value_PointAY < 0)
value_PointAY = 0;
hexData_send[5] = value_PointAY;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
//direction to down
if(Key_PressCheck(SW1_DOWN) == 1)
{
hexData_send[4] = 0x16; //CMD_CorrA_PY
value_PointAY++;
if(value_PointAY > 50)
value_PointAY = 50;
hexData_send[5] = value_PointAY;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
}
QString strX = QString::number(value_PointAX,10); //set PX_Value display
ui->Point_PXVal->setText(strX);
QString strY = QString::number(value_PointAY,10); //set PX_Value display
ui->Point_PYVal->setText(strY);
}
/*
* brief: Point B correction -50 =< PB(x) <= 0
* 0 =< PB(y) <= 50
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_POINT_B_clicked()
{
signed short tmp_crc;
if(status_fpcorr) //when fpcorr open ,can do this operate
{
//send FPCorr SW, this data is invalid
hexData_send[6] = 0;
hexData_send[7] = 0;
hexData_send[8] = 0;
hexData_send[9] = 0;
hexData_send[10] = 0;
hexData_send[11] = 0;
//direction to left
if(Key_PressCheck(SW4_LEFT) == 1)
{
hexData_send[4] = 0x17; //CMD_CorrB_PX
value_PointBX--;
if(value_PointBX < -50)
value_PointBX = -50;
hexData_send[5] = value_PointBX;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
//direction to right
if(Key_PressCheck(SW3_RIGHT) == 1)
{
hexData_send[4] = 0x17; //CMD_CorrB_PX
value_PointBX++;
if(value_PointBX > 0)
value_PointBX = 0;
hexData_send[5] = value_PointBX;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
//direction to up
if(Key_PressCheck(SW6_UP) == 1)
{
hexData_send[4] = 0x18; //CMD_CorrB_PY
value_PointBY--;
if(value_PointBY < 0)
value_PointBY = 0;
hexData_send[5] = value_PointBY;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
//direction to down
if(Key_PressCheck(SW1_DOWN) == 1)
{
hexData_send[4] = 0x18; //CMD_CorrB_PY
value_PointBY++;
if(value_PointBY > 50)
value_PointBY = 50;
hexData_send[5] = value_PointBY;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
}
QString strX = QString::number(value_PointBX,10); //set PX_Value display
ui->Point_PXVal->setText(strX);
QString strY = QString::number(value_PointBY,10); //set PX_Value display
ui->Point_PYVal->setText(strY);
}
/*
* brief: Point C correction -50 =< PC(x) <= 0
* -50 =< PC(y) <= 0
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_POINT_C_clicked()
{
signed short tmp_crc;
if(status_fpcorr) //when fpcorr open ,can do this operate
{
//send FPCorr SW, this data is invalid
hexData_send[6] = 0;
hexData_send[7] = 0;
hexData_send[8] = 0;
hexData_send[9] = 0;
hexData_send[10] = 0;
hexData_send[11] = 0;
//direction to left
if(Key_PressCheck(SW4_LEFT) == 1)
{
hexData_send[4] = 0x19; //CMD_CorrC_PX
value_PointCX--;
if(value_PointCX < -50)
value_PointCX = -50;
hexData_send[5] = value_PointCX;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
//direction to right
if(Key_PressCheck(SW3_RIGHT) == 1)
{
hexData_send[4] = 0x19; //CMD_CorrC_PX
value_PointCX++;
if(value_PointCX > 0)
value_PointCX = 0;
hexData_send[5] = value_PointCX;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
//direction to up
if(Key_PressCheck(SW6_UP) == 1)
{
hexData_send[4] = 0x1A; //CMD_CorrC_PY.
value_PointCY--;
if(value_PointCY < -50)
value_PointCY = -50;
hexData_send[5] = value_PointCY;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
//direction to down
if(Key_PressCheck(SW1_DOWN) == 1)
{
hexData_send[4] = 0x1A; //CMD_CorrC_PY
value_PointCY++;
if(value_PointCY > 0)
value_PointCY = 0;
hexData_send[5] = value_PointCY;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
}
QString strX = QString::number(value_PointCX,10); //set PX_Value display
ui->Point_PXVal->setText(strX);
QString strY = QString::number(value_PointCY,10); //set PX_Value display
ui->Point_PYVal->setText(strY);
}
/*
* brief: Point D correction 0 =< PD(x) <= 50
* -50 =< PD(y) <= 0
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_POINT_D_clicked()
{
signed short tmp_crc;
if(status_fpcorr) //when fpcorr open ,can do this operate
{
//send FPCorr SW, this data is invalid
hexData_send[6] = 0;
hexData_send[7] = 0;
hexData_send[8] = 0;
hexData_send[9] = 0;
hexData_send[10] = 0;
hexData_send[11] = 0;
//direction to left
if(Key_PressCheck(SW4_LEFT) == 1)
{
hexData_send[4] = 0x1B; //CMD_CorrD_PX
value_PointDX--;
if(value_PointDX < 0)
value_PointDX = 0;
hexData_send[5] = value_PointDX;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
//direction to right
if(Key_PressCheck(SW3_RIGHT) == 1)
{
hexData_send[4] = 0x1B; //CMD_CorrD_PX
value_PointDX++;
if(value_PointDX > 50)
value_PointDX = 50;
hexData_send[5] = value_PointDX;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
//direction to up
if(Key_PressCheck(SW6_UP) == 1)
{
hexData_send[4] = 0x1C; //CMD_CorrD_PY.
value_PointDY--;
if(value_PointDY < -50)
value_PointDY = -50;
hexData_send[5] = value_PointDY;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
//direction to down
if(Key_PressCheck(SW1_DOWN) == 1)
{
hexData_send[4] = 0x1C; //CMD_CorrD_PY
value_PointDY++;
if(value_PointDY > 0)
value_PointDY = 0;
hexData_send[5] = value_PointDY;
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
}
QString strX = QString::number(value_PointDX,10); //set PX_Value display
ui->Point_PXVal->setText(strX);
QString strY = QString::number(value_PointDY,10); //set PX_Value display
ui->Point_PYVal->setText(strY);
}
/*
* brief: Set Point ABCD x_value y_value to default value
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_DEFAULT_VALUE_clicked()
{
signed short tmp_crc;
if(status_fpcorr) //when fpcorr open ,can do this operate
{
if(Key_PressCheck(SW2_OK) == 1)
{
value_PointAX = 0;
value_PointAY = 0;
value_PointBX = 0;
value_PointBY = 0;
value_PointCX = 0;
value_PointCY = 0;
value_PointDX = 0;
value_PointDY = 0;
//set FPCorr default, this data is invalid
hexData_send[5] = 0;
hexData_send[6] = 0;
hexData_send[7] = 0;
hexData_send[8] = 0;
hexData_send[9] = 0;
hexData_send[10] = 0;
hexData_send[11] = 0;
hexData_send[4] = 0x1D; //CMD_Deflt_Val
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
QString strX = QString::number(value_PointDX,10); //set PX_Value display
ui->Point_PXVal->setText(strX);
QString strY = QString::number(value_PointDY,10); //set PX_Value display
ui->Point_PYVal->setText(strY);
}
}
/*
* brief: return to the status, which before FPCorr value.
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_RETURN_BEFORE_VALUE_clicked()
{
signed short tmp_crc;
if(status_fpcorr) //when fpcorr open ,can do this operate
{
if(Key_PressCheck(SW2_OK) == 1)
{
//set FPCorr default, this data is invalid
hexData_send[5] = 0;
hexData_send[6] = 0;
hexData_send[7] = 0;
hexData_send[8] = 0;
hexData_send[9] = 0;
hexData_send[10] = 0;
hexData_send[11] = 0;
hexData_send[4] = 0x1E; //CMD_ReturnBefore
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
}
}
/*
* brief: Reset all value.
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_OPT_Reset_clicked()
{
signed short tmp_crc;
if(Key_PressCheck(SW2_OK) == 1)
{
//set all value
value_hCali = 0;
value_vCali = 0;
value_zRota = 0;
value_digFo = 0;
value_unifoBri = 0;
value_hLinear = 0;
value_vLinear = 0;
//set all label and progress bar
//HCali
QString str = QString::number(value_hCali,10); //set ProgressBar display real time value
ui->value_HPro->setText(str);
ui->PBar_ValueHCali->setValue(value_hCali); //update progressBar
//VCali
str = QString::number(value_vCali,10); //set ProgressBar display real time value
ui->value_VPro->setText(str);
ui->PBar_ValueVCali->setValue(value_vCali); //update progressBar
//ZRota
str = QString::number(value_zRota,10); //set ProgressBar display real time value
ui->value_ZPro->setText(str);
ui->PBar_ValueZRota->setValue(value_zRota); //update progressBar
//DigFocus
str = QString::number(value_digFo,10); //set ProgressBar display real time value
ui->value_DgPro->setText(str);
ui->PBar_ValueDigFocus->setValue(value_digFo); //update progressBar
//UnifoBri
str = QString::number(value_unifoBri,10); //set ProgressBar display real time value
ui->value_VUbPro->setText(str);
ui->PBar_ValueUnifoBri->setValue(value_unifoBri); //update progressBar
//HLinear
str = QString::number(value_hLinear,10); //set ProgressBar display real time value
ui->value_HLPro->setText(str);
ui->PBar_ValueHLinear->setValue(value_hLinear); //update progressBar
//VLinear
str = QString::number(value_vLinear,10); //set ProgressBar display real time value
ui->value_VLPro->setText(str);
ui->PBar_ValueVLinear->setValue(value_vLinear); //update progressBar
//clear record last time location data
value_localx = 0;
value_localy = 0;
value_localz = 0;
//Rectify must on or off by user, can not set auto
//set FPCorr default, this data is invalid
hexData_send[5] = 0;
hexData_send[6] = 0;
hexData_send[7] = 0;
hexData_send[8] = 0;
hexData_send[9] = 0;
hexData_send[10] = 0;
hexData_send[11] = 0;
hexData_send[4] = 0x11; //CMD_Reset
tmp_crc = tw_crcValueCalculate(hexData_send); //send data by uart
hexData_send[12] = (tmp_crc & 0xFF00) >> 8;
hexData_send[13] = (tmp_crc & 0x00FF);
tw_SendHexData(hexData_send); //send data by uart
}
}
/*
* brief: Switch mode between t613 and rasp
* param: none
* return: none
* notice: none
*/
void TW_LightingUI::on_OPT_LighRaspSW_clicked()
{
if(Key_PressCheck(SW2_OK) == 1)
{
if(ui->OPT_LighRaspSW->text() == "RASPBERRY")
{
ui->OPT_LighRaspSW->setText("T613");
}
else
{
ui->OPT_LighRaspSW->setText("RASPBERRY");
}
}
}
***.h
#ifndef TW_LIGHTINGUI_H
#define TW_LIGHTINGUI_H
#include <QMainWindow>
#include <QTimer>
namespace Ui {
class TW_LightingUI;
}
class TW_LightingUI : public QMainWindow
{
Q_OBJECT
public:
explicit TW_LightingUI(QWidget *parent = 0);
~TW_LightingUI();
QTimer *timer_gyro;
QTimer *timer_senddata;
private slots:
void tw_button_update();
void tw_button_selected(unsigned char value_button);
void tw_button_funcSelected(unsigned char value_func);
void tw_angleDisplay();
void tw_UIangleDisplay();
void on_GYRO_clicked();
void on_FUN_HCali_clicked();
void on_FUN_VCali_clicked();
void on_FUN_ZRota_clicked();
void on_FUN_DigFocus_clicked();
void on_FUN_UnifoBri_clicked();
void on_FUN_HLinear_clicked();
void on_FUN_VLinear_clicked();
void on_OPT_CaliLoca_clicked();
void on_OPT_Rectify_clicked();
void on_SW_FPCorr_clicked();
void on_POINT_A_clicked();
void on_POINT_B_clicked();
void on_POINT_C_clicked();
void on_POINT_D_clicked();
void on_DEFAULT_VALUE_clicked();
void on_RETURN_BEFORE_VALUE_clicked();
void on_GYRO_XVALUE_textChanged(const QString &arg1);
void on_OPT_Reset_clicked();
void on_OPT_LighRaspSW_clicked();
private:
Ui::TW_LightingUI *ui;
};
#endif // TW_LIGHTINGUI_H
这里面我们会有使用定时器。来跑线程。
最后的UI附上: