Compare commits

...

152 Commits

Author SHA1 Message Date
Kyle Reed a832bd433d Fileman icon toolbar (#975)
* Add cut/copy/paste menu with icons
* Add icons, file limit to fileman
2023-05-11 22:46:38 +02:00
Brumi-2021 f9fdeb3419 Adding the 3 x WFM BW filters to Mic App (#976)
adding the 3 x WFM BW filters to Mic App and other minor msg correction and adding comments to code
2023-05-11 22:45:32 +02:00
gullradriel 3c2fc74f82 Recon skip fix (#974)
* definitely fixed, tested, documented bad consecutive match skip problem
* stability fix for config when no list
* fixed boundaries
* replaced 1000000 by #define OneMHz 1000000
2023-05-11 22:42:46 +02:00
gullradriel 69927e3c2d All logs to LOGS directory (#973)
* Added #define LOG_ROOT_DIR
* using LOG_ROOT_DIR as root path of log
2023-05-11 21:56:24 +02:00
jLynx 1edd3716a1 Revert "specific directory for screens and logs (#971)" (#972)
This reverts commit bc1ad5598c.
2023-05-11 11:44:19 +12:00
gullradriel bc1ad5598c specific directory for screens and logs (#971)
* Changed to LOGS directory, creating if not existing. Adjusted to upper case.
* Changed to SCREENSHOTS directory, creating if not existing
2023-05-10 21:11:06 +02:00
Kyle Reed 8cae998146 Fileman copy/paste support (#970)
* Add copy/paste UI instead of file save
2023-05-10 18:51:09 +02:00
gullradriel 9a22a760ad Record button remove (#968)
* removed unused debug and record buttons
* added log checkbox
* changed ignore and log to false at app start for pocsag
* fixed warning: suggest parentheses around arithmetic in operand of '^' proc signal
* ui comsetic fix
2023-05-10 14:12:49 +02:00
gullradriel 909b00bdae Fixing units KHz => kHz (#967)
Co-authored-by: GullCode <gullradriel@hotmail.com>
2023-05-10 13:26:21 +02:00
gullradriel 58e731c56e Wfm freqm options (#966)
* added WFM 180K and 40K options in freqman
* Make audio app use freqman funcs to load modulations bandwidths
2023-05-10 13:16:23 +02:00
wifwucite 04e77e0ee8 Update PRESETS.TXT (#962)
LoRa bands added
2023-05-08 22:03:45 +02:00
Mark Thompson 55b93a7044 Update Looking Glass PRESETS.TXT to add yet more bands (#964)
Added FM RADIO, AVIATION, AMATEUR RADIO (HAM), and ITU-defined FREQ BANDS.  (we do realize that 902-928MHz is also used for ISM, and that FM list is having two nearly identical bands.)
2023-05-08 21:58:15 +02:00
Kyle Reed f22046eccc Add "Auto" mode to FrequencyField (#959)
* Add "Auto" mode to FrequencyField
* Use exponential function instead of hyperbolic
* Fix tabs
* Back to hyperbolic, better feel
2023-05-07 22:01:43 +02:00
Brumi-2021 dfadd38e32 Adding 2 WFM filters more to current Audio App ( bw 180Khz and 40 khz to support rx for weather NOAA APT) (#961)
* First part new filter 40k for NOAA in Audio App

* Adding a third WFM filter 180Khz general pursose
2023-05-07 16:08:45 +02:00
jLynx 3cb927c840 Delete sdcard/FIRMWARE directory 2023-05-06 08:19:26 +12:00
jLynx 8ba5715db0 Update version.txt 2023-05-06 08:03:59 +12:00
jLynx c7e8506ad0 Update past_version.txt 2023-05-06 08:03:44 +12:00
gullradriel 8cb0a91bb5 Merge pull request #958 from gullradriel/recon-skip-fix
fix skip consecutive match
2023-05-05 17:03:00 +02:00
GullCode 1bcbefeb96 fix skip consecutive match 2023-05-05 17:01:08 +02:00
gullradriel 31031edbd1 Merge pull request #956 from bernd-herzog/boot_improvements
removed need for cpld mode setup for QFP100
2023-05-05 15:37:58 +02:00
bernd-herzog 7116f92d07 fixed spelling 2023-05-05 13:39:04 +02:00
bernd-herzog df8e79f9e6 refactoring 2023-05-05 12:58:28 +02:00
bernd-herzog e80e4e3bfd refactoring 2023-05-05 12:58:14 +02:00
bernd-herzog da6c6bb03c refactoring 2023-05-05 12:46:59 +02:00
bernd-herzog 75718c79b9 removed need for cpld mode setup for QFP100 2023-05-05 11:15:49 +02:00
gullradriel 9b263def37 Merge pull request #954 from gullradriel/recon-fix
Recon fix
2023-05-04 15:27:47 +02:00
GullCode c7d88da1a6 restoring bad substitue on text_ctcss filler 2023-05-04 15:26:33 +02:00
GullCode 7b6f8b271c Fixed so ui glitches, start when empty file and direct click on config. Added yellow coloration when loaded file was truncated (too big). Added/changed some error messages 2023-05-04 15:20:12 +02:00
GullCode 1b18b3ac45 fixing limit so we can detect if a list is the same size as the limit or truncated 2023-05-04 15:19:13 +02:00
gullradriel 68fc2a143f Merge pull request #953 from gullradriel/freqman-limits
fixing freqman limits
2023-05-04 12:11:15 +02:00
GullCode 1deebaff09 fixing freqman limits 2023-05-04 12:09:42 +02:00
gullradriel d6118c9fc4 Merge pull request #951 from kallanreed/fileloadview-fix
Fix nav.pop order on FileLoadView
2023-05-04 07:43:54 +02:00
Kyle Reed 44a62aef21 Fix nav.pop order on FileLoadView 2023-05-03 15:29:01 -07:00
gullradriel 0742fc169d Merge pull request #950 from kallanreed/fileman_ux2
Fileman fit and finish
2023-05-03 22:32:00 +02:00
Kyle Reed 62859f901f Fix indents 2023-05-03 13:23:15 -07:00
Kyle Reed c6316f5aa6 Fileman fit and finish 2023-05-03 13:13:15 -07:00
gullradriel 5f2043d229 Merge pull request #949 from gullradriel/pmem-defaults
Pmem defaults
2023-05-03 19:51:47 +02:00
gullradriel 074658c4bb Merge branch 'eried:next' into pmem-defaults 2023-05-03 19:51:15 +02:00
GullCode d641ae5b47 Fixed size of things 2023-05-03 19:50:12 +02:00
gullradriel bec70b4ee5 Merge pull request #948 from gullradriel/pmem-defaults
Pmem defaults
2023-05-03 19:48:05 +02:00
GullCode c4373d1560 indentation 2023-05-03 19:45:01 +02:00
GullCode 1dae2c0d25 indentation 2023-05-03 19:44:08 +02:00
GullCode 658d0c9b3a Added reset persitent memory 2023-05-03 19:42:57 +02:00
gullradriel 2f343adf21 Merge pull request #941 from kallanreed/fileman_ux
Fileman UI and Perf Fixes
2023-05-03 17:13:05 +02:00
gullradriel f7a5f2c437 Merge pull request #946 from Brumi-2021/noise_Signal_Generator_LFSR_polynomial_of_16_32_bits
Leaving only 1 Noise signal generator GUI option , (the best one , using  LFSR polynomial of 16 bits)
2023-05-03 13:57:06 +02:00
Brumi-2021 5a336d5e71 Compact with unique, best Noise Gererator option. 2023-05-03 13:49:50 +02:00
gullradriel 91675e26cb Merge pull request #945 from bernd-herzog/touchscreen_multiinput_fix
fixed touch handling issue causing multiple inputs
2023-05-03 11:43:34 +02:00
bernd-herzog 078da8ca16 Improved sensitivity for non pointy touches 2023-05-03 11:18:37 +02:00
bernd-herzog 77260bc68a fixed touch handling issue causing multiple inputs 2023-05-03 10:47:43 +02:00
gullradriel ca143f9788 Merge pull request #944 from joyel24/meteomodem-M20-radiosondes-altitude
Add Meteomodem M20 radiosondes altitude
2023-05-03 06:31:47 +02:00
Kyle Reed 3fc23354ce Fix path separator, revert UI 2023-05-02 20:49:41 -07:00
joyel24 d48e25167f fix altitude inaccuracy 2023-05-03 05:37:31 +02:00
joyel24 cfe5a6bfe4 Merge branch 'eried:next' into meteomodem-M20-radiosondes-altitude 2023-05-03 02:09:20 +02:00
Brumi-2021 d77102426a Finally Noise Signal with best option 16 bit LFSR 2023-05-02 21:29:35 +02:00
Kyle Reed 11f4edc892 Modal dialog for partner file action, fix lifetime 2023-05-02 09:38:08 -07:00
Brumi-2021 804fa0d3c4 Minor GUI corrections-Signal Generator 2023-05-02 17:41:00 +02:00
Brumi-2021 d5f20c45b9 Adding 16 bit LFSR , to Noise Signal Generator App 2023-05-02 17:19:23 +02:00
Kyle Reed 2cba96ff36 Support for partner file rename/delete 2023-05-01 09:25:32 -07:00
Joel M 7139abb947 alt divided by 100 2023-05-01 16:54:29 +02:00
Kyle Reed bf4ed416bd Remove expensive path.string() calls, UI changes 2023-04-30 22:42:28 -07:00
gullradriel 06643df6a5 Merge pull request #938 from gullradriel/pmemsettings-create-folder
Added SETTINGS folder creating for PMem files
2023-04-30 18:42:51 +02:00
GullCode 81752c8d78 Added SETTINGS folder creating for PMem files 2023-04-30 18:41:24 +02:00
gullradriel 0cb8c9200a Merge pull request #937 from gullradriel/hackrf-flashing-tool-update
Updating to release 2023.01.1
2023-04-30 18:27:41 +02:00
GullCode 8e64221384 Updating to release 2023.01.1 https://github.com/greatscottgadgets/hackrf/releases/tag/v2023.01.1 2023-04-30 18:26:22 +02:00
gullradriel fe1837ec23 Merge pull request #936 from Brumi-2021/solving_bug_in_noise_option_Signal_Generator_tool
Solving Noise generation in Signal gen App
2023-04-30 17:33:18 +02:00
Brumi-2021 ee53b28e60 Solving Noise generation in Signal gen App 2023-04-30 18:03:40 +02:00
gullradriel 18c986cd76 Merge pull request #931 from kallanreed/cursor_text_input
Add a TextField widget that supports a cursor.
2023-04-30 17:28:42 +02:00
gullradriel a1c3cbcea9 Merge pull request #935 from gullradriel/looking-glass-update
Looking glass update
2023-04-30 15:01:57 +02:00
GullCode 1135a42932 better roundings/per pixel marker 2023-04-30 14:56:17 +02:00
Joel M a74d0e5167 altitude 3 bytes 2023-04-30 13:59:21 +02:00
gullradriel c5579e25fd Merge pull request #932 from joyel24/meteomodem-M20-radiosondes
Identifying meteomodem m20 radiosondes & extract GNSS location
2023-04-30 13:25:42 +02:00
Joel M e8b8f0ca5c Disable inaccurate altitude for the moment 2023-04-30 12:06:37 +02:00
GullCode 98e7116230 Changed to per pixel marker, short freq display, adjusted <24Mhz view to look like SPEC one 2023-04-29 21:46:19 +02:00
Joel M c916eaf43f Detects M20 radiosondes and decode GNSS location 2023-04-29 14:00:28 +02:00
Joel M e3169a3495 add Meteomodem_M20 to packet class in sonde_packet.hpp 2023-04-29 13:49:27 +02:00
Kyle Reed 4b37f1bb2f Add a TestField widget that supports a cursor. 2023-04-28 19:26:53 -07:00
gullradriel cb93f2636e Merge pull request #929 from gullradriel/freq-disp-fix
Freq disp fix
2023-04-28 13:01:12 +02:00
GullCode 596c304b08 Took out unused func declaration 2023-04-28 12:59:51 +02:00
GullCode 63f7be02b6 Used correct to_string_short_freq instead of erroneous calculation 2023-04-28 12:57:00 +02:00
GullCode de99afa19b Took out unused func declaration 2023-04-28 12:55:58 +02:00
gullradriel 5c4e27ea29 Merge pull request #927 from gullradriel/dsp-warning-fix
Dsp warning fix
2023-04-27 16:08:18 +02:00
GullCode 54e4230191 indentation 2023-04-27 16:07:57 +02:00
GullCode f069383c2a Fix unused warnings in ssb_execute 2023-04-27 16:06:47 +02:00
gullradriel d3a356d415 Merge pull request #926 from gullradriel/gitignore-fix
restoring gitignore
2023-04-27 15:51:54 +02:00
GullCode f0e4fdcbcc restoring gitignore, bad move on last commit 2023-04-27 15:50:59 +02:00
ittercho d5f6f42fae Addition of water meters (#892)
Water Meters frequency list
NRK and RMF radio stations frequencies list
Fixed and ordered as much as possible PRESETS.TXT
Co-authored-by: gullradriel
2023-04-27 15:44:32 +02:00
gullradriel 7a89858cc6 Merge pull request #925 from gullradriel/level-mem-workaround
Automatically reduce rssi graph history
2023-04-27 15:42:06 +02:00
gullradriel 15c9a76536 Merge pull request #924 from bernd-herzog/dfu_menu
added frame drop rate for m4 signal processing
2023-04-27 15:41:46 +02:00
GullCode d7359a8cd5 Automatically reduce rssi graph history when hidden, restore size on show. Prevent Memory exhaustion in apps like 'Level' or any app eating a bit too much mem before launching a FrequencyPadView 2023-04-27 15:38:29 +02:00
Bernd Herzog 50e5bc60ee added frame miss rate for m4 signal processing 2023-04-26 22:28:14 +02:00
jLynx 9385be4f1e Merge pull request #920 from zxkmm/ready_to_pr_2_20230426_imp_issue_917
implemented issue#917
2023-04-27 07:01:02 +12:00
zxkmmOnHaseeWSL 9cddab9a5e fix mistakenly remane dir as file -- credit:Gull 2023-04-26 19:09:38 +08:00
zxkmmOnHaseeWSL 6e01a1d0dc change ?: to if else 2023-04-26 16:20:05 +08:00
gullradriel f73cd39d2d Merge pull request #922 from NotherNgineer/next
#910 Brighter color for .C8/.C16 files in fileman
2023-04-26 09:29:57 +02:00
Mark Thompson 0303c658ea Brighter color for .C8/.C16 files in fileman
See https://github.com/eried/portapack-mayhem/issues/910
2023-04-26 02:04:37 -05:00
gullradriel 94ddb63b1d Merge pull request #921 from zxkmm/ready_to_pr_20230426_3_textual_change_for_flash_unity
textual change for  the flash unity
2023-04-26 08:29:51 +02:00
gullradriel b1aa607a7c Merge pull request #907 from NotherNgineer/next
Support for ERT SCM+ meter protocol
2023-04-26 08:28:39 +02:00
Mark Thompson 509f86c1f7 Merge branch 'eried:next' into next 2023-04-26 01:25:46 -05:00
zxkmmOnHaseeWSL b45ca43e27 textual change for the flash unity 2023-04-26 13:29:11 +08:00
zxkmmOnHaseeWSL 47482d1e58 fixed var.clear 2023-04-26 13:22:50 +08:00
zxkmmOnHaseeWSL 59dfe5b50b implemented issue#917 2023-04-26 13:01:51 +08:00
Mark Thompson b1f5023fe1 Removed unneeded space characters 2023-04-24 15:29:51 -05:00
gullradriel a54b94fe53 Merge pull request #915 from gullradriel/recon-update
Recon description flashing on range fix
2023-04-24 21:15:56 +02:00
GullCode 45bdabcef9 Fix for description being updated at each step on a range 2023-04-24 21:14:34 +02:00
Mark Thompson 6cdada1118 Include ERT packet type in ert.txt log file 2023-04-24 09:59:43 -05:00
gullradriel cffc72c516 Merge pull request #913 from gullradriel/looking-glass-zoom
Looking glass zoom update
2023-04-24 13:56:04 +02:00
GullCode e53514aa12 tweaking scan start values and ranges, allowing <24MHz range 2023-04-24 13:51:31 +02:00
Bernd Herzog 775de5ce6f Merge pull request #912 from bernd-herzog/dfu_menu
improved stability of cpu usage calculation
2023-04-24 13:05:36 +02:00
Bernd Herzog 4ff92be23b refactoring 2023-04-24 13:04:59 +02:00
Bernd Herzog 948d8d947e improved stability of cpu usage calculation 2023-04-24 13:00:34 +02:00
jLynx 55c300ac4b Merge pull request #909 from bernd-herzog/dfu_menu
Dfu menu
2023-04-24 10:26:11 +12:00
Bernd Herzog 29b7a5ee56 improved m4 m0 communication 2023-04-23 23:48:20 +02:00
Bernd Herzog 2ef9ebd7bd implemented M4 stats 2023-04-23 21:48:45 +02:00
Bernd Herzog 850a79c9bb added m0 stats to dfu screen 2023-04-23 19:52:38 +02:00
Bernd Herzog 812f0f8211 added overlay to system view 2023-04-23 16:21:33 +02:00
jLynx d00c21adb7 Merge pull request #908 from zxkmm/ready_to_pr_20230423_fix_stealth_in_replay
fix stealth doesn't work
2023-04-23 21:11:45 +12:00
zxkmmOnHaseeWSL 925c1548a8 fix stealth doesn't work 2023-04-23 16:47:06 +08:00
jLynx cd1f1bd388 Merge pull request #906 from zxkmm/fix_fileman_refactor
fix last commit aka fileman refactor exception
2023-04-23 19:12:40 +12:00
zxkmmOnHaseeWSL 474fe00146 formatting fix 2023-04-23 14:53:06 +08:00
Mark Thompson 44b2e5ea61 Support for ERT SCM+ meter protocol 2023-04-23 01:34:56 -05:00
Mark Thompson 48ed7b1b1a Support for ERT SCM+ meter protocol 2023-04-23 01:33:42 -05:00
Mark Thompson 6201be82ea Support for ERT SCM+ meter protocol 2023-04-23 01:31:45 -05:00
Mark Thompson fe1d296b48 Support for ERT SCM+ meter protocol 2023-04-23 01:29:51 -05:00
Mark Thompson 697876d86a Support for ERT SCM+ meter protocol 2023-04-23 01:26:37 -05:00
Brumi-2021 b72c765911 Merge pull request #904 from zxkmm/ready_to_pr_20230421
make the title touchable, and back/return when touch it
2023-04-22 21:39:10 +02:00
zxkmmOnHaseeWSL 2a14888b80 fix last commit aka fileman refactor exception 2023-04-22 22:58:10 +08:00
jLynx 99f1bded4d Merge pull request #905 from zxkmm/ready_to_pr_20230422
add Refactor in fileman app
2023-04-22 21:52:53 +12:00
zxkmmOnHaseeWSL d8e9fad205 fix indentation for pr 20230422-2 2023-04-22 17:51:31 +08:00
zxkmmOnHaseeWSL 0e8dc1567c fix indentation for pr 20230422 2023-04-22 17:50:21 +08:00
zxkmmOnHaseeWSL 4ff71dcfca add Refactor in fileman app 2023-04-22 17:21:51 +08:00
zxkmmOnHaseeWSL ed0f0eb15e touchable title, little width adjust again... sorry 2023-04-22 13:31:27 +08:00
zxkmmOnHaseeWSL 193a80edea smaller touchable title 2023-04-22 13:02:41 +08:00
zxkmmOnHaseeWSL df0c85db8f touchable title 2023-04-21 21:34:18 +08:00
Bernd Herzog c5738c46d5 Merge pull request #899 from bernd-herzog/dfu_menu
Dfu button
2023-04-17 08:17:21 +02:00
Bernd Herzog 0acf7ec2c2 refactoring 2023-04-16 20:33:02 +02:00
Bernd Herzog dc560ba01f improved debug app layout 2023-04-16 20:31:14 +02:00
Bernd Herzog d74fd92451 added dfu button to debug app 2023-04-16 19:51:06 +02:00
Bernd Herzog bcefa774cd added dfu button to debug app 2023-04-16 18:23:54 +02:00
gullradriel 8382eaf45f Merge pull request #896 from gullradriel/looking-fast-slow
Looking fast slow
2023-04-13 11:11:45 +02:00
GullCode 9f700a30c0 Changed text to MAX HOLD to make a difference with existing 'MAX' 2023-04-13 11:02:32 +02:00
GullCode d815e6c952 Merge branch 'next' of github.com:gullradriel/portapack-mayhem into looking-fast-slow 2023-04-13 10:38:13 +02:00
GullCode e60ec953ab move text and button a bit so it's fitting when big 2023-04-13 10:36:15 +02:00
GullCode 72d1e21fc6 added adjust_range, fast scan and slow scan, lock/unlock range, integer division results when possible, default step of 1 2023-04-13 10:18:16 +02:00
jLynx e4d42817ee Merge pull request #895 from JimiHFord/patch-1
fix typo
2023-04-13 16:16:19 +12:00
Jimi Ford 5729bde214 fix typo 2023-04-13 00:11:30 -04:00
gullradriel ec7a77896a Update ui_looking_glass_app.hpp
size of db is uint8_t, adjusting live-v and peak-v array to uint8_t
2023-04-11 20:41:42 +02:00
eried 99c26c3b7b Adding step files of the enclosure 2023-04-11 09:55:21 +02:00
Brumi-2021 aa20bff2b9 Merge pull request #887 from gullradriel/looking-glass-fix
Peak view entry menu and functionnalities
2023-04-10 23:10:19 +02:00
GullCode f5e949047d correct clear size in peak-v and live-v 2023-04-10 21:39:50 +02:00
GullCode afb75af5b1 removed redundant set_dirty 2023-04-09 22:32:35 +02:00
GullCode 7f99b1181e Added MAX:FREQ , RST , JMP on LIVE-V and PEAK-V. Ploter is having a y shift in these modes 2023-04-09 22:07:50 +02:00
GullCode cec0fe3288 Peak view entry menu and functionnalities 2023-04-09 14:45:07 +02:00
118 changed files with 35608 additions and 1029 deletions
+1 -1
View File
@@ -1 +1 @@
v1.5.4
v1.6.0
+1 -1
View File
@@ -1 +1 @@
v1.6.0
v1.7.0
+1
View File
@@ -13,6 +13,7 @@
/sdcard/FREQMAN/BHT*
/sdcard/FREQMAN/R.TXT
/sdcard/FREQMAN/XXX.TXT
/armbin
# Compiled Object files
*.slo
+1 -1
View File
@@ -39,7 +39,7 @@ The current **stable release** is on the [![GitHub release (latest by date)](htt
## How can I collaborate
You can write [documentation](https://github.com/eried/portapack-mayhem/wiki), fix bugs and [answer issues](https://github.com/eried/portapack-mayhem/issues) or add new functionality. Please check the following [guide](https://github.com/eried/portapack-mayhem/wiki/How-to-collaborate) with details.
Consider that the hardware and firmware has been created and maintain by a [lot](https://github.com/mossmann/hackrf/graphs/contributors) of [people](https://github.com/eried/portapack-mayhem/graphs/contributors), so always try colaborating your time and effort first. For coding related questions, if something does not fit as an issue, please join our Discord by clicking the chat badge on [top](#portapack-mayhem).
Consider that the hardware and firmware has been created and maintain by a [lot](https://github.com/mossmann/hackrf/graphs/contributors) of [people](https://github.com/eried/portapack-mayhem/graphs/contributors), so always try collaborating your time and effort first. For coding related questions, if something does not fit as an issue, please join our Discord by clicking the chat badge on [top](#portapack-mayhem).
[![Contributors](https://contrib.rocks/image?repo=eried/portapack-mayhem)](https://github.com/eried/portapack-mayhem/graphs/contributors)
+2
View File
@@ -155,6 +155,7 @@ set(CPPSRC
${COMMON}/ui_widget.cpp
${COMMON}/utility.cpp
${COMMON}/wm8731.cpp
${COMMON}/performance_counter.cpp
app_settings.cpp
audio.cpp
baseband_api.cpp
@@ -230,6 +231,7 @@ set(CPPSRC
apps/ui_nrf_rx.cpp
apps/ui_aprs_tx.cpp
apps/ui_bht_tx.cpp
apps/ui_dfu_menu.cpp
apps/ui_coasterp.cpp
apps/ui_debug.cpp
apps/ui_encoders.cpp
+2 -1
View File
@@ -98,9 +98,10 @@ ACARSAppView::ACARSAppView(NavigationView& nav) {
logging = v;
};
make_new_directory(LOG_ROOT_DIR);
logger = std::make_unique<ACARSLogger>();
if (logger)
logger->append("acars.txt");
logger->append( LOG_ROOT_DIR "/ACARS.TXT" );
}
ACARSAppView::~ACARSAppView() {
+2 -1
View File
@@ -397,9 +397,10 @@ AISAppView::AISAppView(NavigationView& nav) : nav_ { nav } {
this->on_show_list();
};
make_new_directory(LOG_ROOT_DIR);
logger = std::make_unique<AISLogger>();
if( logger ) {
logger->append(u"ais.txt");
logger->append( LOG_ROOT_DIR "/AIS.TXT" );
}
}
@@ -36,6 +36,8 @@ using namespace tonekey;
#include "string_format.hpp"
#include "freqman.hpp"
namespace ui {
/* AMOptionsView *********************************************************/
@@ -51,6 +53,7 @@ AMOptionsView::AMOptionsView(
&options_config,
});
freqman_set_bandwidth_option( AM_MODULATION , options_config ); // adding the common message from freqman.cpp to the options_config
options_config.set_selected_index(receiver_model.am_configuration());
options_config.on_change = [this](size_t n, OptionsField::value_t) {
receiver_model.set_am_configuration(n);
@@ -72,6 +75,7 @@ NBFMOptionsView::NBFMOptionsView(
&field_squelch
});
freqman_set_bandwidth_option( NFM_MODULATION , options_config ); // adding the common message from freqman.cpp to the options_config
options_config.set_selected_index(receiver_model.nbfm_configuration());
options_config.on_change = [this](size_t n, OptionsField::value_t) {
receiver_model.set_nbfm_configuration(n);
@@ -83,6 +87,27 @@ NBFMOptionsView::NBFMOptionsView(
};
}
/* WFMOptionsView *******************************************************/
WFMOptionsView::WFMOptionsView(
const Rect parent_rect, const Style* const style
) : View { parent_rect }
{
set_style(style);
add_children({
&label_config,
&options_config,
});
freqman_set_bandwidth_option( WFM_MODULATION , options_config ); // adding the common message from freqman.cpp to the options_config
options_config.set_selected_index(receiver_model.wfm_configuration());
options_config.on_change = [this](size_t n, OptionsField::value_t) {
receiver_model.set_wfm_configuration(n);
};
}
/* SPECOptionsView *******************************************************/
SPECOptionsView::SPECOptionsView(
@@ -346,6 +371,7 @@ void AnalogAudioView::on_show_options_modulation() {
break;
case ReceiverModel::Mode::WidebandFMAudio:
widget = std::make_unique<WFMOptionsView>(options_view_rect, &style_options_group);
waterfall.show_audio_spectrum_view(true);
text_ctcss.hidden(true);
break;
+20 -10
View File
@@ -54,12 +54,7 @@ private:
OptionsField options_config {
{ 3 * 8, 0 * 16 },
5,
{
{ "DSB 9k ", 0 },
{ "DSB 6k ", 0 },
{ "USB+3k ", 0 },
{ "LSB-3k ", 0 },
{ "CW ", 0 },
{ // using common messages from freqman.cpp
}
};
};
@@ -76,10 +71,7 @@ private:
OptionsField options_config {
{ 3 * 8, 0 * 16 },
4,
{
{ " 8k5", 0 },
{ "11k ", 0 },
{ "16k ", 0 },
{ // using common messages from freqman.cpp
}
};
@@ -96,6 +88,24 @@ private:
};
};
class WFMOptionsView : public View {
public:
WFMOptionsView(const Rect parent_rect, const Style* const style);
private:
Text label_config {
{ 0 * 8, 0 * 16, 2 * 8, 1 * 16 },
"BW",
};
OptionsField options_config {
{ 3 * 8, 0 * 16 },
3,
{ // using common messages from freqman.cpp
}
};
};
class AnalogAudioView;
class SPECOptionsView : public View {
+5 -2
View File
@@ -41,6 +41,7 @@ std::string type(Packet::Type value) {
case Packet::Type::Unknown: return "???";
case Packet::Type::IDM: return "IDM";
case Packet::Type::SCM: return "SCM";
case Packet::Type::SCMPLUS: return "SCM+";
}
}
@@ -62,7 +63,8 @@ std::string commodity_type(CommodityType value) {
void ERTLogger::on_packet(const ert::Packet& packet) {
const auto formatted = packet.symbols_formatted();
log_file.write_entry(packet.received_at(), formatted.data + "/" + formatted.errors);
std::string entry = ert::format::type(packet.type()) + " " + formatted.data + "/" + formatted.errors;
log_file.write_entry(packet.received_at(), entry);
}
const ERTRecentEntry::Key ERTRecentEntry::invalid_key { };
@@ -128,9 +130,10 @@ ERTAppView::ERTAppView(NavigationView&) {
static_cast<int8_t>(receiver_model.vga()),
}); */
make_new_directory(LOG_ROOT_DIR);
logger = std::make_unique<ERTLogger>();
if( logger ) {
logger->append(u"ert.txt");
logger->append( LOG_ROOT_DIR "/ERT.TXT" );
}
}
+2 -1
View File
@@ -129,9 +129,10 @@ POCSAGAppView::POCSAGAppView(NavigationView& nav) {
ignore_address /= 10;
}
make_new_directory(LOG_ROOT_DIR);
logger = std::make_unique<POCSAGLogger>();
if (logger)
logger->append("pocsag.txt");
logger->append( LOG_ROOT_DIR "/POCSAG.TXT" );
audio::output::start();
audio::output::unmute();
+14 -14
View File
@@ -64,8 +64,8 @@ private:
std::app_settings settings { };
std::app_settings::AppSettings app_settings { };
bool logging { true };
bool ignore { true };
bool logging { false };
bool ignore { false };
uint32_t last_address = 0xFFFFFFFF;
pocsag::POCSAGState pocsag_state { };
@@ -91,13 +91,7 @@ private:
FrequencyField field_frequency {
{ 0 * 8, 0 * 8 },
};
Checkbox check_log {
{ 24 * 8, 21 },
3,
"LOG",
true
};
NumberField field_volume{
NumberField field_volume{
{ 28 * 8, 0 * 16 },
2,
{ 0, 99 },
@@ -106,16 +100,22 @@ private:
};
Checkbox check_ignore {
{ 1 * 8, 21 },
12,
"Ignore addr:",
true
{ 0 * 8, 21 },
8,
"Ign addr",
false
};
SymField sym_ignore {
{ 16 * 8, 21 },
{ 13 * 8, 25 },
7,
SymField::SYMFIELD_DEC
};
Checkbox check_log {
{ 240 - 8 * 8, 21 },
3,
"LOG",
false
};
Console console {
{ 0, 3 * 16, 240, 256 }
+7 -1
View File
@@ -161,10 +161,16 @@ void ReplayAppView::start() {
sample_rate * 8,
baseband_bandwidth,
rf::Direction::Transmit,
rf_amp, // previous code line : "receiver_model.rf_amp()," was passing the same rf_amp of all Receiver Apps
rf_amp, // previous code line : "receiver_model.rf_amp()," was passing the same rf_amp of all Receiver Apps
static_cast<int8_t>(receiver_model.lna()),
static_cast<int8_t>(receiver_model.vga())
});
if (portapack::persistent_memory::stealth_mode()){
DisplaySleepMessage message;
EventDispatcher::send_message(message);
}
}
void ReplayAppView::stop(const bool do_loop) {
+1 -1
View File
@@ -206,7 +206,7 @@ void SoundBoardView::refresh_list() {
file_list[n].string().substr(0, 30),
ui::Color::white(),
nullptr,
[this](){
[this](KeyEvent){
on_select_entry();
}
});
+2 -1
View File
@@ -194,9 +194,10 @@ TPMSAppView::TPMSAppView(NavigationView&) {
options_temperature.set_selected_index(0, true);
make_new_directory(LOG_ROOT_DIR);
logger = std::make_unique<TPMSLogger>();
if( logger ) {
logger->append(u"tpms.txt");
logger->append( LOG_ROOT_DIR "/TPMS.TXT" );
}
}
+5 -2
View File
@@ -117,6 +117,8 @@ ADSBRxAircraftDetailsView::ADSBRxAircraftDetailsView(
std::unique_ptr<ADSBLogger> logger { };
make_new_directory(LOG_ROOT_DIR);
icao_code = to_string_hex(entry_copy.ICAO_address, 6);
text_icao_address.set(to_string_hex(entry_copy.ICAO_address, 6));
@@ -351,7 +353,7 @@ void ADSBRxView::sort_entries_by_state()
}
void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
logger = std::make_unique<ADSBLogger>();
logger = std::make_unique<ADSBLogger>();
rtc::RTC datetime;
std::string callsign;
std::string str_info;
@@ -422,6 +424,7 @@ void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
} else if(msg_type == AIRBORNE_VEL && msg_sub >= VEL_GND_SUBSONIC && msg_sub <= VEL_AIR_SUPERSONIC){
entry.set_frame_velo(frame);
if (logger) {
logger->append( LOG_ROOT_DIR "/ADSB.TXT" );
logentry += "Type:" + to_string_dec_uint(msg_sub) +
" Hdg:" + to_string_dec_uint(entry.velo.heading) +
" Spd: "+ to_string_dec_int(entry.velo.speed);
@@ -432,7 +435,7 @@ void ADSBRxView::on_frame(const ADSBFrameMessage * message) {
} // frame.get_DF() == DF_ADSB
if (logger) {
logger->append(u"adsb.txt");
logger->append( LOG_ROOT_DIR "/ADSB.TXT" );
// will log each frame in format:
// 20171103100227 8DADBEEFDEADBEEFDEADBEEFDEADBEEF ICAO:nnnnnn callsign Alt:nnnnnn Latnnn.nn Lonnnn.nn
logger->log_str(logentry);
+13 -13
View File
@@ -60,9 +60,9 @@ AFSKRxView::AFSKRxView(NavigationView& nav) {
&field_lna,
&field_vga,
&field_frequency,
&check_log,
&text_debug,
&button_modem_setup,
&record_view,
&console
});
@@ -74,13 +74,6 @@ AFSKRxView::AFSKRxView(NavigationView& nav) {
field_rf_amp.set_value(app_settings.rx_amp);
}
// DEBUG
record_view.on_error = [&nav](std::string message) {
nav.display_modal("Error", message);
};
record_view.set_sampling_rate(24000);
// Auto-configure modem for LCR RX (will be removed later)
update_freq(467225500); // 462713300
auto def_bell202 = &modem_defs[0];
@@ -105,13 +98,19 @@ AFSKRxView::AFSKRxView(NavigationView& nav) {
};
};
check_log.set_value(logging);
check_log.on_select = [this](Checkbox&, bool v) {
logging = v;
};
button_modem_setup.on_select = [&nav](Button&) {
nav.push<ModemSetupView>();
};
make_new_directory(LOG_ROOT_DIR);
logger = std::make_unique<AFSKLogger>();
if (logger)
logger->append("AFSK_LOG.TXT");
logger->append( LOG_ROOT_DIR "/AFSK.TXT" );
// Auto-configure modem for LCR RX (will be removed later)
baseband::set_afsk(persistent_memory::modem_baudrate(), 8, 0, false);
@@ -153,22 +152,23 @@ void AFSKRxView::on_data(uint32_t value, bool is_data) {
console.write(str_console);
if (logger) str_log += str_byte;
if (logger && logging) str_log += str_byte;
if ((value != 0x7F) && (prev_value == 0x7F)) {
// Message split
console.writeln("");
console_color++;
if (logger) {
if (logger && logging) {
logger->log_raw_data(str_log);
str_log = "";
}
}
prev_value = value;
} else {
}
else {
// Baudrate estimation
text_debug.set("~" + to_string_dec_uint(value));
text_debug.set("Baudrate estimation: ~" + to_string_dec_uint(value));
}
}
+11 -10
View File
@@ -64,6 +64,7 @@ private:
uint8_t console_color { 0 };
uint32_t prev_value { 0 };
std::string str_log { "" };
bool logging { false };
RFAmpField field_rf_amp {
{ 13 * 8, 0 * 16 }
@@ -85,23 +86,23 @@ private:
{ 0 * 8, 0 * 16 },
};
Text text_debug {
{ 0 * 8, 1 * 16, 10 * 8, 16 },
Checkbox check_log {
{ 0 * 8, 1 * 16 },
3,
"LOG",
false
};
Text text_debug {
{ 0 * 8, 12 + 2 * 16, 240, 16 },
"DEBUG"
};
Button button_modem_setup {
{ 12 * 8, 1 * 16, 96, 24 },
{ 240 - 12 * 8, 1 * 16, 96, 24 },
"Modem setup"
};
// DEBUG
RecordView record_view {
{ 0 * 8, 3 * 16, 30 * 8, 1 * 16 },
u"AFS_????", RecordView::FileType::WAV, 4096, 4
};
Console console {
{ 0, 4 * 16, 240, 240 }
};
+2 -1
View File
@@ -141,9 +141,10 @@ APRSRxView::APRSRxView(NavigationView& nav, Rect parent_rect) : View(parent_rect
options_region.set_selected_index(0, true);
make_new_directory(LOG_ROOT_DIR);
logger = std::make_unique<APRSLogger>();
if (logger)
logger->append("APRS_RX_LOG.TXT");
logger->append( LOG_ROOT_DIR "/APRS.TXT" );
baseband::set_aprs(1200);
-10
View File
@@ -54,9 +54,7 @@ BTLERxView::BTLERxView(NavigationView& nav) {
&field_lna,
&field_vga,
&field_frequency,
&text_debug,
&button_modem_setup,
&record_view,
&console
});
@@ -68,13 +66,6 @@ BTLERxView::BTLERxView(NavigationView& nav) {
field_rf_amp.set_value(app_settings.rx_amp);
}
// DEBUG
record_view.on_error = [&nav](std::string message) {
nav.display_modal("Error", message);
};
record_view.set_sampling_rate(24000);
// Auto-configure modem for LCR RX (will be removed later)
update_freq(2426000000);
auto def_bell202 = &modem_defs[0];
@@ -103,7 +94,6 @@ BTLERxView::BTLERxView(NavigationView& nav) {
nav.push<ModemSetupView>();
};
// Auto-configure modem for LCR RX (will be removed later)
baseband::set_btle(persistent_memory::modem_baudrate(), 8, 0, false);
+1 -14
View File
@@ -53,7 +53,6 @@ private:
uint8_t console_color { 0 };
uint32_t prev_value { 0 };
std::string str_log { "" };
RFAmpField field_rf_amp {
{ 13 * 8, 0 * 16 }
@@ -75,23 +74,11 @@ private:
{ 0 * 8, 0 * 16 },
};
Text text_debug {
{ 0 * 8, 1 * 16, 10 * 8, 16 },
"DEBUG"
};
Button button_modem_setup {
{ 12 * 8, 1 * 16, 96, 24 },
{ 240 - 12 * 8, 1 * 16, 96, 24 },
"Modem setup"
};
// DEBUG
RecordView record_view {
{ 0 * 8, 3 * 16, 30 * 8, 1 * 16 },
u"AFS_????", RecordView::FileType::WAV, 4096, 4
};
Console console {
{ 0, 4 * 16, 240, 240 }
};
+55 -17
View File
@@ -266,7 +266,9 @@ bool ControlsSwitchesWidget::on_key(const KeyEvent key) {
}
void ControlsSwitchesWidget::paint(Painter& painter) {
const std::array<Rect, 7> button_rects { {
const auto pos = screen_pos();
const std::array<Rect, 8> button_rects { {
{ 64, 32, 16, 16 }, // Right
{ 0, 32, 16, 16 }, // Left
{ 32, 64, 16, 16 }, // Down
@@ -274,27 +276,63 @@ void ControlsSwitchesWidget::paint(Painter& painter) {
{ 32, 32, 16, 16 }, // Select
{ 16, 96, 16, 16 }, // Encoder phase 0
{ 48, 96, 16, 16 }, // Encoder phase 1
{ 96, 0, 16, 16 }, // Dfu
} };
const auto pos = screen_pos();
auto switches_raw = control::debug::switches();
auto switches_debounced = get_switches_state().to_ulong();
auto switches_event = key_event_mask;
for(const auto r : button_rects) {
const auto c =
((switches_event & 1) ?
Color::red() :
((switches_debounced & 1) ?
Color::green() :
((switches_raw & 1) ?
Color::yellow() :
Color::blue()
)
)
);
painter.fill_rectangle(r + pos, c);
painter.fill_rectangle(r + pos, Color::blue());
}
const std::array<Rect, 8> raw_rects { {
{ 64 + 1, 32 + 1, 16 - 2, 16 - 2 }, // Right
{ 0 + 1, 32 + 1, 16 - 2, 16 - 2 }, // Left
{ 32 + 1, 64 + 1, 16 - 2, 16 - 2 }, // Down
{ 32 + 1, 0 + 1, 16 - 2, 16 - 2 }, // Up
{ 32 + 1, 32 + 1, 16 - 2, 16 - 2 }, // Select
{ 16 + 1, 96 + 1, 16 - 2, 16 - 2 }, // Encoder phase 0
{ 48 + 1, 96 + 1, 16 - 2, 16 - 2 }, // Encoder phase 1
{ 96 + 1, 0 + 1, 16 - 2, 16 - 2 }, // Dfu
} };
auto switches_raw = control::debug::switches();
for(const auto r : raw_rects) {
if (switches_raw & 1)
painter.fill_rectangle(r + pos, Color::yellow());
switches_raw >>= 1;
}
const std::array<Rect, 6> debounced_rects { {
{ 64 + 2, 32 + 2, 16 - 4, 16 - 4 }, // Right
{ 0 + 2, 32 + 2, 16 - 4, 16 - 4 }, // Left
{ 32 + 2, 64 + 2, 16 - 4, 16 - 4 }, // Down
{ 32 + 2, 0 + 2, 16 - 4, 16 - 4 }, // Up
{ 32 + 2, 32 + 2, 16 - 4, 16 - 4 }, // Select
{ 96 + 2, 0 + 2, 16 - 4, 16 - 4 }, // Dfu
} };
auto switches_debounced = get_switches_state().to_ulong();
for(const auto r : debounced_rects) {
if (switches_debounced & 1)
painter.fill_rectangle(r + pos, Color::green());
switches_debounced >>= 1;
}
const std::array<Rect, 6> events_rects { {
{ 64 + 3, 32 + 3, 16 - 6, 16 - 6 }, // Right
{ 0 + 3, 32 + 3, 16 - 6, 16 - 6 }, // Left
{ 32 + 3, 64 + 3, 16 - 6, 16 - 6 }, // Down
{ 32 + 3, 0 + 3, 16 - 6, 16 - 6 }, // Up
{ 32 + 3, 32 + 3, 16 - 6, 16 - 6 }, // Select
{ 96 + 3, 0 + 3, 16 - 6, 16 - 6 }, // Dfu
} };
auto switches_event = key_event_mask;
for(const auto r : events_rects) {
if (switches_event & 1)
painter.fill_rectangle(r + pos, Color::red());
switches_event >>= 1;
}
}
+99
View File
@@ -0,0 +1,99 @@
/*
* 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_dfu_menu.hpp"
#include "portapack_shared_memory.hpp"
#include "performance_counter.hpp"
namespace ui {
DfuMenu::DfuMenu(NavigationView& nav) : nav_ (nav) {
add_children({
&text_head,
&labels,
&text_info_line_1,
&text_info_line_2,
&text_info_line_3,
&text_info_line_4,
&text_info_line_5,
&text_info_line_6,
&text_info_line_7,
&text_info_line_8
});
}
void DfuMenu::paint(Painter& painter) {
auto utilisation = get_cpu_utilisation_in_percent();
text_info_line_1.set(to_string_dec_uint(chCoreStatus(), 6));
text_info_line_2.set(to_string_dec_uint((uint32_t)get_free_stack_space(), 6));
text_info_line_3.set(to_string_dec_uint(utilisation, 6));
text_info_line_4.set(to_string_dec_uint(shared_memory.m4_heap_usage, 6));
text_info_line_5.set(to_string_dec_uint(shared_memory.m4_stack_usage, 6));
text_info_line_6.set(to_string_dec_uint(shared_memory.m4_cpu_usage, 6));
text_info_line_7.set(to_string_dec_uint(shared_memory.m4_buffer_missed, 6));
text_info_line_8.set(to_string_dec_uint(chTimeNow()/1000, 6));
constexpr auto margin = 5;
constexpr auto lines = 8 + 2;
painter.fill_rectangle(
{
{6 * CHARACTER_WIDTH - margin, 3 * LINE_HEIGHT - margin},
{15 * CHARACTER_WIDTH + margin * 2, lines * LINE_HEIGHT + margin * 2}
},
ui::Color::black()
);
painter.fill_rectangle(
{
{5 * CHARACTER_WIDTH - margin, 3 * LINE_HEIGHT - margin},
{CHARACTER_WIDTH, lines * LINE_HEIGHT + margin * 2}
},
ui::Color::dark_cyan()
);
painter.fill_rectangle(
{
{21 * CHARACTER_WIDTH + margin, 3 * LINE_HEIGHT - margin},
{CHARACTER_WIDTH, lines * LINE_HEIGHT + margin * 2}
},
ui::Color::dark_cyan()
);
painter.fill_rectangle(
{
{5 * CHARACTER_WIDTH - margin, 3 * LINE_HEIGHT - margin - 8},
{17 * CHARACTER_WIDTH + margin * 2, 8}
},
ui::Color::dark_cyan()
);
painter.fill_rectangle(
{
{5 * CHARACTER_WIDTH - margin, (lines+3) * LINE_HEIGHT + margin},
{17 * CHARACTER_WIDTH + margin * 2, 8}
},
ui::Color::dark_cyan()
);
}
} /* namespace ui */
+73
View File
@@ -0,0 +1,73 @@
/*
* 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.
*/
#ifndef __UI_DFU_MENU_H__
#define __UI_DFU_MENU_H__
#include <cstdint>
#include "ui_widget.hpp"
#include "event_m0.hpp"
#include "debug.hpp"
#include "string_format.hpp"
#define LINE_HEIGHT 16
#define CHARACTER_WIDTH 8
namespace ui {
class NavigationView;
class DfuMenu : public View {
public:
DfuMenu(NavigationView& nav);
~DfuMenu() = default;
void paint(Painter& painter) override;
private:
NavigationView& nav_;
Text text_head {{ 6 * CHARACTER_WIDTH, 3 * LINE_HEIGHT, 11 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, "Performance"};
Labels labels {
{ { 6 * CHARACTER_WIDTH, 5 * LINE_HEIGHT }, "M0 heap:", Color::dark_cyan() },
{ { 6 * CHARACTER_WIDTH, 6 * LINE_HEIGHT }, "M0 stack:", Color::dark_cyan() },
{ { 6 * CHARACTER_WIDTH, 7 * LINE_HEIGHT }, "M0 cpu %:", Color::dark_cyan() },
{ { 6 * CHARACTER_WIDTH, 8 * LINE_HEIGHT }, "M4 heap:", Color::dark_cyan() },
{ { 6 * CHARACTER_WIDTH, 9 * LINE_HEIGHT }, "M4 stack:", Color::dark_cyan() },
{ { 6 * CHARACTER_WIDTH,10 * LINE_HEIGHT }, "M4 cpu %:", Color::dark_cyan() },
{ { 6 * CHARACTER_WIDTH,11 * LINE_HEIGHT }, "M4 miss:", Color::dark_cyan() },
{ { 6 * CHARACTER_WIDTH,12 * LINE_HEIGHT }, "uptime:", Color::dark_cyan() }
};
Text text_info_line_1 {{ 15 * CHARACTER_WIDTH, 5 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""};
Text text_info_line_2 {{ 15 * CHARACTER_WIDTH, 6 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""};
Text text_info_line_3 {{ 15 * CHARACTER_WIDTH, 7 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""};
Text text_info_line_4 {{ 15 * CHARACTER_WIDTH, 8 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""};
Text text_info_line_5 {{ 15 * CHARACTER_WIDTH, 9 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""};
Text text_info_line_6 {{ 15 * CHARACTER_WIDTH,10 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""};
Text text_info_line_7 {{ 15 * CHARACTER_WIDTH,11 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""};
Text text_info_line_8 {{ 15 * CHARACTER_WIDTH,12 * LINE_HEIGHT, 5 * CHARACTER_WIDTH, 1 * LINE_HEIGHT }, ""};
};
} /* namespace ui */
#endif/*__UI_DFU_MENU_H__*/
+475 -198
View File
@@ -20,83 +20,200 @@
* Boston, MA 02110-1301, USA.
*/
/* TODO:
* - Paging menu items
*/
#include <algorithm>
#include "ui_fileman.hpp"
#include "string_format.hpp"
#include "portapack.hpp"
#include "event_m0.hpp"
using namespace portapack;
namespace fs = std::filesystem;
namespace {
using namespace ui;
bool is_hidden_file(const fs::path& path) {
return !path.empty() && path.native()[0] == u'.';
}
// Gets a truncated name from a path for display.
std::string truncate(const fs::path& path, size_t max_length) {
auto name = path.string();
return name.length() <= max_length ? name : name.substr(0, max_length);
}
// Gets a human readable file size string.
std::string get_pretty_size(uint32_t file_size) {
static const std::string suffix[5] = { "B", "kB", "MB", "GB", "??" };
size_t suffix_index = 0;
while (file_size >= 1024) {
file_size /= 1024;
suffix_index++;
}
if (suffix_index > 4)
suffix_index = 4;
return to_string_dec_uint(file_size) + suffix[suffix_index];
}
// Case insensitive path equality on underlying "native" string.
bool iequal(
const fs::path& lhs,
const fs::path& rhs
) {
const auto& lhs_str = lhs.native();
const auto& rhs_str = rhs.native();
// NB: Not correct for Unicode/locales.
if (lhs_str.length() == rhs_str.length()) {
for (size_t i = 0; i < lhs_str.length(); ++i)
if (towupper(lhs_str[i]) != towupper(rhs_str[i]))
return false;
return true;
}
return false;
}
// Inserts the entry into the entry list sorted directories first then by file name.
void insert_sorted(std::vector<fileman_entry>& entries, fileman_entry&& entry) {
auto it = std::lower_bound(std::begin(entries), std::end(entries), entry,
[](const fileman_entry& lhs, const fileman_entry& rhs) {
if (lhs.is_directory && !rhs.is_directory)
return true;
else if (!lhs.is_directory && rhs.is_directory)
return false;
else
return lhs.path < rhs.path;
});
entries.insert(it, std::move(entry));
}
// Returns the partner file path or an empty path if no partner is found.
fs::path get_partner_file(fs::path path) {
if (fs::is_directory(path))
return { };
const fs::path txt_path{ u".TXT" };
const fs::path c16_path{ u".C16" };
auto ext = path.extension();
if (iequal(ext, txt_path))
ext = c16_path;
else if (iequal(ext, c16_path))
ext = txt_path;
else
return { };
path.replace_extension(ext);
return fs::file_exists(path) && !fs::is_directory(path) ? path : fs::path{ };
}
// Modal prompt to update the partner file if it exists.
// Runs continuation on_partner_action to update the partner file.
// Returns true is a partner is found, otherwise false.
// Path must be the full path to the file.
bool partner_file_prompt(
NavigationView& nav,
const fs::path& path,
std::string action_name,
std::function<void(const fs::path&, bool)> on_partner_action
) {
auto partner = get_partner_file(path);
if (partner.empty())
return false;
nav.push_under_current<ModalMessageView>(
"Partner File",
partner.filename().string() + "\n" + action_name + " this file too?",
YESNO,
[&nav, partner, on_partner_action](bool choice) {
if (on_partner_action)
on_partner_action(partner, choice);
}
);
return true;
}
fs::path get_unique_filename(const fs::path& path, const fs::path& file) {
auto stem = file.stem();
auto ext = file.extension();
auto serial = 1;
fs::path new_path = file;
while (fs::file_exists(path / new_path)) {
new_path = stem;
new_path += fs::path{ u"_" };
new_path += to_string_dec_int(serial++);
new_path += ext;
}
return new_path;
}
}
namespace ui {
void FileManBaseView::load_directory_contents(const std::filesystem::path& dir_path) {
/* FileManBaseView ***********************************************************/
void FileManBaseView::load_directory_contents(const fs::path& dir_path) {
current_path = dir_path;
text_current.set(dir_path.string().length()? dir_path.string().substr(0, 30 - 6):"(sd root)");
entry_list.clear();
auto filtering = (bool)extension_filter.size();
// List directories and files, put directories up top
if (dir_path.string().length())
entry_list.push_back({ u"..", 0, true });
auto filtering = !extension_filter.empty();
for (const auto& entry : std::filesystem::directory_iterator(dir_path, u"*")) {
text_current.set(dir_path.empty() ? "(sd root)" : truncate(dir_path, 24));
for (const auto& entry : fs::directory_iterator(dir_path, u"*")) {
// Hide files starting with '.' (hidden / tmp).
if (is_hidden_file(entry.path()))
continue;
// do not display dir / files starting with '.' (hidden / tmp)
if (entry.path().string().length() && entry.path().filename().string()[0] != '.') {
if (std::filesystem::is_regular_file(entry.status())) {
bool matched = true;
if (filtering) {
auto entry_extension = entry.path().extension().string();
for (auto &c: entry_extension)
c = toupper(c);
if (entry_extension != extension_filter)
matched = false;
}
if (matched)
entry_list.push_back({ entry.path(), (uint32_t)entry.size(), false });
} else if (std::filesystem::is_directory(entry.status())) {
entry_list.insert(entry_list.begin(), { entry.path(), 0, true });
}
if (fs::is_regular_file(entry.status())) {
if (!filtering || iequal(entry.path().extension(), extension_filter))
insert_sorted(entry_list, { entry.path(), (uint32_t)entry.size(), false });
} else if (fs::is_directory(entry.status())) {
insert_sorted(entry_list, { entry.path(), 0, true });
}
}
// Add "parent" directory if not at the root.
if (!dir_path.empty())
entry_list.insert(entry_list.begin(), { parent_dir_path, 0, true });
}
std::filesystem::path FileManBaseView::get_selected_path() {
auto selected_path_str = current_path.string();
auto entry_path = entry_list[menu_view.highlighted_index()].entry_path.string();
if (entry_path == "..") {
selected_path_str = get_parent_dir().string();
} else {
if (selected_path_str.back() != '/')
selected_path_str += '/';
selected_path_str += entry_path;
}
return selected_path_str;
fs::path FileManBaseView::get_selected_full_path() const {
if (get_selected_entry().path == parent_dir_path)
return current_path.parent_path();
return current_path / get_selected_entry().path;
}
std::filesystem::path FileManBaseView::get_parent_dir() {
auto current_path_str = current_path.string();
return current_path.string().substr(0, current_path_str.find_last_of('/'));
const fileman_entry& FileManBaseView::get_selected_entry() const {
// TODO: return reference to an "empty" entry on OOB?
return entry_list[menu_view.highlighted_index()];
}
FileManBaseView::FileManBaseView(
NavigationView& nav,
std::string filter
) : nav_ (nav),
extension_filter { filter }
) : nav_{ nav },
extension_filter{ filter }
{
add_children({
&labels,
&text_current,
&text_info,
&button_exit
});
@@ -105,121 +222,117 @@ FileManBaseView::FileManBaseView(
};
if (!sdcIsCardInserted(&SDCD1)) {
empty_root=true;
empty_ = EmptyReason::NoSDC;
text_current.set("NO SD CARD!");
return;
}
load_directory_contents(current_path);
if (!entry_list.size()) {
empty_ = EmptyReason::NoFiles;
text_current.set("EMPTY SD CARD!");
} else {
load_directory_contents(current_path);
if (!entry_list.size())
{
empty_root = true;
text_current.set("EMPTY SD CARD!");
} else {
menu_view.on_left = [&nav, this]() {
load_directory_contents(get_parent_dir());
refresh_list();
};
}
menu_view.on_left = [this]() {
pop_dir();
};
}
}
void FileManBaseView::focus() {
if (empty_root) {
if (empty_ != EmptyReason::NotEmpty) {
button_exit.focus();
} else {
menu_view.focus();
}
}
void FileManBaseView::push_dir(const fs::path& path) {
if (path == parent_dir_path) {
pop_dir();
} else {
current_path /= path;
saved_index_stack.push_back(menu_view.highlighted_index());
menu_view.set_highlighted(0);
reload_current();
}
}
void FileManBaseView::pop_dir() {
if (saved_index_stack.empty())
return;
current_path = current_path.parent_path();
reload_current();
menu_view.set_highlighted(saved_index_stack.back());
saved_index_stack.pop_back();
}
void FileManBaseView::refresh_list() {
if (on_refresh_widgets)
on_refresh_widgets(false);
auto prev_highlight = menu_view.highlighted_index();
menu_view.clear();
for (size_t n = 0; n < entry_list.size(); n++) {
auto entry = &entry_list[n];
auto entry_name = entry->entry_path.filename().string().substr(0, 20);
if (entry->is_directory) {
for (const auto& entry : entry_list) {
auto entry_name = truncate(entry.path, 20);
if (entry.is_directory) {
menu_view.add_item({
entry_name,
ui::Color::yellow(),
&bitmap_icon_dir,
[this](){
[this](KeyEvent key) {
if (on_select_entry)
on_select_entry();
on_select_entry(key);
}
});
} else {
auto file_size = entry->size;
size_t suffix_index = 0;
while (file_size >= 1024) {
file_size /= 1024;
suffix_index++;
}
if (suffix_index > 4)
suffix_index = 4;
std::string size_str = to_string_dec_uint(file_size) + suffix[suffix_index];
auto entry_extension = entry->entry_path.extension().string();
for (auto &c: entry_extension)
c = toupper(c);
// Associate extension to icon and color
size_t c;
for (c = 0; c < file_types.size() - 1; c++) {
if (entry_extension == file_types[c].extension)
break;
}
const auto& assoc = get_assoc(entry.path.extension());
auto size_str = get_pretty_size(entry.size);
menu_view.add_item({
entry_name + std::string(21 - entry_name.length(), ' ') + size_str,
file_types[c].color,
file_types[c].icon,
[this](){
assoc.color,
assoc.icon,
[this](KeyEvent key) {
if (on_select_entry)
on_select_entry();
on_select_entry(key);
}
});
}
// HACK: Should page menu items instead of limiting the number.
if (menu_view.item_count() >= max_items_shown)
break;
}
menu_view.set_highlighted(0); // Refresh
text_info.set(menu_view.item_count() >= max_items_shown ? "Too many files!" : "");
menu_view.set_highlighted(prev_highlight);
}
/*void FileSaveView::on_save_name() {
text_prompt(nav_, &filename_buffer, 8, [this](std::string * buffer) {
nav_.pop();
});
void FileManBaseView::reload_current() {
load_directory_contents(current_path);
refresh_list();
}
FileSaveView::FileSaveView(
NavigationView& nav
) : FileManBaseView(nav)
const FileManBaseView::file_assoc_t& FileManBaseView::get_assoc(
const fs::path& ext) const
{
name_buffer.clear();
add_children({
&text_save,
&button_save_name,
&live_timestamp
});
button_save_name.on_select = [this, &nav](Button&) {
on_save_name();
};
}*/
size_t index = 0;
void FileLoadView::refresh_widgets(const bool v) {
(void)v; //avoid unused warning
set_dirty();
for (; index < file_types.size() - 1; ++index)
if (iequal(ext, file_types[index].extension))
return file_types[index];
// Default to last entry in the list.
return file_types[index];
}
/* FileLoadView **************************************************************/
FileLoadView::FileLoadView(
NavigationView& nav,
std::string filter
@@ -238,104 +351,268 @@ FileLoadView::FileLoadView(
refresh_list();
on_select_entry = [&nav, this]() {
if (entry_list[menu_view.highlighted_index()].is_directory) {
load_directory_contents(get_selected_path());
refresh_list();
on_select_entry = [this](KeyEvent) {
if (get_selected_entry().is_directory) {
push_dir(get_selected_entry().path);
} else {
nav_.pop();
if (on_changed)
on_changed(current_path.string() + '/' + entry_list[menu_view.highlighted_index()].entry_path.string());
on_changed(get_selected_full_path());
}
};
}
void FileManagerView::on_rename(NavigationView& nav) {
text_prompt(nav, name_buffer, max_filename_length, [this](std::string& buffer) {
std::string destination_path = current_path.string();
if (destination_path.back() != '/')
destination_path += '/';
destination_path = destination_path + buffer;
rename_file(get_selected_path(), destination_path);
load_directory_contents(current_path);
refresh_list();
void FileLoadView::refresh_widgets(const bool) {
set_dirty();
}
/* FileSaveView **************************************************************/
/*
FileSaveView::FileSaveView(
NavigationView& nav,
const fs::path& path,
const fs::path& file
) : nav_{ nav },
path_{ path },
file_{ file }
{
add_children({
&labels,
&text_path,
&button_edit_path,
&text_name,
&button_edit_name,
&button_save,
&button_cancel,
});
button_edit_path.on_select = [this](Button&) {
buffer_ = path_.string();
text_prompt(nav_, buffer_, max_filename_length,
[this](std::string&) {
path_ = buffer_;
refresh_widgets();
});
};
button_edit_name.on_select = [this](Button&) {
buffer_ = file_.string();
text_prompt(nav_, buffer_, max_filename_length,
[this](std::string&) {
file_ = buffer_;
refresh_widgets();
});
};
button_save.on_select = [this](Button&) {
if (on_save)
on_save(path_ / file_);
else
nav_.pop();
};
button_cancel.on_select = [this](Button&) {
nav_.pop();
};
refresh_widgets();
}
void FileSaveView::refresh_widgets() {
text_path.set(truncate(path_, 30));
text_name.set(truncate(file_, 30));
set_dirty();
}
*/
/* FileManagerView ***********************************************************/
void FileManagerView::on_rename() {
auto& entry = get_selected_entry();
name_buffer = entry.path.filename().string();
uint32_t cursor_pos = (uint32_t)name_buffer.length();
if (auto pos = name_buffer.find_last_of(".");
pos != name_buffer.npos && !entry.is_directory)
cursor_pos = pos;
text_prompt(nav_, name_buffer, cursor_pos, max_filename_length,
[this](std::string& renamed) {
auto renamed_path = fs::path{ renamed };
rename_file(get_selected_full_path(), current_path / renamed_path);
auto has_partner = partner_file_prompt(nav_, get_selected_full_path(), "Rename",
[this, renamed_path](const fs::path& partner, bool should_rename) mutable {
if (should_rename) {
auto new_name = renamed_path.replace_extension(partner.extension());
rename_file(current_path / partner, current_path / new_name);
}
reload_current();
}
);
if (!has_partner)
reload_current();
});
}
void FileManagerView::on_delete() {
delete_file(get_selected_path());
load_directory_contents(current_path);
refresh_list();
auto name = get_selected_entry().path.filename().string();
nav_.push<ModalMessageView>("Delete", "Delete " + name + "\nAre you sure?", YESNO,
[this](bool choice) {
if (choice) {
delete_file(get_selected_full_path());
auto has_partner = partner_file_prompt(
nav_, get_selected_full_path(), "Delete",
[this](const fs::path& partner, bool should_delete) {
if (should_delete)
delete_file(current_path / partner);
reload_current();
}
);
if (!has_partner)
reload_current();
}
}
);
}
void FileManagerView::on_new_dir() {
name_buffer = "";
text_prompt(nav_, name_buffer, max_filename_length, [this](std::string& dir_name) {
make_new_directory(current_path / dir_name);
reload_current();
});
}
void FileManagerView::on_new_file() {
name_buffer = "";
text_prompt(nav_, name_buffer, max_filename_length, [this](std::string& file_name) {
make_new_file(current_path / file_name);
reload_current();
});
}
void FileManagerView::on_paste() {
// TODO: handle partner file. Need to fix nav stack first.
auto new_name = get_unique_filename(current_path, clipboard_path.filename());
fs::filesystem_error result;
if (clipboard_mode == ClipboardMode::Cut)
result = rename_file(clipboard_path, current_path / new_name);
else if (clipboard_mode == ClipboardMode::Copy)
result = copy_file(clipboard_path, current_path / new_name);
if (result.code() != FR_OK)
nav_.display_modal("Paste Failed", result.what());
clipboard_path = fs::path{ };
clipboard_mode = ClipboardMode::None;
menu_view.focus();
reload_current();
}
bool FileManagerView::selected_is_valid() const {
return !entry_list.empty() &&
get_selected_entry().path != parent_dir_path;
}
void FileManagerView::refresh_widgets(const bool v) {
button_rename.hidden(v);
button_new_dir.hidden(v);
button_delete.hidden(v);
set_dirty();
}
button_cut.hidden(v);
button_copy.hidden(v);
button_paste.hidden(v);
button_new_dir.hidden(v);
button_new_file.hidden(v);
FileManagerView::~FileManagerView() {
// Flush ?
set_dirty();
}
FileManagerView::FileManagerView(
NavigationView& nav
) : FileManBaseView(nav, "")
{
if (!empty_root) {
on_refresh_widgets = [this](bool v) {
refresh_widgets(v);
};
add_children({
&menu_view,
&labels,
&text_date,
&button_rename,
&button_new_dir,
&button_delete
});
menu_view.on_highlight = [this]() {
text_date.set(to_string_FAT_timestamp(file_created_date(get_selected_path())));
};
refresh_list();
on_select_entry = [this]() {
if (entry_list[menu_view.highlighted_index()].is_directory) {
load_directory_contents(get_selected_path());
refresh_list();
} else
button_rename.focus();
};
button_new_dir.on_select = [this, &nav](Button&) {
name_buffer.clear();
text_prompt(nav, name_buffer, max_filename_length, [this](std::string& buffer) {
make_new_directory(current_path.string() + '/' + buffer);
load_directory_contents(current_path);
refresh_list();
});
};
button_rename.on_select = [this, &nav](Button&) {
name_buffer = entry_list[menu_view.highlighted_index()].entry_path.filename().string().substr(0, max_filename_length);
on_rename(nav);
};
button_delete.on_select = [this, &nav](Button&) {
// Use display_modal ?
nav.push<ModalMessageView>("Delete", "Delete " + entry_list[menu_view.highlighted_index()].entry_path.filename().string() + "\nAre you sure?", YESNO,
[this](bool choice) {
if (choice)
on_delete();
}
);
};
}
// Don't bother with the UI in the case of no SDC.
if (empty_ == EmptyReason::NoSDC)
return;
on_refresh_widgets = [this](bool v) {
refresh_widgets(v);
};
add_children({
&menu_view,
&labels,
&text_date,
&button_rename,
&button_delete,
&button_cut,
&button_copy,
&button_paste,
&button_new_dir,
&button_new_file
});
menu_view.on_highlight = [this]() {
if (selected_is_valid())
text_date.set(to_string_FAT_timestamp(file_created_date(get_selected_full_path())));
else
text_date.set("");
};
refresh_list();
on_select_entry = [this](KeyEvent key) {
if (key == KeyEvent::Select && get_selected_entry().is_directory) {
push_dir(get_selected_entry().path);
} else {
button_rename.focus();
}
};
button_rename.on_select = [this]() {
if (selected_is_valid())
on_rename();
};
button_delete.on_select = [this]() {
if (selected_is_valid())
on_delete();
};
button_cut.on_select = [this]() {
if (selected_is_valid() && !get_selected_entry().is_directory) {
clipboard_path = get_selected_full_path();
clipboard_mode = ClipboardMode::Cut;
} else
nav_.display_modal("Cut", "Can't cut that.");
};
button_copy.on_select = [this]() {
if (selected_is_valid() && !get_selected_entry().is_directory) {
clipboard_path = get_selected_full_path();
clipboard_mode = ClipboardMode::Copy;
} else
nav_.display_modal("Copy", "Can't copy that.");
};
button_paste.on_select = [this]() {
if (clipboard_mode != ClipboardMode::None)
on_paste();
else
nav_.display_modal("Paste", "Cut or copy a file first.");
};
button_new_dir.on_select = [this]() {
on_new_dir();
};
button_new_file.on_select = [this]() {
on_new_file();
};
}
}
+173 -67
View File
@@ -31,11 +31,23 @@
namespace ui {
struct fileman_entry {
std::filesystem::path entry_path { };
std::filesystem::path path { };
uint32_t size { };
bool is_directory { };
};
enum class EmptyReason : uint8_t {
NotEmpty,
NoFiles,
NoSDC
};
enum class ClipboardMode : uint8_t {
None,
Cut,
Copy
};
class FileManBaseView : public View {
public:
FileManBaseView(
@@ -43,50 +55,58 @@ public:
std::string filter
);
void focus() override;
void load_directory_contents(const std::filesystem::path& dir_path);
std::filesystem::path get_selected_path();
virtual ~FileManBaseView() { }
void focus() override;
std::string title() const override { return "Fileman"; };
protected:
NavigationView& nav_;
static constexpr size_t max_filename_length = 30 - 2;
const std::string suffix[5] = { "B", "kB", "MB", "GB", "??" };
static constexpr size_t max_filename_length = 64;
static constexpr size_t max_items_shown = 128;
struct file_assoc_t {
std::string extension;
std::filesystem::path extension;
const Bitmap* icon;
ui::Color color;
};
const std::vector<file_assoc_t> file_types = {
{ ".TXT", &bitmap_icon_file_text, ui::Color::white() },
{ ".PNG", &bitmap_icon_file_image, ui::Color::green() },
{ ".BMP", &bitmap_icon_file_image, ui::Color::green() },
{ ".C8", &bitmap_icon_file_iq, ui::Color::blue() },
{ ".C16", &bitmap_icon_file_iq, ui::Color::blue() },
{ ".WAV", &bitmap_icon_file_wav, ui::Color::dark_magenta() },
{ "", &bitmap_icon_file, ui::Color::light_grey() }
{ u".TXT", &bitmap_icon_file_text, ui::Color::white() },
{ u".PNG", &bitmap_icon_file_image, ui::Color::green() },
{ u".BMP", &bitmap_icon_file_image, ui::Color::green() },
{ u".C8", &bitmap_icon_file_iq, ui::Color::dark_cyan() },
{ u".C16", &bitmap_icon_file_iq, ui::Color::dark_cyan() },
{ u".WAV", &bitmap_icon_file_wav, ui::Color::dark_magenta() },
{ u"", &bitmap_icon_file, ui::Color::light_grey() } // NB: Must be last.
};
bool empty_root { false };
std::function<void(void)> on_select_entry { nullptr };
std::function<void(bool)> on_refresh_widgets { nullptr };
std::vector<fileman_entry> entry_list { };
std::filesystem::path current_path { u"" };
std::string extension_filter { "" };
void change_category(int32_t category_id);
std::filesystem::path get_parent_dir();
std::filesystem::path get_selected_full_path() const;
const fileman_entry& get_selected_entry() const;
void push_dir(const std::filesystem::path& path);
void pop_dir();
void refresh_list();
void reload_current();
void load_directory_contents(const std::filesystem::path& dir_path);
const file_assoc_t& get_assoc(const std::filesystem::path& ext) const;
NavigationView& nav_;
EmptyReason empty_ { EmptyReason::NotEmpty };
std::function<void(KeyEvent)> on_select_entry { nullptr };
std::function<void(bool)> on_refresh_widgets { nullptr };
const std::filesystem::path parent_dir_path { u".." };
std::filesystem::path current_path { u"" };
std::filesystem::path extension_filter { u"" };
std::vector<fileman_entry> entry_list { };
std::vector<uint32_t> saved_index_stack { };
Labels labels {
{ { 0, 0 }, "Path:", Color::light_grey() }
};
Text text_current {
{ 6 * 8, 0 * 8, 24 * 8, 16 },
"",
@@ -96,57 +116,109 @@ protected:
{ 0, 2 * 8, 240, 26 * 8 },
true
};
// HACK: for item count limit.
Text text_info {
{ 1 * 8, 35 * 8, 15 * 8, 16 },
""
};
Button button_exit {
{ 16 * 8, 34 * 8, 14 * 8, 32 },
{ 21 * 8, 34 * 8, 9 * 8, 32 },
"Exit"
};
};
/*class FileSaveView : public FileManBaseView {
public:
FileSaveView(NavigationView& nav);
~FileSaveView();
private:
std::string name_buffer { };
void on_save_name();
Text text_save {
{ 4 * 8, 15 * 8, 8 * 8, 16 },
"Save as:",
};
Button button_save_name {
{ 4 * 8, 18 * 8, 12 * 8, 32 },
"Name (set)"
};
LiveDateTime live_timestamp {
{ 17 * 8, 24 * 8, 11 * 8, 16 }
};
};*/
class FileLoadView : public FileManBaseView {
public:
std::function<void(std::filesystem::path)> on_changed { };
FileLoadView(NavigationView& nav, std::string filter);
virtual ~FileLoadView() { }
private:
void refresh_widgets(const bool v);
};
/*
// It would be nice to be able to launch FileLoadView
// but it will OOM if launched from within FileManager.
class FileSaveView : public View {
public:
FileSaveView(
NavigationView& nav,
const std::filesystem::path& path,
const std::filesystem::path& file);
std::function<void(std::filesystem::path)> on_save { };
private:
static constexpr size_t max_filename_length = 64;
void refresh_widgets();
NavigationView& nav_;
std::filesystem::path path_;
std::filesystem::path file_;
std::string buffer_ { };
Labels labels {
{ { 0 * 8, 1 * 16 }, "Path:", Color::light_grey() },
{ { 0 * 8, 6 * 16 }, "Filename:", Color::light_grey() },
};
Text text_path {
{ 0 * 8, 2 * 16, 30 * 8, 16 },
"",
};
Button button_edit_path {
{ 18 * 8, 3 * 16, 11 * 8, 32 },
"Edit Path"
};
Text text_name {
{ 0 * 8, 7 * 16, 30 * 8, 16 },
"",
};
Button button_edit_name {
{ 18 * 8, 8 * 16, 11 * 8, 32 },
"Edit Name"
};
Button button_save {
{ 10 * 8, 16 * 16, 9 * 8, 32 },
"Save"
};
Button button_cancel {
{ 20 * 8, 16 * 16, 9 * 8, 32 },
"Cancel"
};
};
*/
class FileManagerView : public FileManBaseView {
public:
FileManagerView(NavigationView& nav);
~FileManagerView();
virtual ~FileManagerView() { }
private:
// Passed by ref to other views needing lifetime extension.
std::string name_buffer { };
std::filesystem::path clipboard_path { };
ClipboardMode clipboard_mode { ClipboardMode::None };
void refresh_widgets(const bool v);
void on_rename(NavigationView& nav);
void on_rename();
void on_delete();
void on_paste();
void on_new_dir();
void on_new_file();
// True if the selected entry is a real file item.
bool selected_is_valid() const;
Labels labels {
{ { 0, 26 * 8 }, "Created ", Color::light_grey() }
@@ -157,20 +229,54 @@ private:
""
};
Button button_rename {
{ 0 * 8, 29 * 8, 14 * 8, 32 },
"Rename"
NewButton button_rename {
{ 0 * 8, 29 * 8, 4 * 8, 32 },
{ },
&bitmap_icon_rename,
Color::dark_blue()
};
Button button_delete {
{ 16 * 8, 29 * 8, 14 * 8, 32 },
"Delete"
NewButton button_delete {
{ 4 * 8, 29 * 8, 4 * 8, 32 },
{ },
&bitmap_icon_trash,
Color::red()
};
Button button_new_dir {
{ 0 * 8, 34 * 8, 14 * 8, 32 },
"New dir"
NewButton button_cut {
{ 9 * 8, 29 * 8, 4 * 8, 32 },
{ },
&bitmap_icon_cut,
Color::dark_grey()
};
NewButton button_copy {
{ 13 * 8, 29 * 8, 4 * 8, 32 },
{ },
&bitmap_icon_copy,
Color::dark_grey()
};
NewButton button_paste {
{ 17 * 8, 29 * 8, 4 * 8, 32 },
{ },
&bitmap_icon_paste,
Color::dark_grey()
};
NewButton button_new_dir {
{ 22 * 8, 29 * 8, 4 * 8, 32 },
{ },
&bitmap_icon_new_dir,
Color::green()
};
NewButton button_new_file {
{ 26 * 8, 29 * 8, 4 * 8, 32 },
{ },
&bitmap_icon_new_file,
Color::green()
};
};
} /* namespace ui */
@@ -44,7 +44,7 @@ FlashUtilityView::FlashUtilityView(NavigationView& nav) : nav_ (nav) {
filename.string().substr(0, max_filename_length),
ui::Color::red(),
&bitmap_icon_temperature,
[this, path]() {
[this, path](KeyEvent) {
this->firmware_selected(path);
}
});
+1 -1
View File
@@ -120,7 +120,7 @@ void FreqManBaseView::refresh_list() {
freqman_item_string(database[n], 30),
ui::Color::white(),
nullptr,
[this](){
[this](KeyEvent){
if (on_select_frequency)
on_select_frequency();
}
-2
View File
@@ -48,8 +48,6 @@ namespace ui {
void focus() override;
void big_display_freq( int64_t f );
const Style style_grey { // level
.font = font::fixed_8x16,
.background = Color::black(),
+374 -158
View File
@@ -26,10 +26,9 @@ using namespace portapack;
namespace ui
{
void GlassView::focus()
{
field_marker.focus();
button_marker.focus();
}
GlassView::~GlassView()
@@ -39,6 +38,24 @@ namespace ui
baseband::shutdown();
}
// Returns the next multiple of num that is a multiple of multiplier
int64_t GlassView::next_mult_of(int64_t num, int64_t multiplier) {
return ((num / multiplier) + 1) * multiplier;
}
void GlassView::adjust_range(int64_t* f_min, int64_t* f_max, int64_t width) {
int64_t span = *f_max - *f_min;
int64_t num_intervals = span / width;
if( span % width != 0 )
{
num_intervals++;
}
int64_t new_span = num_intervals * width;
int64_t delta_span = (new_span - span) / 2;
*f_min -= delta_span;
*f_max += delta_span;
}
void GlassView::on_lna_changed(int32_t v_db)
{
receiver_model.set_lna(v_db);
@@ -49,40 +66,71 @@ namespace ui
receiver_model.set_vga(v_db);
}
void GlassView::add_spectrum_pixel(int16_t color)
void GlassView::reset_live_view( bool clear_screen )
{
spectrum_row[pixel_index] = spectrum_rgb3_lut[color] ;
spectrum_data[pixel_index] = ( live_frequency_integrate * spectrum_data[pixel_index] + color ) / (live_frequency_integrate + 1); // smoothing
max_freq_hold = 0 ;
max_freq_power = -1000 ;
if( clear_screen )
{
// only clear screen in peak mode
if( live_frequency_view == 2 )
{
display.fill_rectangle( { { 0 , 108 + 16 } , { 240 , 320 - (108 + 16) } } , { 0 , 0 , 0 } );
}
}
}
void GlassView::add_spectrum_pixel( uint8_t power )
{
static int64_t last_max_freq = 0 ;
spectrum_row[pixel_index] = spectrum_rgb3_lut[power] ; // row of colors
spectrum_data[pixel_index] = ( live_frequency_integrate * spectrum_data[pixel_index] + power ) / (live_frequency_integrate + 1); // smoothing
pixel_index ++ ;
if (pixel_index == 240) // got an entire waterfall line
{
if( live_frequency_view )
{
constexpr int rssi_sample_range = 256;
//constexpr float rssi_voltage_min = 0.4;
constexpr float rssi_voltage_max = 2.2;
constexpr float adc_voltage_max = 3.3;
//constexpr int raw_min = rssi_sample_range * rssi_voltage_min / adc_voltage_max;
constexpr int raw_min = 0 ;
constexpr int raw_max = rssi_sample_range * rssi_voltage_max / adc_voltage_max;
constexpr int raw_delta = raw_max - raw_min;
const range_t<int> y_max_range { 0 , 320 - 108 };
if( live_frequency_view > 0 )
{
constexpr int rssi_sample_range = 256;
constexpr float rssi_voltage_min = 0.4;
constexpr float rssi_voltage_max = 2.2;
constexpr float adc_voltage_max = 3.3;
constexpr int raw_min = rssi_sample_range * rssi_voltage_min / adc_voltage_max;
constexpr int raw_max = rssi_sample_range * rssi_voltage_max / adc_voltage_max;
constexpr int raw_delta = raw_max - raw_min;
const range_t<int> y_max_range { 0 , 320 - ( 108 + 16 ) };
//drawing
//display.fill_rectangle( { { 0 , 108 } , { 240 , 320 - 108 } } , { 0 , 0 , 0 } );
for( uint16_t xpos = 0 ; xpos < 240 ; xpos ++ )
{
int16_t point = y_max_range.clip( ( ( spectrum_data[ xpos ] - raw_min ) * ( 320 - 108 ) ) / raw_delta );
uint8_t color_gradient = (point * 255) / 212 ;
display.fill_rectangle( { { xpos , 108 } , { 1 , 320 - point } } , { 0 , 0 , 0 } );
display.fill_rectangle( { { xpos , 320 - point } , { 1 , point } } , { color_gradient , 0 , uint8_t( 255 - color_gradient ) } );
}
}
else
{
display.draw_pixels({{0, display.scroll(1)}, {240, 1}}, spectrum_row); // new line at top, one less var, speedier
}
//drawing and keeping track of max freq
for( uint16_t xpos = 0 ; xpos < 240 ; xpos ++ )
{
// save max powerwull freq
if( spectrum_data[ xpos ] > max_freq_power )
{
max_freq_power = spectrum_data[ xpos ];
max_freq_hold = f_min + ( (f_max - f_min) * xpos) / 240 ;
}
int16_t point = y_max_range.clip( ( ( spectrum_data[ xpos ] - raw_min ) * ( 320 - ( 108 + 16 ) ) ) / raw_delta );
uint8_t color_gradient = (point * 255) / 212 ;
// clear if not in peak view
if( live_frequency_view != 2 )
{
display.fill_rectangle( { { xpos , 108 + 16 } , { 1 , 320 - point } } , { 0 , 0 , 0 } );
}
display.fill_rectangle( { { xpos , 320 - point } , { 1 , point } } , { color_gradient , 0 , uint8_t( 255 - color_gradient ) } );
}
if( last_max_freq != max_freq_hold )
{
last_max_freq = max_freq_hold ;
freq_stats.set( "MAX HOLD: "+to_string_short_freq( max_freq_hold ) );
}
PlotMarker( marker );
}
else
{
display.draw_pixels({{0, display.scroll(1)}, {240, 1}}, spectrum_row); // new line at top, one less var, speedier
}
pixel_index = 0; // Start New cascade line
}
}
@@ -91,53 +139,123 @@ namespace ui
// Each having the radio signal power for it's corresponding frequency slot
void GlassView::on_channel_spectrum(const ChannelSpectrum &spectrum)
{
// default fast scan offset
uint8_t offset = 2 ;
baseband::spectrum_streaming_stop();
// Convert bins of this spectrum slice into a representative max_power and when enough, into pixels
// Spectrum.db has 256 bins. Center 12 bins are ignored (DC spike is blanked) Leftmost and rightmost 2 bins are ignored
// All things said and done, we actually need 240 of those bins:
for (uint8_t bin = 0; bin < 240; bin++)
if( fast_scan || ( LOOKING_GLASS_SLICE_WIDTH < LOOKING_GLASS_SLICE_WIDTH_MAX ) )
{
if (bin < 120)
// Convert bins of this spectrum slice into a representative max_power and when enough, into pixels
// Spectrum.db has 256 bins.
// All things said and done, we actually need 240 of those bins
for (uint8_t bin = 0; bin < 240; bin++)
{
if (spectrum.db[134 + bin] > max_power) // 134
max_power = spectrum.db[134 + bin];
}
else
{
if (spectrum.db[bin - 118] > max_power) // 118
max_power = spectrum.db[bin - 118];
}
bins_Hz_size += each_bin_size; // add this bin Hz count into the "pixel fulfilled bag of Hz"
if (bins_Hz_size >= marker_pixel_step) // new pixel fullfilled
{
if (min_color_power < max_power)
add_spectrum_pixel(max_power); // Pixel will represent max_power
else
add_spectrum_pixel(0); // Filtered out, show black
max_power = 0;
if (!pixel_index) // Received indication that a waterfall line has been completed
// if the view is done in one pass, show it like in analog_audio_app
if( ( LOOKING_GLASS_SLICE_WIDTH < LOOKING_GLASS_SLICE_WIDTH_MAX ) )
{
bins_Hz_size = 0; // Since this is an entire pixel line, we don't carry "Pixels into next bin"
f_center = f_center_ini; // Start a new sweep
radio::set_tuning_frequency(f_center); // tune rx for this new slice directly, faster than using persistent memory saving
chThdSleepMilliseconds(10);
baseband::spectrum_streaming_start(); // Do the RX
return;
// Center 16 bins are ignored (DC spike is blanked)
if (bin < 120)
{
if (spectrum.db[256 - 120 + bin] > max_power) // 134
max_power = spectrum.db[256 - 120 + bin];
}
else
{
if (spectrum.db[ bin - 120] > max_power) // 118
max_power = spectrum.db[bin - 120];
}
}
else // view is made in multiple pass, use original bin picking
{
// Center 12 bins are ignored (DC spike is blanked) Leftmost and rightmost 2 bins are ignored
if (bin < 120)
{
if (spectrum.db[134 + bin] > max_power) // 134
max_power = spectrum.db[134 + bin];
}
else
{
if (spectrum.db[bin - 118] > max_power) // 118
max_power = spectrum.db[bin - 118];
}
}
if( bin == 120 )
{
bins_Hz_size += 12 * each_bin_size; // add DC bin Hz count into the "pixel fulfilled bag of Hz"
}
else
{
bins_Hz_size += each_bin_size; // add this bin Hz count into the "pixel fulfilled bag of Hz"
}
bins_Hz_size -= marker_pixel_step; // reset bins size, but carrying the eventual excess Hz into next pixel
}
}
f_center += LOOKING_GLASS_SLICE_WIDTH; // Move into the next bandwidth slice NOTE: spectrum.sampling_rate = LOOKING_GLASS_SLICE_WIDTH
if (bins_Hz_size >= marker_pixel_step) // new pixel fullfilled
{
if (min_color_power < max_power)
add_spectrum_pixel(max_power); // Pixel will represent max_power
else
add_spectrum_pixel(0); // Filtered out, show black
max_power = 0;
if (!pixel_index) // Received indication that a waterfall line has been completed
{
bins_Hz_size = 0; // Since this is an entire pixel line, we don't carry "Pixels into next bin"
f_center = f_center_ini - offset * each_bin_size ; // Start a new sweep
radio::set_tuning_frequency(f_center); // tune rx for this new slice directly, faster than using persistent memory saving
chThdSleepMilliseconds(10);
baseband::spectrum_streaming_start(); // Do the RX
return;
}
bins_Hz_size -= marker_pixel_step; // reset bins size, but carrying the eventual excess Hz into next pixel
}
}
f_center += ( 256 - ( 2 * offset ) ) * each_bin_size ; // Move into the next bandwidth slice NOTE: spectrum.sampling_rate = LOOKING_GLASS_SLICE_WIDTH
// lost bins are taken in account so next slice first ignored bins overlap previous kept ones
}
else //slow scan
{
offset = 32 ;
uint8_t bin_length = 80 ;
for (uint8_t bin = offset ; bin < bin_length + offset ; bin++)
{
if (bin < 120)
{
if (spectrum.db[134 + bin] > max_power) // 134
max_power = spectrum.db[134 + bin];
}
else
{
if (spectrum.db[bin - 118] > max_power) // 118
max_power = spectrum.db[bin - 118];
}
bins_Hz_size += each_bin_size; // add this bin Hz count into the "pixel fulfilled bag of Hz"
if (bins_Hz_size >= marker_pixel_step) // new pixel fullfilled
{
if (min_color_power < max_power)
add_spectrum_pixel(max_power); // Pixel will represent max_power
else
add_spectrum_pixel(0); // Filtered out, show black
max_power = 0;
if (!pixel_index) // Received indication that a waterfall line has been completed
{
bins_Hz_size = 0; // Since this is an entire pixel line, we don't carry "Pixels into next bin"
f_center = f_center_ini - offset * each_bin_size ; // Start a new sweep
radio::set_tuning_frequency(f_center); // tune rx for this new slice directly, faster than using persistent memory saving
chThdSleepMilliseconds(10);
baseband::spectrum_streaming_start(); // Do the RX
return;
}
bins_Hz_size -= marker_pixel_step; // reset bins size, but carrying the eventual excess Hz into next pixel
}
}
f_center += bin_length * each_bin_size ;
}
radio::set_tuning_frequency(f_center); // tune rx for this new slice directly, faster than using persistent memory saving
chThdSleepMilliseconds(5);
// receiver_model.set_tuning_frequency(f_center); //tune rx for this slice
baseband::spectrum_streaming_start(); // Do the RX
}
@@ -155,50 +273,71 @@ namespace ui
void GlassView::on_range_changed()
{
reset_live_view( false );
f_min = field_frequency_min.value();
f_max = field_frequency_max.value();
search_span = f_max - f_min;
field_marker.set_range(f_min, f_max); // Move the marker between range
field_marker.set_value(f_min + (search_span / 2)); // Put MARKER AT MIDDLE RANGE
text_range.set(to_string_dec_uint(search_span));
if( locked_range )
{
button_range.set_text(">"+to_string_dec_uint(search_span)+"<");
}
else
{
button_range.set_text(" "+to_string_dec_uint(search_span)+" ");
}
f_min = (f_min)*MHZ_DIV; // Transpose into full frequency realm
f_max = (f_max)*MHZ_DIV;
search_span = search_span * MHZ_DIV;
adjust_range( &f_min , &f_max , 240 );
marker_pixel_step = search_span / 240; // Each pixel value in Hz
text_marker_pm.set(to_string_dec_uint((marker_pixel_step / X2_MHZ_DIV) + 1)); // Give idea of +/- marker precision
marker_pixel_step = (f_max - f_min) / 240; // Each pixel value in Hz
marker = f_min + (f_max - f_min) / 2 ;
button_marker.set_text( to_string_short_freq( marker ) );
PlotMarker( marker ); // Refresh marker on screen
int32_t marker_step = marker_pixel_step / MHZ_DIV;
if (!marker_step)
field_marker.set_step(1); // in case selected range is less than 240 (pixels)
else
field_marker.set_step(marker_step); // step needs to be a pixel wide.
f_center_ini = f_min + (LOOKING_GLASS_SLICE_WIDTH / 2); // Initial center frequency for sweep
PlotMarker(field_marker.value()); // Refresh marker on screen
f_center = f_center_ini; // Reset sweep into first slice
pixel_index = 0; // reset pixel counter
max_power = 0;
bins_Hz_size = 0; // reset amount of Hz filled up by pixels
if( (f_max - f_min) <= LOOKING_GLASS_SLICE_WIDTH_MAX )
{
LOOKING_GLASS_SLICE_WIDTH = (f_max - f_min) ;
receiver_model.set_sampling_rate(LOOKING_GLASS_SLICE_WIDTH);
receiver_model.set_baseband_bandwidth(LOOKING_GLASS_SLICE_WIDTH/2);
}
else if( LOOKING_GLASS_SLICE_WIDTH != LOOKING_GLASS_SLICE_WIDTH_MAX )
{
LOOKING_GLASS_SLICE_WIDTH = LOOKING_GLASS_SLICE_WIDTH_MAX ;
receiver_model.set_sampling_rate(LOOKING_GLASS_SLICE_WIDTH);
receiver_model.set_baseband_bandwidth(LOOKING_GLASS_SLICE_WIDTH);
}
if( next_mult_of( LOOKING_GLASS_SLICE_WIDTH , 256 ) > LOOKING_GLASS_SLICE_WIDTH_MAX )
LOOKING_GLASS_SLICE_WIDTH = LOOKING_GLASS_SLICE_WIDTH_MAX ;
else
LOOKING_GLASS_SLICE_WIDTH = next_mult_of( LOOKING_GLASS_SLICE_WIDTH , 256 );
receiver_model.set_squelch_level(0);
each_bin_size = LOOKING_GLASS_SLICE_WIDTH / 256 ;
f_center_ini = f_min + (LOOKING_GLASS_SLICE_WIDTH / 2) ; // Initial center frequency for sweep
f_center = f_center_ini ; // Reset sweep into first slice
baseband::set_spectrum(LOOKING_GLASS_SLICE_WIDTH, field_trigger.value());
receiver_model.set_tuning_frequency(f_center_ini); // tune rx for this slice
}
void GlassView::PlotMarker(rf::Frequency pos)
{
pos = pos * MHZ_DIV;
pos -= f_min;
pos = pos / marker_pixel_step; // Real pixel
portapack::display.fill_rectangle({0, 100, 240, 8}, Color::black()); // Clear old marker and whole marker rectangle btw
portapack::display.fill_rectangle({(int)pos - 2, 100, 5, 3}, Color::red()); // Red marker top
portapack::display.fill_rectangle({(int)pos - 1, 103, 3, 3}, Color::red()); // Red marker middle
portapack::display.fill_rectangle({(int)pos, 106, 1, 2}, Color::red()); // Red marker bottom
uint8_t shift_y = 0 ;
if( live_frequency_view > 0 ) // plot one line down when in live view
{
shift_y = 16 ;
}
portapack::display.fill_rectangle({0, 100 + shift_y, 240, 8}, Color::black()); // Clear old marker and whole marker rectangle btw
portapack::display.fill_rectangle({(int)pos - 2, 100 + shift_y, 5, 3}, Color::red()); // Red marker top
portapack::display.fill_rectangle({(int)pos - 1, 103 + shift_y, 3, 3}, Color::red()); // Red marker middle
portapack::display.fill_rectangle({(int)pos, 106 + shift_y, 1, 2}, Color::red()); // Red marker bottom
}
GlassView::GlassView(
@@ -211,98 +350,116 @@ namespace ui
&field_frequency_max,
&field_lna,
&field_vga,
&text_range,
&button_range,
&steps_config,
&scan_type,
&view_config,
&level_integration,
&filter_config,
&field_rf_amp,
&range_presets,
&field_marker,
&text_marker_pm,
&field_trigger});
&button_marker,
&field_trigger,
&button_jump,
&button_rst,
&freq_stats});
load_Presets(); // Load available presets from TXT files (or default)
field_frequency_min.set_value(presets_db[0].min); // Defaults to first preset
field_frequency_min.set_step( steps );
field_frequency_min.on_change = [this](int32_t v)
{
int32_t steps_ = steps ;
if( steps_ < 24 )
steps_ = 24 ;
if( v > 7200 - steps_ )
reset_live_view( true );
int32_t min_size = steps ;
if( locked_range )
min_size = search_span ;
if( min_size < 2 )
min_size = 2 ;
if( v > 7200 - min_size )
{
v = 7200 - steps_ ;
v = 7200 - min_size ;
field_frequency_min.set_value( v );
}
if (v >= (field_frequency_max.value() - steps_ ) )
field_frequency_max.set_value( v + steps_ );
if (v > (field_frequency_max.value() - min_size ) )
field_frequency_max.set_value( v + min_size );
if( locked_range )
field_frequency_max.set_value( v + min_size );
this->on_range_changed();
};
field_frequency_min.set_value(presets_db[0].min); // Defaults to first preset
field_frequency_min.set_step( steps );
field_frequency_min.on_select = [this, &nav](NumberField& field) {
auto new_view = nav_.push<FrequencyKeypadView>(field_frequency_min.value()*1000000);
new_view->on_changed = [this, &field](rf::Frequency f) {
int32_t freq = f / 1000000 ;
int32_t steps_ = steps ;
if( steps_ < 24 )
steps_ = 24 ;
if( freq > (7200 - steps_ ) )
freq= 7200 - steps_ ;
int32_t min_size = steps ;
if( locked_range )
min_size = search_span ;
if( min_size < 2 )
min_size = 2 ;
if( freq > (7200 - min_size ) )
freq = 7200 - min_size ;
field_frequency_min.set_value( freq );
if( field_frequency_max.value() < ( freq + steps_ ) )
field_frequency_max.set_value( freq + steps_ );
if( field_frequency_max.value() < ( freq + min_size ) )
field_frequency_max.set_value( freq + min_size );
this->on_range_changed();
};
};
field_frequency_max.set_value(presets_db[0].max); // Defaults to first preset
field_frequency_max.set_step( steps );
field_frequency_max.on_change = [this](int32_t v)
{
int32_t steps_ = steps ;
if( steps_ < 24 )
steps_ = 24 ;
if( v < steps_ )
reset_live_view( true );
int32_t min_size = steps ;
if( locked_range )
min_size = search_span ;
if( min_size < 2 )
min_size = 2 ;
if( v < min_size )
{
v = steps_ ;
v = min_size ;
field_frequency_max.set_value( v );
}
if (v < (field_frequency_min.value() + steps_) )
field_frequency_min.set_value(v - steps_);
if (v < (field_frequency_min.value() + min_size) )
field_frequency_min.set_value(v - min_size);
if( locked_range )
field_frequency_min.set_value( v - min_size );
this->on_range_changed();
};
field_frequency_max.set_value(presets_db[0].max); // Defaults to first preset
field_frequency_max.set_step( steps );
field_frequency_max.on_select = [this, &nav](NumberField& field) {
auto new_view = nav_.push<FrequencyKeypadView>(field_frequency_max.value()*1000000);
new_view->on_changed = [this, &field](rf::Frequency f) {
int32_t steps_ = steps ;
if( steps_ < 24 )
steps_ = 24 ;
int32_t min_size = steps ;
if( locked_range )
min_size = search_span ;
if( min_size < 2 )
min_size = 2 ;
int32_t freq = f / 1000000 ;
if( freq < 24 )
freq = 24 ;
if( freq < min_size )
freq = min_size ;
field_frequency_max.set_value( freq );
if( field_frequency_min.value() > ( freq - steps) )
field_frequency_min.set_value( freq - steps );
if( field_frequency_min.value() > ( freq - min_size) )
field_frequency_min.set_value( freq - min_size );
this->on_range_changed();
};
};
field_lna.set_value(receiver_model.lna());
field_lna.on_change = [this](int32_t v)
{
reset_live_view( true );
this->on_lna_changed(v);
};
field_lna.set_value(receiver_model.lna());
field_vga.set_value(receiver_model.vga());
field_vga.on_change = [this](int32_t v_db)
{
reset_live_view( true );
this->on_vga_changed(v_db);
};
field_vga.set_value(receiver_model.vga());
steps_config.set_selected_index(3); //default of 250 Mhz steps
steps_config.on_change = [this](size_t n, OptionsField::value_t v)
{
(void)n;
@@ -310,39 +467,67 @@ namespace ui
field_frequency_max.set_step( v );
steps = v ;
};
steps_config.set_selected_index(0); //default of 1 Mhz steps
scan_type.on_change = [this](size_t n, OptionsField::value_t v)
{
(void)n;
fast_scan = v ;
};
scan_type.set_selected_index(0); // default legacy fast scan
view_config.on_change = [this](size_t n, OptionsField::value_t v)
{
(void)n;
live_frequency_view = v ;
if( v )
{
display.scroll_disable();
level_integration.hidden( false );
}
else
{
level_integration.hidden( true );
set_dirty();
display.scroll_set_area(109, 319); // Restart scroll on the correct coordinates
}
// clear between changes
display.fill_rectangle( { { 0 , 108 } , { 240 , 320 - 108 } } , { 0 , 0 , 0 } );
(void)n;
// clear between changes
reset_live_view( true );
if( v == 0 )
{
live_frequency_view = 0 ;
level_integration.hidden( true );
freq_stats.hidden( true );
button_jump.hidden( true );
button_rst.hidden( true );
display.scroll_set_area(109, 319); // Restart scroll on the correct coordinates
}
else if( v == 1 )
{
display.fill_rectangle( { { 0 , 108 } , { 240 , 24 } } , { 0 , 0 , 0 } );
live_frequency_view = 1 ;
display.scroll_disable();
level_integration.hidden( false );
freq_stats.hidden( false );
button_jump.hidden( false );
button_rst.hidden( false );
}
else if( v == 2 )
{
display.fill_rectangle( { { 0 , 108 } , { 240 , 24 } } , { 0 , 0 , 0 } );
live_frequency_view = 2 ;
display.scroll_disable();
level_integration.hidden( false );
freq_stats.hidden( false );
button_jump.hidden( false );
button_rst.hidden( false );
}
set_dirty();
};
view_config.set_selected_index(0); //default spectrum
level_integration.on_change = [this](size_t n, OptionsField::value_t v)
{
(void)n;
live_frequency_integrate = v ;
(void)n;
reset_live_view( true );
live_frequency_integrate = v ;
};
level_integration.set_selected_index(2); //default integration of ( 3 * old value + new_value ) / 4
level_integration.set_selected_index(3); //default integration of ( 3 * old value + new_value ) / 4
filter_config.set_selected_index(0);
filter_config.on_change = [this](size_t n, OptionsField::value_t v) {
(void)n;
reset_live_view( true );
min_color_power = v;
};
filter_config.set_selected_index(0);
range_presets.on_change = [this](size_t n, OptionsField::value_t v)
{
@@ -352,26 +537,57 @@ namespace ui
this->on_range_changed();
};
field_marker.on_change = [this](int32_t v)
button_marker.on_change = [this]()
{
PlotMarker(v); // Refresh marker on screen
marker = marker + button_marker.get_encoder_delta() * marker_pixel_step ;
if( marker < f_min )
marker = f_min ;
if( marker > f_max )
marker = f_max ;
button_marker.set_text( to_string_short_freq( marker ) );
button_marker.set_encoder_delta( 0 );
PlotMarker( marker ); // Refresh marker on screen
};
field_marker.on_select = [this](NumberField &)
button_marker.on_select = [this](ButtonWithEncoder &)
{
f_center = field_marker.value();
f_center = f_center * MHZ_DIV;
receiver_model.set_tuning_frequency(f_center); // Center tune rx in marker freq.
receiver_model.set_tuning_frequency(marker); // Center tune rx in marker freq.
receiver_model.set_frequency_step(MHZ_DIV); // Preset a 1 MHz frequency step into RX -> AUDIO
nav_.pop();
nav_.push<AnalogAudioView>(); // Jump into audio view
};
field_trigger.set_value(32); // Defaults to 32, as normal triggering resolution
field_trigger.on_change = [this](int32_t v)
{
baseband::set_spectrum(LOOKING_GLASS_SLICE_WIDTH, v);
};
field_trigger.set_value(32); // Defaults to 32, as normal triggering resolution
button_range.on_select = [this](Button&) {
if( locked_range )
{
locked_range = false ;
button_range.set_style(&style_white);
button_range.set_text(" "+to_string_dec_uint(search_span)+" ");
}
else
{
locked_range = true ;
button_range.set_style(&style_red);
button_range.set_text(">"+to_string_dec_uint(search_span)+"<");
}
};
button_jump.on_select = [this](Button&) {
receiver_model.set_tuning_frequency(max_freq_hold); // Center tune rx in marker freq.
receiver_model.set_frequency_step(MHZ_DIV); // Preset a 1 MHz frequency step into RX -> AUDIO
nav_.pop();
nav_.push<AnalogAudioView>(); // Jump into audio view
};
button_rst.on_select = [this](Button&) {
reset_live_view( true );
};
display.scroll_set_area(109, 319);
baseband::set_spectrum(LOOKING_GLASS_SLICE_WIDTH, field_trigger.value()); // trigger:
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2020 euquiq
* Copyright (C) 2023 gullradriel, Nilorea Studio Inc.
*
* This file is part of PortaPack.
*
@@ -36,13 +37,14 @@
namespace ui
{
#define LOOKING_GLASS_SLICE_WIDTH 20000000 // Each slice bandwidth 20 MHz
#define LOOKING_GLASS_SLICE_WIDTH_MAX 20000000
#define MHZ_DIV 1000000
#define X2_MHZ_DIV 2000000
class GlassView : public View
{
public:
GlassView(NavigationView &nav);
GlassView( const GlassView &);
@@ -64,15 +66,37 @@ namespace ui
rf::Frequency max{};
std::string label{};
};
const Style style_white { // free range
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::white(),
};
const Style style_red { // locked range
.font = font::fixed_8x16,
.background = Color::black(),
.foreground = Color::red(),
};
std::vector<preset_entry> presets_db{};
// Each slice bandwidth 20 MHz and a multiple of 256
// since we are using LOOKING_GLASS_SLICE_WIDTH/256 as the each_bin_size
// it should also be a multiple of 2 since we are using LOOKING_GLASS_SLICE_WIDTH / 2 as centering freq
int64_t LOOKING_GLASS_SLICE_WIDTH = 20000000;
// frequency rounding helpers
int64_t next_mult_of(int64_t num, int64_t multiplier);
void adjust_range(int64_t* f_min, int64_t* f_max, int64_t width);
void on_channel_spectrum(const ChannelSpectrum& spectrum);
void do_timers();
void on_range_changed();
void on_lna_changed(int32_t v_db);
void on_vga_changed(int32_t v_db);
void add_spectrum_pixel(int16_t color);
void reset_live_view( bool clear_screen );
void add_spectrum_pixel(uint8_t power);
void PlotMarker(rf::Frequency pos);
void load_Presets();
void txtline_process(std::string& line);
@@ -83,24 +107,29 @@ namespace ui
rf::Frequency search_span { 0 };
rf::Frequency f_center { 0 };
rf::Frequency f_center_ini { 0 };
rf::Frequency marker { 0 };
rf::Frequency marker_pixel_step { 0 };
rf::Frequency each_bin_size { LOOKING_GLASS_SLICE_WIDTH / 240 };
rf::Frequency each_bin_size { LOOKING_GLASS_SLICE_WIDTH / 256 };
rf::Frequency bins_Hz_size { 0 };
uint8_t min_color_power { 0 };
uint32_t pixel_index { 0 };
std::array<Color, 240> spectrum_row = { 0 };
std::array<int16_t, 240> spectrum_data = { 0 };
std::array<uint8_t, 240> spectrum_data = { 0 };
ChannelSpectrumFIFO* fifo { nullptr };
uint8_t max_power = 0;
int32_t steps = 250 ; // default of 250 Mhz steps
bool live_frequency_view = false ;
int32_t steps = 0 ;
uint8_t live_frequency_view = 0 ;
int16_t live_frequency_integrate = 3 ;
int64_t max_freq_hold = 0 ;
int16_t max_freq_power = -1000 ;
bool fast_scan = true ; // default to legacy fast scan
bool locked_range = false ;
Labels labels{
{{0, 0}, "MIN: MAX: LNA VGA ", Color::light_grey()},
{{0, 1 * 16}, " RANGE: FILTER: AMP:", Color::light_grey()},
{{0, 1 * 16}, "RANGE: FILTER: AMP:", Color::light_grey()},
{{0, 2 * 16}, "PRESET:", Color::light_grey()},
{{0, 3 * 16}, "MARKER: MHz +/- MHz", Color::light_grey()},
{{0, 3 * 16}, "MARKER: MHz", Color::light_grey()},
{{0, 4 * 16}, "RES: STEP:", Color::light_grey()}
};
@@ -128,47 +157,12 @@ namespace ui
{ 27 * 8, 0 * 16 }
};
Text text_range{
Button button_range{
{7 * 8, 1 * 16, 4 * 8, 16},
""};
OptionsField steps_config{
{ 14 * 8, 4 * 16},
4,
{
{"1", 1},
{"50", 50},
{"100", 100},
{"250", 250},
{"500", 500},
}};
OptionsField view_config{
{ 19 * 8, 4 * 16},
7,
{
{"SPCTR-V", false },
{"LEVEL-V", true },
}};
OptionsField level_integration{
{ 27 * 8, 4 * 16},
2,
{
{"x1", 1 },
{"x2", 2 },
{"x3", 3 },
{"x4", 4 },
{"x5", 5 },
{"x6", 6 },
{"x7", 7 },
{"x8", 8 },
{"x9", 9 },
}};
OptionsField filter_config{
{19 * 8, 1 * 16},
{20 * 8, 1 * 16},
4,
{
{"OFF ", 0},
@@ -186,16 +180,10 @@ namespace ui
{" NONE (WIFI 2.4GHz)", 0},
}};
NumberField field_marker{
{7 * 8, 3 * 16},
4,
{0, 7200},
25,
' '};
Text text_marker_pm{
{20 * 8, 3 * 16, 2 * 8, 16},
""};
ButtonWithEncoder button_marker{
{7 * 8, 3 * 16 , 10 * 8 , 16},
" "
};
NumberField field_trigger{
{4 * 8, 4 * 16},
@@ -204,6 +192,68 @@ namespace ui
2,
' '};
OptionsField steps_config{
{ 13 * 8, 4 * 16},
3,
{
{"1", 1},
{"25", 25},
{"50", 50},
{"100", 100},
{"250", 250},
{"500", 500},
}
};
OptionsField scan_type{
{ 17 * 8, 4 * 16},
2,
{
{"F-", true },
{"S-", false },
}
};
OptionsField view_config{
{ 19 * 8, 4 * 16},
7,
{
{"SPCTR-V", 0 },
{"LEVEL-V", 1 },
{"PEAK-V" , 2 },
}
};
OptionsField level_integration{
{ 27 * 8, 4 * 16},
2,
{
{"x0", 0 },
{"x1", 1 },
{"x2", 2 },
{"x3", 3 },
{"x4", 4 },
{"x5", 5 },
{"x6", 6 },
{"x7", 7 },
{"x8", 8 },
{"x9", 9 },
}};
Button button_jump {
{ 240 - 4 * 8 , 5 * 16 , 4 * 8, 16 },
"JMP"
};
Button button_rst {
{ 240 - 9 * 8 , 5 * 16 , 4 * 8, 16 },
"RST"
};
Text freq_stats{
{0 * 8, 5 * 16 , 240 - 10 * 8 , 8 },
""
};
MessageHandlerRegistration message_handler_spectrum_config {
Message::ID::ChannelSpectrumConfig,
+14 -10
View File
@@ -167,14 +167,14 @@ void MicTXView::rxaudio(bool is_on) {
}
else { // We are in NFM/FM or WFM (NFM BW:8k5 or 11k / FM BW 16k / WFM BW:200k)
if (enable_wfm) { // WFM , BW 200Khz aprox ,
if (enable_wfm) { // WFM , BW 200Khz aprox , or the two new addional BW filters (180k, 40k)
baseband::run_image(portapack::spi_flash::image_tag_wfm_audio);
receiver_model.set_modulation(ReceiverModel::Mode::WidebandFMAudio);
receiver_model.set_wfm_configuration(0); // there are only 1 x config filters 200k WFM . (not like 8k5/11k/16k)
// receiver_model.set_wfm_configuration(n); // it is called above , depending user's selection (200k, 180k,40k).
} else { // NFM BW:8k5 or 11k / FM BW 16k
baseband::run_image(portapack::spi_flash::image_tag_nfm_audio);
receiver_model.set_modulation(ReceiverModel::Mode::NarrowbandFMAudio); //
// receiver_model.set_nbfm_configuration(n); is called above , depending 8k5, 11k, 16k
// receiver_model.set_nbfm_configuration(n); is called above , depending user's selection (8k5, 11k, 16k).
}
}
receiver_model.set_sampling_rate(3072000);
@@ -423,10 +423,12 @@ MicTXView::MicTXView(
rxaudio(rx_enabled); //Update now if we have RX audio on
options_tone_key.hidden(0); // we are in WFM mode , we should have active the Key-tones & CTCSS option.
rxbw.emplace_back(" 200k-WFM ", 0); // locked a fixed option , to display it .
rxbw.emplace_back(" 200k-WFM ", 0); // We allow the user selection of the 3 x WFM BW filters, (0) WFM-200K, (1) WFM-180K , (2) WFM-40K .
rxbw.emplace_back(" 180k-WFM ", 1);
rxbw.emplace_back(" 40k-WFM ", 2);
field_rxbw.set_options(rxbw); // store that aux GUI option to the field_rxbw.
field_rxbw.hidden(0); // we are in WFM mode, we need to show to the user the selected BW WFM filer .
field_rxbw.hidden(0); // we are in WFM mode, we need to show to the user the selected BW WFM filter .
field_bw.hidden(0); // we are in WFM mode, we need to allow WFM deviation parameter , in non FM mode.
break;
case 2: //{ "AM", 2 }
@@ -436,7 +438,7 @@ MicTXView::MicTXView(
set_dirty(); // Refresh display
options_tone_key.hidden(1); // we hide that Key-tones & CTCSS input selecction, (no meaning in AM/DSB/SSB).
rxbw.emplace_back(" DSB1-9k ", 0); // we offer in AM DSB two audio BW 9k / 6k .
rxbw.emplace_back(" DSB1-9k ", 0); // we offer in AM DSB two audio BW 9k / 6k .
rxbw.emplace_back(" DSB2-6k ", 1);
field_rxbw.set_options(rxbw); // store that aux GUI option to the field_rxbw.
@@ -450,7 +452,7 @@ MicTXView::MicTXView(
check_rogerbeep.set_value(false); // reset the possible activation of roger beep, because it is not compatible with SSB , by now.
check_rogerbeep.hidden(1); // hide that roger beep selection.
rxbw.emplace_back(" USB+3k ", 0); // locked a fixed option , to display it .
rxbw.emplace_back(" USB+3k ", 0); // locked a fixed option , to display it .
field_rxbw.set_options(rxbw); // store that aux GUI option to the field_rxbw.
set_dirty(); // Refresh display
@@ -461,7 +463,7 @@ MicTXView::MicTXView(
check_rogerbeep.set_value(false); // reset the possible activation of roger beep, because it is not compatible with SSB , by now.
check_rogerbeep.hidden(1); // hide that roger beep selection.
rxbw.emplace_back(" LSB-3k ", 0); // locked a fixed option , to display it .
rxbw.emplace_back(" LSB-3k ", 0); // locked a fixed option , to display it .
field_rxbw.set_options(rxbw); // store that aux GUI option to the field_rxbw.
set_dirty(); // Refresh display
@@ -565,12 +567,14 @@ MicTXView::MicTXView(
}
else { // we are not in NFM/FM mode .(we could be in any of the rest : AM /USB/LSB/DSB-SC)
if (enable_am) { // we are in AM TX mode , we will allow both independent RX audio BW : AM 9K (9K00AE3 / AM 6K (6K00AE3). (In AM option v can be 0 (9k) , 1 (6k)
receiver_model.set_am_configuration(v ); // we are in AM TX mode , we need to select proper AM full path config AM-9K filter. 0+0 =>AM-9K(0), 0+1=1 =>AM-6K(1),
receiver_model.set_am_configuration(v); // we are in AM TX mode , we need to select proper AM full path config AM-9K filter. 0+0 =>AM-9K(0), 0+1=1 =>AM-6K(1),
}
if (enable_dsb) { // we are in DSB-SC in TX mode , we will allow both independent RX SSB demodulation (USB / LSB side band). in that submenu, v is 0 (SSB1 USB) or 1 (SSB2 LSB)
receiver_model.set_am_configuration(v +2 ); // we are in DSB-SC TX mode , we need to select proper SSB filter. 0+2 =>usb(2), 1+2=3 =>lsb(3),
}
if (enable_wfm) {
receiver_model.set_wfm_configuration(v); // we are in WFM case, we need to select proper WFB RX BW filter , WFM BW 200K(0), WFM BW 180K(1) , WFM BW 40K(2)
}
}
};
-8
View File
@@ -54,9 +54,7 @@ NRFRxView::NRFRxView(NavigationView& nav) {
&field_lna,
&field_vga,
&field_frequency,
&text_debug,
&button_modem_setup,
&record_view,
&console
});
@@ -68,12 +66,6 @@ NRFRxView::NRFRxView(NavigationView& nav) {
field_rf_amp.set_value(app_settings.rx_amp);
}
// DEBUG
record_view.on_error = [&nav](std::string message) {
nav.display_modal("Error", message);
};
record_view.set_sampling_rate(24000);
// Auto-configure modem for LCR RX (will be removed later)
update_freq(2480000000);
auto def_bell202 = &modem_defs[0];
+1 -14
View File
@@ -52,7 +52,6 @@ private:
uint8_t console_color { 0 };
uint32_t prev_value { 0 };
std::string str_log { "" };
RFAmpField field_rf_amp {
{ 13 * 8, 0 * 16 }
@@ -74,23 +73,11 @@ private:
{ 0 * 8, 0 * 16 },
};
Text text_debug {
{ 0 * 8, 1 * 16, 10 * 8, 16 },
"DEBUG"
};
Button button_modem_setup {
{ 12 * 8, 1 * 16, 96, 24 },
{ 240 - 12 * 8, 1 * 16, 96, 24 },
"Modem setup"
};
// DEBUG
RecordView record_view {
{ 0 * 8, 3 * 16, 30 * 8, 1 * 16 },
u"AFS_????", RecordView::FileType::WAV, 4096, 4
};
Console console {
{ 0, 4 * 16, 240, 240 }
};
+225 -163
View File
@@ -30,10 +30,9 @@
#define MSG_RECON_SET_MODULATION 10000 // for handle_retune to know that recon thread triggered a modulation change. f is the index of the modulation
#define MSG_RECON_SET_BANDWIDTH 20000 // for handle_retune to know that recon thread triggered a bandwidth change. f is the new bandwidth value index for current modulation
#define MSG_RECON_SET_STEP 30000 // for handle_retune to know that recon thread triggered a bandwidth change. f is the new bandwidth value index for current modulation
#define MSG_RECON_SET_RECEIVER_BANDWIDTH 40000 // for handle_retune to know that recon thread triggered a receiver bandwidth change. f is the new bandwidth in hz
#define MSG_RECON_SET_RECEIVER_BANDWIDTH 40000 // for handle_retune to know that recon thread triggered a receiver bandwidth change. f is the new bandwidth in hz
#define MSG_RECON_SET_RECEIVER_SAMPLERATE 50000 // for handle_retune to know that recon thread triggered a receiver samplerate change. f is the new samplerate in hz/s
using namespace portapack;
using portapack::memory::map::backup_ram;
@@ -92,10 +91,10 @@ namespace ui {
return _recon;
}
void ReconThread::set_freq_lock(const uint32_t v) {
void ReconThread::set_freq_lock(const int32_t v) {
_freq_lock = v;
}
uint32_t ReconThread::is_freq_lock() {
int32_t ReconThread::is_freq_lock() {
return _freq_lock;
}
int64_t ReconThread::get_current_freq() {
@@ -104,7 +103,7 @@ namespace ui {
void ReconThread::change_recon_direction() {
_fwd = !_fwd;
// chThdSleepMilliseconds(300); //Give some pause after reversing recon direction
//chThdSleepMilliseconds(300); //Give some pause after reversing recon direction
}
bool ReconThread::get_recon_direction() {
@@ -205,6 +204,7 @@ namespace ui {
while( !chThdShouldTerminate() && frequency_list_.size() > 0 )
{
uint32_t remaining_sleep = _lock_duration ;
if( !_freq_delete )
{
has_looped = false ;
@@ -414,10 +414,10 @@ namespace ui {
if( has_looped && !_continuous )
{
// signal pause to handle_retune
receiver_model.set_tuning_frequency( freq ); // Retune to actual freq
message.freq = freq ;
message.range = MSG_RECON_PAUSE ;
EventDispatcher::send_message(message);
receiver_model.set_tuning_frequency( freq ); // Retune to actual freq
}
if( _stepper < 0 ) _stepper ++ ;
if( _stepper > 0 ) _stepper -- ;
@@ -429,9 +429,23 @@ namespace ui {
restart_recon = false ;
}
} // if( _freq_lock == 0 || _stepper != 0 || _index_stepper != 0 )
// needed to stabilize consecutive match without skipping
// the little the rest, the more reactive and more CPU hog
// the bigger the rest, less CPU and more delay when switching
while( _freq_lock != -1 && _freq_lock < (int32_t)_lock_nb_match && !chThdShouldTerminate() )
{
chThdSleepMilliseconds( 10 );
if( remaining_sleep >= 10 )
remaining_sleep -= 10 ;
else
remaining_sleep = 0 ;
}
if( _freq_lock == -1 )
_freq_lock = 0 ;
} // if( _recon || _stepper != 0 || _index_stepper != 0 )
} // if( !freq_delete )
chThdSleepMilliseconds( _lock_duration ); //Needed to (eventually) stabilize the receiver into new freq
if( remaining_sleep > 0 )
chThdSleepMilliseconds( remaining_sleep ); //Needed to (eventually) stabilize the receiver into new freq
} //while( !chThdShouldTerminate() && frequency_list_.size() > 0 )
}//if (frequency_list_.size() > 0 )
} //ReconThread::run
@@ -443,9 +457,7 @@ namespace ui {
void ReconView::set_display_freq( int64_t freq )
{
int64_t freqMHz = ( freq / 1000000 );
int64_t freqMhzFloatingPart = ( freq - ( 1000000 * freqMHz ) ) / 100 ;
big_display.set( "FREQ: "+to_string_dec_int( freqMHz )+"."+to_string_dec_int( freqMhzFloatingPart )+" MHz" );
big_display.set( "FREQ: "+to_string_short_freq( freq )+" MHz" );
}
void ReconView::handle_retune( int64_t freq , uint32_t index ) {
@@ -477,8 +489,8 @@ namespace ui {
receiver_model.disable();
baseband::shutdown();
change_mode( freq );
if ( !recon_thread->is_recon() ) //for some motive, audio output gets stopped.
audio::output::start(); //So if recon was stopped we resume audio
if ( !recon_thread->is_recon() ) // for some motive, audio output gets stopped.
audio::output::start(); // so if recon was stopped we resume audio
receiver_model.enable();
field_mode.set_selected_index( freq );
return ;
@@ -528,32 +540,32 @@ namespace ui {
}
}
}
}
uint32_t freq_lock = recon_thread->is_freq_lock();
if( freq_lock == 0 ) {
//NO FREQ LOCK, ONGOING STANDARD SCANNING
if( index < 1000 && index < frequency_list.size() )
text_cycle.set_text( to_string_dec_uint( index + 1 , 3 ) );
if(frequency_list[index].description.size() > 0)
{
text_cycle.set_text( to_string_dec_uint( index + 1 , 3 ) );
if(frequency_list[index].description.size() > 0)
switch( frequency_list[current_index].type )
{
switch( frequency_list[current_index].type )
{
case RANGE:
desc_cycle.set( "R: " + frequency_list[current_index].description ); //Show new description
break ;
case HAMRADIO:
desc_cycle.set( "H: " + frequency_list[current_index].description ); //Show new description
break ;
default:
case SINGLE:
desc_cycle.set( "S: " + frequency_list[current_index].description ); //Show new description
break ;
}
case RANGE:
desc_cycle.set( "R: " + frequency_list[current_index].description ); //Show new description
break ;
case HAMRADIO:
desc_cycle.set( "H: " + frequency_list[current_index].description ); //Show new description
break ;
default:
case SINGLE:
desc_cycle.set( "S: " + frequency_list[current_index].description ); //Show new description
break ;
}
}
else
{
desc_cycle.set( "...no description..." ); //Show new description
}
}
uint32_t freq_lock = recon_thread->is_freq_lock();
if( freq_lock == 0 ) {
//NO FREQ LOCK, ONGOING STANDARD SCANNING
big_display.set_style(&style_white);
if( !userpause )
button_pause.set_text("<PAUSE>");
@@ -647,9 +659,11 @@ namespace ui {
static int32_t last_db = 999999 ;
static int32_t last_nb_match = 999999 ;
static int32_t last_timer = -1 ;
if( recon_thread && frequency_list.size() > 0 )
if( recon_thread )
{
int32_t nb_match = recon_thread->is_freq_lock();
if( nb_match == -1 )
nb_match = 0 ;
if( last_db != db )
{
last_db = db ;
@@ -672,15 +686,6 @@ namespace ui {
text_timer.set( "TIMER: " + to_string_dec_int( timer ) );
}
}
else
{
if( refresh_display )
{
text_max.set( to_string_dec_int( db ) + " db" );
freq_stats.set( "RSSI: " +to_string_dec_int( rssi.get_min() )+"/"+to_string_dec_int( rssi.get_avg() )+"/"+to_string_dec_int( rssi.get_max() )+" db" );
text_timer.set( "TIMER: " + to_string_dec_int( timer ) );
}
}
}
ReconView::ReconView( NavigationView& nav) : nav_ { nav } {
@@ -722,21 +727,23 @@ namespace ui {
} );
// Recon directory
if( check_sd_card() ) { // Check to see if SD Card is mounted
if( check_sd_card() ) { // Check to see if SD Card is mounted
make_new_directory( u"/RECON" );
sd_card_mounted = true ;
}
def_step = 0 ;
change_mode(AM_MODULATION); //Start on AM
field_mode.set_by_value(AM_MODULATION); //Reflect the mode into the manual selector
//HELPER: Pre-setting a manual range, based on stored frequency
rf::Frequency stored_freq = persistent_memory::tuned_frequency();
receiver_model.set_tuning_frequency( stored_freq );
frequency_range.min = stored_freq - 1000000;
if( stored_freq - OneMHz > 0 )
frequency_range.min = stored_freq - OneMHz ;
else
frequency_range.min = 0 ;
button_manual_start.set_text(to_string_short_freq(frequency_range.min));
frequency_range.max = stored_freq + 1000000;
if( stored_freq + OneMHz < MAX_UFREQ )
frequency_range.max = stored_freq + OneMHz ;
else
frequency_range.max = MAX_UFREQ ;
button_manual_end.set_text(to_string_short_freq(frequency_range.max));
// Loading settings
autostart = persistent_memory::recon_autostart_recon();
@@ -748,14 +755,12 @@ namespace ui {
load_hamradios = persistent_memory::recon_load_hamradios();
update_ranges = persistent_memory::recon_update_ranges_when_recon();
//Loading input and output file from settings
ReconSetupLoadStrings( "RECON/RECON.CFG" , input_file , output_file , recon_lock_duration , recon_lock_nb_match , squelch , recon_match_mode , wait , recon_lock_duration , volume );
field_volume.set_value( volume );
// load auto common app settings
if( sd_card_mounted )
{
//Loading input and output file from settings
ReconSetupLoadStrings( "RECON/RECON.CFG" , input_file , output_file , recon_lock_duration , recon_lock_nb_match , squelch , recon_match_mode , wait , recon_lock_duration , volume );
// load auto common app settings
auto rc = settings.load("recon", &app_settings);
if(rc == SETTINGS_OK) {
field_lna.set_value(app_settings.lna);
@@ -764,12 +769,7 @@ namespace ui {
receiver_model.set_rf_amp(app_settings.rx_amp);
}
}
button_scanner_mode.set_style( &style_blue );
button_scanner_mode.set_text( "RECON" );
file_name.set( "=>" );
field_squelch.set_value( squelch );
button_manual_start.on_select = [this, &nav](ButtonWithEncoder& button) {
auto new_view = nav_.push<FrequencyKeypadView>(frequency_range.min);
new_view->on_changed = [this, &button](rf::Frequency f) {
@@ -791,11 +791,11 @@ namespace ui {
{
auto new_view = nav_.push<FrequencyKeypadView>(current_index);
new_view->on_changed = [this, &button](rf::Frequency f) {
f = f / 1000000 ;
f = f / OneMHz ;
if( f >= 1 && f <= frequency_list.size() )
{
recon_thread-> set_index_stepper( f - 1 - current_index );
recon_thread->set_freq_lock( 0 );
recon_thread->set_freq_lock( -1 );
}
};
}
@@ -803,9 +803,9 @@ namespace ui {
button_manual_start.on_change = [this]() {
frequency_range.min = frequency_range.min + button_manual_start.get_encoder_delta() * freqman_entry_get_step_value( def_step );
if( frequency_range.min < 1 )
if( frequency_range.min < 0 )
{
frequency_range.min = 1 ;
frequency_range.min = 0 ;
}
if( frequency_range.min > ( MAX_UFREQ - freqman_entry_get_step_value( def_step ) ) )
{
@@ -858,7 +858,7 @@ namespace ui {
recon_thread -> set_recon_direction( fwd );
button_dir.set_text( "FW>" );
recon_thread-> set_index_stepper( 1 );
recon_thread->set_freq_lock( 0 );
recon_thread->set_freq_lock( -1 );
}
else if( text_cycle.get_encoder_delta() < 0 )
{
@@ -866,7 +866,7 @@ namespace ui {
recon_thread -> set_recon_direction( fwd );
button_dir.set_text( "<RW" );
recon_thread-> set_index_stepper( -1 );
recon_thread->set_freq_lock( 0 );
recon_thread->set_freq_lock( -1 );
}
}
text_cycle.set_encoder_delta( 0 );
@@ -929,7 +929,7 @@ namespace ui {
recon_thread -> set_recon_direction( fwd );
button_dir.set_text( "FW>" );
recon_thread-> set_stepper( 1 );
recon_thread->set_freq_lock( 0 );
recon_thread->set_freq_lock( -1 );
}
else if( button_pause.get_encoder_delta() < 0 )
{
@@ -937,7 +937,7 @@ namespace ui {
recon_thread -> set_recon_direction( fwd );
button_dir.set_text( "<RW" );
recon_thread-> set_stepper( -1 );
recon_thread->set_freq_lock( 0 );
recon_thread->set_freq_lock( -1 );
}
}
button_pause.set_encoder_delta( 0 );
@@ -1001,21 +1001,21 @@ namespace ui {
switch( frequency_list[current_index].type )
{
case RANGE:
desc_cycle.set( "R: " + frequency_list[current_index].description ); //Show new description
desc_cycle.set( "R: " + frequency_list[current_index].description );
break ;
case HAMRADIO:
desc_cycle.set( "H: " + frequency_list[current_index].description ); //Show new description
desc_cycle.set( "H: " + frequency_list[current_index].description );
break ;
default:
case SINGLE:
desc_cycle.set( "S: " + frequency_list[current_index].description ); //Show new description
desc_cycle.set( "S: " + frequency_list[current_index].description );
break ;
}
}
else
{
desc_cycle.set( "no description" ); //Show new description
show_max( true ); //UPDATE new list size on screen
desc_cycle.set( "...no description..." );
show_max( true );
}
text_cycle.set_text( to_string_dec_uint( current_index + 1 , 3 ) );
@@ -1139,7 +1139,7 @@ namespace ui {
recon_thread -> set_recon_direction( fwd );
button_dir.set_text( "FW>" );
recon_thread-> set_stepper( 1 );
recon_thread->set_freq_lock( 0 );
recon_thread->set_freq_lock( -1 );
}
else if( button_remove.get_encoder_delta() < 0 )
{
@@ -1147,7 +1147,7 @@ namespace ui {
recon_thread -> set_recon_direction( fwd );
button_dir.set_text( "<RW" );
recon_thread-> set_stepper( -1 );
recon_thread->set_freq_lock( 0 );
recon_thread->set_freq_lock( -1 );
}
}
button_remove.set_encoder_delta( 0 );
@@ -1169,7 +1169,6 @@ namespace ui {
def_step = step_mode.selected_index(); // max range val
manual_freq_entry . type = RANGE ;
manual_freq_entry . description =
"R " + to_string_short_freq(frequency_range.min) + ">"
@@ -1190,11 +1189,14 @@ namespace ui {
freq_stats.set( "0/0/0" );
show_max(); /* display step information */
text_cycle.set_text( "MANUAL SEARCH" );
text_cycle.set_text( "1" );
text_max.set( "/1" );
button_scanner_mode.set_style( &style_white );
button_scanner_mode.set_text( "MSEARCH" );
file_name.set_style( &style_white );
file_name.set( "=> MANUAL RANGE" );
file_name.set( "MANUAL RANGE RECON" );
desc_cycle.set_style( &style_white );
desc_cycle.set( "MANUAL RANGE RECON" );
start_recon_thread();
user_resume();
@@ -1232,7 +1234,7 @@ namespace ui {
button_restart.on_select = [this](Button&) {
if( frequency_list.size() > 0 )
{
def_step = step_mode.selected_index(); //Use def_step from manual selector
def_step = step_mode.selected_index(); //Use def_step from manual selector
frequency_file_load( true );
if( recon_thread )
{
@@ -1251,9 +1253,20 @@ namespace ui {
show_max();
user_resume();
}
if( scanner_mode )
{
file_name.set_style( &style_red );
button_scanner_mode.set_style( &style_red );
button_scanner_mode.set_text( "SCANNER" );
}
else
{
file_name.set_style( &style_blue );
button_scanner_mode.set_style( &style_blue );
button_scanner_mode.set_text( "RECON" );
}
};
button_add.on_select = [this](ButtonWithEncoder&) { //frequency_list[current_index]
if( !scanner_mode)
{
@@ -1326,7 +1339,7 @@ namespace ui {
recon_thread -> set_recon_direction( fwd );
button_dir.set_text( "FW>" );
recon_thread-> set_stepper( 1 );
recon_thread->set_freq_lock( 0 );
recon_thread->set_freq_lock( -1 );
}
else if( button_add.get_encoder_delta() < 0 )
{
@@ -1334,7 +1347,7 @@ namespace ui {
recon_thread -> set_recon_direction( fwd );
button_dir.set_text( "<RW" );
recon_thread-> set_stepper( -1 );
recon_thread->set_freq_lock( 0 );
recon_thread->set_freq_lock( -1 );
}
}
button_add.set_encoder_delta( 0 );
@@ -1375,9 +1388,11 @@ namespace ui {
button_recon_setup.on_select = [this,&nav](Button&) {
ReconSetupSaveStrings( "RECON/RECON.CFG" , input_file , output_file , recon_lock_duration , recon_lock_nb_match , squelch , recon_match_mode , wait , recon_lock_duration , field_volume.value() );
audio::output::stop();
recon_thread->stop(); //STOP SCANNER THREAD
frequency_list.clear();
user_pause();
ReconSetupSaveStrings( "RECON/RECON.CFG" , input_file , output_file , recon_lock_duration , recon_lock_nb_match , squelch , recon_match_mode , wait , recon_lock_duration , field_volume.value() );
auto open_view = nav.push<ReconSetupView>(input_file,output_file,recon_lock_duration,recon_lock_nb_match,recon_match_mode);
open_view -> on_changed = [this](std::vector<std::string> result) {
@@ -1385,7 +1400,7 @@ namespace ui {
output_file = result[1];
recon_lock_duration = strtol( result[2].c_str() , nullptr , 10 );
recon_lock_nb_match = strtol( result[3].c_str() , nullptr , 10 );
recon_match_mode = strtol( result[4].c_str() , nullptr , 10 );
recon_match_mode = strtol( result[4].c_str() , nullptr , 10 );
ReconSetupSaveStrings( "RECON/RECON.CFG" , input_file , output_file , recon_lock_duration , recon_lock_nb_match , squelch , recon_match_mode , wait , recon_lock_duration , field_volume.value() );
@@ -1398,64 +1413,62 @@ namespace ui {
load_hamradios = persistent_memory::recon_load_hamradios();
update_ranges = persistent_memory::recon_update_ranges_when_recon();
frequency_file_load( true );
frequency_file_load( false );
if( recon_thread )
{
recon_thread->set_lock_duration( recon_lock_duration );
recon_thread->set_lock_nb_match( recon_lock_nb_match );
recon_thread->set_continuous( continuous );
recon_thread->set_recon_direction( fwd );
}
if( autostart )
{
user_resume();
}
else
{
user_pause();
}
if( update_ranges )
{
button_manual_start.set_text( to_string_short_freq( frequency_list[ current_index ] . frequency_a ) );
frequency_range.min = frequency_list[ current_index ] . frequency_a ;
if( frequency_list[ current_index ] . frequency_b != 0 )
if( autostart )
{
button_manual_end.set_text( to_string_short_freq( frequency_list[ current_index ] . frequency_b ) );
frequency_range.max = frequency_list[ current_index ] . frequency_b ;
user_resume();
}
else
{
button_manual_end.set_text( to_string_short_freq( frequency_list[ current_index ] . frequency_a ) );
frequency_range.max = frequency_list[ current_index ] . frequency_a ;
user_pause();
}
if( update_ranges && frequency_list.size() != 0 )
{
current_index = 0 ;
button_manual_start.set_text( to_string_short_freq( frequency_list[ current_index ] . frequency_a ) );
frequency_range.min = frequency_list[ current_index ] . frequency_a ;
if( frequency_list[ current_index ] . frequency_b != 0 )
{
button_manual_end.set_text( to_string_short_freq( frequency_list[ current_index ] . frequency_b ) );
frequency_range.max = frequency_list[ current_index ] . frequency_b ;
}
else
{
button_manual_end.set_text( to_string_short_freq( frequency_list[ current_index ] . frequency_a ) );
frequency_range.max = frequency_list[ current_index ] . frequency_a ;
}
}
}
lock_wait = ( 4 * ( recon_lock_duration * recon_lock_nb_match ) ) / 100 ;
lock_wait = lock_wait * 100 ; // poor man's rounding
if( lock_wait < 400 )
lock_wait = 400 ;
field_lock_wait.set_value( lock_wait );
show_max();
return ;
if( userpause != true )
{
timer = 0 ;
user_resume();
}
else
{
if( recon_thread && frequency_list.size() != 0 )
{
RetuneMessage message { };
message.freq = recon_thread->get_current_freq();
message.range = current_index ;
EventDispatcher::send_message(message);
}
}
};
if( userpause != true )
{
timer = 0 ;
user_resume();
}
else
{
RetuneMessage message { };
message.freq = recon_thread->get_current_freq();
message.range = current_index ;
EventDispatcher::send_message(message);
}
};
//PRE-CONFIGURATION:
field_wait.on_change = [this](int32_t v)
{
wait = v ;
@@ -1476,6 +1489,7 @@ namespace ui {
field_wait.set_style( &style_green );
}
};
field_lock_wait.on_change = [this](int32_t v)
{
lock_wait = v ;
@@ -1500,6 +1514,22 @@ namespace ui {
field_lock_wait.set_style(&style_red);
}
};
field_squelch.on_change = [this](int32_t v) {
squelch = v ;
};
field_volume.on_change = [this](int32_t v) {
this->on_headphone_volume_changed(v);
};
//PRE-CONFIGURATION:
change_mode(AM_MODULATION); //Start on AM
field_mode.set_by_value(AM_MODULATION); //Reflect the mode into the manual selector
button_scanner_mode.set_style( &style_blue );
button_scanner_mode.set_text( "RECON" );
file_name.set( "=>" );
field_squelch.set_value( squelch );
field_wait.set_value(wait);
lock_wait = ( 4 * ( recon_lock_duration * recon_lock_nb_match ) );
@@ -1507,16 +1537,13 @@ namespace ui {
if( lock_wait < 400 )
lock_wait = 400 ;
field_lock_wait.set_value(lock_wait);
field_squelch.on_change = [this](int32_t v) {
squelch = v ;
};
field_volume.on_change = [this](int32_t v) { this->on_headphone_volume_changed(v); };
field_volume.set_value((receiver_model.headphone_volume() - audio::headphone::volume_range().max).decibel() + 99);
//FILL STEP OPTIONS
freqman_set_modulation_option( field_mode );
freqman_set_step_option( step_mode );
receiver_model.set_tuning_frequency( portapack::persistent_memory::tuned_frequency() ); // Retune
if( filedelete )
{
@@ -1524,11 +1551,11 @@ namespace ui {
}
frequency_file_load( false ); /* do not stop all at start */
if( recon_thread && frequency_list.size() > 0 )
if( recon_thread )
{
recon_thread->set_lock_duration( recon_lock_duration );
recon_thread->set_lock_nb_match( recon_lock_nb_match );
if( update_ranges )
if( update_ranges && frequency_list.size() > 0 )
{
button_manual_start.set_text( to_string_short_freq( frequency_list[ current_index ] . frequency_a ) );
frequency_range.min = frequency_list[ current_index ] . frequency_a ;
@@ -1543,7 +1570,6 @@ namespace ui {
frequency_range.max = frequency_list[ current_index ] . frequency_a ;
}
}
if( autostart )
{
timer = 0 ; //Will trigger a recon_resume() on_statistics_update, also advancing to next freq.
@@ -1566,42 +1592,77 @@ namespace ui {
}
audio::output::stop();
if( !scanner_mode)
def_step = step_mode.selected_index(); // use def_step from manual selector
frequency_list.clear(); // clear the existing frequency list (expected behavior)
std::string file_input = input_file ; // default recon mode
if( scanner_mode )
{
def_step = step_mode.selected_index(); //Use def_step from manual selector
frequency_list.clear(); // clear the existing frequency list (expected behavior)
if( !load_freqman_file_ex( input_file , frequency_list, load_freqs, load_ranges, load_hamradios ) )
{
desc_cycle.set(" NO " + input_file + ".TXT FILE ..." );
file_name.set_style( &style_white );
file_name.set( "=> NO DATA" );
}
else
{
file_name.set_style( &style_blue );
file_name.set( "=> "+input_file );
}
step_mode.set_selected_index(def_step); //Impose the default step into the manual step selector
file_input = output_file ;
file_name.set_style( &style_red );
button_scanner_mode.set_style( &style_red );
button_scanner_mode.set_text( "SCANNER" );
}
else
{
def_step = step_mode.selected_index(); //Use def_step from manual selector
frequency_list.clear(); // clear the existing frequency list (expected behavior)
if( !load_freqman_file_ex( output_file , frequency_list, load_freqs, load_ranges, load_hamradios ) )
file_name.set_style( &style_blue );
button_scanner_mode.set_style( &style_blue );
button_scanner_mode.set_text( "RECON" );
}
file_name.set_style( &style_white );
desc_cycle.set_style( &style_white );
if( !load_freqman_file_ex( file_input , frequency_list, load_freqs, load_ranges, load_hamradios ) )
{
file_name.set_style( &style_red );
desc_cycle.set_style( &style_red );
desc_cycle.set(" NO " + file_input + ".TXT FILE ..." );
file_name.set( "=> NO DATA" );
}
else
{
file_name.set( "=> "+file_input );
if( frequency_list.size() == 0 )
{
desc_cycle.set(" NO " + output_file + ".TXT FILE ..." );
file_name.set_style( &style_white );
file_name.set( "=> EMPTY" );
file_name.set_style( &style_red );
desc_cycle.set_style( &style_red );
desc_cycle.set("/0 no entries in list" );
file_name.set( "BadOrEmpty "+file_input );
}
else
{
file_name.set( "=> "+output_file );
file_name.set_style( &style_red );
if( frequency_list.size() > FREQMAN_MAX_PER_FILE )
{
file_name.set_style( &style_yellow );
desc_cycle.set_style( &style_yellow );
}
}
step_mode.set_selected_index(def_step); //Impose the default step into the manual step selector
}
step_mode.set_selected_index(def_step); //Impose the default step into the manual step selector
start_recon_thread();
std::string description = "...no description..." ;
if( frequency_list.size() != 0 )
{
current_index = 0 ;
recon_thread-> set_freq_index( 0 );
switch( frequency_list[current_index].type )
{
case RANGE:
description = "R: " + frequency_list[current_index].description ;
break ;
case HAMRADIO:
description = "H: " + frequency_list[current_index].description ;
break ;
default:
case SINGLE:
description = "S: " + frequency_list[current_index].description ;
break ;
}
text_cycle.set_text( to_string_dec_uint( current_index + 1 , 3 ) );
}
else
{
text_cycle.set_text( " " );
}
desc_cycle.set( description );
}
void ReconView::on_statistics_update(const ChannelStatistics& statistics) {
@@ -1629,7 +1690,7 @@ namespace ui {
status = 0 ;
update_stats = true ;
continuous_lock = false ;
recon_thread->set_freq_lock( 0 ); //in lock period, still analyzing the signal
recon_thread->set_freq_lock( -1 ); //in lock period, still analyzing the signal
recon_resume(); // RESUME!
big_display.set_style(&style_white);
}
@@ -1664,7 +1725,7 @@ namespace ui {
}
}
}
else // freq_lock < max_lock , LOCKING
else if( freq_lock >= 0 ) // freq_lock < max_lock , LOCKING
{
if( actual_db > squelch ) //MATCHING LEVEL
{
@@ -1695,6 +1756,7 @@ namespace ui {
{
timer = 0 ;
update_stats = true ;
recon_thread->set_freq_lock( -1 );
}
}
}
@@ -1751,12 +1813,12 @@ namespace ui {
void ReconView::recon_resume() {
audio::output::stop();
if( !recon_thread->is_recon() )
recon_thread->set_recon(true); // RESUME!
recon_thread->set_recon(true); // RESUME!
big_display.set_style(&style_white); //Back to grey color
}
void ReconView::user_pause() {
timer = 0 ; // Will trigger a recon_resume() on_statistics_update, also advancing to next freq.
timer = 0 ; // Will trigger a recon_resume() on_statistics_update, also advancing to next freq.
//button_pause.set_text("<RESUME>"); //PAUSED, show resume
userpause=true;
continuous_lock=false;
@@ -1764,9 +1826,9 @@ namespace ui {
}
void ReconView::user_resume() {
timer = 0 ; // Will trigger a recon_resume() on_statistics_update, also advancing to next freq.
timer = 0 ; // Will trigger a recon_resume() on_statistics_update, also advancing to next freq.
//button_pause.set_text("<PAUSE>"); //Show button for pause
userpause=false; // Resume recon
userpause=false; // Resume recon
continuous_lock=false;
recon_resume();
}
+11 -7
View File
@@ -39,6 +39,14 @@
#include "file.hpp"
#include "app_settings.hpp"
// maximum usable freq
#define MAX_UFREQ 7200000000
// 1Mhz helper
#ifdef OneMHz
#undef OneMHz
#endif
#define OneMHz 1000000
namespace ui {
@@ -57,8 +65,8 @@ namespace ui {
void set_match_mode( const uint32_t v );
uint32_t get_lock_nb_match();
void set_freq_lock(const uint32_t v);
uint32_t is_freq_lock();
void set_freq_lock(const int32_t v);
int32_t is_freq_lock();
int64_t get_current_freq();
void set_stepper(const int64_t v);
@@ -118,8 +126,6 @@ namespace ui {
void focus() override;
void big_display_freq( int64_t f );
const Style style_grey { // recon
.font = font::fixed_8x16,
.background = Color::black(),
@@ -178,7 +184,7 @@ namespace ui {
bool check_sd_card();
void handle_coded_squelch(const uint32_t value);
jammer::jammer_range_t frequency_range { false, 0, 0 }; //perfect for manual recon task too...
jammer::jammer_range_t frequency_range { false, 0, MAX_UFREQ }; //perfect for manual recon task too...
int32_t squelch { 0 };
int32_t db { 0 };
int32_t timer { 0 };
@@ -200,8 +206,6 @@ namespace ui {
bool load_hamradios = { true };
bool update_ranges = { true };
bool fwd = { true };
// maximum usable freq
long long int MAX_UFREQ = { 7200000000 };
uint32_t recon_lock_nb_match = { 10 };
uint32_t recon_lock_duration = { 50 };
uint32_t recon_match_mode = { 0 };
-2
View File
@@ -88,8 +88,6 @@ public:
void focus() override;
void big_display_freq(rf::Frequency f);
const Style style_grey { // scanning
.font = font::fixed_8x16,
.background = Color::black(),
+1 -1
View File
@@ -40,7 +40,7 @@ public:
void focus() override;
std::string title() const override { return "Flash Utility"; };
std::string title() const override { return "SD over USB"; };
private:
NavigationView& nav_;
+17 -3
View File
@@ -41,7 +41,6 @@ using namespace portapack;
#include "freqman.hpp"
namespace ui {
SetDateTimeView::SetDateTimeView(
NavigationView& nav
) {
@@ -306,7 +305,6 @@ namespace ui {
checkbox_load_app_settings.set_value(persistent_memory::load_app_settings());
checkbox_save_app_settings.set_value(persistent_memory::save_app_settings());
button_save.on_select = [&nav, this](Button&) {
persistent_memory::set_load_app_settings(checkbox_load_app_settings.value());
persistent_memory::set_save_app_settings(checkbox_save_app_settings.value());
@@ -405,11 +403,16 @@ namespace ui {
&check_load_mem_at_startup,
&button_save_mem_to_file,
&button_load_mem_from_file,
&button_load_mem_defaults,
&button_return
});
bool load_mem_at_startup = false ;
File pmem_flag_file_handle ;
std::string folder = "SETTINGS";
make_new_directory(folder);
std::string pmem_flag_file = "/SETTINGS/PMEM_FILEFLAG" ;
auto result = pmem_flag_file_handle.open(pmem_flag_file);
if(!result.is_valid())
@@ -443,7 +446,7 @@ namespace ui {
else
{
auto result = delete_file( pmem_flag_file );
if( result != 0 )
if( result.code() != FR_OK )
{
text_pmem_status.set("!err. deleting pmem flagfile!");
}
@@ -479,6 +482,17 @@ namespace ui {
}
};
button_load_mem_defaults.on_select = [&nav, this](Button&) {
nav.push<ModalMessageView>(
"Warning!",
"This will reset the p.mem\nand set the default settings",
YESNO,
[this](bool choice) {
if (choice) {
portapack::persistent_memory::cache::defaults();
}
} );
};
button_return.on_select = [&nav, this](Button&) {
nav.pop();
+9 -4
View File
@@ -314,7 +314,7 @@ private:
25,
"Save app settings"
};
Button button_save {
{ 2 * 8, 16 * 16, 12 * 8, 32 },
"Save"
@@ -464,15 +464,20 @@ private:
};
Button button_save_mem_to_file {
{ 0, 9 * 16, 240, 32 },
{ 0, 8 * 16, 240, 32 },
"save p.mem to sdcard"
};
Button button_load_mem_from_file {
{ 0, 12 * 16, 240, 32 },
{ 0, 10 * 16 + 4 , 240, 32 },
"load p.mem from sdcard"
};
Button button_load_mem_defaults {
{ 0, 12 * 16 + 8 , 240, 32 },
"! reset p.mem, load defaults !"
};
Button button_return {
{ 16 * 8, 16 * 16, 12 * 8, 32 },
"Return",
+13 -13
View File
@@ -49,26 +49,26 @@ private:
void on_tx_progress(const uint32_t progress, const bool done);
const std::string shape_strings[7] = {
"CW",
"Sine",
"Triangle",
"Saw up",
"Saw down",
"Square",
"Noise"
"CW-just carrier",
"Sine signal ",
"Triangle signal",
"Saw up signal ",
"Saw down signal",
"Square signal ",
"Noise signal " // using 16 bits LFSR register, 16 order polynomial feedback.
};
bool auto_update { false };
Labels labels {
{ { 6 * 8, 4 + 10 }, "Shape:", Color::light_grey() },
{ { 7 * 8, 7 * 8 }, "Tone: Hz", Color::light_grey() },
{ { 3 * 8, 4 + 10 }, "Shape:", Color::light_grey() },
{ { 6 * 8, 7 * 8 }, "Tone: Hz", Color::light_grey() },
{ { 22 * 8, 15 * 8 + 4 }, "s.", Color::light_grey() },
{ { 8 * 8, 20 * 8 }, "Modulation: FM", Color::light_grey() }
};
ImageOptionsField options_shape {
{ 13 * 8, 4, 32, 32 },
{ 10 * 8, 4, 32, 32 },
Color::white(),
Color::black(),
{
@@ -83,7 +83,7 @@ private:
};
Text text_shape {
{ 18 * 8, 4 + 10, 8 * 8, 16 },
{ 15 * 8, 4 + 10, 8 * 8, 16 },
""
};
@@ -94,12 +94,12 @@ private:
};
Button button_update {
{ 6 * 8, 10 * 8, 8 * 8, 3 * 8 },
{ 5 * 8, 10 * 8, 8 * 8, 3 * 8 },
"Update"
};
Checkbox checkbox_auto {
{ 16 * 8, 10 * 8 },
{ 15 * 8, 10 * 8 },
4,
"Auto"
};
+2 -2
View File
@@ -133,12 +133,12 @@ SondeView::SondeView(NavigationView& nav) {
999); //set a dummy heading out of range to draw a cross...probably not ideal?
};
make_new_directory(LOG_ROOT_DIR);
logger = std::make_unique<SondeLogger>();
if (logger)
logger->append(u"sonde.txt");
logger->append( LOG_ROOT_DIR "/SONDE.TXT" );
// initialize audio:
field_volume.set_value((receiver_model.headphone_volume() - audio::headphone::volume_range().max).decibel() + 99);
field_volume.on_change = [this](int32_t v) {
+3 -2
View File
@@ -73,8 +73,8 @@ void NBFMConfig::apply(const uint8_t squelch_level) const {
void WFMConfig::apply() const {
const WFMConfigureMessage message {
taps_200k_wfm_decim_0,
taps_200k_wfm_decim_1,
decim_0, // taps_200k_decim_0 , taps_180k_wfm_decim_0, taps_40k_wfm_decim_0
decim_1, // taps_200k_decim_1 or taps_180k_wfm_decim_1, taps_40k_wfm_decim_1
taps_64_lp_156_198,
75000,
audio_48k_hpf_30hz_config,
@@ -84,6 +84,7 @@ void WFMConfig::apply() const {
audio::set_rate(audio::Rate::Hz_48000);
}
void set_tone(const uint32_t index, const uint32_t delta, const uint32_t duration) {
shared_memory.bb_data.tones_data.tone_defs[index].delta = delta;
shared_memory.bb_data.tones_data.tone_defs[index].duration = duration;
+3
View File
@@ -53,6 +53,9 @@ struct NBFMConfig {
};
struct WFMConfig {
const fir_taps_real<24> decim_0; // To handle both WFM filters , 200k and 40K for NOAA APT
const fir_taps_real<16> decim_1;
void apply() const;
};
+131
View File
@@ -2543,6 +2543,137 @@ static constexpr Bitmap bitmap_target {
{ 16, 16 }, bitmap_target_data
};
static constexpr uint8_t bitmap_icon_trash_data[] = {
0x00, 0x00,
0xC0, 0x01,
0x20, 0x02,
0xFC, 0x1F,
0x00, 0x00,
0xA8, 0x0A,
0xA8, 0x0A,
0xA8, 0x0A,
0xA8, 0x0A,
0xA8, 0x0A,
0xA8, 0x0A,
0xA8, 0x0A,
0xA8, 0x0A,
0x08, 0x08,
0xF0, 0x07,
0x00, 0x00,
};
static constexpr Bitmap bitmap_icon_trash {
{ 16, 16 }, bitmap_icon_trash_data
};
static constexpr uint8_t bitmap_icon_copy_data[] = {
0x00, 0x00,
0xFC, 0x00,
0x84, 0x01,
0xC4, 0x0F,
0x74, 0x18,
0x44, 0x38,
0x44, 0x78,
0x74, 0x40,
0x44, 0x44,
0x44, 0x44,
0x74, 0x5F,
0x44, 0x44,
0x44, 0x44,
0x7C, 0x40,
0xC0, 0x7F,
0x00, 0x00,
};
static constexpr Bitmap bitmap_icon_copy {
{ 16, 16 }, bitmap_icon_copy_data
};
static constexpr uint8_t bitmap_icon_cut_data[] = {
0x00, 0x00,
0x10, 0x10,
0x30, 0x18,
0x20, 0x08,
0x60, 0x0C,
0x40, 0x04,
0xC0, 0x06,
0x80, 0x00,
0x80, 0x01,
0x80, 0x01,
0xC0, 0x03,
0x78, 0x1E,
0x44, 0x22,
0x44, 0x22,
0x44, 0x22,
0x38, 0x1C,
};
static constexpr Bitmap bitmap_icon_cut {
{ 16, 16 }, bitmap_icon_cut_data
};
static constexpr uint8_t bitmap_icon_paste_data[] = {
0x00, 0x00,
0xE0, 0x00,
0x18, 0x03,
0xE4, 0x04,
0x04, 0x04,
0x04, 0x04,
0x84, 0x3F,
0x84, 0x20,
0x84, 0x2E,
0x84, 0x20,
0x84, 0x2E,
0x84, 0x20,
0x84, 0x2E,
0xF8, 0x20,
0x80, 0x3F,
0x00, 0x00,
};
static constexpr Bitmap bitmap_icon_paste {
{ 16, 16 }, bitmap_icon_paste_data
};
static constexpr uint8_t bitmap_icon_new_dir_data[] = {
0x00, 0x00,
0x1E, 0x00,
0x21, 0x00,
0xE1, 0x7F,
0x01, 0xC0,
0x81, 0x81,
0x81, 0x81,
0x81, 0x81,
0xF1, 0x8F,
0xF1, 0x8F,
0x81, 0x81,
0x81, 0x81,
0x81, 0x81,
0x03, 0xC0,
0xFE, 0x7F,
0x00, 0x00,
};
static constexpr Bitmap bitmap_icon_new_dir {
{ 16, 16 }, bitmap_icon_new_dir_data
};
static constexpr uint8_t bitmap_icon_new_file_data[] = {
0x00, 0x00,
0xFC, 0x07,
0x04, 0x0C,
0x04, 0x1C,
0x04, 0x3C,
0x84, 0x21,
0x84, 0x21,
0x84, 0x21,
0xF4, 0x2F,
0xF4, 0x2F,
0x84, 0x21,
0x84, 0x21,
0x84, 0x21,
0x04, 0x20,
0xFC, 0x3F,
0x00, 0x00,
};
static constexpr Bitmap bitmap_icon_new_file {
{ 16, 16 }, bitmap_icon_new_file_data
};
} /* namespace ui */
+9 -1
View File
@@ -43,6 +43,7 @@ using namespace lpc43xx;
#include <array>
#include "ui_font_fixed_8x16.hpp"
#include "ui_navigation.hpp"
extern "C" {
@@ -262,6 +263,8 @@ void EventDispatcher::on_touch_event(ui::TouchEvent event) {
void EventDispatcher::handle_lcd_frame_sync() {
DisplayFrameSyncMessage message;
message_map.send(&message);
static_cast<ui::SystemView *>(top_widget)->paint_overlay();
painter.paint_widget_tree(top_widget);
portapack::backlight()->on();
@@ -304,7 +307,12 @@ void EventDispatcher::handle_switches() {
if( switches_state[i] ) {
const auto event = static_cast<ui::KeyEvent>(i);
if( !event_bubble_key(event) ) {
context.focus_manager().update(top_widget, event);
if (switches_state[(size_t)ui::KeyEvent::Dfu]) {
static_cast<ui::SystemView *>(top_widget)->toggle_overlay();
}
else {
context.focus_manager().update(top_widget, event);
}
}
in_key_event = true;
+94 -7
View File
@@ -197,12 +197,44 @@ std::vector<std::filesystem::path> scan_root_directories(const std::filesystem::
return directory_list;
}
uint32_t delete_file(const std::filesystem::path& file_path) {
return f_unlink(reinterpret_cast<const TCHAR*>(file_path.c_str()));
std::filesystem::filesystem_error delete_file(const std::filesystem::path& file_path) {
return { f_unlink(reinterpret_cast<const TCHAR*>(file_path.c_str())) };
}
uint32_t rename_file(const std::filesystem::path& file_path, const std::filesystem::path& new_name) {
return f_rename(reinterpret_cast<const TCHAR*>(file_path.c_str()), reinterpret_cast<const TCHAR*>(new_name.c_str()));
std::filesystem::filesystem_error rename_file(
const std::filesystem::path& file_path,
const std::filesystem::path& new_name
) {
return { f_rename(reinterpret_cast<const TCHAR*>(file_path.c_str()), reinterpret_cast<const TCHAR*>(new_name.c_str())) };
}
std::filesystem::filesystem_error copy_file(
const std::filesystem::path& file_path,
const std::filesystem::path& dest_path
) {
File src;
File dst;
constexpr size_t buffer_size = 512;
uint8_t buffer[buffer_size];
auto error = src.open(file_path);
if (error.is_valid()) return error.value();
error = dst.create(dest_path);
if (error.is_valid()) return error.value();
while (true) {
auto result = src.read(buffer, buffer_size);
if (result.is_error()) return result.error();
result = dst.write(buffer, result.value());
if (result.is_error()) return result.error();
if (result.value() < buffer_size)
break;
}
return { };
}
FATTimestamp file_created_date(const std::filesystem::path& file_path) {
@@ -213,8 +245,20 @@ FATTimestamp file_created_date(const std::filesystem::path& file_path) {
return { filinfo.fdate, filinfo.ftime };
}
uint32_t make_new_directory(const std::filesystem::path& dir_path) {
return f_mkdir(reinterpret_cast<const TCHAR*>(dir_path.c_str()));
std::filesystem::filesystem_error make_new_file(
const std::filesystem::path& file_path
) {
File f;
auto result = f.create(file_path);
return result.is_valid()
? result.value()
: std::filesystem::filesystem_error{ };
}
std::filesystem::filesystem_error make_new_directory(
const std::filesystem::path& dir_path
) {
return { f_mkdir(reinterpret_cast<const TCHAR*>(dir_path.c_str())) };
}
namespace std {
@@ -250,6 +294,15 @@ std::string filesystem_error::what() const {
}
}
path path::parent_path() const {
const auto index = _s.find_last_of(preferred_separator);
if( index == _s.npos ) {
return { }; // NB: Deviation from STL.
} else {
return _s.substr(0, index);
}
}
path path::extension() const {
const auto t = filename().native();
const auto index = t.find_last_of(u'.');
@@ -296,6 +349,14 @@ path& path::replace_extension(const path& replacement) {
return *this;
}
bool operator==(const path& lhs, const path& rhs) {
return lhs.native() == rhs.native();
}
bool operator!=(const path& lhs, const path& rhs) {
return !(lhs == rhs);
}
bool operator<(const path& lhs, const path& rhs) {
return lhs.native() < rhs.native();
}
@@ -304,6 +365,18 @@ bool operator>(const path& lhs, const path& rhs) {
return lhs.native() > rhs.native();
}
path operator+(const path& lhs, const path& rhs) {
path result = lhs;
result += rhs;
return result;
}
path operator/(const path& lhs, const path& rhs) {
path result = lhs;
result /= rhs;
return result;
}
directory_iterator::directory_iterator(
std::filesystem::path path,
std::filesystem::path wild
@@ -311,7 +384,7 @@ directory_iterator::directory_iterator(
{
impl = std::make_shared<Impl>();
const auto result = f_findfirst(&impl->dir, &impl->filinfo, reinterpret_cast<const TCHAR*>(path.c_str()), reinterpret_cast<const TCHAR*>(pattern.c_str()));
if( result != FR_OK ) {
if( result != FR_OK || impl->filinfo.fname[0] == (TCHAR)'\0') {
impl.reset();
// TODO: Throw exception if/when I enable exceptions...
}
@@ -333,6 +406,20 @@ bool is_regular_file(const file_status s) {
return !(s & AM_DIR);
}
bool file_exists(const path& file_path) {
FILINFO filinfo;
auto fr = f_stat(reinterpret_cast<const TCHAR*>(file_path.c_str()), &filinfo);
return fr == FR_OK;
}
bool is_directory(const path& file_path) {
FILINFO filinfo;
auto fr = f_stat(reinterpret_cast<const TCHAR*>(file_path.c_str()), &filinfo);
return fr == FR_OK && is_directory(static_cast<file_status>(filinfo.fattrib));
}
space_info space(const path& p) {
DWORD free_clusters { 0 };
FATFS* fs;
+21 -3
View File
@@ -123,6 +123,7 @@ struct path {
return *this;
}
path parent_path() const;
path extension() const;
path filename() const;
path stem() const;
@@ -151,14 +152,25 @@ struct path {
return *this;
}
path& operator/=(const path& p) {
if (_s.back() != preferred_separator)
_s += preferred_separator;
_s += p._s;
return *this;
}
path& replace_extension(const path& replacement = path());
private:
string_type _s;
};
bool operator==(const path& lhs, const path& rhs);
bool operator!=(const path& lhs, const path& rhs);
bool operator<(const path& lhs, const path& rhs);
bool operator>(const path& lhs, const path& rhs);
path operator+(const path& lhs, const path& rhs);
path operator/(const path& lhs, const path& rhs);
using file_status = BYTE;
@@ -227,6 +239,8 @@ inline bool operator!=(const directory_iterator& lhs, const directory_iterator&
bool is_directory(const file_status s);
bool is_regular_file(const file_status s);
bool file_exists(const path& file_path);
bool is_directory(const path& file_path);
space_info space(const path& p);
@@ -238,13 +252,17 @@ struct FATTimestamp {
uint16_t FAT_time;
};
uint32_t delete_file(const std::filesystem::path& file_path);
uint32_t rename_file(const std::filesystem::path& file_path, const std::filesystem::path& new_name);
std::filesystem::filesystem_error delete_file(const std::filesystem::path& file_path);
std::filesystem::filesystem_error rename_file(const std::filesystem::path& file_path, const std::filesystem::path& new_name);
std::filesystem::filesystem_error copy_file(const std::filesystem::path& file_path, const std::filesystem::path& dest_path);
FATTimestamp file_created_date(const std::filesystem::path& file_path);
uint32_t make_new_directory(const std::filesystem::path& dir_path);
std::filesystem::filesystem_error make_new_file(const std::filesystem::path& file_path);
std::filesystem::filesystem_error make_new_directory(const std::filesystem::path& dir_path);
std::vector<std::filesystem::path> scan_root_files(const std::filesystem::path& directory, const std::filesystem::path& extension);
std::vector<std::filesystem::path> scan_root_directories(const std::filesystem::path& directory);
/* Gets an auto incrementing filename. */
std::filesystem::path next_filename_stem_matching_pattern(std::filesystem::path filename_stem_pattern);
/* Values added to FatFs FRESULT enum, values outside the FRESULT data type */
+33 -31
View File
@@ -47,44 +47,46 @@ options_t freqman_entry_bandwidths[ 4 ] = {
},
{ //WFM
{ "200k" , 0 },
{ "180k" , 1 },
{ " 40k" , 2 },
}
};
options_t freqman_entry_steps = {
{ "0.1KHz " , 100 },
{ "1KHz " , 1000 },
{ "5KHz (SA AM)" , 5000 },
{ "6.25KHz(NFM)" , 6250 },
{ "8.33KHz(AIR)" , 8330 },
{ "9KHz (EU AM)" , 9000 },
{ "10KHz(US AM)" , 10000 },
{ "12.5KHz(NFM)" , 12500 },
{ "15KHz (HFM)" , 15000 },
{ "25KHz (N1)" , 25000 },
{ "30KHz (OIRT)" , 30000 },
{ "50KHz (FM1)" , 50000 },
{ "100KHz (FM2)" , 100000 },
{ "250KHz (N2)" , 250000 },
{ "500KHz (WFM)" , 500000 },
{ "0.1kHz " , 100 },
{ "1kHz " , 1000 },
{ "5kHz (SA AM)" , 5000 },
{ "6.25kHz(NFM)" , 6250 },
{ "8.33kHz(AIR)" , 8330 },
{ "9kHz (EU AM)" , 9000 },
{ "10kHz(US AM)" , 10000 },
{ "12.5kHz(NFM)" , 12500 },
{ "15kHz (HFM)" , 15000 },
{ "25kHz (N1)" , 25000 },
{ "30kHz (OIRT)" , 30000 },
{ "50kHz (FM1)" , 50000 },
{ "100kHz (FM2)" , 100000 },
{ "250kHz (N2)" , 250000 },
{ "500kHz (WFM)" , 500000 },
{ "1MHz " , 1000000 }
};
options_t freqman_entry_steps_short = {
{ "0.1KHz" , 100 },
{ "1KHz" , 1000 },
{ "5KHz" , 5000 },
{ "6.25KHz" , 6250 },
{ "8.33KHz" , 8330 },
{ "9KHz" , 9000 },
{ "10KHz" , 10000 },
{ "12.5KHz" , 12500 },
{ "15KHz" , 15000 },
{ "25KHz" , 25000 },
{ "30KHz" , 30000 },
{ "50KHz" , 50000 },
{ "100KHz" , 100000 },
{ "250KHz" , 250000 },
{ "500KHz" , 500000 },
{ "0.1kHz" , 100 },
{ "1kHz" , 1000 },
{ "5kHz" , 5000 },
{ "6.25kHz" , 6250 },
{ "8.33kHz" , 8330 },
{ "9kHz" , 9000 },
{ "10kHz" , 10000 },
{ "12.5kHz" , 12500 },
{ "15kHz" , 15000 },
{ "25kHz" , 25000 },
{ "30kHz" , 30000 },
{ "50kHz" , 50000 },
{ "100kHz" , 100000 },
{ "250kHz" , 250000 },
{ "500kHz" , 500000 },
{ "1MHz" , 1000000 }
};
@@ -229,7 +231,7 @@ bool load_freqman_file_ex(std::string& file_stem, freqman_db& db, bool load_freq
{
db.push_back({ frequency_a, frequency_b, description, type , modulation , bandwidth , step , tone });
n++;
if (n >= FREQMAN_MAX_PER_FILE) return true;
if (n > FREQMAN_MAX_PER_FILE) return true;
}
line_start = line_end + 1;
+5 -4
View File
@@ -31,9 +31,10 @@
#include "string_format.hpp"
#include "ui_widget.hpp"
#define FREQMAN_DESC_MAX_LEN 30
#define FREQMAN_MAX_PER_FILE 500 /* MAX PER FILES */
#define FREQMAN_MAX_PER_FILE_STR "500" /*STRING OF FREQMAN_MAX_PER_FILE */
#define FREQMAN_DESC_MAX_LEN 24 // This is the number of characters that can be drawn in front of "R: TEXT..." before taking a full screen line
#define FREQMAN_MAX_PER_FILE 115 // Maximum of entries we can read. This is a hardware limit
// It was tested and lowered to leave a bit of space to the caller
#define FREQMAN_MAX_PER_FILE_STR "115" // STRING OF FREQMAN_MAX_PER_FILE
using namespace ui;
using namespace std;
@@ -86,7 +87,7 @@ struct freqman_entry {
freqman_entry_type type { }; // SINGLE,RANGE,HAMRADIO
freqman_index_t modulation { }; // AM,NFM,WFM
freqman_index_t bandwidth { }; // AM_DSB, ...
freqman_index_t step { }; // 5Khz (SA AM,...
freqman_index_t step { }; // 5khz (SA AM,...
tone_index tone { }; // 0XZ, 11 1ZB,...
};
+4 -2
View File
@@ -42,7 +42,7 @@ using namespace hackrf::one;
static Thread* thread_controls_event = NULL;
static std::array<Debounce, 7> switch_debounce;
static std::array<Debounce, 8> switch_debounce;
static Encoder encoder;
@@ -193,11 +193,13 @@ void controls_init() {
SwitchesState get_switches_state() {
SwitchesState result;
for(size_t i=0; i<result.size(); i++) {
for(size_t i=0; i<result.size()-1; i++) {
// TODO: Ignore multiple keys at the same time?
result[i] = switch_debounce[i].state();
}
result[result.size()-1] = switch_debounce[switch_debounce.size()-1].state();
return result;
}
+2 -1
View File
@@ -33,9 +33,10 @@ enum class Switch {
Down = 2,
Up = 3,
Sel = 4,
Dfu = 5,
};
using SwitchesState = std::bitset<5>;
using SwitchesState = std::bitset<6>;
using EncoderPosition = uint32_t;
+3
View File
@@ -27,8 +27,11 @@
#include "file.hpp"
#include "lpc43xx_cpp.hpp"
using namespace lpc43xx;
#define LOG_ROOT_DIR "LOGS"
class LogFile {
public:
Optional<File::Error> append(const std::filesystem::path& filename) {
+3 -3
View File
@@ -145,14 +145,14 @@ Continuous (Fox-oring)
rffc507x::RFFC507x first_if;
static void event_loop() {
ui::Context context;
ui::SystemView system_view {
static ui::Context context;
static ui::SystemView system_view {
context,
portapack::display.screen_rect()
};
EventDispatcher event_dispatcher { &system_view, context };
MessageHandlerRegistration message_handler_display_sleep {
static MessageHandlerRegistration message_handler_display_sleep {
Message::ID::DisplaySleep,
[&event_dispatcher](const Message* const) {
event_dispatcher.set_display_sleep(true);
+7 -4
View File
@@ -61,7 +61,7 @@ portapack::IO io {
portapack::gpio_io_stbx,
portapack::gpio_addr,
portapack::gpio_lcd_te,
portapack::gpio_unused,
portapack::gpio_dfu,
};
portapack::BacklightCAT4004 backlight_cat4004;
@@ -489,10 +489,13 @@ bool init() {
chThdSleepMilliseconds(10);
if( !portapack::cpld::update_if_necessary(portapack_cpld_config()) ) {
portapack::cpld::CpldUpdateStatus result = portapack::cpld::update_if_necessary(portapack_cpld_config());
if ( result == portapack::cpld::CpldUpdateStatus::Program_failed ) {
chThdSleepMilliseconds(10);
// If using a "2021/12 QFP100", press and hold the left button while booting. Should only need to do once.
if (load_config() != 3 && load_config() != 4){
// Mode left (R1) and right (R2,H2,H2+) bypass going into hackrf mode after failing CPLD update
// Mode center (autodetect), up (R1) and down (R2,H2,H2+) will go into hackrf mode after failing CPLD update
if (load_config() != 3 /* left */ && load_config() != 4 /* right */){
shutdown_base();
return false;
}
+4 -2
View File
@@ -52,8 +52,10 @@ static constexpr std::array<baseband::NBFMConfig, 3> nbfm_configs { {
{ taps_16k0_decim_0, taps_16k0_decim_1, taps_16k0_channel, 5000 },
} };
static constexpr std::array<baseband::WFMConfig, 1> wfm_configs { {
{ },
static constexpr std::array<baseband::WFMConfig, 3> wfm_configs { {
{taps_200k_wfm_decim_0, taps_200k_wfm_decim_1 },
{taps_180k_wfm_decim_0, taps_180k_wfm_decim_1 },
{taps_40k_wfm_decim_0, taps_40k_wfm_decim_1 },
} };
} /* namespace */
+11 -6
View File
@@ -81,16 +81,21 @@ void Manager::feed(const Frame& frame) {
const auto touch_raw = frame.touch;
//const auto touch_stable = touch_debounce.state();
const auto touch_stable = frame.touch;
bool touch_pressure = false;
bool touch_down_pressure = false;
bool touch_up_pressure = false;
// Only feed coordinate averaging if there's a touch.
// TODO: Separate threshold to gate coordinates for filtering?
if( touch_raw ) {
const auto metrics = calculate_metrics(frame);
// TODO: Add touch pressure hysteresis?
touch_pressure = (metrics.r < r_touch_threshold);
if( touch_pressure ) {
constexpr float r_touch_down_threshold = 3200.0f;
constexpr float r_touch_up_threshold = r_touch_down_threshold * 2.0f;
touch_down_pressure = (metrics.r < r_touch_down_threshold);
touch_up_pressure = (metrics.r < r_touch_up_threshold);
if( touch_down_pressure ) {
filter_x.feed(metrics.x * 1024);
filter_y.feed(metrics.y * 1024);
}
@@ -101,7 +106,7 @@ void Manager::feed(const Frame& frame) {
switch(state) {
case State::NoTouch:
if( touch_stable && touch_pressure && !persistent_memory::disable_touchscreen()) {
if( touch_stable && touch_down_pressure && !persistent_memory::disable_touchscreen()) {
if( point_stable() ) {
state = State::TouchDetected;
touch_started();
@@ -110,7 +115,7 @@ void Manager::feed(const Frame& frame) {
break;
case State::TouchDetected:
if( touch_stable && touch_pressure ) {
if( touch_stable && touch_up_pressure ) {
touch_moved();
} else {
state = State::NoTouch;
-1
View File
@@ -219,7 +219,6 @@ private:
TouchDetected,
};
static constexpr float r_touch_threshold = 640;
static constexpr size_t touch_count_threshold { 3 };
static constexpr uint32_t touch_stable_bound { 8 };
+1 -16
View File
@@ -30,10 +30,6 @@
namespace ui {
void AlphanumView::paint(Painter&) {
draw_cursor();
}
AlphanumView::AlphanumView(
NavigationView& nav,
std::string& str,
@@ -41,7 +37,7 @@ AlphanumView::AlphanumView(
) : TextEntryView(nav, str, max_length)
{
size_t n;
add_children({
&button_mode,
&text_raw,
@@ -77,16 +73,7 @@ AlphanumView::AlphanumView(
field_raw.set_value('0');
field_raw.on_select = [this](NumberField&) {
char_add(field_raw.value());
update_text();
};
button_ok.on_select = [this, &nav](Button&) {
if (on_changed)
on_changed(_str);
nav.pop();
};
update_text();
}
void AlphanumView::set_mode(const uint32_t new_mode) {
@@ -120,8 +107,6 @@ void AlphanumView::on_button(Button& button) {
char_delete();
else
char_add(c);
update_text();
}
bool AlphanumView::on_encoder(const EncoderEvent delta) {
-1
View File
@@ -40,7 +40,6 @@ public:
AlphanumView& operator=(const AlphanumView&) = delete;
AlphanumView& operator=(AlphanumView&&) = delete;
void paint(Painter& painter) override;
bool on_encoder(const EncoderEvent delta) override;
private:
+9 -3
View File
@@ -163,6 +163,12 @@ void MenuView::clear() {
}
menu_items.clear();
highlighted_item = 0;
offset = 0;
}
size_t MenuView::item_count() const {
return menu_items.size();
}
void MenuView::add_item(MenuItem new_item) {
@@ -209,7 +215,7 @@ MenuItemView* MenuView::item_view(size_t index) const {
bool MenuView::set_highlighted(int32_t new_value) {
int32_t item_count = (int32_t)menu_items.size();
if (new_value < 0)
if (new_value < 0 || item_count == 0)
return false;
if (new_value >= item_count)
@@ -238,7 +244,7 @@ bool MenuView::set_highlighted(int32_t new_value) {
return true;
}
uint32_t MenuView::highlighted_index() {
uint32_t MenuView::highlighted_index() const {
return highlighted_item;
}
@@ -262,7 +268,7 @@ bool MenuView::on_key(const KeyEvent key) {
case KeyEvent::Select:
case KeyEvent::Right:
if( menu_items[highlighted_item].on_select ) {
menu_items[highlighted_item].on_select();
menu_items[highlighted_item].on_select(key);
}
return true;
+3 -2
View File
@@ -39,7 +39,7 @@ struct MenuItem {
std::string text;
ui::Color color;
const Bitmap* bitmap;
std::function<void(void)> on_select;
std::function<void(KeyEvent)> on_select;
// TODO: Prevent default-constructed MenuItems.
// I managed to construct a menu with three extra, unspecified menu items
@@ -83,11 +83,12 @@ public:
void add_item(MenuItem new_item);
void add_items(std::initializer_list<MenuItem> new_items);
void clear();
size_t item_count() const;
MenuItemView* item_view(size_t index) const;
bool set_highlighted(int32_t new_value);
uint32_t highlighted_index();
uint32_t highlighted_index() const;
void set_parent_rect(const Rect new_parent_rect) override;
void on_focus() override;
+16 -1
View File
@@ -87,7 +87,22 @@ bool FrequencyField::on_key(const ui::KeyEvent event) {
}
bool FrequencyField::on_encoder(const EncoderEvent delta) {
set_value(value() + (delta * step));
if (step == 0) { // 'Auto' mode.'
auto ms = RTT2MS(halGetCounterValue());
auto delta_ms = last_ms_ <= ms ? ms - last_ms_ : ms;
last_ms_ = ms;
// The goal is to map 'scale' to a range of about 10 to 10M.
// The faster the encoder is rotated, the larger the step.
// Linear doesn't feel right. Hyperbolic felt better.
// To get these magic numbers, I graphed the function until the
// curve shape seemed about right then tested on device.
delta_ms = std::min(145ull, delta_ms) + 5; // Prevent DIV/0
int64_t scale = 200'000'000 / (0.001'55 * pow(delta_ms, 5.45)) + 8;
set_value(value() + (delta * scale));
} else {
set_value(value() + (delta * step));
}
return true;
}
+2
View File
@@ -63,6 +63,7 @@ private:
const range_t range;
rf::Frequency value_ { 0 };
rf::Frequency step { 25000 };
uint64_t last_ms_ { 0 };
rf::Frequency clamp_value(rf::Frequency value);
};
@@ -247,6 +248,7 @@ public:
parent_pos,
5,
{
{ " Auto", 0 }, /* Faster == larger step. */
{ " 10", 10 }, /* Fine tuning SSB voice pitch,in HF and QO-100 sat #669 */
{ " 50", 50 }, /* added 50Hz/10Hz,but we do not increase GUI digit decimal */
{ " 100", 100 },
+17
View File
@@ -434,6 +434,23 @@ namespace ui {
void RSSIGraph::set_nb_columns( int16_t nb )
{
nb_columns = nb ;
while( graph_list.size() > nb_columns )
{
graph_list.erase( graph_list.begin() );
}
}
void RSSIGraph::on_hide() {
nb_columns_before_hide = nb_columns ;
nb_columns = 1 ;
while( graph_list.size() > nb_columns )
{
graph_list.erase( graph_list.begin() );
}
}
void RSSIGraph::on_show() {
nb_columns = nb_columns_before_hide ;
}
void RSSI::on_focus() {
+4
View File
@@ -115,8 +115,12 @@ namespace ui {
void paint(Painter& painter) override;
void add_values(int16_t rssi_min, int16_t rssi_avg, int16_t rssi_max, int16_t db );
void set_nb_columns( int16_t nb );
void on_hide() override ;
void on_show() override ;
private:
uint16_t nb_columns_before_hide = 16 ;
uint16_t nb_columns = 16 ;
RSSIGraphList graph_list { } ;
};
+27 -49
View File
@@ -29,9 +29,25 @@ using namespace portapack;
namespace ui {
void text_prompt(NavigationView& nav, std::string& str, const size_t max_length, const std::function<void(std::string&)> on_done) {
void text_prompt(
NavigationView& nav,
std::string& str,
size_t max_length,
std::function<void(std::string&)> on_done
) {
text_prompt(nav, str, str.length(), max_length, on_done);
}
void text_prompt(
NavigationView& nav,
std::string& str,
uint32_t cursor_pos,
size_t max_length,
std::function<void(std::string&)> on_done
) {
//if (persistent_memory::ui_config_textentry() == 0) {
auto te_view = nav.push<AlphanumView>(str, max_length);
te_view->set_cursor(cursor_pos);
te_view->on_changed = [on_done](std::string& value) {
if (on_done)
on_done(value);
@@ -45,76 +61,38 @@ void text_prompt(NavigationView& nav, std::string& str, const size_t max_length,
}*/
}
void TextEntryView::update_text() {
if (cursor_pos < 30)
text_input.set(_str + std::string(_max_length - _str.length(), ' '));
else
text_input.set('<' + _str.substr(cursor_pos - 29, 29));
draw_cursor();
}
/* TextEntryView ***********************************************************/
void TextEntryView::char_delete() {
if (!cursor_pos) return;
cursor_pos--;
_str.resize(cursor_pos);
text_input.char_delete();
}
void TextEntryView::char_add(const char c) {
if (cursor_pos >= _max_length) return;
_str += c;
cursor_pos++;
text_input.char_add(c);
}
void TextEntryView::draw_cursor() {
Point draw_pos;
draw_pos = { text_input.screen_rect().location().x() + std::min((Coord)cursor_pos, (Coord)28) * 8,
text_input.screen_rect().location().y() + 16 };
// Erase previous
display.fill_rectangle(
{ { text_input.screen_rect().location().x(), draw_pos.y() }, { text_input.screen_rect().size().width(), 4 } },
Color::black()
);
// Draw new
display.fill_rectangle(
{ draw_pos, { 8, 4 } },
Color::white()
);
void TextEntryView::set_cursor(uint32_t pos) {
text_input.set_cursor(pos);
}
void TextEntryView::focus() {
button_ok.focus();
text_input.focus();
}
TextEntryView::TextEntryView(
NavigationView& nav,
std::string& str,
size_t max_length
) : _str(str),
_max_length(max_length)
) : text_input{ str, max_length, { 0, 0 } }
{
// Trim from right
//_str->erase(std::find_if(_str->rbegin(), _str->rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), _str->end());
if (_str.length() > _max_length)
_str.resize(_max_length);
_str.reserve(_max_length);
cursor_pos = _str.length();
add_children({
&text_input,
&button_ok
});
button_ok.on_select = [this, &nav](Button&) {
_str.resize(cursor_pos);
button_ok.on_select = [this, &str, &nav](Button&) {
if (on_changed)
on_changed(_str);
on_changed(str);
nav.pop();
};
}
+19 -11
View File
@@ -34,6 +34,8 @@ public:
void focus() override;
std::string title() const override { return "Text entry"; };
void set_cursor(uint32_t pos);
protected:
TextEntryView(NavigationView& nav, std::string& str, size_t max_length);
@@ -45,24 +47,30 @@ protected:
void char_add(const char c);
void char_delete();
void draw_cursor();
void update_text();
std::string& _str;
size_t _max_length;
uint32_t cursor_pos { 0 };
Text text_input {
{ 0, 0, 240, 16 }
};
TextField text_input;
Button button_ok {
{ 10 * 8, 33 * 8, 9 * 8, 32 },
"OK"
};
};
void text_prompt(NavigationView& nav, std::string& str, size_t max_length, const std::function<void(std::string&)> on_done = nullptr);
// Show the TextEntry view to receive keyboard input.
// NB: This function returns immediately. 'str' is taken
// by reference and its lifetime must be ensured by the
// caller until the TextEntry view is dismissed.
void text_prompt(
NavigationView& nav,
std::string& str,
size_t max_length,
std::function<void(std::string&)> on_done = nullptr);
void text_prompt(
NavigationView& nav,
std::string& str,
uint32_t cursor_pos,
size_t max_length,
std::function<void(std::string&)> on_done = nullptr);
} /* namespace ui */
+31
View File
@@ -29,6 +29,7 @@
#include "bmp_splash.hpp"
#include "bmp_modal_warning.hpp"
#include "portapack_persistent_memory.hpp"
#include "portapack_shared_memory.hpp"
#include "ui_about_simple.hpp"
#include "ui_adsb_rx.hpp"
@@ -748,6 +749,36 @@ Context& SystemView::context() const {
return context_;
}
void SystemView::toggle_overlay() {
if (overlay_active){
this->remove_child(&this->overlay);
this->set_dirty();
shared_memory.request_m4_performance_counter = 0;
}
else{
this->add_child(&this->overlay);
this->set_dirty();
shared_memory.request_m4_performance_counter = 1;
shared_memory.m4_cpu_usage = 0;
shared_memory.m4_heap_usage = 0;
shared_memory.m4_stack_usage = 0;
}
overlay_active = !overlay_active;
}
void SystemView::paint_overlay() {
static bool last_paint_state = false;
if (overlay_active){
// paint background only every other second
if ((((chTimeNow()>>10) & 0x01) == 0x01) == last_paint_state)
return;
last_paint_state = !last_paint_state;
this->overlay.set_dirty();
}
}
/* ***********************************************************************/
void BMPView::focus() {
+16 -1
View File
@@ -33,6 +33,7 @@
#include "ui_channel.hpp"
#include "ui_audio.hpp"
#include "ui_sd_card_status_view.hpp"
#include "ui_dfu_menu.hpp"
#include "bitmap.hpp"
#include "ff.h"
@@ -75,6 +76,15 @@ namespace ui
{
return reinterpret_cast<T *>(push_view(std::unique_ptr<View>(new T(*this, std::forward<Args>(args)...))));
}
// Pushes a new view under the current on the stack so the current view returns into this new one.
template <class T, class... Args>
void push_under_current(Args &&...args)
{
auto new_view = std::unique_ptr<View>(new T(*this, std::forward<Args>(args)...));
view_stack.insert(view_stack.end() - 1, std::move(new_view));
}
template <class T, class... Args>
T *replace(Args &&...args)
{
@@ -125,7 +135,7 @@ namespace ui
Color::dark_grey()};
ImageButton button_back{
{2, 0 * 16, 16, 16},
{0, 0 * 16, 12 * 8, 16}, // Back button also covers the title for easier touch.
&bitmap_icon_previous,
Color::white(),
Color::dark_grey()};
@@ -290,10 +300,15 @@ namespace ui
const Rect parent_rect);
Context &context() const override;
void toggle_overlay();
void paint_overlay();
private:
bool overlay_active {false};
SystemStatusView status_view{navigation_view};
InformationView info_view{navigation_view};
DfuMenu overlay{navigation_view};
NavigationView navigation_view{};
Context &context_;
};
+1
View File
@@ -139,6 +139,7 @@ set(CPPSRC
${COMMON}/chibios_cpp.cpp
debug.cpp
${COMMON}/gcc.cpp
${COMMON}/performance_counter.cpp
tone_gen.cpp
)
+9
View File
@@ -20,6 +20,7 @@
*/
#include "baseband_dma.hpp"
#include "portapack_shared_memory.hpp"
#include <cstdint>
#include <cstddef>
@@ -103,8 +104,12 @@ static constexpr auto& gpdma_channel_sgpio = gpdma::channels[portapack::sgpio_gp
static ThreadWait thread_wait;
volatile uint32_t buffer_transfered = 0;
volatile uint32_t buffer_handled = 0;
static void transfer_complete() {
const auto next_lli_index = gpdma_channel_sgpio.next_lli() - &lli_loop[0];
buffer_transfered++;
thread_wait.wake_from_interrupt(next_lli_index);
}
@@ -158,6 +163,10 @@ void disable() {
baseband::buffer_t wait_for_buffer() {
const auto next_index = thread_wait.sleep();
buffer_handled++;
auto buffer_missed = buffer_transfered - buffer_handled;
shared_memory.m4_buffer_missed = buffer_missed;
if( next_index >= 0 ) {
const size_t free_index = (next_index + transfers_per_buffer - 2) & transfers_mask;
+4
View File
@@ -508,6 +508,8 @@
}
#endif
/**
* @brief System tick event hook.
* @details This hook is invoked in the system tick handler immediately
@@ -516,6 +518,8 @@
#if !defined(SYSTEM_TICK_EVENT_HOOK) || defined(__DOXYGEN__)
#define SYSTEM_TICK_EVENT_HOOK() { \
/* System tick event code here.*/ \
extern void update_performance_counters(); \
update_performance_counters(); \
}
#endif
+24
View File
@@ -26,6 +26,7 @@
#include <hal.h>
#include "portapack_shared_memory.hpp"
#include "performance_counter.hpp"
void write_m4_panic_msg(const char *panic_message, struct extctx *ctxp) {
if (ctxp == nullptr) {
@@ -116,5 +117,28 @@ CH_IRQ_HANDLER(HardFaultVector) {
#endif
}
void update_performance_counters() {
auto performance_counter_active = shared_memory.request_m4_performance_counter;
if (performance_counter_active == 0x00)
return;
static bool last_paint_state = false;
if ((((chTimeNow()>>10) & 0x01) == 0x01) == last_paint_state)
return;
// Idle thread state is sometimes unuseable
if (chThdGetTicks(chSysGetIdleThread()) > 0x10000000)
return;
last_paint_state = !last_paint_state;
auto utilisation = get_cpu_utilisation_in_percent();
auto free_stack = (uint32_t)get_free_stack_space();
auto free_heap = chCoreStatus();
shared_memory.m4_cpu_usage = utilisation;
shared_memory.m4_stack_usage = free_stack;
shared_memory.m4_heap_usage = free_heap;
}
} /* extern "C" */
+6
View File
@@ -83,6 +83,12 @@ SSB::SSB() : hilbert() {
}
void SSB::execute(const buffer_s16_t& audio, const buffer_c8_t& buffer, bool& configured_in, uint32_t& new_beep_index, uint32_t& new_beep_timer,TXProgressMessage& new_txprogress_message, AudioLevelReportMessage& new_level_message, uint32_t& new_power_acc_count, uint32_t& new_divider ) {
//unused
(void)configured_in ;
(void)new_beep_index ;
(void)new_beep_timer ;
(void)new_txprogress_message ;
// No way to activate correctly the roger beep in this option, Maybe not enough M4 CPU power , Let's block roger beep in SSB selection by now .
int32_t sample = 0;
int8_t re = 0, im = 0;
+2
View File
@@ -20,6 +20,7 @@
*/
#include "event_m4.hpp"
#include "debug.hpp"
#include "portapack_shared_memory.hpp"
@@ -120,3 +121,4 @@ void EventDispatcher::handle_spectrum() {
const UpdateSpectrumMessage message;
baseband_processor->on_message(&message);
}
+8
View File
@@ -87,6 +87,7 @@ void ERTProcessor::consume_symbol(
) {
const uint_fast8_t sliced_symbol = (raw_symbol >= 0.0f) ? 1 : 0;
scm_builder.execute(sliced_symbol);
scmplus_builder.execute(sliced_symbol);
idm_builder.execute(sliced_symbol);
}
@@ -97,6 +98,13 @@ void ERTProcessor::scm_handler(
shared_memory.application_queue.push(message);
}
void ERTProcessor::scmplus_handler(
const baseband::Packet& packet
) {
const ERTPacketMessage message { ert::Packet::Type::SCMPLUS, packet };
shared_memory.application_queue.push(message);
}
void ERTProcessor::idm_handler(
const baseband::Packet& packet
) {
+15 -1
View File
@@ -44,10 +44,14 @@ constexpr uint64_t scm_preamble_and_sync_manchester { 0b101010101001011001100110
constexpr size_t scm_preamble_and_sync_length { 42 - 10 };
constexpr size_t scm_payload_length_max { 150 };
// ''.join(['%d%d' % (c, 1-c) for c in map(int, bin(0x16a3)[2:].zfill(16))])
constexpr uint64_t scmplus_preamble_and_sync_manchester { 0b01010110011010011001100101011010 };
constexpr size_t scmplus_preamble_and_sync_length { 32 - 0 };
constexpr size_t scmplus_payload_length_max { 224 };
// ''.join(['%d%d' % (c, 1-c) for c in map(int, bin(0x555516a3)[2:].zfill(32))])
constexpr uint64_t idm_preamble_and_sync_manchester { 0b0110011001100110011001100110011001010110011010011001100101011010 };
constexpr size_t idm_preamble_and_sync_length { 64 - 16 };
constexpr size_t idm_payload_length_max { 1408 };
class ERTProcessor : public BasebandProcessor {
@@ -80,6 +84,15 @@ private:
}
};
PacketBuilder<BitPattern, NeverMatch, FixedLength> scmplus_builder {
{ scmplus_preamble_and_sync_manchester, scmplus_preamble_and_sync_length, 1 },
{ },
{ scmplus_payload_length_max },
[this](const baseband::Packet& packet) {
this->scmplus_handler(packet);
}
};
PacketBuilder<BitPattern, NeverMatch, FixedLength> idm_builder {
{ idm_preamble_and_sync_manchester, idm_preamble_and_sync_length, 1 },
{ },
@@ -91,6 +104,7 @@ private:
void consume_symbol(const float symbol);
void scm_handler(const baseband::Packet& packet);
void scmplus_handler(const baseband::Packet& packet);
void idm_handler(const baseband::Packet& packet);
float sum_half_period[2];
+29 -12
View File
@@ -49,7 +49,7 @@ void SigGenProcessor::execute(const buffer_c8_t& buffer) {
// Sine
sample = (sine_table_i8[(tone_phase & 0xFF000000) >> 24]);
} else if (tone_shape == 2) {
// Tri
// Triangle
int8_t a = (tone_phase & 0xFF000000) >> 24;
sample = (a & 0x80) ? ((a << 1) ^ 0xFF) - 0x80 : (a << 1) + 0x80;
} else if (tone_shape == 3) {
@@ -61,24 +61,40 @@ void SigGenProcessor::execute(const buffer_c8_t& buffer) {
} else if (tone_shape == 5) {
// Square
sample = (((tone_phase & 0xFF000000) >> 24) & 0x80) ? 127 : -128;
} else if (tone_shape == 6) {
// Noise
sample = (lfsr & 0xFF000000) >> 24;
feedback = ((lfsr >> 31) ^ (lfsr >> 29) ^ (lfsr >> 15) ^ (lfsr >> 11)) & 1;
lfsr = (lfsr << 1) | feedback;
if (!lfsr) lfsr = 0x1337; // Shouldn't do this :(
} else if (tone_shape == 6) {
// Noise generator, pseudo random noise generator, 16 bits linear-feedback shift register (LFSR) algorithm, variant Fibonacci.
// https://en.wikipedia.org/wiki/Linear-feedback_shift_register
// 16 bits LFSR .taps: 16, 15, 13, 4 ;feedback polynomial: x^16 + x^15 + x^13 + x^4 + 1
// Periode 65535= 2^n-1, quite continuous .
if (counter == 0) { // we slow down the shift register, because the pseudo random noise clock freq was too high for modulator.
bit_16 = ((lfsr_16 >> 0) ^ (lfsr_16 >> 1) ^ (lfsr_16 >> 3) ^ (lfsr_16 >> 4) ^ ((lfsr_16 >> 12) & 1) );
lfsr_16 = (lfsr_16 >> 1) | (bit_16 << 15);
sample = (lfsr_16 & 0x00FF); // main pseudo random noise generator.
}
if (counter == 5) { // after many empiric test, that combination mix of >>4 and >>5, gives a reasonable trade off white noise / good rf power level .
sample = ((lfsr_16 & 0b0000111111110000) >> 4); // just changing the spectrum shape .
}
if (counter == 10) {
sample = ((lfsr_16 & 0b0001111111100000) >> 5); // just changing the spectrum shape .
}
counter++;
if (counter ==15) {
counter=0;
}
}
if (tone_shape < 6) { // we are in periodic signals, we need tone phases update.
tone_phase += tone_delta;
}
tone_phase += tone_delta;
// Do FM
// Do FM modulation
delta = sample * fm_delta;
phase += delta;
sphase = phase + (64 << 24);
re = (sine_table_i8[(sphase & 0xFF000000) >> 24]);
im = (sine_table_i8[(phase & 0xFF000000) >> 24]);
im = (sine_table_i8[( phase & 0xFF000000) >> 24]);
}
buffer.p[i] = {re, im};
@@ -104,7 +120,8 @@ void SigGenProcessor::on_message(const Message* const msg) {
fm_delta = message.bw * (0xFFFFFFULL / 1536000);
tone_shape = message.shape;
lfsr = 0x54DF0119;
// lfsr = seed_value ; // Finally not used , init lfsr 8 bits.
lfsr_16 = seed_value_16; // init lfsr 16 bits.
configured = true;
break;
+10 -6
View File
@@ -38,14 +38,18 @@ private:
BasebandThread baseband_thread { 1536000, this, NORMALPRIO + 20, baseband::Direction::Transmit };
uint32_t tone_delta { 0 }, fm_delta { };
uint32_t lfsr { }, feedback { }, tone_shape { };
uint32_t tone_delta { 0 }, fm_delta { },tone_phase { 0 };
uint8_t tone_shape { };
uint32_t sample_count { 0 };
bool auto_off { };
uint32_t tone_phase { 0 }, phase { 0 }, delta { 0 }, sphase { 0 };
int8_t sample { 0 };
int8_t re { 0 }, im { 0 };
int32_t phase { 0 }, sphase { 0 }, delta { 0 }; // they may have sign in the pseudo random sample generation.
int8_t sample { 0 }, re { 0 }, im { 0 }; // they have sign + and -.
uint16_t seed_value_16 = {0xACE1}; // seed 16 bits lfsr : any nonzero start state will work.
uint16_t lfsr_16 { }, bit_16 { }; // bit must be 16-bit to allow bit<<15 later in the code */
uint8_t counter {0};
// uint8_t seed_value = {0x56}; // Finally not used lfsr of 8 bits , seed 8blfsr : any nonzero start state will work.
// uint8_t lfsr { }, bit { }; // Finally not used lfsr of 8 bits , bit must be 8-bit to allow bit<<7 later in the code */
TXProgressMessage txprogress_message { };
};
@@ -45,3 +45,5 @@ int main() {
return 0;
}
void update_performance_counters() {}
@@ -508,7 +508,7 @@ static const std::array<scu_setup_t, 26> pins_setup_portapack { {
{ 2, 1, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* U0_RXD: PortaPack P2_1/ADDR */
{ 2, 3, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* I2C1_SDA: PortaPack P2_3/LCD_TE */
{ 2, 4, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* I2C1_SCL: PortaPack P2_4/LCD_RDX */
{ 2, 8, scu_config_normal_drive_t { .mode=4, .epd=0, .epun=1, .ehs=0, .ezi=0, .zif=0 } }, /* P2_8: 10K PD, BOOT2, DFU switch, PortaPack P2_8/<unused> */
{ 2, 8, scu_config_normal_drive_t { .mode=1, .epd=0, .epun=0, .ehs=0, .ezi=1, .zif=1 } }, /* P2_8: 10K PD, BOOT2, DFU switch, PortaPack P2_8/<unused> */
{ 2, 9, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* P2_9: 10K PD, BOOT3, PortaPack P2_9/LCD_WRX */
{ 2, 13, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* P2_13: PortaPack P2_13/DIR */
{ 7, 0, scu_config_normal_drive_t { .mode=0, .epd=0, .epun=1, .ehs=0, .ezi=1, .zif=0 } }, /* GPIO3_8: PortaPack GPIO3_8(IO) */
+4 -4
View File
@@ -33,7 +33,7 @@
namespace portapack {
namespace cpld {
bool update_if_necessary(
CpldUpdateStatus update_if_necessary(
const Config config
) {
jtag::GPIOTarget target {
@@ -51,7 +51,7 @@ bool update_if_necessary(
/* Run-Test/Idle */
if( !cpld.idcode_ok() ) {
return false;
return CpldUpdateStatus::Idcode_check_failed;
}
cpld.sample();
@@ -62,7 +62,7 @@ bool update_if_necessary(
* in passive state.
*/
if( !cpld.silicon_id_ok() ) {
return false;
return CpldUpdateStatus::Silicon_id_check_failed;
}
/* Verify CPLD contents against current bitstream. */
@@ -86,7 +86,7 @@ bool update_if_necessary(
cpld.disable();
}
return ok;
return ok ? CpldUpdateStatus::Success : CpldUpdateStatus::Program_failed;
}
} /* namespace cpld */
+8 -1
View File
@@ -27,7 +27,14 @@
namespace portapack {
namespace cpld {
bool update_if_necessary(
enum class CpldUpdateStatus {
Success = 0,
Idcode_check_failed = 1,
Silicon_id_check_failed = 2,
Program_failed = 3
};
CpldUpdateStatus update_if_necessary(
const Config config
);
+53
View File
@@ -450,6 +450,59 @@ constexpr fir_taps_real<64> taps_64_lp_156_198 {
} },
};
// WFM 180kHZ General purpose filter with sharp transition , it improves Commercial WFM S/N in weak signals //////////////////////////////////////////////
// IFIR image-reject filter: fs=3072000, pass=90000, stop=250000, decim=4, fout=768000
constexpr fir_taps_real<24> taps_180k_wfm_decim_0 = {
.low_frequency_normalized = -90000.0f / 3072000.0f,
.high_frequency_normalized = 90000.0f / 3072000.0f,
.transition_normalized = 160000.0f / 3072000.0f,
.taps = { {
55, 122, 244, 424, 666, 965, 1308, 1669,
2019, 2321, 2544, 2663, 2663, 2544, 2321, 2019,
1669, 1308, 965, 666, 424, 244, 122, 55,
} },
};
// IFIR prototype filter: fs=768000, pass=90000, stop=110000, decim=2, fout=384000
constexpr fir_taps_real<16> taps_180k_wfm_decim_1 = {
.low_frequency_normalized = -90000.0f / 768000.0f,
.high_frequency_normalized = 90000.0f / 768000.0f,
.transition_normalized = 20000.0f / 768000.0f,
.taps = { {
55, 19, -356, -916, -529, 2139, 6695, 10392,
10392, 6695, 2139, -529, -916, -356, 19, 55,
} },
};
// WFM 40kHZ filter for NOAA APT reception in 137Mhz band with sharp transition //////////////////////////////////////////////
// IFIR image-reject filter: fs=3072000, pass=20000, stop=97000, decim=4, fout=768000
constexpr fir_taps_real<24> taps_40k_wfm_decim_0 = {
.low_frequency_normalized = -20000.0f / 3072000.0f,
.high_frequency_normalized = 20000.0f / 3072000.0f,
.transition_normalized = 67000.0f / 3072000.0f,
.taps = { {
46, 112, 230, 408, 650, 953, 1301, 1671,
2029, 2340, 2570, 2692, 2692, 2570, 2340, 2029,
1671, 1301, 953, 650, 408, 230, 112, 46,
} },
};
// IFIR prototype filter: fs=768000, pass=20000, stop=55000, decim=2, fout=384000
constexpr fir_taps_real<16> taps_40k_wfm_decim_1 = {
.low_frequency_normalized = -20000.0f / 768000.0f,
.high_frequency_normalized = 20000.0f / 768000.0f,
.transition_normalized = 35000.0f / 768000.0f,
.taps = { {
83, 299, 743, 1456, 2396, 3418, 4297, 4808,
4808, 4297, 3418, 2396, 1456, 743, 299, 83,
} },
};
// TPMS decimation filters ////////////////////////////////////////////////
// IFIR image-reject filter: fs=2457600, pass=100000, stop=407200, decim=4, fout=614400
+12 -2
View File
@@ -47,6 +47,9 @@ ID Packet::id() const {
const auto lsb = reader_.read(35, 24);
return (msb << 24) | lsb;
}
if( type() == Type::SCMPLUS ) {
return reader_.read(2 * 8, 32);
}
if( type() == Type::IDM ) {
return reader_.read(5 * 8, 32);
}
@@ -57,6 +60,9 @@ Consumption Packet::consumption() const {
if( type() == Type::SCM ) {
return reader_.read(11, 24);
}
if( type() == Type::SCMPLUS ) {
return reader_.read(6 * 8, 32);
}
if( type() == Type::IDM ) {
return reader_.read(25 * 8, 32);
}
@@ -67,6 +73,9 @@ CommodityType Packet::commodity_type() const {
if( type() == Type::SCM ) {
return reader_.read(5, 4);
}
if( type() == Type::SCMPLUS ) {
return reader_.read(1 * 8 + 4, 4);
}
if( type() == Type::IDM ) {
return reader_.read(4 * 8 + 4, 4);
}
@@ -80,7 +89,8 @@ FormattedSymbols Packet::symbols_formatted() const {
bool Packet::crc_ok() const {
switch(type()) {
case Type::SCM: return crc_ok_scm();
case Type::IDM: return crc_ok_idm();
case Type::SCMPLUS:
case Type::IDM: return crc_ok_ccitt();
default: return false;
}
}
@@ -95,7 +105,7 @@ bool Packet::crc_ok_scm() const {
return ert_bch.checksum() == 0x0000;
}
bool Packet::crc_ok_idm() const {
bool Packet::crc_ok_ccitt() const {
CRC<16> ert_crc_ccitt { 0x1021, 0xffff, 0x1d0f };
for(size_t i=0; i<length(); i+=8) {
ert_crc_ccitt.process_byte(reader_.read(i, 8));
+2 -1
View File
@@ -45,6 +45,7 @@ public:
Unknown = 0,
IDM = 1,
SCM = 2,
SCMPLUS = 3,
};
Packet(
@@ -80,7 +81,7 @@ private:
const Reader reader_;
const Type type_;
bool crc_ok_idm() const;
bool crc_ok_ccitt() const;
bool crc_ok_scm() const;
};
+57
View File
@@ -0,0 +1,57 @@
/*
* 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 "performance_counter.hpp"
#include "ch.h"
uint8_t get_cpu_utilisation_in_percent() {
static systime_t last_time = 0;
static systime_t last_idle_ticks = 0;
auto now = chTimeNow();
auto idle_ticks = chThdGetTicks(chSysGetIdleThread());
if (last_time == 0) {
last_time = now;
last_idle_ticks = idle_ticks;
return 0;
}
int32_t time_elapsed = now - last_time;
int32_t idle_elapsed = idle_ticks - last_idle_ticks;
int32_t working_ticks = time_elapsed - idle_elapsed;
if (working_ticks < 0)
working_ticks = 0;
auto utilisation = working_ticks * 100 / time_elapsed;
last_time = now;
last_idle_ticks = idle_ticks;
if (utilisation > 100) {
return 100;
}
return (uint8_t) utilisation;
}
+29
View File
@@ -0,0 +1,29 @@
/*
* 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.
*/
#ifndef __PERFORMANCE_COUNTER_H__
#define __PERFORMANCE_COUNTER_H__
#include <stdint.h>
uint8_t get_cpu_utilisation_in_percent();
#endif /* __PERFORMANCE_COUNTER_H__ */
+1 -1
View File
@@ -36,7 +36,7 @@ namespace portapack {
constexpr GPIO gpio_io_stbx = gpio[GPIO5_0]; /* P2_0 */
constexpr GPIO gpio_addr = gpio[GPIO5_1]; /* P2_1 */
constexpr GPIO gpio_lcd_te = gpio[GPIO5_3]; /* P2_3 */
constexpr GPIO gpio_unused = gpio[GPIO5_7]; /* P2_8 */
constexpr GPIO gpio_dfu = gpio[GPIO5_7]; /* P2_8 */
constexpr GPIO gpio_lcd_rdx = gpio[GPIO5_4]; /* P2_4 */
constexpr GPIO gpio_lcd_wrx = gpio[GPIO1_10]; /* P2_9 */
constexpr GPIO gpio_dir = gpio[GPIO1_13]; /* P2_13 */
+2 -1
View File
@@ -110,7 +110,8 @@ uint32_t IO::io_update(const TouchPinsConfig write_value) {
}
gpio_addr.write(addr);
return switches_raw;
auto dfu_btn = portapack::io.dfu_read() & 0x01;
return (switches_raw & 0x7f) | (dfu_btn << 7);
}
}
+4
View File
@@ -214,6 +214,10 @@ public:
return gpio_rot_a.read();
}
uint32_t dfu_read() {
return gpio_rot_b.read();
}
private:
const GPIO gpio_dir;
const GPIO gpio_lcd_rdx;
@@ -64,6 +64,12 @@ struct SharedMemory {
JammerChannel jammer_channels[24];
uint8_t data[512];
} bb_data { { { { 0, 0 } }, 0, { 0 } } };
uint8_t volatile request_m4_performance_counter{ 0 };
uint8_t volatile m4_cpu_usage{ 0 };
uint16_t volatile m4_stack_usage{ 0 };
uint16_t volatile m4_heap_usage{ 0 };
uint16_t volatile m4_buffer_missed{ 0 };
};
extern SharedMemory& shared_memory;
+15
View File
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
* Copyright (C) 2017 Furrtek
* Early 2023 joyel24 added meteomodem M20 support
*
* This file is part of PortaPack.
*
@@ -64,6 +65,8 @@ Packet::Packet(
type_ = Type::Meteomodem_M10;
else if (id_byte == 0x648F)
type_ = Type::Meteomodem_M2K2;
else if (id_byte == 0x4520) //https://raw.githubusercontent.com/projecthorus/radiosonde_auto_rx/master/demod/mod/m20mod.c
type_ = Type::Meteomodem_M20;
}
}
@@ -109,6 +112,12 @@ GPS_data Packet::get_GPS_data() const
result.lat = reader_bi_m.read(14 * 8, 32) / ((1ULL << 32) / 360.0);
result.lon = reader_bi_m.read(18 * 8, 32) / ((1ULL << 32) / 360.0);
}
else if (type_ == Type::Meteomodem_M20)
{
result.alt = reader_bi_m.read(8 * 8, 24) / 100.0 ; // <|
result.lat = reader_bi_m.read(28 * 8, 32) / 1000000.0 ; // <| Inspired by https://raw.githubusercontent.com/projecthorus/radiosonde_auto_rx/master/demod/mod/m20mod.c
result.lon = reader_bi_m.read(32 * 8, 32) / 1000000.0 ; // <|
}
else if (type_ == Type::Vaisala_RS41_SG)
{
@@ -147,6 +156,10 @@ uint32_t Packet::battery_voltage() const
{
if (type_ == Type::Meteomodem_M10)
return (reader_bi_m.read(69 * 8, 8) + (reader_bi_m.read(70 * 8, 8) << 8)) * 1000 / 150;
else if (type_ == Type::Meteomodem_M20)
{
return 0; //NOT SUPPPORTED YET
}
else if (type_ == Type::Meteomodem_M2K2)
return reader_bi_m.read(69 * 8, 8) * 66; // Actually 65.8
else if (type_ == Type::Vaisala_RS41_SG)
@@ -279,6 +292,8 @@ std::string Packet::type_string() const
return "Meteomodem ???";
case Type::Meteomodem_M10:
return "Meteomodem M10";
case Type::Meteomodem_M20:
return "Meteomodem M20";
case Type::Meteomodem_M2K2:
return "Meteomodem M2K2";
case Type::Vaisala_RS41_SG:
+1
View File
@@ -51,6 +51,7 @@ public:
Meteomodem_M10 = 2,
Meteomodem_M2K2 = 3,
Vaisala_RS41_SG = 4,
Meteomodem_M20 = 5,
};
Packet(const baseband::Packet& packet, const Type type);
+2 -1
View File
@@ -325,7 +325,8 @@ enum class KeyEvent {
Down = 2,
Up = 3,
Select = 4,
Back = 5, /* Left and Up together */
Dfu = 5,
Back = 6, /* Left and Up together */
};
using EncoderEvent = int32_t;
+2 -2
View File
@@ -43,7 +43,7 @@ int Painter::draw_char(const Point p, const Style& style, const char c) {
}
int Painter::draw_string(Point p, const Font& font, const Color foreground,
const Color background, const std::string text) {
const Color background, const std::string& text) {
bool escape = false;
size_t width = 0;
@@ -71,7 +71,7 @@ int Painter::draw_string(Point p, const Font& font, const Color foreground,
return width;
}
int Painter::draw_string(Point p, const Style& style, const std::string text) {
int Painter::draw_string(Point p, const Style& style, const std::string& text) {
return draw_string(p, style.font, style.foreground, style.background, text);
}
+2 -2
View File
@@ -49,8 +49,8 @@ public:
int draw_char(const Point p, const Style& style, const char c);
int draw_string(Point p, const Font& font, const Color foreground,
const Color background, const std::string text);
int draw_string(Point p, const Style& style, const std::string text);
const Color background, const std::string& text);
int draw_string(Point p, const Style& style, const std::string& text);
void draw_bitmap(const Point p, const Bitmap& bitmap, const Color background, const Color foreground);
+141 -1
View File
@@ -1143,9 +1143,18 @@ NewButton::NewButton(
Rect parent_rect,
std::string text,
const Bitmap* bitmap
) : NewButton { parent_rect, text, bitmap, Color::dark_cyan() }
{ }
NewButton::NewButton(
Rect parent_rect,
std::string text,
const Bitmap* bitmap,
Color color
) : Widget { parent_rect },
text_ { text },
bitmap_ (bitmap)
bitmap_ { bitmap },
color_ { color }
{
set_focusable(true);
}
@@ -1535,6 +1544,137 @@ bool OptionsField::on_touch(const TouchEvent event) {
return true;
}
/* TextField ***********************************************************/
TextField::TextField(
std::string& str,
size_t max_length,
Point position,
uint32_t length
) : Widget{ { position, { 8 * static_cast<int>(length), 16 } } },
text_{ str },
max_length_{ std::max<size_t>(max_length, str.length()) },
char_count_{ std::max<uint32_t>(length, 1) },
cursor_pos_{ text_.length() },
insert_mode_{ true }
{
set_focusable(true);
}
const std::string& TextField::value() const {
return text_;
}
void TextField::set_cursor(uint32_t pos) {
cursor_pos_ = std::min<size_t>(pos, text_.length());
set_dirty();
}
void TextField::set_insert_mode() {
insert_mode_ = true;
}
void TextField::set_overwrite_mode() {
insert_mode_ = false;
}
void TextField::char_add(char c) {
// Don't add if inserting and at max_length and
// don't overwrite if past the end of the text.
if ((text_.length() >= max_length_ && insert_mode_) ||
(cursor_pos_ >= text_.length() && !insert_mode_))
return;
if (insert_mode_)
text_.insert(cursor_pos_, 1, c);
else
text_[cursor_pos_] = c;
cursor_pos_++;
set_dirty();
}
void TextField::char_delete() {
if (cursor_pos_ == 0)
return;
cursor_pos_--;
text_.erase(cursor_pos_, 1);
set_dirty();
}
void TextField::paint(Painter& painter) {
constexpr int char_width = 8;
auto rect = screen_rect();
auto text_style = has_focus() ? style().invert() : style();
auto offset = 0;
// Does the string need to be shifted?
if (cursor_pos_ >= char_count_)
offset = cursor_pos_ - char_count_ + 1;
// Clear the control.
painter.fill_rectangle(rect, text_style.background);
// Draw the text starting at the offset.
for (uint32_t i = 0; i < char_count_ && i + offset < text_.length(); i++) {
painter.draw_char(
{ rect.location().x() + (static_cast<int>(i) * char_width), rect.location().y() },
text_style,
text_[i + offset]
);
}
// Determine cursor position on screen (either the cursor position or the last char).
int32_t cursor_x = char_width * (offset > 0 ? char_count_ - 1 : cursor_pos_);
Point cursor_point{ screen_pos().x() + cursor_x, screen_pos().y() };
auto cursor_style = text_style.invert();
// Invert the cursor character when in overwrite mode.
if (!insert_mode_ && (cursor_pos_) < text_.length())
painter.draw_char(cursor_point, cursor_style, text_[cursor_pos_]);
// Draw the cursor.
Rect cursor_box{ cursor_point, { char_width, 16 } };
painter.draw_rectangle(cursor_box, cursor_style.background);
}
bool TextField::on_key(const KeyEvent key) {
if (key == KeyEvent::Left && cursor_pos_ > 0)
cursor_pos_--;
else if (key == KeyEvent::Right && cursor_pos_ < text_.length())
cursor_pos_++;
else if (key == KeyEvent::Select)
insert_mode_ = !insert_mode_;
else
return false;
set_dirty();
return true;
}
bool TextField::on_encoder(const EncoderEvent delta) {
int32_t new_pos = cursor_pos_ + delta;
// Let the encoder wrap around the ends of the text.
if (new_pos < 0)
new_pos = text_.length();
else if (static_cast<size_t>(new_pos) > text_.length())
new_pos = 0;
set_cursor(new_pos);
return true;
}
bool TextField::on_touch(const TouchEvent event) {
if (event.type == TouchEvent::Type::Start)
focus();
set_dirty();
return true;
}
/* NumberField ***********************************************************/
NumberField::NumberField(
+48 -4
View File
@@ -414,7 +414,6 @@ private:
bool instant_exec_ { false };
};
class ButtonWithEncoder : public Widget {
public:
std::function<void(ButtonWithEncoder&)> on_select { };
@@ -457,8 +456,6 @@ private:
bool instant_exec_ { false };
};
class NewButton : public Widget {
public:
std::function<void(void)> on_select { };
@@ -469,6 +466,7 @@ public:
NewButton(const NewButton&) = delete;
NewButton& operator=(const NewButton&) = delete;
NewButton(Rect parent_rect, std::string text, const Bitmap* bitmap);
NewButton(Rect parent_rect, std::string text, const Bitmap* bitmap, Color color);
NewButton(
) : NewButton { { }, { }, { } }
{
@@ -489,8 +487,8 @@ public:
private:
std::string text_;
Color color_ = Color::dark_cyan();
const Bitmap* bitmap_;
Color color_;
};
class Image : public Widget {
@@ -610,6 +608,52 @@ private:
size_t selected_index_ { 0 };
};
// A TextField is bound to a string reference and allows the string
// to be manipulated. The field itself does not provide the UI for
// setting the value. It provides the UI of rendering the text,
// a cursor, and an API to edit the string content.
class TextField : public Widget {
public:
TextField(std::string& str, Point position, uint32_t length = 30)
: TextField{str, 64, position, length} { }
// Str: the string containing the content to edit.
// Max_length: max length the string is allowed to use.
// Position: the top-left corner of the control.
// Length: the number of characters to display.
// - Characters are 8 pixels wide.
// - The screen can show 30 characters max.
// - The control is 16 pixels tall.
TextField(std::string& str, size_t max_length, Point position, uint32_t length = 30);
TextField(const TextField&) = delete;
TextField(TextField&&) = delete;
TextField& operator=(const TextField&) = delete;
TextField& operator=(TextField&&) = delete;
const std::string& value() const;
void set_cursor(uint32_t pos);
void set_insert_mode();
void set_overwrite_mode();
void char_add(char c);
void char_delete();
void paint(Painter& painter) override;
bool on_key(const KeyEvent key) override;
bool on_encoder(const EncoderEvent delta) override;
bool on_touch(const TouchEvent event) override;
protected:
std::string& text_;
size_t max_length_;
uint32_t char_count_;
uint32_t cursor_pos_;
bool insert_mode_;
};
class NumberField : public Widget {
public:
std::function<void(NumberField&)> on_select { };

Some files were not shown because too many files have changed in this diff Show More