Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GS] Add Imperial Units #381

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/merge-criteria.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
contains_dotgithub=$(echo '${{ steps.changed-files.outputs.all_changed_files }}' | jq 'map(select(. == ".github")) | length')
is_manual_trigger=$(echo '${{ github.event.inputs.commit_sha }}')

if [[ -z "$is_manual_trigger" || "${GITHUB_REF}" == "refs/heads/main" || $contains_dot -gt 0 || $contains_dotgithub -gt 0 ]]; then
if [[ -n "$is_manual_trigger" || "${GITHUB_REF}" == "refs/heads/main" || $contains_dot -gt 0 || $contains_dotgithub -gt 0 ]]; then
filtered_array='["flight_computer","ground_station","telemetry"]'
else
filtered_array='${{ steps.changed-files.outputs.all_changed_files }}'
Expand Down
6 changes: 6 additions & 0 deletions ground_station/src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void Config::save() {
systemParser.setLinkPhrase2(config.linkPhrase2);
systemParser.setTelemetryMode(static_cast<bool>(config.receiverMode));
systemParser.setNeverStopLoggingFlag(config.neverStopLogging);
systemParser.setUnitSystem(config.unitSystem);
systemParser.setTimeZone(config.timeZoneOffset);
systemParser.setMagCalib(config.mag_calib);
systemParser.saveFile("/config.json");
Expand Down Expand Up @@ -73,6 +74,11 @@ void Config::load() {
} else {
console.log.println(config.timeZoneOffset);
}
if (!systemParser.getUnitSystem(config.unitSystem)) {
config.unitSystem = UnitSystem::kMetric;
} else {
console.log.println(unit_map[static_cast<uint8_t>(config.unitSystem)]);
}

config.neverStopLogging = stop;
config.receiverMode = static_cast<ReceiverTelemetryMode_e>(mode);
Expand Down
16 changes: 14 additions & 2 deletions ground_station/src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@

#pragma once

#include "systemParser.hpp"

#include <cstdint>

#include "hmi/settings.hpp"

enum ReceiverTelemetryMode_e : bool { SINGLE = false, DUAL = true };

enum class UnitSystem : uint8_t { kMetric = 0, kImperial = 1 };

struct mag_calib_t {
int32_t mag_offset_x;
int32_t mag_offset_y;
int32_t mag_offset_z;
int32_t mag_scale_x;
int32_t mag_scale_y;
int32_t mag_scale_z;
};

// Maximum number of characters for link & test phrases
inline constexpr uint32_t kMaxPhraseLen = 16;

Expand All @@ -21,6 +32,7 @@ struct systemConfig_t {
char linkPhrase2[kMaxPhraseLen + 1];
char testingPhrase[kMaxPhraseLen + 1];
mag_calib_t mag_calib;
UnitSystem unitSystem;
};

class Config {
Expand Down
69 changes: 69 additions & 0 deletions ground_station/src/hmi/settings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/// Copyright (C) 2020, 2024 Control and Telemetry Systems GmbH
///
/// SPDX-License-Identifier: GPL-3.0-or-later

#include "hmi/settings.hpp"
#include "config.hpp"

// NOLINTNEXTLINE(cppcoreguidelines-interfaces-global-init)
const device_settings_t settingsTable[][4] = {
{
{"Stop Logging",
"Down: Stop the log at touchdown",
"Never: Never stop logging after liftoff",
TOGGLE,
{.lookup = TABLE_LOGGING},
&systemConfig.config.neverStopLogging},

{
"Version",
"Firmware Version: " FIRMWARE_VERSION,
"",
BUTTON,
{.fun_ptr = nullptr},
nullptr,
},
{
"Start Bootloader",
"Press A to start the bootloader",
"Make sure you are connected to a computer",
BUTTON,
{.fun_ptr = Utils::startBootloader},
nullptr,
},
},
{
{"Mode",
"Single: Use both receiver to track one rocket",
"Dual: Use both receivers individually",
TOGGLE,
{.lookup = TABLE_MODE},
&systemConfig.config.receiverMode},
{"Link Phrase 1",
"Single Mode: Set phrase for both receivers",
"Dual Mode: Set phrase for the left receiver",
STRING,
{.stringLength = kMaxPhraseLen},
systemConfig.config.linkPhrase1},
{"Link Phrase 2",
"Single Mode: No functionality",
"Dual Mode: Set phrase for the right receiver",
STRING,
{.stringLength = kMaxPhraseLen},
systemConfig.config.linkPhrase2},
{"Testing Phrase",
"Set the phrase for the testing mode",
"",
STRING,
{.stringLength = kMaxPhraseLen},
systemConfig.config.testingPhrase},
},
{
{"Time Zone",
"Time offset relative to UTC",
"",
NUMBER,
{.minmax = {.min = -12, .max = 12}},
&systemConfig.config.timeZoneOffset},
{"Units", "Metric: meters", "Imperial: feet", TOGGLE, {.lookup = TABLE_UNIT}, &systemConfig.config.unitSystem},
}};
70 changes: 6 additions & 64 deletions ground_station/src/hmi/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const char* const mode_map[2] = {

const char* const unit_map[2] = {
"METRIC",
"RETARDED",
"IMPERIAL",
};

const char* const logging_map[2] = {
Expand All @@ -76,69 +76,11 @@ const lookup_table_entry_t lookup_tables[] = {
};

enum {
kSettingPages = 2,
kSettingPages = 3,
};

const char* const settingPageName[kSettingPages] = {"General", "Telemetry"};

// NOLINTNEXTLINE(cppcoreguidelines-interfaces-global-init)
const device_settings_t settingsTable[][4] = {
{
{"Time Zone",
"Set the time offset",
"",
NUMBER,
{.minmax = {.min = -12, .max = 12}},
&systemConfig.config.timeZoneOffset},
{"Stop Logging",
"Down: Stop the log at touchdown",
"Never: Never stop logging after liftoff",
TOGGLE,
{.lookup = TABLE_LOGGING},
&systemConfig.config.neverStopLogging},
{
"Version",
"Firmware Version: " FIRMWARE_VERSION,
"",
BUTTON,
{.fun_ptr = nullptr},
nullptr,
},
{
"Start Bootloader",
"Press A to start the bootloader",
"Make sure you are connected to a computer",
BUTTON,
{.fun_ptr = Utils::startBootloader},
nullptr,
},
},
{
{"Mode",
"Single: Use both receiver to track one rocket",
"Dual: Use both receivers individually",
TOGGLE,
{.lookup = TABLE_MODE},
&systemConfig.config.receiverMode},
{"Link Phrase 1",
"Single Mode: Set phrase for both receivers",
"Dual Mode: Set phrase for the left receiver",
STRING,
{.stringLength = kMaxPhraseLen},
systemConfig.config.linkPhrase1},
{"Link Phrase 2",
"Single Mode: No functionality",
"Dual Mode: Set phrase for the right receiver",
STRING,
{.stringLength = kMaxPhraseLen},
systemConfig.config.linkPhrase2},
{"Testing Phrase",
"Set the phrase for the testing mode",
"",
STRING,
{.stringLength = kMaxPhraseLen},
systemConfig.config.testingPhrase},
},
};
const char* const settingPageName[kSettingPages] = {"General", "Telemetry", "Location"};

extern const device_settings_t settingsTable[][4];

const uint16_t settingsTableValueCount[kSettingPages] = {4, 4};
const uint16_t settingsTableValueCount[kSettingPages] = {3, 4, 2};
72 changes: 46 additions & 26 deletions ground_station/src/hmi/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "window.hpp"
#include "bmp.hpp"
#include "config.hpp"
#include "utils.hpp"

#include <Fonts/FreeMonoBold12pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
Expand Down Expand Up @@ -362,12 +364,25 @@ void Window::updateLiveData(TelemetryData *data, int16_t index, uint16_t color)
drawCentreString(stateName[data->state()], static_cast<int16_t>(xOffset + 100), 42);

display.setCursor(static_cast<int16_t>(xOffset + 35), 70);
display.print(data->altitude());
display.print(" m");
const int32_t altitude_m = data->altitude();
if (systemConfig.config.unitSystem == UnitSystem::kMetric) {
display.print(altitude_m);
display.print(" m");
} else {
display.print(Utils::MetersToFeet(altitude_m));
display.print(" ft");
}

display.setCursor(static_cast<int16_t>(xOffset + 35), 95);
display.print(data->velocity());
display.print(" m/s");

const int16_t velocity_m_s = data->velocity();
if (systemConfig.config.unitSystem == UnitSystem::kMetric) {
display.print(velocity_m_s);
display.print(" m/s");
} else {
display.print(Utils::MetersToFeet(velocity_m_s));
display.print(" ft/s");
}

display.setCursor(static_cast<int16_t>(xOffset + 35), 120);
display.print(data->lat(), 4);
Expand Down Expand Up @@ -515,8 +530,14 @@ void Window::updateRecovery(Navigation *navigation) {
}

display.setCursor(70, 170);
display.print(navigation->getDistance());
display.print("m");
const float distance_m = navigation->getDistance();
if (systemConfig.config.unitSystem == UnitSystem::kMetric) {
display.print(distance_m);
display.print(" m");
} else {
display.print(Utils::MetersToFeet(distance_m));
display.print(" ft");
}

display.setFont(&FreeSans9pt7b);

Expand Down Expand Up @@ -1026,7 +1047,7 @@ void Window::initSensorCalibrateDone() {
display.refresh();
}

void Window::initSettings(int16_t submenu) {
void Window::initSettings(int16_t submenuIdx) {
clearMainScreen();

display.drawLine(0, 49, 400, 49, BLACK);
Expand All @@ -1036,21 +1057,17 @@ void Window::initSettings(int16_t submenu) {
display.setTextColor(WHITE);

display.fillRect(0, 19, 400, 30, BLACK);
drawCentreString(settingPageName[submenu], 200, 42);
drawCentreString(settingPageName[submenuIdx], 200, 42);

display.setTextColor(BLACK);
for (int i = 0; i < settingsTableValueCount[submenu]; i++) {
addSettingEntry(i, &settingsTable[submenu][i]);
for (int i = 0; i < settingsTableValueCount[submenuIdx]; i++) {
addSettingEntry(i, &settingsTable[submenuIdx][i]);
}

if (submenu == 0) {
display.fillTriangle(386, 33, 378, 25, 378, 41, WHITE);
} else {
display.fillTriangle(13, 33, 21, 25, 21, 41, WHITE);
}
drawSettingsTriangles(submenuIdx, WHITE);

oldSettingsIndex = -1;
subMenuSettingIndex = submenu;
subMenuSettingIndex = submenuIdx;

display.drawLine(0, 177, 400, 177, BLACK);
display.refresh();
Expand Down Expand Up @@ -1112,28 +1129,31 @@ void Window::updateSettings(int16_t index) {
highlightSetting(oldSettingsIndex, BLACK);
}
} else {
if (subMenuSettingIndex == 0) {
display.fillTriangle(386, 33, 378, 25, 378, 41, BLACK);
} else {
display.fillTriangle(13, 33, 21, 25, 21, 41, BLACK);
}
drawSettingsTriangles(subMenuSettingIndex, BLACK);
}

if (index >= 0) {
highlightSetting(index, WHITE);
} else {
if (subMenuSettingIndex == 0) {
display.fillTriangle(386, 33, 378, 25, 378, 41, WHITE);
} else {
display.fillTriangle(13, 33, 21, 25, 21, 41, WHITE);
}
drawSettingsTriangles(subMenuSettingIndex, WHITE);
display.fillRect(0, 178, 400, 62, WHITE);
}

oldSettingsIndex = index;
display.refresh();
}

void Window::drawSettingsTriangles(int16_t submenuIdx, int16_t color) {
if (submenuIdx == 0) { // first page
display.fillTriangle(386, 33, 378, 25, 378, 41, color);
} else if (submenuIdx == kSettingPages - 1) { // last page
display.fillTriangle(13, 33, 21, 25, 21, 41, color);
} else { // other pages
display.fillTriangle(386, 33, 378, 25, 378, 41, color);
display.fillTriangle(13, 33, 21, 25, 21, 41, color);
}
}

void Window::highlightSetting(int16_t index, uint16_t color) {
display.setFont(&FreeSans12pt7b);
const auto yPos = static_cast<int16_t>(52 + 30 * index);
Expand Down
3 changes: 2 additions & 1 deletion ground_station/src/hmi/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ class Window {
void initSensorCalibrateDone();
void updateSensors(Navigation *navigation);

void initSettings(int16_t submenu);
void initSettings(int16_t submenuIdx);
void updateSettings(int16_t index);
void drawSettingsTriangles(int16_t submenuIdx, int16_t color);

void initBox(const char *text);

Expand Down
Loading
Loading