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

External module api #2290

Merged
merged 14 commits into from
Oct 14, 2024
1 change: 1 addition & 0 deletions firmware/application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ set(CPPSRC
apps/ui_debug_max17055.cpp
apps/ui_dfu_menu.cpp
apps/ui_encoders.cpp
apps/ui_external_module_view.cpp
apps/ui_fileman.cpp
apps/ui_flash_utility.cpp
apps/ui_freqman.cpp
Expand Down
2 changes: 2 additions & 0 deletions firmware/application/apps/ui_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "ui_painter.hpp"
#include "ui_external_items_menu_loader.hpp"
#include "ui_debug_max17055.hpp"
#include "ui_external_module_view.hpp"

#include "portapack.hpp"
#include "portapack_persistent_memory.hpp"
Expand Down Expand Up @@ -514,6 +515,7 @@ void DebugMenuView::on_populate() {
{"Temperature", ui::Theme::getInstance()->fg_darkcyan->foreground, &bitmap_icon_temperature, [this]() { nav_.push<TemperatureView>(); }},
{"Touch Test", ui::Theme::getInstance()->fg_darkcyan->foreground, &bitmap_icon_notepad, [this]() { nav_.push<DebugScreenTest>(); }},
{"Reboot", ui::Theme::getInstance()->fg_darkcyan->foreground, &bitmap_icon_setup, [this]() { nav_.push<DebugReboot>(); }},
{"Ext Module", ui::Theme::getInstance()->fg_darkcyan->foreground, &bitmap_icon_peripherals_details, [this]() { nav_.push<ExternalModuleView>(); }},
});

if (i2cdev::I2CDevManager::get_dev_by_model(I2C_DEVMDL::I2CDEVMDL_MAX17055)) {
Expand Down
122 changes: 122 additions & 0 deletions firmware/application/apps/ui_external_module_view.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Copyright (C) 2024 Bernd Herzog
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/

#include "ui_external_module_view.hpp"
#include "portapack.hpp"
#include "ui_standalone_view.hpp"

#include "i2cdevmanager.hpp"
#include "i2cdev_ppmod.hpp"

#include <optional>

namespace ui {

void ExternalModuleView::focus() {
dummy.focus();
}

void ExternalModuleView::on_tick_second() {
i2cdev::I2CDevManager::manual_scan();

auto dev = (i2cdev::I2cDev_PPmod*)i2cdev::I2CDevManager::get_dev_by_model(I2C_DEVMDL::I2CDECMDL_PPMOD);

if (!dev) {
text_header.set("No module connected");
text_name.set("");
text_version.set("");
text_number_apps.set("");
text_app1_name.set("");
text_app2_name.set("");
text_app3_name.set("");
text_app4_name.set("");
text_app5_name.set("");
return;
}

auto device_info = dev->readDeviceInfo();

if (device_info.has_value() == false) {
text_header.set("No module connected");
text_name.set("");
text_version.set("");
text_number_apps.set("");
text_app1_name.set("");
text_app2_name.set("");
text_app3_name.set("");
text_app4_name.set("");
text_app5_name.set("");
return;
}

text_header.set("Module found");

std::string btnText = (std::string) "Module: " + device_info->module_name;
text_name.set(btnText);
text_version.set("Version: " + std::to_string(device_info->module_version));
text_number_apps.set("No# Apps: " + std::to_string(device_info->application_count));

for (uint32_t i = 0; i < device_info->application_count && i < 5; i++) {
auto appInfo = dev->getStandaloneAppInfo(i);
if (appInfo.has_value() == false) {
continue;
}

std::string btnText = (std::string) "App " + std::to_string(device_info->application_count) + ": " + (const char*)appInfo->app_name;

switch (appInfo->menu_location) {
case app_location_t::UTILITIES:
btnText += " (Utilities)";
break;
case app_location_t::RX:
btnText += " (RX)";
break;
case app_location_t::TX:
btnText += " (TX)";
break;
case app_location_t::DEBUG:
btnText += " (Debug)";
break;
case app_location_t::HOME:
btnText += " (Home)";
break;
}

switch (i) {
case 0:
text_app1_name.set(btnText);
break;
case 1:
text_app2_name.set(btnText);
break;
case 2:
text_app3_name.set(btnText);
break;
case 3:
text_app4_name.set(btnText);
break;
case 4:
text_app5_name.set(btnText);
break;
}
}
}
} // namespace ui
94 changes: 94 additions & 0 deletions firmware/application/apps/ui_external_module_view.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (C) 2024 Bernd Herzog
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/

#pragma once
bernd-herzog marked this conversation as resolved.
Show resolved Hide resolved

#include "ui.hpp"
#include "ui_widget.hpp"
#include "ui_painter.hpp"
#include "ui_menu.hpp"
#include "ui_navigation.hpp"

#include "rffc507x.hpp"
#include "portapack.hpp"
#include "memory_map.hpp"
#include "irq_controls.hpp"

#include <functional>
#include <utility>

#include "i2cdevmanager.hpp"
#include "i2cdev_ppmod.hpp"

namespace ui {

class ExternalModuleView : public View {
public:
ExternalModuleView(NavigationView& nav)
: nav_(nav) {
add_children({&text_header,
&text_name,
&text_version,
&text_number_apps,
&text_app1_name,
&text_app2_name,
&text_app3_name,
&text_app4_name,
&text_app5_name,
&dummy});

text_header.set("No module connected");

signal_token_tick_second = rtc_time::signal_tick_second += [this]() {
on_tick_second();
};
}

~ExternalModuleView() {
rtc_time::signal_tick_second -= signal_token_tick_second;
}

std::string title() const override { return "Ext Module"; };
void focus() override;

private:
NavigationView& nav_;
Text text_header{{16, 16, 208, 16}};
Text text_name{{24, 32, 200, 16}};
Text text_version{{24, 48, 200, 16}};
Text text_number_apps{{24, 64, 200, 16}};

Text text_app1_name{{24, 96, 200, 16}};
Text text_app2_name{{24, 112, 200, 16}};
Text text_app3_name{{24, 128, 200, 16}};
Text text_app4_name{{24, 144, 200, 16}};
Text text_app5_name{{24, 160, 200, 16}};

Button dummy{
{240, 0, 0, 0},
""};

SignalToken signal_token_tick_second{};

void on_tick_second();
};

} // namespace ui
Loading
Loading