Skip to content

Commit

Permalink
Add preflight check before takeoff setting
Browse files Browse the repository at this point in the history
  • Loading branch information
fvantienen committed May 16, 2024
1 parent 9acff22 commit 59a37ed
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/common/aircraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ void Aircraft::setSetting(uint8_t setting_no, float value) {
}
}
}

bool Aircraft::checklistFinished() {
for(auto item: checklist) {
if(item->type == "checkbox" && item->value != "true") {
return false;
}
else if(item->type == "text" && item->value == "") {
return false;
}
}
return true;
}
1 change: 1 addition & 0 deletions src/common/aircraft.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Aircraft: public QObject
void setSetting(uint8_t setting_no, float value);

bool isReal() {return real;}
bool checklistFinished();

private:
QString ac_id;
Expand Down
1 change: 1 addition & 0 deletions src/common/setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Setting: public QObject
QList<shared_ptr<StripButton>> getStripButtons() {return strip_buttons;}
uint8_t getNo() {return setting_no;}
QString getName() { if(shortname != "") { return shortname;} else {return var;}}
QString getFullName() {return var;}
QList<QString>& getValues() {return values;}
tuple<float, float, float> getBounds() {return make_tuple(min, max, step);}
void setUserValue(float v) {
Expand Down
27 changes: 23 additions & 4 deletions src/widgets/checklist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,26 @@ Checklist::Checklist(QString ac_id, QWidget *parent) :
QFrame(parent),
ui(new Ui::Checklist)
{
// Get the settings
// Get the global settings
auto settings_path = appConfig()->value("SETTINGS_PATH").toString();
QSettings settings(settings_path, QSettings::IniFormat);
pprzlink_id = settings.value("pprzlink/id").toString();

// Setup the UI
ui->setupUi(this);

QList<ChecklistItem*> checklist = AircraftManager::get()->getAircraft(ac_id)->getChecklist();
// Get the uav settings and find the PFC settings
auto ac = AircraftManager::get()->getAircraft(ac_id);
auto ac_settings = ac->getSettingMenu()->getAllSettings();
Setting* pfc_setting = nullptr;
for(auto setting: ac_settings) {
if(setting->getFullName() == "preflight_ground_done") {
pfc_setting = setting;
}
}

// Go through the checklist items and create the widget
QList<ChecklistItem*> checklist = ac->getChecklist();
for(auto item: checklist) {
if(item->type == "checkbox") {
auto widget_item = new QCheckBox(item->description);
Expand All @@ -32,8 +43,12 @@ Checklist::Checklist(QString ac_id, QWidget *parent) :

connect(widget_item, &QCheckBox::toggled, this,
[=](bool state) {
item->value = (state)? QString("true") : QString("false");
item->value = (state)? "true":"false";
sendMessage(ac_id, item);

if(pfc_setting != nullptr) {
ac->setSetting(pfc_setting, ac->checklistFinished()? 1:0);
}
});
}
else if(item->type == "text") {
Expand All @@ -44,10 +59,14 @@ Checklist::Checklist(QString ac_id, QWidget *parent) :
widget_item->addWidget(widget_input);
ui->verticalLayout->addLayout(widget_item);

connect(widget_input, &QLineEdit::returnPressed, this,
connect(widget_input, &QLineEdit::editingFinished, this,
[=]() {
item->value = widget_input->text();
sendMessage(ac_id, item);

if(pfc_setting != nullptr) {
ac->setSetting(pfc_setting, ac->checklistFinished()? 1:0);
}
});
}
}
Expand Down

0 comments on commit 59a37ed

Please sign in to comment.