@ -109,72 +109,53 @@ TogglesPanel::TogglesPanel(SettingsWindow *parent) : ListWidget(parent) {
}
}
DevicePanel : : DevicePanel ( QWidget * parent ) : ListWidget ( parent ) {
setSpacing ( 50 ) ;
DevicePanel : : DevicePanel ( SettingsWindow * parent ) : ListWidget ( parent ) {
Params params = Params ( ) ;
setSpacing ( 50 ) ;
addItem ( new LabelControl ( " Dongle ID " , getDongleId ( ) . value_or ( " N/A " ) ) ) ;
addItem ( new LabelControl ( " Serial " , params . get ( " HardwareSerial " ) . c_str ( ) ) ) ;
// offroad-only buttons
auto dcamBtn = new ButtonControl ( " Driver Camera " , " PREVIEW " ,
" Preview the driver facing camera to help optimize device mounting position for best driver monitoring experience. (vehicle must be off) " ) ;
" Preview the driver facing camera to help optimize device mounting position for best driver monitoring experience. (vehicle must be off) " ) ;
connect ( dcamBtn , & ButtonControl : : clicked , [ = ] ( ) { emit showDriverView ( ) ; } ) ;
addItem ( dcamBtn ) ;
QString resetCalibDesc = " openpilot requires the device to be mounted within 4° left or right and within 5° up or down. openpilot is continuously calibrating, resetting is rarely required. " ;
auto resetCalibBtn = new ButtonControl ( " Reset Calibration " , " RESET " , resetCalibDesc ) ;
auto resetCalibBtn = new ButtonControl ( " Reset Calibration " , " RESET " , " " ) ;
connect ( resetCalibBtn , & ButtonControl : : showDescription , this , & DevicePanel : : updateCalibDescription ) ;
connect ( resetCalibBtn , & ButtonControl : : clicked , [ & ] ( ) {
if ( ConfirmationDialog : : confirm ( " Are you sure you want to reset calibration? " , this ) ) {
params . remove ( " CalibrationParams " ) ;
}
} ) ;
connect ( resetCalibBtn , & ButtonControl : : showDescription , [ & ] ( ) {
QString desc = resetCalibDesc ;
std : : string calib_bytes = params . get ( " CalibrationParams " ) ;
if ( ! calib_bytes . empty ( ) ) {
try {
AlignedBuffer aligned_buf ;
capnp : : FlatArrayMessageReader cmsg ( aligned_buf . align ( calib_bytes . data ( ) , calib_bytes . size ( ) ) ) ;
auto calib = cmsg . getRoot < cereal : : Event > ( ) . getLiveCalibration ( ) ;
if ( calib . getCalStatus ( ) ! = 0 ) {
double pitch = calib . getRpyCalib ( ) [ 1 ] * ( 180 / M_PI ) ;
double yaw = calib . getRpyCalib ( ) [ 2 ] * ( 180 / M_PI ) ;
desc + = QString ( " Your device is pointed %1° %2 and %3° %4. " )
. arg ( QString : : number ( std : : abs ( pitch ) , ' g ' , 1 ) , pitch > 0 ? " up " : " down " ,
QString : : number ( std : : abs ( yaw ) , ' g ' , 1 ) , yaw > 0 ? " right " : " left " ) ;
}
} catch ( kj : : Exception ) {
qInfo ( ) < < " invalid CalibrationParams " ;
}
}
resetCalibBtn - > setDescription ( desc ) ;
} ) ;
addItem ( resetCalibBtn ) ;
ButtonControl * retrainingBtn = nullptr ;
if ( ! params . getBool ( " Passive " ) ) {
retrainingBtn = new ButtonControl ( " Review Training Guide " , " REVIEW " , " Review the rules, features, and limitations of openpilot " ) ;
auto retrainingBtn = new ButtonControl ( " Review Training Guide " , " REVIEW " , " Review the rules, features, and limitations of openpilot " ) ;
connect ( retrainingBtn , & ButtonControl : : clicked , [ = ] ( ) {
if ( ConfirmationDialog : : confirm ( " Are you sure you want to review the training guide? " , this ) ) {
emit reviewTrainingGuide ( ) ;
}
} ) ;
addItem ( retrainingBtn ) ;
}
ButtonControl * regulatoryBtn = nullptr ;
if ( Hardware : : TICI ( ) ) {
regulatoryBtn = new ButtonControl ( " Regulatory " , " VIEW " , " " ) ;
auto regulatoryBtn = new ButtonControl ( " Regulatory " , " VIEW " , " " ) ;
connect ( regulatoryBtn , & ButtonControl : : clicked , [ = ] ( ) {
const std : : string txt = util : : read_file ( " ../assets/offroad/fcc.html " ) ;
RichTextDialog : : alert ( QString : : fromStdString ( txt ) , this ) ;
} ) ;
addItem ( regulatoryBtn ) ;
}
for ( auto btn : { dcamBtn , resetCalibBtn , retrainingBtn , regulatoryBtn } ) {
if ( btn ) {
connect ( parent , SIGNAL ( offroadTransition ( bool ) ) , btn , SLOT ( setEnabled ( bool ) ) ) ;
addItem ( btn ) ;
QObject : : connect ( parent , & SettingsWindow : : offroadTransition , [ = ] ( bool offroad ) {
for ( auto btn : findChildren < ButtonControl * > ( ) ) {
btn - > setEnabled ( offroad ) ;
}
}
} ) ;
// power buttons
QHBoxLayout * power_layout = new QHBoxLayout ( ) ;
@ -183,34 +164,12 @@ DevicePanel::DevicePanel(QWidget* parent) : ListWidget(parent) {
QPushButton * reboot_btn = new QPushButton ( " Reboot " ) ;
reboot_btn - > setObjectName ( " reboot_btn " ) ;
power_layout - > addWidget ( reboot_btn ) ;
QObject : : connect ( reboot_btn , & QPushButton : : clicked , [ & ] ( ) {
if ( QUIState : : ui_state . status = = UIStatus : : STATUS_DISENGAGED ) {
if ( ConfirmationDialog : : confirm ( " Are you sure you want to reboot? " , this ) ) {
// Check engaged again in case it changed while the dialog was open
if ( QUIState : : ui_state . status = = UIStatus : : STATUS_DISENGAGED ) {
params . putBool ( " DoReboot " , true ) ;
}
}
} else {
ConfirmationDialog : : alert ( " Disengage to Reboot " , this ) ;
}
} ) ;
QObject : : connect ( reboot_btn , & QPushButton : : clicked , this , & DevicePanel : : reboot ) ;
QPushButton * poweroff_btn = new QPushButton ( " Power Off " ) ;
poweroff_btn - > setObjectName ( " poweroff_btn " ) ;
power_layout - > addWidget ( poweroff_btn ) ;
QObject : : connect ( poweroff_btn , & QPushButton : : clicked , [ & ] ( ) {
if ( QUIState : : ui_state . status = = UIStatus : : STATUS_DISENGAGED ) {
if ( ConfirmationDialog : : confirm ( " Are you sure you want to power off? " , this ) ) {
// Check engaged again in case it changed while the dialog was open
if ( QUIState : : ui_state . status = = UIStatus : : STATUS_DISENGAGED ) {
params . putBool ( " DoShutdown " , true ) ;
}
}
} else {
ConfirmationDialog : : alert ( " Disengage to Power Off " , this ) ;
}
} ) ;
QObject : : connect ( poweroff_btn , & QPushButton : : clicked , this , & DevicePanel : : poweroff ) ;
setStyleSheet ( R " (
QPushButton {
@ -225,6 +184,56 @@ DevicePanel::DevicePanel(QWidget* parent) : ListWidget(parent) {
addItem ( power_layout ) ;
}
void DevicePanel : : updateCalibDescription ( ) {
QString desc =
" openpilot requires the device to be mounted within 4° left or right and "
" within 5° up or down. openpilot is continuously calibrating, resetting is rarely required. " ;
std : : string calib_bytes = Params ( ) . get ( " CalibrationParams " ) ;
if ( ! calib_bytes . empty ( ) ) {
try {
AlignedBuffer aligned_buf ;
capnp : : FlatArrayMessageReader cmsg ( aligned_buf . align ( calib_bytes . data ( ) , calib_bytes . size ( ) ) ) ;
auto calib = cmsg . getRoot < cereal : : Event > ( ) . getLiveCalibration ( ) ;
if ( calib . getCalStatus ( ) ! = 0 ) {
double pitch = calib . getRpyCalib ( ) [ 1 ] * ( 180 / M_PI ) ;
double yaw = calib . getRpyCalib ( ) [ 2 ] * ( 180 / M_PI ) ;
desc + = QString ( " Your device is pointed %1° %2 and %3° %4. " )
. arg ( QString : : number ( std : : abs ( pitch ) , ' g ' , 1 ) , pitch > 0 ? " up " : " down " ,
QString : : number ( std : : abs ( yaw ) , ' g ' , 1 ) , yaw > 0 ? " right " : " left " ) ;
}
} catch ( kj : : Exception ) {
qInfo ( ) < < " invalid CalibrationParams " ;
}
}
qobject_cast < ButtonControl * > ( sender ( ) ) - > setDescription ( desc ) ;
}
void DevicePanel : : reboot ( ) {
if ( QUIState : : ui_state . status = = UIStatus : : STATUS_DISENGAGED ) {
if ( ConfirmationDialog : : confirm ( " Are you sure you want to reboot? " , this ) ) {
// Check engaged again in case it changed while the dialog was open
if ( QUIState : : ui_state . status = = UIStatus : : STATUS_DISENGAGED ) {
Params ( ) . putBool ( " DoReboot " , true ) ;
}
}
} else {
ConfirmationDialog : : alert ( " Disengage to Reboot " , this ) ;
}
}
void DevicePanel : : poweroff ( ) {
if ( QUIState : : ui_state . status = = UIStatus : : STATUS_DISENGAGED ) {
if ( ConfirmationDialog : : confirm ( " Are you sure you want to power off? " , this ) ) {
// Check engaged again in case it changed while the dialog was open
if ( QUIState : : ui_state . status = = UIStatus : : STATUS_DISENGAGED ) {
Params ( ) . putBool ( " DoShutdown " , true ) ;
}
}
} else {
ConfirmationDialog : : alert ( " Disengage to Power Off " , this ) ;
}
}
SoftwarePanel : : SoftwarePanel ( QWidget * parent ) : ListWidget ( parent ) {
gitBranchLbl = new LabelControl ( " Git Branch " ) ;
gitCommitLbl = new LabelControl ( " Git Commit " ) ;