Skip to content

Commit

Permalink
Refine input handling and add new types in ModeEnum
Browse files Browse the repository at this point in the history
The InputSwitchHandler now also initializes prefixValue inside the conditional expression to simplify the code. Moreover, FLOATMODE2DECIMALS and METERSPERSECOND are added to ModeEnum to support additional types of data input. Further, some superfluous includes and version setting in Dashboard.h have been removed.
  • Loading branch information
BitsAndDroids committed Dec 2, 2023
1 parent 14251f3 commit 467452e
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 19 deletions.
1 change: 0 additions & 1 deletion constants.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef CONSTANTS_H
#define CONSTANTS_H
namespace constants {
inline constexpr char VERSION[]{"1.7.0-1"};
inline constexpr int supportedEngines{4};
inline constexpr int supportedMixtureLevers{4};
inline constexpr int supportedPropellerLevers{4};
Expand Down
12 changes: 0 additions & 12 deletions dashboard/Dashboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,14 @@
#include "dashboard/workers/MFSWorker.h"

#include "outputmenu/handlers/sethandler.h"
#include <qcombobox.h>
#include <qpushbutton.h>
#include <qstandardpaths.h>
#include "widgets/settingsmenu/builder/formbuilder.h"
#include "elements/ModeIndexCombobox.h"
#include "elements/ModeIndexCheckbox.h"
#include <QCoreApplication>
#include <QFile>
#include <QMainWindow>
#include <QNetworkReply>
#include <QSettings>

#include "serial/SerialPort.hpp"
#include "constants.h"
#include "services/ServiceWorker.h"
#include "dashboard/controller/DashboardController.h"
#include "dashboard/Elements/MenuBar.h"
#include "dashboard/controller/ComPortWidgetController.h"

const std::string version = constants::VERSION;

class Dashboard : public QMainWindow {
Q_OBJECT
Expand Down
2 changes: 0 additions & 2 deletions dashboard/elements/MenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ void MenuBar::populateMenuBar(QMainWindow *parent) {
Settings->addAction(openLogging);
//codeMenu->addAction(generateCode);
Settings->addAction(calibrateAxis);

Settings->addAction("Version " + QString(constants::VERSION));
// libraryMenu->addAction(libraryGenerator);

connect(WasmUpdateEventFile, &QAction::triggered, this,
Expand Down
2 changes: 2 additions & 0 deletions dashboard/models/ComBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ComBundle.h"

#include <thread>
#include <QDebug>

bool ComBundle::isOutputInBundle(int id){
return this->outputs.contains(id);
Expand All @@ -15,6 +16,7 @@ ComBundle::ComBundle(QString port, bool delayBoot){
if (delayBoot){
//sleep for x seconds to allow for boards to reset (i.e. Arduino due)
std::this_thread::sleep_for(std::chrono::seconds(3));
qDebug() << "Sleeping for 3 seconds";
}
}

Expand Down
2 changes: 1 addition & 1 deletion dist/outputs.json
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@
"dataType": 0,
"cbText":"Kohlsman HG",
"prefix": 337,
"type": 6
"type": 3
}
],
"GPS": [{
Expand Down
2 changes: 2 additions & 0 deletions enums/ModeEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ static enum ModeEnum {
INTEGERMODE = 0,
PERCENTAGEMODE = 5,
FLOATMODE = 2,
FLOATMODE2DECIMALS = 3,
STRINGMODE = 12,
KOHLSMANMODE = 6,
BOOLMODE = 4,
METERSPERSECOND = 7,
} modes;

#endif //BITSANDDROIDSGUI_MODEENUM_H
5 changes: 2 additions & 3 deletions handlers/InputSwitchHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,8 @@ void InputSwitchHandler::switchHandling(const char* stringToParse) {

if (strlen(stringToParse) > 2) {
try {
int prefixValue = stoi(stringStd.substr(0,4));
if (prefixValue < 1000 && inputs.count(prefixValue) > 0) {
Input input = inputs[prefixValue];
if (const int prefixValue = stoi(stringStd.substr(0,4)); prefixValue < 1000 && inputs.count(prefixValue) > 0) {
const Input input = inputs[prefixValue];
emit logMessage(
"Received data: " + std::string(stringToParse) + " command: " + input.getEvent(),
LogLevel::DEBUGLOG);
Expand Down
15 changes: 15 additions & 0 deletions utils/OutputConverters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#include <QString>
#include "OutputConverters.h"

#include <iomanip>
#include <sstream>

#include "enums/ModeEnum.h"

OutputConverters::OutputConverters() = default;
Expand Down Expand Up @@ -42,11 +46,22 @@ std::string OutputConverters::formatOutgoingString(float received, Output output
input_string = prefix + std::to_string(received);
break;
}
case FLOATMODE2DECIMALS: {
std::ostringstream stream;
stream << std::fixed << std::setprecision(2) << received;
input_string = prefix + stream.str();
break;
}
case PERCENTAGEMODE: {
intVal = (int)(received * 100);
input_string = prefix + std::to_string(intVal);
break;
}
case METERSPERSECOND: {
intVal = (int)(received * 1.94384);
input_string = prefix + std::to_string(intVal);
break;
}
default: {
intVal = (int)received;
input_string = prefix + std::to_string(intVal);
Expand Down

0 comments on commit 467452e

Please sign in to comment.