Skip to content

Commit

Permalink
External sensor tester app (#1949)
Browse files Browse the repository at this point in the history
* added tilt
* added extsensors app
* added icon
* Added EnvironmentData to ExtSensor app and message.hpp
* Added gotenv command
  • Loading branch information
htotoo committed Mar 7, 2024
1 parent 908c0e2 commit 2648f18
Show file tree
Hide file tree
Showing 8 changed files with 329 additions and 5 deletions.
6 changes: 6 additions & 0 deletions firmware/application/external/external.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ set(EXTCPPSRC
external/keyfob/main.cpp
external/keyfob/ui_keyfob.cpp
external/keyfob/ui_keyfob.hpp

#extsensors
external/extsensors/main.cpp
external/extsensors/ui_extsensors.cpp
external/extsensors/ui_extsensors.hpp
)

set(EXTAPPLIST
Expand All @@ -80,4 +85,5 @@ set(EXTAPPLIST
spainter
keyfob
tetris
extsensors
)
9 changes: 9 additions & 0 deletions firmware/application/external/external.ld
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ MEMORY
ram_external_app_spainter(rwx) : org = 0xADBC0000, len = 32k
ram_external_app_keyfob(rwx) : org = 0xADBD0000, len = 32k
ram_external_app_tetris(rwx) : org = 0xADBE0000, len = 32k
ram_external_app_extsensors(rwx) : org = 0xADBF0000, len = 32k
}

SECTIONS
Expand Down Expand Up @@ -132,4 +133,12 @@ SECTIONS
*(*ui*external_app*tetris*);
} > ram_external_app_tetris

.external_app_extsensors : ALIGN(4) SUBALIGN(4)
{
KEEP(*(.external_app.app_extsensors.application_information));
*(*ui*external_app*extsensors*);
} > ram_external_app_extsensors



}
82 changes: 82 additions & 0 deletions firmware/application/external/extsensors/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (C) 2023 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.hpp"
#include "ui_extsensors.hpp"
#include "ui_navigation.hpp"
#include "external_app.hpp"

namespace ui::external_app::extsensors {
void initialize_app(ui::NavigationView& nav) {
nav.push<ExtSensorsView>();
}
} // namespace ui::external_app::extsensors

extern "C" {

__attribute__((section(".external_app.app_extsensors.application_information"), used)) application_information_t _application_information_extsensors = {
/*.memory_location = */ (uint8_t*)0x00000000,
/*.externalAppEntry = */ ui::external_app::extsensors::initialize_app,
/*.header_version = */ CURRENT_HEADER_VERSION,
/*.app_version = */ VERSION_MD5,

/*.app_name = */ "ExtSensor",
/*.bitmap_data = */ {
0x00,
0x00,
0x00,
0x00,
0x04,
0x20,
0x12,
0x48,
0x8A,
0x51,
0xCA,
0x53,
0xCA,
0x53,
0x8A,
0x51,
0x12,
0x48,
0x84,
0x21,
0xC0,
0x03,
0x40,
0x02,
0x60,
0x06,
0x20,
0x04,
0x30,
0x0C,
0xF0,
0x0F,
},
/*.icon_color = */ ui::Color::orange().v,
/*.menu_location = */ app_location_t::DEBUG,

/*.m4_app_tag = portapack::spi_flash::image_tag_none */ {0, 0, 0, 0},
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
};
}
86 changes: 86 additions & 0 deletions firmware/application/external/extsensors/ui_extsensors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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_extsensors.hpp"

#include "rtc_time.hpp"
#include "string_format.hpp"
#include "portapack_persistent_memory.hpp"

using namespace portapack;
using namespace ui;

namespace ui::external_app::extsensors {

void ExtSensorsView::focus() {
text_info.focus();
}

ExtSensorsView::ExtSensorsView(NavigationView& nav)
: nav_{nav} {
add_children({&labels,
&text_info,
&text_gps,
&text_orientation,
&text_envl1,
&text_envl2});
}

ExtSensorsView::~ExtSensorsView() {
}

void ExtSensorsView::on_any() {
if (has_data == false) {
// update text
text_info.set("Found ext module."); // todo do an ext module check for type
}
has_data = true;
}

void ExtSensorsView::on_gps(const GPSPosDataMessage* msg) {
on_any();
std::string tmp = to_string_decimal(msg->lat, 5);
tmp += "; ";
tmp += to_string_decimal(msg->lon, 5);
text_gps.set(tmp);
}

void ExtSensorsView::on_orientation(const OrientationDataMessage* msg) {
on_any();
std::string tmp = to_string_dec_uint(msg->angle);
tmp += (char)176; // °
if (msg->tilt < 400) {
tmp += "; T: " + to_string_dec_int(msg->tilt);
}
text_orientation.set(tmp);
}

void ExtSensorsView::on_environment(const EnvironmentDataMessage* msg) {
on_any();
std::string tmp = "T: " + to_string_decimal(msg->temperature, 2); // temperature
tmp += (char)176; // °
tmp += "C";
tmp += "; H: " + to_string_decimal(msg->humidity, 1) + "%"; // humidity
text_envl1.set(tmp);
tmp = "P: " + to_string_decimal(msg->pressure, 1) + " hPa; L:"; // pressure
tmp += to_string_dec_int(msg->light) + " LUX"; // light
text_envl2.set(tmp);
}

} // namespace ui::external_app::extsensors
96 changes: 96 additions & 0 deletions firmware/application/external/extsensors/ui_extsensors.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2017 Furrtek
*
* 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.
*/

// Code from https://github.com/Flipper-XFW/Xtreme-Apps/tree/04c3a60093e2c2378e79498b4505aa8072980a42/ble_spam/protocols
// Thanks for the work of the original creators!
// Saying thanks in the main view!

#ifndef __UI_EXTSENSORS_H__
#define __UI_EXTSENSORS_H__

#include "ui.hpp"
#include "ui_language.hpp"
#include "ui_navigation.hpp"
#include "ui_record_view.hpp"
#include "app_settings.hpp"
#include "utility.hpp"

using namespace ui;

namespace ui::external_app::extsensors {

class ExtSensorsView : public View {
public:
ExtSensorsView(NavigationView& nav);
~ExtSensorsView();

void focus() override;

std::string title() const override {
return "ExtSensor";
};

private:
NavigationView& nav_;

bool has_data = false;

Labels labels{
{{0 * 8, 3 * 16}, "GPS:", Color::light_grey()},
{{0 * 8, 5 * 16}, "ORI:", Color::light_grey()},
{{0 * 8, 7 * 16}, "ENV:", Color::light_grey()}};

Text text_info{{0 * 8, 0 * 8, 30 * 8, 16 * 1}, "Connect a compatible module..."};
Text text_gps{{5 * 8, 3 * 16, 24 * 8, 16}, "-"};
Text text_orientation{{5 * 8, 5 * 16, 24 * 8, 16}, "-"};
Text text_envl1{{5 * 8, 7 * 16, 24 * 8, 16}, "-"};
Text text_envl2{{1 * 8, 9 * 16, 24 * 8, 16}, "-"};

void on_any();

void on_gps(const GPSPosDataMessage* msg);
void on_orientation(const OrientationDataMessage* msg);
void on_environment(const EnvironmentDataMessage* msg);

MessageHandlerRegistration message_handler_gps{
Message::ID::GPSPosData,
[this](Message* const p) {
const auto message = static_cast<const GPSPosDataMessage*>(p);
this->on_gps(message);
}};
MessageHandlerRegistration message_handler_orientation{
Message::ID::OrientationData,
[this](Message* const p) {
const auto message = static_cast<const OrientationDataMessage*>(p);
this->on_orientation(message);
}};

MessageHandlerRegistration message_handler_environment{
Message::ID::EnvironmentData,
[this](Message* const p) {
const auto message = static_cast<const EnvironmentDataMessage*>(p);
this->on_environment(message);
}};
};
}; // namespace ui::external_app::extsensors

#endif /*__UI_EXTSENSORS_H__*/
27 changes: 24 additions & 3 deletions firmware/application/usb_serial_shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,13 +922,33 @@ static void cmd_gotgps(BaseSequentialStream* chp, int argc, char* argv[]) {
}

static void cmd_gotorientation(BaseSequentialStream* chp, int argc, char* argv[]) {
const char* usage = "usage: gotorientation <angle>\r\n";
if (argc != 1) {
const char* usage = "usage: gotorientation <angle> [tilt]\r\n";
if (argc != 1 && argc != 2) {
chprintf(chp, usage);
return;
}
uint16_t angle = strtol(argv[0], NULL, 10);
OrientationDataMessage msg{angle};
int16_t tilt = 400;
if (argc >= 2) tilt = strtol(argv[1], NULL, 10);
OrientationDataMessage msg{angle, tilt};
EventDispatcher::send_message(msg);
chprintf(chp, "ok\r\n");
}

static void cmd_gotenv(BaseSequentialStream* chp, int argc, char* argv[]) {
const char* usage = "usage: gotenv <temperature> [humidity] [pressure] [light]\r\n";
if (argc < 1 || argc > 4) {
chprintf(chp, usage);
return;
}
float temp = atof(argv[0]);
float humi = 0;
float pressure = 0;
uint16_t light = 0;
if (argc > 1) humi = atof(argv[1]);
if (argc > 2) pressure = atof(argv[2]);
if (argc > 3) light = strtol(argv[3], NULL, 10);
EnvironmentDataMessage msg{temp, humi, pressure, light};
EventDispatcher::send_message(msg);
chprintf(chp, "ok\r\n");
}
Expand Down Expand Up @@ -1055,6 +1075,7 @@ static const ShellCommand commands[] = {
{"appstart", cmd_appstart},
{"gotgps", cmd_gotgps},
{"gotorientation", cmd_gotorientation},
{"gotenv", cmd_gotenv},
{"sysinfo", cmd_sysinfo},
{"radioinfo", cmd_radioinfo},
{"pmemreset", cmd_pmemreset},
Expand Down
27 changes: 25 additions & 2 deletions firmware/common/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class Message {
SubGhzDData = 62,
GPSPosData = 63,
OrientationData = 64,
EnvironmentData = 65,
MAX
};

Expand Down Expand Up @@ -1328,11 +1329,33 @@ class GPSPosDataMessage : public Message {
class OrientationDataMessage : public Message {
public:
constexpr OrientationDataMessage(
uint16_t angle = 400)
uint16_t angle = 400,
int16_t tilt = 400)
: Message{ID::OrientationData},
angle{angle} {
angle{angle},
tilt{tilt} {
}
uint16_t angle = 400; //>360 -> no orientation set
int16_t tilt = 400;
};

class EnvironmentDataMessage : public Message {
public:
constexpr EnvironmentDataMessage(
float temperature = 0,
float humidity = 0,
float pressure = 0,
uint16_t light = 0)
: Message{ID::EnvironmentData},
temperature{temperature},
humidity{humidity},
pressure{pressure},
light{light} {
}
float temperature = 0; // celsius
float humidity = 0; // percent (rh)
float pressure = 0; // hpa
uint16_t light = 0; // lux
};

#endif /*__MESSAGE_H__*/
Loading

0 comments on commit 2648f18

Please sign in to comment.