Skip to content

Commit

Permalink
Add Settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
andreock committed Jan 3, 2025
1 parent 7bb78db commit 3537e9a
Show file tree
Hide file tree
Showing 12 changed files with 392 additions and 7 deletions.
40 changes: 40 additions & 0 deletions lib/SubGHZ/SubGHZ.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* This file is part of the Capibara zero (https://github.com/CapibaraZero/fw or
* https://capibarazero.github.io/). Copyright (c) 2025 Andrea Canale.
*
* 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, version 3.
*
* 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. If not, see <http://www.gnu.org/licenses/>.
*/

#include "SubGHZ.hpp"

#include <Arduino.h>
Expand Down Expand Up @@ -96,6 +113,29 @@ void SubGHZ::init_receive() {
radio.receiveDirect();
}

int16_t SubGHZ::get_chip_version() {
int16_t version = 0;
#ifndef CC1101_SUBGHZ
SPI2.begin(SX1276_SCK, SX1276_MISO, SX1276_MOSI, _csn);
if(radio.beginFSK() == RADIOLIB_ERR_NONE) {
version = radio.getChipVersion();
}
#else
SPI2.begin(CC1101_SCK, CC1101_MISO, CC1101_MOSI, _csn);
digitalWrite(CC1101_CS, HIGH);

int state = radio.begin(315);
if (state != RADIOLIB_ERR_NONE) {
Serial.print("Error initializing CC1101");
Serial.printf("Status: %i\n", state);
} else {
Serial.println("Initialized correctly");
version = radio.getChipVersion();
}
#endif
return version;
}

void SubGHZ::stop_receive() {
#ifdef ESP32S3_DEVKITC_BOARD
radio.clearDio1Action();
Expand Down
18 changes: 18 additions & 0 deletions lib/SubGHZ/SubGHZ.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* This file is part of the Capibara zero (https://github.com/CapibaraZero/fw or
* https://capibarazero.github.io/). Copyright (c) 2025 Andrea Canale.
*
* 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, version 3.
*
* 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. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef SUBGHZ_LIBRARY_H
#define SUBGHZ_LIBRARY_H

Expand Down Expand Up @@ -53,6 +70,7 @@ class SubGHZ {
SignalStrength scan_frequency(float freq, float bw = 200.0F,
float deviation = 47.0F);
SignalStrength scan_frequency();
int16_t get_chip_version();
void rec_signal(std::vector<byte> *orig_signal);
void send_signal(float freq, Modulation modulation, byte *payload,
size_t length);
Expand Down
46 changes: 46 additions & 0 deletions lib/UI/navigation/Settings/SettingsNavigation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This file is part of the Capibara zero (https://github.com/CapibaraZero/fw or
* https://capibarazero.github.io/). Copyright (c) 2025 Andrea Canale.
*
* 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, version 3.
*
* 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. If not, see <http://www.gnu.org/licenses/>.
*/

#include "../../pages/Settings/SettingsPage.hpp"
#include "gui.hpp"
#include "../navigation.hpp"
#include "../../navigation/SubGHZ/SubGHZNavigation.hpp"

static SettingsPage *settings = nullptr;
static Gui *gui = nullptr;

void goto_back_to_home() {
init_main_gui();
}

void goto_settings_ui() {
String subghz_rev = get_subghz_chip_revision();
size_t pos_limit = SD.cardType() != CARD_NONE ? 11 : 9;
size_t lower_limit = SD.cardType() != CARD_NONE ? 5 : 3;
#if !defined(WAKEUP_PIN)
pos_limit--;
lower_limit--;
#endif
settings = new SettingsPage(pos_limit, lower_limit, 1, gui->get_screen(), gui);
gui->reset();
settings->display(subghz_rev);
gui->set_current_page(settings, false);
}

void init_settings_navigation(Gui *_gui) {
gui = _gui;
}
22 changes: 22 additions & 0 deletions lib/UI/navigation/Settings/SettingsNavigation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* This file is part of the Capibara zero (https://github.com/CapibaraZero/fw or
* https://capibarazero.github.io/). Copyright (c) 2025 Andrea Canale.
*
* 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, version 3.
*
* 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. If not, see <http://www.gnu.org/licenses/>.
*/

#include "gui.hpp"

void goto_settings_ui();
void init_settings_navigation(Gui *_gui);
void goto_back_to_home();
31 changes: 31 additions & 0 deletions lib/UI/navigation/SubGHZ/SubGHZNavigation.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* This file is part of the Capibara zero (https://github.com/CapibaraZero/fw or
* https://capibarazero.github.io/). Copyright (c) 2025 Andrea Canale.
*
* 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, version 3.
*
* 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. If not, see <http://www.gnu.org/licenses/>.
*/

#include <LittleFS.h>

#include "../../../../include/debug.h"
Expand Down Expand Up @@ -176,3 +193,17 @@ void init_subghz_navigation(Gui *_gui) {
CC1101_IO0, CC1101_IO2);
#endif
}

String get_subghz_chip_revision() {
#ifndef CC1101_SUBGHZ
subghz_module = new SubGHZ(SD_CARD_SCK, SX1276_MISO, SD_CARD_MOSI, SX1276_NSS,
SX1276_DIO1, SX1276_DIO2);
#else
subghz_module = new SubGHZ(SD_CARD_SCK, CC1101_MISO, SD_CARD_MOSI, CC1101_CS,
CC1101_IO0, CC1101_IO2);
#endif
String version = "";
version = subghz_module->get_chip_version();
delete subghz_module;
return version;
}
18 changes: 17 additions & 1 deletion lib/UI/navigation/SubGHZ/SubGHZNavigation.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* This file is part of the Capibara zero (https://github.com/CapibaraZero/fw or
* https://capibarazero.github.io/). Copyright (c) 2025 Andrea Canale.
*
* 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, version 3.
*
* 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. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef SUBGHZ_NAVIGATION_H
#define SUBGHZ_NAVIGATION_H
Expand All @@ -22,5 +38,5 @@ void set_subghz_sender_freq(float freq);
void set_subghz_sender_bandwidth(float bandwidth);
void set_subghz_sender_deviation(float deviation);
void set_subghz_sender_modulation(int modulation);

String get_subghz_chip_revision();
#endif
115 changes: 115 additions & 0 deletions lib/UI/pages/Settings/SettingsPage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* This file is part of the Capibara zero (https://github.com/CapibaraZero/fw or
* https://capibarazero.github.io/). Copyright (c) 2025 Andrea Canale.
*
* 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, version 3.
*
* 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. If not, see <http://www.gnu.org/licenses/>.
*/

#include "SettingsPage.hpp"
#include "../../i18n.hpp"
#include "../../navigation/NFC/NFCNavigation.hpp"
#include "../../navigation/Settings/SettingsNavigation.hpp"
#include "gui.hpp"
#include "../../../../include/device_info.h"
#include "battery_monitor.hpp"
#include "DeepSleep.hpp"

extern String fw_md5; // From main.cpp

SettingsPage::~SettingsPage() {
delete version;
delete chip;
delete board_widget;
delete heap_usage;
delete battery;
if(sd_card_installed()) {
delete sd_card;
delete sd_card_size;
}
delete nfc_version;
delete subghz;
#if defined(WAKEUP_PIN)
delete deep_sleep;
#endif
delete reboot;
delete go_back;
}

void SettingsPage::display(String subghz_rev) {
bool _sd_card_installed = sd_card_installed();

grid = new Grid(screen, _sd_card_installed ? 12 : 9, 1);
grid->set_y_spacing(10);

version = new Text(screen, ST77XX_WHITE, (String)"Version: " + VERSION + " " + fw_md5.substring(0, 6));
String board = "";
#ifdef ESP32S3_DEVKITC_BOARD
board = "ESP32-S3 DevKitC";
#elif ARDUINO_NANO_ESP32
board = "Arduino Nano ESP32";
#elif LILYGO_T_EMBED_CC1101
board = "LilyGo T-Embed CC1101";
#else
board = "Unknown";
#endif
board_widget = new Text(screen, ST77XX_WHITE, board);
heap_usage = new Text(screen, ST77XX_WHITE, "Heap: " +(String)((ESP.getHeapSize() - ESP.getFreeHeap()) / (1024)) + "/" + (ESP.getHeapSize() / (1024)) + "KB");
chip = new Text(screen, ST77XX_WHITE, (String)"Chip: " + DEVICE + " " + ESP.getChipRevision() + " " + ESP.getCpuFreqMHz() + " MHz");
battery = new Text(screen, ST77XX_WHITE, (String)"Battery: " + read_battery_level() + "%");

if(_sd_card_installed) {
sd_card = new Text(screen, ST77XX_WHITE, "SD Card type: " + get_current_sd_type());
sd_card_size = new Text(screen, ST77XX_WHITE, (String)"SD Card usage: " + (float)SD.usedBytes() / (1024 * 1024 * 1024) + "/" + SD.cardSize() / (1024 * 1024 * 1024) + "GB");
}

nfc_version = new Text(screen, ST77XX_WHITE, "PN532 version: " + get_current_pn532_version());

#ifdef CC1101_SUBGHZ
String subghz_module = "CC1101";
#else
String subghz_module = "SX1276";
#endif
subghz = new Text(screen, ST77XX_WHITE, "SubGHZ module: " + subghz_module + " 0x" + subghz_rev);

#if defined(WAKEUP_PIN)
deep_sleep = new List(screen, "Deep Sleep", 2, ST77XX_WHITE, 20, ST77XX_BLACK, go_deep_sleep);
#endif
reboot = new List(screen, "Reboot", 2, ST77XX_WHITE, 20, ST77XX_BLACK, [] () { ESP.restart(); });
go_back = new List(screen, "Go back", 2, ST77XX_WHITE, 20, ST77XX_BLACK, goto_back_to_home);

grid->add(version);
grid->add(chip);
grid->add(board_widget);
grid->add(heap_usage);
grid->add(battery);

if(_sd_card_installed) {
grid->add(sd_card);
grid->add(sd_card_size);
}

grid->add(nfc_version);
grid->add(subghz);

#if defined(WAKEUP_PIN)
grid->add(deep_sleep);
#endif
grid->add(reboot);
grid->add(go_back);
size_t lower_limit = _sd_card_installed ? 5 : 3;
#if !defined(WAKEUP_PIN)
lower_limit--;
#endif
grid->set_selected(lower_limit, true);
grid->display();
}
Loading

0 comments on commit 3537e9a

Please sign in to comment.