mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-14 10:39:30 +00:00
Compare commits
102 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0685fb7a9f | |||
| 6498f5a1b2 | |||
| 77f747aab2 | |||
| 819b4d0fed | |||
| 15df51f976 | |||
| e9e78609b7 | |||
| 785bd06938 | |||
| 300a4b03c6 | |||
| eaa07f8369 | |||
| c31a978e6f | |||
| 266db4b158 | |||
| 290bf543a1 | |||
| e17f4c4ab4 | |||
| 83a4580353 | |||
| 00f40bf171 | |||
| 794daf5257 | |||
| 95eafeb812 | |||
| 94d46036f8 | |||
| 68000f0b94 | |||
| eff68693ad | |||
| 2f468fd37c | |||
| 39424632bb | |||
| cd30022b61 | |||
| be872003ec | |||
| 9e7758718c | |||
| 89b878d3bb | |||
| 56d965f3ae | |||
| fe9f0c228f | |||
| 6562e596e8 | |||
| c27192bdbb | |||
| 927e3b11e7 | |||
| a44a00acf0 | |||
| 6739b43914 | |||
| b306a0d490 | |||
| c6130c6e8d | |||
| 97f2ca42f1 | |||
| e2b642ae25 | |||
| 106d9b1207 | |||
| c8ae419e0b | |||
| 2319dcd0d6 | |||
| 44d9ce00cd | |||
| 5cc5f8faa6 | |||
| 3a0ca480b0 | |||
| 7a2b432bfa | |||
| 86d7b345d0 | |||
| 877ede5f86 | |||
| 19eb1c40ab | |||
| 9c03a18893 | |||
| cd504eb4a7 | |||
| dc976c7f38 | |||
| 266d90a600 | |||
| 2884bb9ab7 | |||
| 133b2d2065 | |||
| 2f2671f76c | |||
| f5c2c78733 | |||
| e4ab7227fc | |||
| 93799bde6d | |||
| 3d979a613a | |||
| ee97b51eb3 | |||
| 70ac1a03a1 | |||
| 2261e53981 | |||
| f86d3e51f1 | |||
| f71f19e719 | |||
| c53adfc765 | |||
| 7e8ad83537 | |||
| 472571b1ed | |||
| 106e56abc3 | |||
| 4129d57c09 | |||
| caac5e1041 | |||
| 6b02ba6e5d | |||
| c01597baf2 | |||
| 43a5163b77 | |||
| c46cc431c9 | |||
| a4d23768c1 | |||
| 344aa0c741 | |||
| fd7637187a | |||
| 674b865ec0 | |||
| 00c9c6b40e | |||
| 113cbc42c9 | |||
| 454b8776b6 | |||
| efdf043d62 | |||
| 0f9d9e589d | |||
| 3b57672dda | |||
| b739dd883c | |||
| bf18851b6b | |||
| 81afec9ea4 | |||
| 60a5222058 | |||
| 7041d507ca | |||
| d3373734e9 | |||
| 200831ad67 | |||
| dafe3b7641 | |||
| 63634407b6 | |||
| 9f06ccf9ae | |||
| 6782e12a15 | |||
| cbbd8103d3 | |||
| e88ab44f49 | |||
| 545dead1ca | |||
| e3b2a65b39 | |||
| 2f4d222403 | |||
| 54d99945f2 | |||
| 65a3c797c6 | |||
| 6a81a981aa |
+6
-7
@@ -1,14 +1,13 @@
|
||||
---
|
||||
BasedOnStyle: Chromium
|
||||
IndentWidth: '4'
|
||||
SortIncludes: 'false'
|
||||
AllowAllArgumentsOnNextLine: 'true'
|
||||
IndentWidth: 4
|
||||
SortIncludes: false
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
ColumnLimit: 0
|
||||
Cpp11BracedListStyle: 'true'
|
||||
AllowShortLoopsOnASingleLine: 'true'
|
||||
AllowShortIfStatementsOnASingleLine: 'true'
|
||||
Cpp11BracedListStyle: true
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AllowShortIfStatementsOnASingleLine: true
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 1
|
||||
Maximum: 1
|
||||
|
||||
...
|
||||
|
||||
@@ -3,7 +3,7 @@ name: Check formatting
|
||||
on: [pull_request]
|
||||
|
||||
jobs:
|
||||
check_date:
|
||||
check_format:
|
||||
runs-on: ubuntu-latest
|
||||
name: Check formatting
|
||||
strategy:
|
||||
@@ -13,11 +13,20 @@ jobs:
|
||||
- "firmware/application"
|
||||
- "firmware/baseband"
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: print latest_commit
|
||||
run: echo ${{ github.sha }}
|
||||
- name: clang-format Check
|
||||
uses: jidicula/clang-format-action@v4.11.0
|
||||
with:
|
||||
check-path: ${{ matrix.path }}
|
||||
fallback-style: Chromium
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: clang-format check (repo pinned)
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
CF="./tools/clang-format.sh"
|
||||
chmod +x "$CF" || true
|
||||
|
||||
"$CF" --version
|
||||
|
||||
ROOT="${{ matrix.path }}"
|
||||
find "$ROOT" -type f \( \
|
||||
-name '*.c' -o -name '*.cpp' -o \
|
||||
-name '*.h' -o -name '*.hpp' \
|
||||
\) -print0 \
|
||||
| xargs -0 -r "$CF" --dry-run --Werror --style=file
|
||||
|
||||
@@ -3,7 +3,7 @@ name: Nightly Release
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 0 * * *"
|
||||
|
||||
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
@@ -21,27 +21,36 @@ jobs:
|
||||
id: should_run
|
||||
continue-on-error: true
|
||||
run: test -z $(git rev-list --after="24 hours" ${{ github.sha }}) && echo "should_run=false" >> $GITHUB_OUTPUT
|
||||
|
||||
build:
|
||||
needs: check_date
|
||||
if: ${{ needs.check_date.outputs.should_run != 'false' }}
|
||||
runs-on: ubuntu-latest
|
||||
name: build (${{ matrix.device_name }})
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- device: default
|
||||
device_name: HackRF
|
||||
cmake_args: ""
|
||||
artifact_suffix: "_hackrf"
|
||||
- device: portarf
|
||||
device_name: PortaRF
|
||||
cmake_args: "-DFLASH_MB_SIZE=2 -DFLASH_MB_LIMIT_SIZE=2"
|
||||
artifact_suffix: "_portarf"
|
||||
- device: hpro
|
||||
device_name: HackRF Pro
|
||||
cmake_args: "-DBOARD=PRALINE"
|
||||
artifact_suffix: "_hpro"
|
||||
steps:
|
||||
- name: Get current date
|
||||
id: date
|
||||
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
|
||||
- name: Get version date
|
||||
id: version_date
|
||||
run: echo "date=n_$(date +'%y%m%d')" >> $GITHUB_OUTPUT
|
||||
- name: Checkout
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 0
|
||||
#ref: next
|
||||
# The branch, tag or SHA to checkout. When checking out the repository that
|
||||
# triggered a workflow, this defaults to the reference or SHA for that event.
|
||||
# Otherwise, uses the default branch.
|
||||
# https://github.com/actions/checkout
|
||||
# So scheduled runs will use the default branch (next) but its now possible to trigger a workflow from another branch
|
||||
submodules: true
|
||||
- name: Git Sumbodule Update
|
||||
run: |
|
||||
@@ -51,10 +60,10 @@ jobs:
|
||||
- name: Make build folder
|
||||
run: mkdir ${{ github.workspace }}/build
|
||||
- name: Run the Docker image
|
||||
run: docker run -e VERSION_STRING=${{ steps.version_date.outputs.date }} -i -v ${{ github.workspace }}:/havoc portapack-dev
|
||||
run: docker run -e VERSION_STRING=${{ steps.version_date.outputs.date }} -i -v ${{ github.workspace }}:/havoc portapack-dev ${{ matrix.cmake_args }}
|
||||
- name: Create Small SD Card ZIP - No World Map
|
||||
run: |
|
||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-mayhem-firmware.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version_date.outputs.date }}.bin && cp build/firmware/portapack-mayhem_OCI.ppfw.tar sdcard/FIRMWARE/mayhem_nightly_${{ steps.version_date.outputs.date }}_OCI.ppfw.tar && mkdir -p sdcard/APPS && cp build/firmware/application/*.ppma sdcard/APPS && cp build/firmware/standalone/*/*.ppmp sdcard/APPS && cd sdcard && zip -r ../sdcard-no-map.zip . && cd ..
|
||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-mayhem-firmware.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version_date.outputs.date }}.bin && cp build/firmware/portapack-mayhem_OCI.ppfw.tar sdcard/FIRMWARE/mayhem_nightly_${{ steps.version_date.outputs.date }}${{ matrix.artifact_suffix }}_OCI.ppfw.tar && mkdir -p sdcard/APPS && cp build/firmware/application/*.ppma sdcard/APPS && cp build/firmware/standalone/*/*.ppmp sdcard/APPS && cd sdcard && zip -r ../sdcard-no-map.zip . && cd ..
|
||||
- name: Download world map
|
||||
run: |
|
||||
wget https://github.com/portapack-mayhem/mayhem-firmware/releases/download/world_map/world_map.zip
|
||||
@@ -69,7 +78,47 @@ jobs:
|
||||
zip -j firmware.zip build/firmware/portapack-mayhem-firmware.bin && cd flashing && zip -r ../firmware.zip *
|
||||
- name: Create SD Card ZIP
|
||||
run: |
|
||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-mayhem-firmware.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version_date.outputs.date }}.bin && cp build/firmware/portapack-mayhem_OCI.ppfw.tar sdcard/FIRMWARE/mayhem_nightly_${{ steps.version_date.outputs.date }}_OCI.ppfw.tar && mkdir -p sdcard/APPS && cp build/firmware/application/*.ppma sdcard/APPS && cp build/firmware/standalone/*/*.ppmp sdcard/APPS && cd sdcard && zip -r ../sdcard.zip . && cd ..
|
||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-mayhem-firmware.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version_date.outputs.date }}.bin && cp build/firmware/portapack-mayhem_OCI.ppfw.tar sdcard/FIRMWARE/mayhem_nightly_${{ steps.version_date.outputs.date }}${{ matrix.artifact_suffix }}_OCI.ppfw.tar && mkdir -p sdcard/APPS && cp build/firmware/application/*.ppma sdcard/APPS && cp build/firmware/standalone/*/*.ppmp sdcard/APPS && cd sdcard && zip -r ../sdcard.zip . && cd ..
|
||||
- name: Upload firmware zip artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: firmware-${{ matrix.device }}
|
||||
path: ./firmware.zip
|
||||
- name: Upload SD card artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: sdcard-${{ matrix.device }}
|
||||
path: ./sdcard.zip
|
||||
- name: Upload SD card no-map artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: sdcard-no-map-${{ matrix.device }}
|
||||
path: ./sdcard-no-map.zip
|
||||
- name: Upload OCI tar artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: oci-tar-${{ matrix.device }}
|
||||
path: build/firmware/portapack-mayhem_OCI.ppfw.tar
|
||||
|
||||
release:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Get current date
|
||||
id: date
|
||||
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
|
||||
- name: Get version date
|
||||
id: version_date
|
||||
run: echo "date=n_$(date +'%y%m%d')" >> $GITHUB_OUTPUT
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: true
|
||||
- name: Download all artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
- name: Create changelog
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -96,43 +145,114 @@ jobs:
|
||||
${{ steps.changelog.outputs.content }}
|
||||
draft: false
|
||||
prerelease: true
|
||||
- name: Upload Firmware TAR Asset
|
||||
id: upload-firmware-tar-asset
|
||||
# Default device assets
|
||||
- name: Upload Default Firmware TAR Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: build/firmware/portapack-mayhem_OCI.ppfw.tar
|
||||
asset_name: mayhem_nightly_${{ steps.version_date.outputs.date }}_OCI.ppfw.tar
|
||||
asset_path: artifacts/oci-tar-default/portapack-mayhem_OCI.ppfw.tar
|
||||
asset_name: OCI_hackrf_mayhem_nightly_${{ steps.version_date.outputs.date }}.ppfw.tar
|
||||
asset_content_type: application/x-tar
|
||||
- name: Upload Firmware Asset
|
||||
id: upload-firmware-asset
|
||||
- name: Upload Default Firmware Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./firmware.zip
|
||||
asset_name: mayhem_nightly_${{ steps.version_date.outputs.date }}_FIRMWARE.zip
|
||||
asset_path: artifacts/firmware-default/firmware.zip
|
||||
asset_name: FIRMWARE_hackrf_mayhem_nightly_${{ steps.version_date.outputs.date }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload SD Card Assets
|
||||
id: upload-sd-card-asset
|
||||
- name: Upload Default SD Card Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./sdcard.zip
|
||||
asset_name: mayhem_nightly_${{ steps.version_date.outputs.date }}_COPY_TO_SDCARD.zip
|
||||
asset_path: artifacts/sdcard-default/sdcard.zip
|
||||
asset_name: COPY_TO_SDCARD_hackrf_mayhem_nightly_${{ steps.version_date.outputs.date }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload SD Card Assets - No Map
|
||||
id: upload-sd-card-asset-no-map
|
||||
- name: Upload Default SD Card Asset - No Map
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./sdcard-no-map.zip
|
||||
asset_name: mayhem_nightly_${{ steps.version_date.outputs.date }}_COPY_TO_SDCARD-no-world-map.zip
|
||||
asset_path: artifacts/sdcard-no-map-default/sdcard-no-map.zip
|
||||
asset_name: COPY_TO_SDCARD_hackrf_mayhem_nightly_${{ steps.version_date.outputs.date }}-no-world-map.zip
|
||||
asset_content_type: application/zip
|
||||
# PortaRF device assets
|
||||
- name: Upload PortaRF Firmware TAR Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/oci-tar-portarf/portapack-mayhem_OCI.ppfw.tar
|
||||
asset_name: OCI_portarf_mayhem_nightly_${{ steps.version_date.outputs.date }}.ppfw.tar
|
||||
asset_content_type: application/x-tar
|
||||
- name: Upload PortaRF Firmware Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/firmware-portarf/firmware.zip
|
||||
asset_name: FIRMWARE_portarf_mayhem_nightly_${{ steps.version_date.outputs.date }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload PortaRF SD Card Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/sdcard-portarf/sdcard.zip
|
||||
asset_name: COPY_TO_SDCARD_portarf_mayhem_nightly_${{ steps.version_date.outputs.date }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload PortaRF SD Card Asset - No Map
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/sdcard-no-map-portarf/sdcard-no-map.zip
|
||||
asset_name: COPY_TO_SDCARD_portarf_mayhem_nightly_${{ steps.version_date.outputs.date }}-no-world-map.zip
|
||||
asset_content_type: application/zip
|
||||
# HPro device assets
|
||||
- name: Upload HPro Firmware TAR Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/oci-tar-hpro/portapack-mayhem_OCI.ppfw.tar
|
||||
asset_name: OCI_hpro_mayhem_nightly_${{ steps.version_date.outputs.date }}.ppfw.tar
|
||||
asset_content_type: application/x-tar
|
||||
- name: Upload HPro Firmware Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/firmware-hpro/firmware.zip
|
||||
asset_name: FIRMWARE_hpro_mayhem_nightly_${{ steps.version_date.outputs.date }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload HPro SD Card Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/sdcard-hpro/sdcard.zip
|
||||
asset_name: COPY_TO_SDCARD_hpro_mayhem_nightly_${{ steps.version_date.outputs.date }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload HPro SD Card Asset - No Map
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/sdcard-no-map-hpro/sdcard-no-map.zip
|
||||
asset_name: COPY_TO_SDCARD_hpro_mayhem_nightly_${{ steps.version_date.outputs.date }}-no-world-map.zip
|
||||
asset_content_type: application/zip
|
||||
|
||||
@@ -1,25 +1,36 @@
|
||||
name: Stable Release
|
||||
|
||||
on:
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
name: build (${{ matrix.device_name }})
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- device: default
|
||||
device_name: HackRF
|
||||
cmake_args: ""
|
||||
artifact_suffix: "_hackrf"
|
||||
- device: portarf
|
||||
device_name: PortaRF
|
||||
cmake_args: "-DFLASH_MB_SIZE=2 -DFLASH_MB_LIMIT_SIZE=2"
|
||||
artifact_suffix: "_portarf"
|
||||
- device: hpro
|
||||
device_name: HackRF Pro
|
||||
cmake_args: "-DBOARD=PRALINE"
|
||||
artifact_suffix: "_hpro"
|
||||
steps:
|
||||
- name: Get current date
|
||||
id: date
|
||||
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
|
||||
- name: Checkout
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 0
|
||||
#ref: next
|
||||
# The branch, tag or SHA to checkout. When checking out the repository that
|
||||
# triggered a workflow, this defaults to the reference or SHA for that event.
|
||||
# Otherwise, uses the default branch.
|
||||
# https://github.com/actions/checkout
|
||||
# So scheduled runs will use the default branch (next) but its now possible to trigger a workflow from another branch
|
||||
submodules: true
|
||||
- name: Git Sumbodule Update
|
||||
run: |
|
||||
@@ -27,18 +38,15 @@ jobs:
|
||||
- name: Get version
|
||||
id: version
|
||||
run: echo "version=$(cat .github/workflows/version.txt)" >> $GITHUB_OUTPUT
|
||||
- name: Get past version
|
||||
id: past_version
|
||||
run: echo "past_version=$(cat .github/workflows/past_version.txt)" >> $GITHUB_OUTPUT
|
||||
- name: Build the Docker image
|
||||
run: docker build -t portapack-dev -f dockerfile-nogit . --tag my-image-name:$(date +%s)
|
||||
- name: Make build folder
|
||||
run: mkdir ${{ github.workspace }}/build
|
||||
- name: Run the Docker image
|
||||
run: docker run -e VERSION_STRING=${{ steps.version.outputs.version }} -i -v ${{ github.workspace }}:/havoc portapack-dev
|
||||
run: docker run -e VERSION_STRING=${{ steps.version.outputs.version }} -i -v ${{ github.workspace }}:/havoc portapack-dev ${{ matrix.cmake_args }}
|
||||
- name: Create Small SD Card ZIP - No World Map
|
||||
run: |
|
||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-mayhem-firmware.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version.outputs.version }}.bin && cp build/firmware/portapack-mayhem_OCI.ppfw.tar sdcard/FIRMWARE/mayhem_${{ steps.version.outputs.version }}_OCI.ppfw.tar && mkdir -p sdcard/APPS && cp build/firmware/application/*.ppma sdcard/APPS && cp build/firmware/standalone/*/*.ppmp sdcard/APPS && cd sdcard && zip -r ../sdcard-no-map.zip . && cd ..
|
||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-mayhem-firmware.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version.outputs.version }}.bin && cp build/firmware/portapack-mayhem_OCI.ppfw.tar sdcard/FIRMWARE/mayhem_${{ steps.version.outputs.version }}${{ matrix.artifact_suffix }}_OCI.ppfw.tar && mkdir -p sdcard/APPS && cp build/firmware/application/*.ppma sdcard/APPS && cp build/firmware/standalone/*/*.ppmp sdcard/APPS && cd sdcard && zip -r ../sdcard-no-map.zip . && cd ..
|
||||
- name: Download world map
|
||||
run: |
|
||||
wget https://github.com/portapack-mayhem/mayhem-firmware/releases/download/world_map/world_map.zip
|
||||
@@ -53,7 +61,50 @@ jobs:
|
||||
zip -j firmware.zip build/firmware/portapack-mayhem-firmware.bin && cd flashing && zip -r ../firmware.zip *
|
||||
- name: Create SD Card ZIP
|
||||
run: |
|
||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-mayhem-firmware.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version.outputs.version }}.bin && cp build/firmware/portapack-mayhem_OCI.ppfw.tar sdcard/FIRMWARE/mayhem_${{ steps.version.outputs.version }}_OCI.ppfw.tar && mkdir -p sdcard/APPS && cp build/firmware/application/*.ppma sdcard/APPS && cp build/firmware/standalone/*/*.ppmp sdcard/APPS && cd sdcard && zip -r ../sdcard.zip . && cd ..
|
||||
mkdir -p sdcard/FIRMWARE && cp build/firmware/portapack-mayhem-firmware.bin sdcard/FIRMWARE/portapack-mayhem_${{ steps.version.outputs.version }}.bin && cp build/firmware/portapack-mayhem_OCI.ppfw.tar sdcard/FIRMWARE/mayhem_${{ steps.version.outputs.version }}${{ matrix.artifact_suffix }}_OCI.ppfw.tar && mkdir -p sdcard/APPS && cp build/firmware/application/*.ppma sdcard/APPS && cp build/firmware/standalone/*/*.ppmp sdcard/APPS && cd sdcard && zip -r ../sdcard.zip . && cd ..
|
||||
- name: Upload firmware zip artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: firmware-${{ matrix.device }}
|
||||
path: ./firmware.zip
|
||||
- name: Upload SD card artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: sdcard-${{ matrix.device }}
|
||||
path: ./sdcard.zip
|
||||
- name: Upload SD card no-map artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: sdcard-no-map-${{ matrix.device }}
|
||||
path: ./sdcard-no-map.zip
|
||||
- name: Upload OCI tar artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: oci-tar-${{ matrix.device }}
|
||||
path: build/firmware/portapack-mayhem_OCI.ppfw.tar
|
||||
|
||||
release:
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Get current date
|
||||
id: date
|
||||
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
with:
|
||||
fetch-depth: 0
|
||||
submodules: true
|
||||
- name: Get version
|
||||
id: version
|
||||
run: echo "version=$(cat .github/workflows/version.txt)" >> $GITHUB_OUTPUT
|
||||
- name: Get past version
|
||||
id: past_version
|
||||
run: echo "past_version=$(cat .github/workflows/past_version.txt)" >> $GITHUB_OUTPUT
|
||||
- name: Download all artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
- name: Create changelog
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -78,7 +129,7 @@ jobs:
|
||||
## Release notes
|
||||
### Revision (${{ steps.version.outputs.version }}):
|
||||
${{ steps.changelog.outputs.content }}
|
||||
|
||||
|
||||
**Full Changelog**: https://github.com/portapack-mayhem/mayhem-firmware/compare/${{ steps.past_version.outputs.past_version }}...${{ steps.version.outputs.version }}
|
||||
|
||||
## Installation
|
||||
@@ -90,44 +141,114 @@ jobs:
|
||||
For certain functionality, like external apps, the world map, GPS simulator, and others you need to uncompress (using [7-zip](https://www.7-zip.org/download.html)) the files from `mayhem_vX.Y.Z_COPY_TO_SDCARD.zip` to a FAT32 formatted MicroSD card.
|
||||
draft: true
|
||||
prerelease: false
|
||||
- name: Upload Firmware TAR Asset
|
||||
id: upload-firmware-tar-asset
|
||||
# Default device assets
|
||||
- name: Upload Default Firmware TAR Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: build/firmware/portapack-mayhem_OCI.ppfw.tar
|
||||
asset_name: mayhem_${{ steps.version.outputs.version }}_OCI.ppfw.tar
|
||||
asset_path: artifacts/oci-tar-default/portapack-mayhem_OCI.ppfw.tar
|
||||
asset_name: OCI_hackrf_mayhem_${{ steps.version.outputs.version }}.ppfw.tar
|
||||
asset_content_type: application/x-tar
|
||||
- name: Upload Firmware Asset
|
||||
id: upload-firmware-asset
|
||||
- name: Upload Default Firmware Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./firmware.zip
|
||||
asset_name: mayhem_${{ steps.version.outputs.version }}_FIRMWARE.zip
|
||||
asset_path: artifacts/firmware-default/firmware.zip
|
||||
asset_name: FIRMWARE_hackrf_mayhem_${{ steps.version.outputs.version }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload SD Card Assets
|
||||
id: upload-sd-card-asset
|
||||
- name: Upload Default SD Card Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./sdcard.zip
|
||||
asset_name: mayhem_${{ steps.version.outputs.version }}_COPY_TO_SDCARD.zip
|
||||
asset_path: artifacts/sdcard-default/sdcard.zip
|
||||
asset_name: COPY_TO_SDCARD_hackrf_mayhem_${{ steps.version.outputs.version }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload SD Card Assets - No Map
|
||||
id: upload-sd-card-asset-no-map
|
||||
- name: Upload Default SD Card Asset - No Map
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./sdcard-no-map.zip
|
||||
asset_name: mayhem_${{ steps.version.outputs.version }}_COPY_TO_SDCARD-no-world-map.zip
|
||||
asset_path: artifacts/sdcard-no-map-default/sdcard-no-map.zip
|
||||
asset_name: COPY_TO_SDCARD_hackrf_mayhem_${{ steps.version.outputs.version }}-no-world-map.zip
|
||||
asset_content_type: application/zip
|
||||
# PortaRF device assets
|
||||
- name: Upload PortaRF Firmware TAR Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/oci-tar-portarf/portapack-mayhem_OCI.ppfw.tar
|
||||
asset_name: OCI_portarf_mayhem_${{ steps.version.outputs.version }}.ppfw.tar
|
||||
asset_content_type: application/x-tar
|
||||
- name: Upload PortaRF Firmware Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/firmware-portarf/firmware.zip
|
||||
asset_name: FIRMWARE_portarf_mayhem_${{ steps.version.outputs.version }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload PortaRF SD Card Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/sdcard-portarf/sdcard.zip
|
||||
asset_name: COPY_TO_SDCARD_portarf_mayhem_${{ steps.version.outputs.version }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload PortaRF SD Card Asset - No Map
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/sdcard-no-map-portarf/sdcard-no-map.zip
|
||||
asset_name: COPY_TO_SDCARD_portarf_mayhem_${{ steps.version.outputs.version }}-no-world-map.zip
|
||||
asset_content_type: application/zip
|
||||
# HPro device assets
|
||||
- name: Upload HPro Firmware TAR Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/oci-tar-hpro/portapack-mayhem_OCI.ppfw.tar
|
||||
asset_name: OCI_hpro_mayhem_${{ steps.version.outputs.version }}.ppfw.tar
|
||||
asset_content_type: application/x-tar
|
||||
- name: Upload HPro Firmware Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/firmware-hpro/firmware.zip
|
||||
asset_name: FIRMWARE_hpro_mayhem_${{ steps.version.outputs.version }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload HPro SD Card Asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/sdcard-hpro/sdcard.zip
|
||||
asset_name: COPY_TO_SDCARD_hpro_mayhem_${{ steps.version.outputs.version }}.zip
|
||||
asset_content_type: application/zip
|
||||
- name: Upload HPro SD Card Asset - No Map
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: artifacts/sdcard-no-map-hpro/sdcard-no-map.zip
|
||||
asset_name: COPY_TO_SDCARD_hpro_mayhem_${{ steps.version.outputs.version }}-no-world-map.zip
|
||||
asset_content_type: application/zip
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
v2.1.0
|
||||
v2.3.1
|
||||
|
||||
@@ -1 +1 @@
|
||||
v2.2.0
|
||||
v2.3.2
|
||||
|
||||
@@ -83,3 +83,5 @@ venv/
|
||||
# generated bitmap arr file
|
||||
# TODO: generate bitmap during build, since we use python during build anyway, lemme know if this is a bad idea @zxkmm
|
||||
/firmware/tools/bitmap.hpp
|
||||
# flashsize is generated by cmake
|
||||
/firmware/flashsize.h
|
||||
|
||||
@@ -27,6 +27,40 @@ set(CMAKE_COLOR_MAKEFILE ON)
|
||||
|
||||
add_compile_options(-fdiagnostics-color=always)
|
||||
|
||||
#Flash size related options
|
||||
#This is the size of the flash memory we SUPPORT. Don't worry, the internl flash app has harder limits based on device type.
|
||||
if(NOT DEFINED FLASH_MB_SIZE)
|
||||
if(BOARD STREQUAL "PRALINE")
|
||||
set(FLASH_MB_SIZE 4) # PRALINE has 4MB flash
|
||||
else()
|
||||
set(FLASH_MB_SIZE 2) # Default to 2MB if not provided. For PortaRf this should be 2MB passed to cmake with -DFLASH_MB_SIZE=2
|
||||
endif()
|
||||
endif()
|
||||
message("Configuring for FLASH_MB_SIZE=${FLASH_MB_SIZE}MB")
|
||||
#This is the flash memory size we build. This can be less, so the FW size will be less, so can be flashed with older utils.
|
||||
if(NOT DEFINED FLASH_MB_LIMIT_SIZE)
|
||||
if(BOARD STREQUAL "PRALINE")
|
||||
set(FLASH_MB_LIMIT_SIZE 3.5) #PRALINE 4 MB = 3.5 firmware + 0.5 MB fpga bitstream.
|
||||
else()
|
||||
set(FLASH_MB_LIMIT_SIZE 1) #TODO: should be ${FLASH_MB_SIZE} remove once we got a stable build for all devices we support with bigger than 1 mb flash
|
||||
endif()
|
||||
endif()
|
||||
message("Configuring for FLASH_MB_LIMIT_SIZE=${FLASH_MB_LIMIT_SIZE}MB")
|
||||
|
||||
if(FLASH_MB_SIZE LESS FLASH_MB_LIMIT_SIZE)
|
||||
message(FATAL_ERROR "Error: The supported flash size is lower than the generated flash file. Build halted.")
|
||||
endif()
|
||||
|
||||
math(EXPR FLASH_BYTES_SIZE "${FLASH_MB_SIZE} * 1024 * 1024")
|
||||
if(BOARD STREQUAL "PRALINE")
|
||||
math(EXPR FLASH_BYTES_LIMIT_SIZE "3584 * 1024") #4 MB = 3.5 firmware + 0.5 MB fpga bitstream.
|
||||
else()
|
||||
math(EXPR FLASH_BYTES_LIMIT_SIZE "${FLASH_MB_LIMIT_SIZE} * 1024 * 1024")
|
||||
endif()
|
||||
|
||||
#generate h files
|
||||
configure_file(flashsize.h.in ${CMAKE_CURRENT_SOURCE_DIR}/firmware/flashsize.h)
|
||||
|
||||
option(USE_CCACHE "Enable ccache, please keep an eye on this because sometimes it's not quite stable and generated unusable binary" OFF)
|
||||
|
||||
project(portapack-h1)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
portapack.ried.cl
|
||||
+19
-1
@@ -56,7 +56,7 @@ add_subdirectory(test)
|
||||
# NOTE: Dependencies break if the .bin files aren't included in DEPENDS. WTF, CMake?
|
||||
add_custom_command(
|
||||
OUTPUT ${FIRMWARE_FILENAME}
|
||||
COMMAND ${MAKE_SPI_IMAGE} ${application_BINARY_DIR}/application.bin ${baseband_BINARY_DIR}/baseband.img ${FIRMWARE_FILENAME}
|
||||
COMMAND ${MAKE_SPI_IMAGE} ${application_BINARY_DIR}/application.bin ${baseband_BINARY_DIR}/baseband.img ${FIRMWARE_FILENAME} ${FLASH_BYTES_LIMIT_SIZE}
|
||||
DEPENDS baseband application ${MAKE_SPI_IMAGE}
|
||||
${baseband_BINARY_DIR}/baseband.img ${application_BINARY_DIR}/application.bin
|
||||
VERBATIM
|
||||
@@ -67,6 +67,24 @@ add_custom_target(
|
||||
DEPENDS ${FIRMWARE_FILENAME} ${HACKRF_FIRMWARE_DFU_FILENAME} ${HACKRF_FIRMWARE_FILENAME}
|
||||
)
|
||||
|
||||
# PRALINE: Append FPGA bitstream to firmware at offset 0x180000
|
||||
# The base firmware is 1MB, FPGA goes at 1MB offset, final size is 2MB
|
||||
if(BOARD STREQUAL "PRALINE")
|
||||
math(EXPR PRALINE_FINAL_SIZE "4 * 1024 * 1024")
|
||||
set(PRALINE_FPGA_BIN ${CMAKE_CURRENT_SOURCE_DIR}/../hackrf/firmware/fpga/build/praline_fpga.bin)
|
||||
set(APPEND_FPGA_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/tools/append_fpga_bitstream.py)
|
||||
add_custom_command(
|
||||
TARGET firmware POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Appending PRALINE FPGA bitstream to firmware..."
|
||||
COMMAND python3 ${APPEND_FPGA_SCRIPT} ${FIRMWARE_FILENAME} ${PRALINE_FPGA_BIN} ${FIRMWARE_FILENAME}.tmp ${PRALINE_FINAL_SIZE}
|
||||
COMMAND ${CMAKE_COMMAND} -E rename ${FIRMWARE_FILENAME}.tmp ${FIRMWARE_FILENAME}
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "PRALINE firmware with FPGA bitstream created:"
|
||||
COMMAND ls -la ${FIRMWARE_FILENAME}
|
||||
COMMENT "Appending PRALINE FPGA bitstream"
|
||||
VERBATIM
|
||||
)
|
||||
endif()
|
||||
|
||||
if(${GCC_VERSION_MISMATCH})
|
||||
set(COMPILER_MISMATCH_MESSAGE "WARNING: Compiler version mismatch, please use the official compiler version ${EXPECTED_GCC_VERSION} when sharing builds! Current compiler version: ${CMAKE_CXX_COMPILER_VERSION}")
|
||||
message(${COMPILER_MISMATCH_MESSAGE})
|
||||
|
||||
@@ -86,6 +86,9 @@ set(CPLD_20150901_DATA_CPP ${CMAKE_CURRENT_BINARY_DIR}/portapack_cpld_20150901_d
|
||||
set(CPLD_20170522_SVF_PATH ${HARDWARE_PATH}/portapack_h1/cpld/20170522/output_files/portapack_h1_cpld.svf)
|
||||
set(CPLD_20170522_DATA_CPP ${CMAKE_CURRENT_BINARY_DIR}/portapack_cpld_20170522_data.cpp)
|
||||
|
||||
set(CPLD_H4M_SVF_PATH ${HARDWARE_PATH}/portapack_h4m/CPLD/AG256SL100/output_files/portapack_h4m_cpld.svf)
|
||||
set(CPLD_H4M_DATA_CPP ${CMAKE_CURRENT_BINARY_DIR}/portapack_cpld_h4m_data.cpp)
|
||||
|
||||
set(HACKRF_CPLD_DATA_HPP ${CMAKE_CURRENT_BINARY_DIR}/hackrf_cpld_data.hpp)
|
||||
set(HACKRF_CPLD_DATA_CPP ${CMAKE_CURRENT_BINARY_DIR}/hackrf_cpld_data.cpp)
|
||||
|
||||
@@ -118,11 +121,16 @@ set(CSRC
|
||||
usb_serial_endpoints.c
|
||||
usb_serial_device_to_host.c
|
||||
i2c_device_to_host.c
|
||||
hackrf_core_mini.c
|
||||
${HACKRF_PATH}/firmware/common/adc.c
|
||||
${HACKRF_PATH}/firmware/common/usb.c
|
||||
${HACKRF_PATH}/firmware/common/usb_queue.c
|
||||
${HACKRF_PATH}/firmware/hackrf_usb/usb_device.c
|
||||
${HACKRF_PATH}/firmware/common/usb_request.c
|
||||
${HACKRF_PATH}/firmware/common/usb_standard_request.c
|
||||
${HACKRF_PATH}/firmware/libopencm3/lib/lpc43xx/scu.c
|
||||
${HACKRF_PATH}/firmware/common/gpio_lpc.c
|
||||
${HACKRF_PATH}/firmware/common/platform_detect.c
|
||||
${CHIBIOS}/os/various/chprintf.c
|
||||
)
|
||||
|
||||
@@ -192,7 +200,6 @@ set(CPPSRC
|
||||
core_control.cpp
|
||||
database.cpp
|
||||
gradient.cpp
|
||||
rfm69.cpp
|
||||
event_m0.cpp
|
||||
file_reader.cpp
|
||||
file.cpp
|
||||
@@ -206,6 +213,9 @@ set(CPPSRC
|
||||
irq_controls.cpp
|
||||
irq_lcd_frame.cpp
|
||||
irq_rtc.cpp
|
||||
keeloq_common.cpp
|
||||
keeloq_file.cpp
|
||||
keeloq_keystore.cpp
|
||||
log_file.cpp
|
||||
metadata_file.cpp
|
||||
flipper_subfile.cpp
|
||||
@@ -238,6 +248,7 @@ set(CPPSRC
|
||||
hw/encoder.cpp
|
||||
hw/max2837.cpp
|
||||
hw/max2839.cpp
|
||||
hw/max2831.cpp
|
||||
hw/max5864.cpp
|
||||
hw/rffc507x.cpp
|
||||
hw/rffc507x_spi.cpp
|
||||
@@ -247,6 +258,7 @@ set(CPPSRC
|
||||
ook_file.cpp
|
||||
ui_baseband_stats_view.cpp
|
||||
ui_navigation.cpp
|
||||
ui_notifications.cpp
|
||||
ui_record_view.cpp
|
||||
ui_sd_card_status_view.cpp
|
||||
ui/ui_alphanum.cpp
|
||||
@@ -261,7 +273,6 @@ set(CPPSRC
|
||||
ui/ui_receiver.cpp
|
||||
ui/ui_rssi.cpp
|
||||
ui/ui_freqlist.cpp
|
||||
ui/ui_tv.cpp
|
||||
ui/ui_spectrum.cpp
|
||||
ui/ui_tabview.cpp
|
||||
ui/ui_textentry.cpp
|
||||
@@ -298,10 +309,8 @@ set(CPPSRC
|
||||
apps/ui_rds.cpp
|
||||
apps/ui_recon_settings.cpp
|
||||
apps/ui_recon.cpp
|
||||
apps/ui_sd_over_usb.cpp
|
||||
apps/ui_search.cpp
|
||||
apps/ui_settings.cpp
|
||||
apps/ui_siggen.cpp
|
||||
apps/ui_sonde.cpp
|
||||
apps/ui_ss_viewer.cpp
|
||||
apps/ui_standalone_view.cpp
|
||||
@@ -321,6 +330,7 @@ set(CPPSRC
|
||||
config_mode.cpp
|
||||
${CPLD_20150901_DATA_CPP}
|
||||
${CPLD_20170522_DATA_CPP}
|
||||
${CPLD_H4M_DATA_CPP}
|
||||
${HACKRF_CPLD_DATA_CPP}
|
||||
ui_external_items_menu_loader.cpp
|
||||
view_factory_base.cpp
|
||||
@@ -406,7 +416,11 @@ set(CPPWARN "-Wall -Wextra -Wno-psabi")
|
||||
# List all default C defines here, like -D_DEBUG=1
|
||||
# TODO: Switch -DCRT0_INIT_DATA depending on load from RAM or SPIFI?
|
||||
# NOTE: _RANDOM_TCC to kill a GCC 4.9.3 error with std::max argument types
|
||||
set(DDEFS "-DLPC43XX -DLPC43XX_M0 -D__NEWLIB__ -DHACKRF_ONE -DTOOLCHAIN_GCC -DTOOLCHAIN_GCC_ARM -D_RANDOM_TCC=0 -D'VERSION_STRING=\"${VERSION}\"' -DVERSION_MD5=${VERSION_MD5} -D'GCC_VERSION_MISMATCH=${GCC_VERSION_MISMATCH}'")
|
||||
# Use BOARD variable if set, otherwise default to HACKRF_ONE
|
||||
if(NOT DEFINED BOARD)
|
||||
set(BOARD "HACKRF_ONE")
|
||||
endif()
|
||||
set(DDEFS "-DLPC43XX -DLPC43XX_M0 -D__NEWLIB__ -D${BOARD} -DTOOLCHAIN_GCC -DTOOLCHAIN_GCC_ARM -D_RANDOM_TCC=0 -D'VERSION_STRING=\"${VERSION}\"' -DVERSION_MD5=${VERSION_MD5} -D'GCC_VERSION_MISMATCH=${GCC_VERSION_MISMATCH}'")
|
||||
|
||||
# List all default ASM defines here, like -D_DEBUG=1
|
||||
set(DADEFS)
|
||||
@@ -464,6 +478,12 @@ add_custom_command(
|
||||
DEPENDS ${EXTRACT_CPLD_DATA} ${CPLD_20170522_SVF_PATH}
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${CPLD_H4M_DATA_CPP}
|
||||
COMMAND ${EXTRACT_CPLD_DATA} ${CPLD_H4M_SVF_PATH} rev_h4m >${CPLD_H4M_DATA_CPP}
|
||||
DEPENDS ${EXTRACT_CPLD_DATA} ${CPLD_H4M_SVF_PATH}
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${HACKRF_CPLD_DATA_CPP}
|
||||
COMMAND ${HACKRF_CPLD_TOOL} --xsvf ${HACKRF_CPLD_XSVF_PATH} --portapack-data ${HACKRF_CPLD_DATA_CPP}
|
||||
@@ -471,6 +491,9 @@ add_custom_command(
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME}.elf ${CSRC} ${CPPSRC} ${ASMSRC})
|
||||
target_link_options(${PROJECT_NAME}.elf PRIVATE
|
||||
"LINKER:--defsym,LD_FLASH_SIZE=${FLASH_BYTES_LIMIT_SIZE}"
|
||||
)
|
||||
set_target_properties(${PROJECT_NAME}.elf PROPERTIES LINK_DEPENDS ${LDSCRIPT})
|
||||
add_definitions(${DEFS})
|
||||
include_directories(. ${INCDIR})
|
||||
|
||||
@@ -68,6 +68,9 @@ void BoundSetting::parse(std::string_view value) {
|
||||
as<bool>() = (parsed != 0);
|
||||
break;
|
||||
}
|
||||
case SettingType::Float:
|
||||
as<float>() = atof(value.data());
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -101,6 +104,11 @@ void BoundSetting::write(File& file) const {
|
||||
case SettingType::Bool:
|
||||
file.write(as<bool>() ? "1" : "0", 1);
|
||||
break;
|
||||
|
||||
case SettingType::Float: {
|
||||
auto float_str = to_string_decimal(as<float>(), 6);
|
||||
file.write(float_str.c_str(), float_str.length());
|
||||
}
|
||||
}
|
||||
|
||||
file.write("\r\n", 2);
|
||||
|
||||
@@ -52,6 +52,7 @@ class BoundSetting {
|
||||
U8,
|
||||
String,
|
||||
Bool,
|
||||
Float
|
||||
};
|
||||
|
||||
public:
|
||||
@@ -73,6 +74,9 @@ class BoundSetting {
|
||||
BoundSetting(std::string_view name, bool* target)
|
||||
: name_{name}, target_{target}, type_{SettingType::Bool} {}
|
||||
|
||||
BoundSetting(std::string_view name, float* target)
|
||||
: name_{name}, target_{target}, type_{SettingType::Float} {}
|
||||
|
||||
std::string_view name() const { return name_; }
|
||||
void parse(std::string_view value);
|
||||
void write(File& file) const;
|
||||
|
||||
@@ -159,7 +159,7 @@ class AISAppView : public View {
|
||||
~AISAppView();
|
||||
|
||||
void set_parent_rect(const Rect new_parent_rect) override;
|
||||
void paint(Painter&) override{};
|
||||
void paint(Painter&) override {};
|
||||
|
||||
void focus() override;
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class BLECommView : public View {
|
||||
~BLECommView();
|
||||
|
||||
void set_parent_rect(const Rect new_parent_rect) override;
|
||||
void paint(Painter&) override{};
|
||||
void paint(Painter&) override {};
|
||||
|
||||
void focus() override;
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@ class BLERxView : public View {
|
||||
~BLERxView();
|
||||
|
||||
void set_parent_rect(const Rect new_parent_rect) override;
|
||||
void paint(Painter&) override{};
|
||||
void paint(Painter&) override {};
|
||||
|
||||
void focus() override;
|
||||
|
||||
|
||||
@@ -225,7 +225,7 @@ void BLETxView::send_packet() {
|
||||
uint8_t min = 0x00;
|
||||
uint8_t max = 0x0F;
|
||||
|
||||
hexDigit = min + std::rand() % (max - min + 1);
|
||||
hexDigit = min + rand() % (max - min + 1);
|
||||
} break;
|
||||
default:
|
||||
hexDigit = 0;
|
||||
|
||||
@@ -105,7 +105,7 @@ class BLETxView : public View {
|
||||
~BLETxView();
|
||||
|
||||
void set_parent_rect(const Rect new_parent_rect) override;
|
||||
void paint(Painter&) override{};
|
||||
void paint(Painter&) override {};
|
||||
|
||||
void focus() override;
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ POCSAGSettingsView::POCSAGSettingsView(
|
||||
: settings_{settings} {
|
||||
add_children(
|
||||
{&labels,
|
||||
&opt_baud_rate,
|
||||
&check_log,
|
||||
&check_log_raw,
|
||||
&check_small_font,
|
||||
@@ -65,6 +66,7 @@ POCSAGSettingsView::POCSAGSettingsView(
|
||||
&field_filter_address,
|
||||
&button_save});
|
||||
|
||||
opt_baud_rate.set_by_value(settings_.baud_rate);
|
||||
check_log.set_value(settings_.enable_logging);
|
||||
check_log_raw.set_value(settings_.enable_raw_log);
|
||||
check_small_font.set_value(settings_.enable_small_font);
|
||||
@@ -81,7 +83,7 @@ POCSAGSettingsView::POCSAGSettingsView(
|
||||
settings_.hide_addr_only = check_hide_addr_only.value();
|
||||
settings_.filter_mode = opt_filter_mode.selected_index_value();
|
||||
settings_.filter_address = field_filter_address.to_integer();
|
||||
|
||||
settings_.baud_rate = opt_baud_rate.selected_index_value();
|
||||
nav.pop();
|
||||
};
|
||||
}
|
||||
@@ -142,7 +144,7 @@ POCSAGAppView::POCSAGAppView(NavigationView& nav)
|
||||
|
||||
audio::output::start();
|
||||
receiver_model.enable();
|
||||
baseband::set_pocsag();
|
||||
baseband::set_pocsag((int8_t)settings_.baud_rate);
|
||||
}
|
||||
|
||||
void POCSAGAppView::focus() {
|
||||
@@ -182,6 +184,7 @@ void POCSAGAppView::refresh_ui() {
|
||||
btn_text = "Filter Last";
|
||||
break;
|
||||
}
|
||||
baseband::set_pocsag((int8_t)settings_.baud_rate);
|
||||
button_filter_last.set_text(btn_text);
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +126,7 @@ struct POCSAGSettings {
|
||||
bool hide_bad_data = false;
|
||||
bool hide_addr_only = false;
|
||||
uint8_t filter_mode = false;
|
||||
int32_t baud_rate = -1;
|
||||
uint32_t filter_address = 0;
|
||||
};
|
||||
|
||||
@@ -139,7 +140,16 @@ class POCSAGSettingsView : public View {
|
||||
private:
|
||||
POCSAGSettings& settings_;
|
||||
|
||||
OptionsField opt_baud_rate{
|
||||
{8 * 8, 0 * 16},
|
||||
4,
|
||||
{{"Auto", -1},
|
||||
{" 512", 0},
|
||||
{"1200", 1},
|
||||
{"2400", 2}}};
|
||||
|
||||
Labels labels{
|
||||
{{2 * 8, 0 * 16}, "Baud:", Theme::getInstance()->fg_light->foreground},
|
||||
{{2 * 8, 12 * 16}, "Filter Mode:", Theme::getInstance()->fg_light->foreground},
|
||||
{{2 * 8, 13 * 16}, "Filter Addr:", Theme::getInstance()->fg_light->foreground},
|
||||
};
|
||||
@@ -221,6 +231,7 @@ class POCSAGAppView : public View {
|
||||
{"filter_address"sv, &settings_.filter_address},
|
||||
{"hide_bad_data"sv, &settings_.hide_bad_data},
|
||||
{"hide_addr_only"sv, &settings_.hide_addr_only},
|
||||
{"baud_rate"sv, &settings_.baud_rate},
|
||||
}};
|
||||
|
||||
void refresh_ui();
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace ui {
|
||||
constexpr std::string_view mayhem_information_list[] = {
|
||||
"#****** Mayhem Community ******",
|
||||
" ",
|
||||
" https://discord.mayhem.app",
|
||||
" https://discord.hackrf.app",
|
||||
" ",
|
||||
"#**** List of contributors ****",
|
||||
" ",
|
||||
|
||||
@@ -320,6 +320,47 @@ void ADSBRxDetailsView::update(const AircraftRecentEntry& entry) {
|
||||
}
|
||||
}
|
||||
|
||||
void ADSBRxDetailsView::get_altitude_color(int32_t alt_ft, uint8_t* r, uint8_t* g, uint8_t* b) {
|
||||
static const struct {
|
||||
int32_t alt;
|
||||
uint8_t r, g, b;
|
||||
} stops[] = {
|
||||
{0, 220, 220, 220}, // 0 ft: White/Grey (Ground)
|
||||
{2000, 255, 255, 0}, // 2k ft: Yellow
|
||||
{10000, 0, 255, 0}, // 10k ft: Green
|
||||
{20000, 0, 255, 255}, // 20k ft: Cyan
|
||||
{30000, 60, 60, 255}, // 30k ft: Blue (Lightened for visibility on Black)
|
||||
{40000, 255, 0, 255} // 40k+ ft: Magenta
|
||||
};
|
||||
if (alt_ft <= stops[0].alt) {
|
||||
*r = stops[0].r;
|
||||
*g = stops[0].g;
|
||||
*b = stops[0].b;
|
||||
return;
|
||||
}
|
||||
const int count = sizeof(stops) / sizeof(stops[0]);
|
||||
if (alt_ft >= stops[count - 1].alt) {
|
||||
*r = stops[count - 1].r;
|
||||
*g = stops[count - 1].g;
|
||||
*b = stops[count - 1].b;
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < count - 1; i++) {
|
||||
if (alt_ft < stops[i + 1].alt) {
|
||||
float t = (float)(alt_ft - stops[i].alt) / (stops[i + 1].alt - stops[i].alt);
|
||||
|
||||
*r = (uint8_t)(stops[i].r + (stops[i + 1].r - stops[i].r) * t);
|
||||
*g = (uint8_t)(stops[i].g + (stops[i + 1].g - stops[i].g) * t);
|
||||
*b = (uint8_t)(stops[i].b + (stops[i + 1].b - stops[i].b) * t);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Fallback: in case no interval matched, default to ground color.
|
||||
*r = stops[0].r;
|
||||
*g = stops[0].g;
|
||||
*b = stops[0].b;
|
||||
}
|
||||
|
||||
void ADSBRxDetailsView::clear_map_markers() {
|
||||
if (geomap_view_)
|
||||
geomap_view_->clear_markers();
|
||||
@@ -335,6 +376,9 @@ bool ADSBRxDetailsView::add_map_marker(const AircraftRecentEntry& entry) {
|
||||
marker.lat = entry.pos.latitude;
|
||||
marker.angle = entry.velo.heading;
|
||||
marker.tag = get_map_tag(entry);
|
||||
uint8_t r, g, b;
|
||||
get_altitude_color(entry.pos.altitude, &r, &g, &b);
|
||||
marker.color = Color(r, g, b);
|
||||
|
||||
auto markerStored = geomap_view_->store_marker(marker);
|
||||
return markerStored == MARKER_STORED;
|
||||
|
||||
@@ -270,6 +270,7 @@ class ADSBRxDetailsView : public View {
|
||||
void focus() override;
|
||||
void update(const AircraftRecentEntry& entry);
|
||||
|
||||
void get_altitude_color(int32_t alt_ft, uint8_t* r, uint8_t* g, uint8_t* b);
|
||||
/* Calls forwarded to map view if shown. */
|
||||
bool map_active() const { return geomap_view_; }
|
||||
void clear_map_markers();
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "baseband_api.hpp"
|
||||
#include "portapack_shared_memory.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
#include "ui_geomap.hpp"
|
||||
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
@@ -49,10 +50,24 @@ APRSTXView::~APRSTXView() {
|
||||
|
||||
void APRSTXView::start_tx() {
|
||||
// TODO: Clean up this API to take string_views to avoid allocations.
|
||||
std::string new_payload = payload;
|
||||
|
||||
std::string gps = text_gps_coord.get();
|
||||
std::string token = "?GPS?";
|
||||
size_t pos = 0;
|
||||
while ((pos = new_payload.find(token, pos)) != std::string::npos) {
|
||||
new_payload.replace(pos, token.size(), gps);
|
||||
pos += gps.size();
|
||||
}
|
||||
|
||||
text_payload.set(new_payload);
|
||||
|
||||
std::string path = text_path.get();
|
||||
|
||||
make_aprs_frame(
|
||||
sym_source.to_string().c_str(), num_ssid_source.value(),
|
||||
sym_dest.to_string().c_str(), num_ssid_dest.value(),
|
||||
payload);
|
||||
new_payload, path);
|
||||
|
||||
// uint8_t * bb_data_ptr = shared_memory.bb_data.data;
|
||||
// text_payload.set(to_string_hex_array(bb_data_ptr + 56, 15));
|
||||
@@ -77,6 +92,61 @@ void APRSTXView::on_tx_progress(const uint32_t progress, const bool done) {
|
||||
}
|
||||
}
|
||||
|
||||
void APRSTXView::process_coordinates(float lat_, float lon_) {
|
||||
std::string s;
|
||||
|
||||
char ns = lat_ >= 0 ? 'N' : 'S';
|
||||
float lat = (lat_ >= 0) ? lat_ : -lat_;
|
||||
uint32_t lat_d = (uint32_t)lat;
|
||||
uint32_t lat_m = (uint32_t)((lat - lat_d) * 6000.0f + 0.5f);
|
||||
|
||||
if (lat_m >= 6000) {
|
||||
lat_m = 0;
|
||||
lat_d++;
|
||||
}
|
||||
|
||||
s += to_string_dec_uint(lat_d, 2, '0');
|
||||
s += to_string_dec_uint(lat_m / 100, 2, '0');
|
||||
s += ".";
|
||||
s += to_string_dec_uint(lat_m % 100, 2, '0');
|
||||
s += ns;
|
||||
|
||||
s += "/";
|
||||
|
||||
char ew = lon_ >= 0 ? 'E' : 'W';
|
||||
float lon = (lon_ >= 0) ? lon_ : -lon_;
|
||||
uint32_t lon_d = (uint32_t)lon;
|
||||
uint32_t lon_m = (uint32_t)((lon - lon_d) * 6000.0f + 0.5f);
|
||||
|
||||
if (lon_m >= 6000) {
|
||||
lon_m = 0;
|
||||
lon_d++;
|
||||
}
|
||||
|
||||
s += to_string_dec_uint(lon_d, 3, '0');
|
||||
s += to_string_dec_uint(lon_m / 100, 2, '0');
|
||||
s += ".";
|
||||
s += to_string_dec_uint(lon_m % 100, 2, '0');
|
||||
s += ew;
|
||||
text_gps_coord.set(s);
|
||||
}
|
||||
|
||||
void APRSTXView::on_gps(const GPSPosDataMessage* message) {
|
||||
if (manual_gps_mode) {
|
||||
return; // no more update once set manually
|
||||
}
|
||||
if (message->lat < -90.0 || message->lat > 90.0 ||
|
||||
message->lon < -180.0 || message->lon > 180.0) {
|
||||
return;
|
||||
}
|
||||
if (message->lat == 0.0f && message->lon == 0.0f) {
|
||||
return;
|
||||
}
|
||||
last_lat = message->lat;
|
||||
last_lon = message->lon;
|
||||
process_coordinates(message->lat, message->lon);
|
||||
}
|
||||
|
||||
APRSTXView::APRSTXView(NavigationView& nav) {
|
||||
baseband::run_image(portapack::spi_flash::image_tag_afsk);
|
||||
|
||||
@@ -87,8 +157,33 @@ APRSTXView::APRSTXView(NavigationView& nav) {
|
||||
&num_ssid_dest,
|
||||
&text_payload,
|
||||
&button_set,
|
||||
&text_gps_coord,
|
||||
&button_mangps,
|
||||
&gps_is_manual,
|
||||
&text_path,
|
||||
&button_setpath,
|
||||
&tx_view});
|
||||
|
||||
sym_source.set_value(symsrc);
|
||||
num_ssid_source.set_value(ssidsrc);
|
||||
sym_dest.set_value(symdst);
|
||||
num_ssid_dest.set_value(ssiddst);
|
||||
text_payload.set(payload);
|
||||
text_path.set(path_cache);
|
||||
|
||||
sym_source.on_change = [this](SymField&) {
|
||||
symsrc = sym_source.to_string();
|
||||
};
|
||||
num_ssid_source.on_change = [this](int32_t v) {
|
||||
ssidsrc = v;
|
||||
};
|
||||
sym_dest.on_change = [this](SymField&) {
|
||||
symdst = sym_dest.to_string();
|
||||
};
|
||||
num_ssid_dest.on_change = [this](int32_t v) {
|
||||
ssiddst = v;
|
||||
};
|
||||
|
||||
button_set.on_select = [this, &nav](Button&) {
|
||||
text_prompt(
|
||||
nav,
|
||||
@@ -99,6 +194,17 @@ APRSTXView::APRSTXView(NavigationView& nav) {
|
||||
text_payload.set(s);
|
||||
});
|
||||
};
|
||||
button_setpath.on_select = [this, &nav](Button&) {
|
||||
text_prompt(
|
||||
nav,
|
||||
path_cache,
|
||||
60,
|
||||
ENTER_KEYBOARD_MODE_ALPHA,
|
||||
[this](std::string& s) {
|
||||
text_path.set(s);
|
||||
path_cache = s;
|
||||
});
|
||||
};
|
||||
|
||||
tx_view.on_edit_frequency = [this, &nav]() {
|
||||
auto new_view = nav.push<FrequencyKeypadView>(transmitter_model.target_frequency());
|
||||
@@ -116,6 +222,23 @@ APRSTXView::APRSTXView(NavigationView& nav) {
|
||||
tx_view.set_transmitting(false);
|
||||
transmitter_model.disable();
|
||||
};
|
||||
|
||||
button_mangps.on_select = [this, &nav](Button&) {
|
||||
nav.push<GeoMapView>(
|
||||
0,
|
||||
GeoPos::alt_unit::METERS,
|
||||
GeoPos::spd_unit::HIDDEN,
|
||||
last_lat,
|
||||
last_lon,
|
||||
[this](int32_t, float lat, float lon, int32_t) {
|
||||
last_lat = lat;
|
||||
last_lon = lon;
|
||||
manual_gps_mode = true;
|
||||
gps_is_manual.set("MANUAL");
|
||||
process_coordinates(lat, lon);
|
||||
});
|
||||
};
|
||||
// process_coordinates(last_lat, last_lon); //don't load last, so won't confuse users
|
||||
}
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
@@ -50,59 +50,109 @@ class APRSTXView : public View {
|
||||
1750000 /* bandwidth */,
|
||||
AFSK_TX_SAMPLERATE /* sampling rate */
|
||||
};
|
||||
app_settings::SettingsManager settings_{
|
||||
"tx_aprs", app_settings::Mode::TX};
|
||||
|
||||
std::string symsrc = "";
|
||||
std::string symdst = "";
|
||||
std::string payload{""};
|
||||
std::string path_cache = "";
|
||||
int32_t ssidsrc = 0;
|
||||
int32_t ssiddst = 0;
|
||||
|
||||
bool manual_gps_mode = false;
|
||||
float last_lat = 0.0f;
|
||||
float last_lon = 0.0f;
|
||||
|
||||
app_settings::SettingsManager settings_{
|
||||
"tx_aprs",
|
||||
app_settings::Mode::TX,
|
||||
{{"symsrc"sv, &symsrc},
|
||||
{"symdst"sv, &symdst},
|
||||
{"ssidsrc"sv, &ssidsrc},
|
||||
{"ssiddst"sv, &ssiddst},
|
||||
{"payload"sv, &payload},
|
||||
{"last_lat"sv, &last_lat},
|
||||
{"last_lon"sv, &last_lon},
|
||||
{"path"sv, &path_cache}}};
|
||||
|
||||
void start_tx();
|
||||
void generate_frame();
|
||||
void generate_frame_pos();
|
||||
void on_tx_progress(const uint32_t progress, const bool done);
|
||||
void on_gps(const GPSPosDataMessage* message);
|
||||
void process_coordinates(float lat, float lon);
|
||||
|
||||
Labels labels{
|
||||
{{UI_POS_X(0), 1 * 16}, "Source: SSID:", Theme::getInstance()->fg_light->foreground}, // 6 alphanum + SSID
|
||||
{{UI_POS_X(0), 2 * 16}, " Dest.: SSID:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 4 * 16}, "Info field:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(0)}, "Source: SSID:", Theme::getInstance()->fg_light->foreground}, // 6 alphanum + SSID
|
||||
{{UI_POS_X(0), UI_POS_Y(1)}, " Dest.: SSID:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(2)}, "Path: (ex.: WIDE1-1,WIDE2-1)", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(6)}, "Info field:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(10)}, "GPS:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X_CENTER(22), UI_POS_Y(14)}, "Use ?GPS? in the info", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X_CENTER(17), UI_POS_Y(15)}, "as a placeholder.", Theme::getInstance()->fg_light->foreground},
|
||||
};
|
||||
|
||||
Text text_path{
|
||||
{UI_POS_X(0), UI_POS_Y(3), UI_POS_MAXWIDTH, UI_POS_HEIGHT(1)},
|
||||
"WIDE1-1",
|
||||
};
|
||||
Text gps_is_manual{
|
||||
{UI_POS_X(6), UI_POS_Y(10), UI_POS_WIDTH(10), UI_POS_HEIGHT(1)},
|
||||
"",
|
||||
};
|
||||
|
||||
SymField sym_source{
|
||||
{7 * 8, 1 * 16},
|
||||
{UI_POS_X(7), UI_POS_Y(0)},
|
||||
6,
|
||||
SymField::Type::Alpha};
|
||||
|
||||
NumberField num_ssid_source{
|
||||
{19 * 8, 1 * 16},
|
||||
{UI_POS_X(19), UI_POS_Y(0)},
|
||||
2,
|
||||
{0, 15},
|
||||
1,
|
||||
' '};
|
||||
|
||||
SymField sym_dest{
|
||||
{7 * 8, 2 * 16},
|
||||
{UI_POS_X(7), UI_POS_Y(1)},
|
||||
6,
|
||||
SymField::Type::Alpha};
|
||||
|
||||
NumberField num_ssid_dest{
|
||||
{19 * 8, 2 * 16},
|
||||
{UI_POS_X(19), UI_POS_Y(1)},
|
||||
2,
|
||||
{0, 15},
|
||||
1,
|
||||
' '};
|
||||
|
||||
Text text_payload{
|
||||
{UI_POS_X(0), 5 * 16, screen_width, 16},
|
||||
"-"};
|
||||
{UI_POS_X(0), UI_POS_Y(7), UI_POS_MAXWIDTH, UI_POS_HEIGHT(1)},
|
||||
""};
|
||||
Button button_set{
|
||||
{UI_POS_X(0), 6 * 16, 80, 32},
|
||||
{UI_POS_X(0), UI_POS_Y(8), UI_POS_WIDTH(10), UI_POS_HEIGHT(2)},
|
||||
"Set"};
|
||||
|
||||
Text text_gps_coord{
|
||||
{UI_POS_X(0), UI_POS_Y(11), UI_POS_WIDTH(20), UI_POS_HEIGHT(1)},
|
||||
"-"};
|
||||
|
||||
Button button_mangps{
|
||||
{UI_POS_X(0), UI_POS_Y(12), UI_POS_WIDTH(14), UI_POS_HEIGHT(2)},
|
||||
"Manual GPS"};
|
||||
Button button_setpath{
|
||||
{UI_POS_X(0), UI_POS_Y(4), UI_POS_WIDTH(14), UI_POS_HEIGHT(2)},
|
||||
"Set Path"};
|
||||
TransmitterView tx_view{
|
||||
(int16_t)UI_POS_Y_BOTTOM(4),
|
||||
5000,
|
||||
0 // disable setting bandwith, since APRS used fixed 10k bandwidth
|
||||
};
|
||||
|
||||
MessageHandlerRegistration message_handler_gps{
|
||||
Message::ID::GPSPosData,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const GPSPosDataMessage*>(p);
|
||||
this->on_gps(message);
|
||||
}};
|
||||
MessageHandlerRegistration message_handler_tx_progress{
|
||||
Message::ID::TXProgress,
|
||||
[this](const Message* const p) {
|
||||
|
||||
@@ -98,7 +98,7 @@ class BattinfoView : public View {
|
||||
"Volt"};
|
||||
|
||||
Button button_exit{
|
||||
{UI_POS_X_CENTER(12), 17 * 16, UI_POS_WIDTH(12), UI_POS_HEIGHT(3)},
|
||||
{UI_POS_X_CENTER(12), UI_POS_Y_BOTTOM(4), UI_POS_WIDTH(12), UI_POS_HEIGHT(2)},
|
||||
"Back"};
|
||||
static msg_t static_fn(void* arg);
|
||||
Thread* thread{nullptr};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -93,6 +93,10 @@ typedef enum {
|
||||
CT_SI5351,
|
||||
CT_AUDIO,
|
||||
CT_MAX17055,
|
||||
#ifdef PRALINE
|
||||
CT_FPGA,
|
||||
#endif
|
||||
CT_SGPIO,
|
||||
} chip_type_t;
|
||||
|
||||
struct RegistersWidgetConfig {
|
||||
@@ -373,6 +377,648 @@ private:
|
||||
};
|
||||
};*/
|
||||
|
||||
/* Radio Signal Path Diagnostics View
|
||||
* Shows status of each component in the RX/TX signal chain:
|
||||
* Antenna -> RF Path -> RFFC5072 -> MAX283x -> MAX5864 -> FPGA -> SGPIO -> MCU
|
||||
*/
|
||||
class RadioDiagnosticsView : public View {
|
||||
public:
|
||||
RadioDiagnosticsView(NavigationView& nav);
|
||||
|
||||
void focus() override;
|
||||
std::string title() const override { return "Radio Diag"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
void update_status();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "=== Signal Path Status ==="};
|
||||
|
||||
Text text_lbl_rffc{{0, 20, 140, 16}, "RFFC5072 (1st IF):"};
|
||||
Text text_rffc_status{{144, 20, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_max{{0, 36, 140, 16}, "MAX283x (2nd IF):"};
|
||||
Text text_max_status{{144, 36, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_adc{{0, 52, 140, 16}, "MAX5864 (ADC):"};
|
||||
Text text_adc_status{{144, 52, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_fpga{{0, 68, 140, 16}, "FPGA/CPLD:"};
|
||||
Text text_fpga_status{{144, 68, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_sgpio{{0, 84, 140, 16}, "SGPIO:"};
|
||||
Text text_sgpio_status{{144, 84, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_clock{{0, 100, 140, 16}, "Si5351 Clocks:"};
|
||||
Text text_clock_status{{144, 100, 96, 16}, "---"};
|
||||
|
||||
Text text_regs_title{{0, 124, 240, 16}, "=== Key Registers ==="};
|
||||
|
||||
Text text_lbl_rffc_reg{{0, 144, 80, 16}, "RFFC R0:"};
|
||||
Text text_rffc_reg{{80, 144, 160, 16}, "---"};
|
||||
|
||||
Text text_lbl_max_reg{{0, 160, 80, 16}, "MAX R0:"};
|
||||
Text text_max_reg{{80, 160, 160, 16}, "---"};
|
||||
|
||||
Text text_lbl_fpga_reg{{0, 176, 80, 16}, "FPGA:"};
|
||||
Text text_fpga_reg{{80, 176, 160, 16}, "---"};
|
||||
|
||||
Text text_lbl_sgpio_reg{{0, 192, 80, 16}, "SGPIO:"};
|
||||
Text text_sgpio_reg{{80, 192, 160, 16}, "---"};
|
||||
|
||||
Text text_test_result{{0, 220, 240, 32}, ""};
|
||||
|
||||
Button button_refresh{
|
||||
{8, 280, 72, 24},
|
||||
"Refresh"};
|
||||
|
||||
Button button_done{
|
||||
{168, 280, 64, 24},
|
||||
"Done"};
|
||||
};
|
||||
|
||||
/* BasebandStatusView ***************************************************/
|
||||
|
||||
class BasebandStatusView : public View {
|
||||
public:
|
||||
BasebandStatusView(NavigationView& nav);
|
||||
|
||||
void focus() override;
|
||||
std::string title() const override { return "Baseband Status"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
void update();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "=== Baseband Counters ==="};
|
||||
|
||||
Text text_lbl_marker{{0, 20, 140, 16}, "Streaming Marker:"};
|
||||
Text text_marker{{144, 20, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_loops{{0, 36, 140, 16}, "Baseband Loops:"};
|
||||
Text text_loops{{144, 36, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_wait{{0, 52, 140, 16}, "DMA Wait Count:"};
|
||||
Text text_wait{{144, 52, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_xfr{{0, 68, 140, 16}, "DMA Xfr Count:"};
|
||||
Text text_xfr{{144, 68, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_missed{{0, 84, 140, 16}, "Buffer Missed:"};
|
||||
Text text_missed{{144, 84, 96, 16}, "---"};
|
||||
|
||||
Text text_status_line1{{0, 110, 240, 16}, ""};
|
||||
Text text_status_line2{{0, 126, 240, 16}, ""};
|
||||
Text text_status_line3{{0, 142, 240, 16}, ""};
|
||||
|
||||
Button button_refresh{
|
||||
{8, 280, 72, 24},
|
||||
"Refresh"};
|
||||
|
||||
Button button_done{
|
||||
{168, 280, 64, 24},
|
||||
"Done"};
|
||||
|
||||
MessageHandlerRegistration message_handler_frame_sync{
|
||||
Message::ID::DisplayFrameSync,
|
||||
[this](const Message* const) { this->update(); }};
|
||||
};
|
||||
|
||||
/* SGPIOLiveMonitorView ***************************************************/
|
||||
|
||||
class SGPIOLiveMonitorView : public View {
|
||||
public:
|
||||
SGPIOLiveMonitorView(NavigationView& nav);
|
||||
|
||||
void focus() override;
|
||||
std::string title() const override { return "SGPIO Live"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
void update();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "=== SGPIO Registers ==="};
|
||||
|
||||
Text text_lbl_ctrl{{0, 20, 140, 16}, "CTRL_ENABLE:"};
|
||||
Text text_ctrl{{144, 20, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_in{{0, 36, 140, 16}, "GPIO_INREG:"};
|
||||
Text text_in{{144, 36, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_ss{{0, 52, 140, 16}, "REG_SS[0]:"};
|
||||
Text text_ss{{144, 52, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_status{{0, 68, 140, 16}, "STATUS_1:"};
|
||||
Text text_status{{144, 68, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_out{{0, 84, 140, 16}, "GPIO_OUTREG:"};
|
||||
Text text_out{{144, 84, 96, 16}, "---"};
|
||||
|
||||
Text text_lbl_oen{{0, 100, 140, 16}, "GPIO_OENREG:"};
|
||||
Text text_oen{{144, 100, 96, 16}, "---"};
|
||||
|
||||
Text text_diag_line1{{0, 126, 240, 16}, ""};
|
||||
Text text_diag_line2{{0, 142, 240, 16}, ""};
|
||||
Text text_diag_line3{{0, 158, 240, 16}, ""};
|
||||
Text text_diag_line4{{0, 174, 240, 16}, ""};
|
||||
|
||||
Button button_refresh{
|
||||
{8, 280, 72, 24},
|
||||
"Refresh"};
|
||||
|
||||
Button button_done{
|
||||
{168, 280, 64, 24},
|
||||
"Done"};
|
||||
|
||||
MessageHandlerRegistration message_handler_frame_sync{
|
||||
Message::ID::DisplayFrameSync,
|
||||
[this](const Message* const) { this->update(); }};
|
||||
};
|
||||
|
||||
/* Radio RX Step-by-Step Test View
|
||||
* Tests radio hardware directly without M0 baseband involvement.
|
||||
* Logs each step to help isolate where the signal chain breaks.
|
||||
*/
|
||||
class RadioRxTestView : public View {
|
||||
public:
|
||||
RadioRxTestView(NavigationView& nav);
|
||||
|
||||
void focus() override;
|
||||
std::string title() const override { return "RX Test"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
bool radio_initialized_{false};
|
||||
uint32_t test_frequency_{433000000}; // 433 MHz default
|
||||
|
||||
void log(const std::string& msg);
|
||||
void log_registers(const std::string& label);
|
||||
void run_init_test();
|
||||
void run_rx_mode_test();
|
||||
void run_freq_test();
|
||||
void run_sgpio_test();
|
||||
void run_full_test();
|
||||
void run_step_test();
|
||||
bool check_gpio_changing();
|
||||
|
||||
Labels labels{
|
||||
{{0, 0}, "=== Radio RX Test ===", Theme::getInstance()->fg_yellow->foreground}};
|
||||
|
||||
Console console{
|
||||
{0, 20, 240, 200}};
|
||||
|
||||
Button button_init{
|
||||
{0, 224, 56, 24},
|
||||
"Init"};
|
||||
|
||||
Button button_rx{
|
||||
{60, 224, 56, 24},
|
||||
"RX"};
|
||||
|
||||
Button button_freq{
|
||||
{120, 224, 56, 24},
|
||||
"Freq"};
|
||||
|
||||
Button button_sgpio{
|
||||
{180, 224, 56, 24},
|
||||
"SGPIO"};
|
||||
|
||||
Button button_full{
|
||||
{0, 252, 56, 24},
|
||||
"Full"};
|
||||
|
||||
Button button_step{
|
||||
{60, 252, 56, 24},
|
||||
"Step"};
|
||||
|
||||
Button button_done{
|
||||
{120, 252, 112, 24},
|
||||
"Done"};
|
||||
};
|
||||
|
||||
/* SGPIO8 Clock Detector View
|
||||
* Samples SGPIO8 pin to verify external clock is present.
|
||||
* Shows toggle count and estimated frequency.
|
||||
*/
|
||||
class SGPIO8ClockDetectorView : public View {
|
||||
public:
|
||||
SGPIO8ClockDetectorView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "SGPIO8 Clock"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
Text text_title{{8, 16, 224, 16}, "SGPIO8 Clock Detector"};
|
||||
Text text_lbl_samples{{8, 48, 160, 16}, "Samples (first 20):"};
|
||||
Text text_samples{{8, 64, 224, 16}, " "};
|
||||
Text text_lbl_toggles{{8, 96, 160, 16}, "Toggle count:"};
|
||||
Text text_toggles{{8, 112, 224, 16}, " "};
|
||||
Text text_status{{8, 144, 224, 32}, " "};
|
||||
|
||||
Button button_sample{{8, 200, 96, 24}, "Sample"};
|
||||
Button button_done{{128, 200, 96, 24}, "Done"};
|
||||
|
||||
void sample_sgpio8();
|
||||
};
|
||||
|
||||
/* Slice Status View
|
||||
* Shows SGPIO slice status: which slices are enabled vs active,
|
||||
* counter values, and data capture status.
|
||||
*/
|
||||
|
||||
/* Si5351 Debug View
|
||||
* Dedicated diagnostic tool for Si5351 clock generator.
|
||||
* Shows PLL lock status, clock configurations, and allows testing.
|
||||
*/
|
||||
class Si5351DebugView : public View {
|
||||
public:
|
||||
Si5351DebugView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "Si5351 Clocks"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
Text text_title{{8, 16, 200, 16}, "Si5351 Clock Generator"};
|
||||
|
||||
Text text_status_label{{8, 40, 80, 16}, "Status Reg:"};
|
||||
Text text_status_value{{96, 40, 144, 16}, ""};
|
||||
|
||||
Text text_pll_a_label{{8, 60, 80, 16}, "PLL A:"};
|
||||
Text text_pll_a_status{{96, 60, 144, 16}, ""};
|
||||
|
||||
Text text_pll_b_label{{8, 80, 80, 16}, "PLL B:"};
|
||||
Text text_pll_b_status{{96, 80, 144, 16}, ""};
|
||||
|
||||
Text text_sys_init_label{{8, 100, 80, 16}, "SYS_INIT:"};
|
||||
Text text_sys_init_status{{96, 100, 144, 16}, ""};
|
||||
|
||||
Text text_xtal_cap_label{{8, 120, 80, 16}, "XTAL Cap:"};
|
||||
Text text_xtal_cap_value{{96, 120, 144, 16}, ""};
|
||||
|
||||
Text text_clk0_label{{8, 150, 72, 16}, "CLK0:"};
|
||||
Text text_clk0_status{{88, 150, 152, 16}, ""};
|
||||
|
||||
Text text_clk0_freq_label{{8, 170, 72, 16}, " Freq:"};
|
||||
Text text_clk0_freq_value{{88, 170, 152, 16}, ""};
|
||||
|
||||
Text text_clk0_div_label{{8, 190, 72, 16}, " Div:"};
|
||||
Text text_clk0_div_value{{88, 190, 152, 16}, ""};
|
||||
|
||||
Text text_clk1_label{{8, 210, 96, 16}, "CLK1 (SCT):"};
|
||||
Text text_clk1_status{{112, 210, 128, 16}, ""};
|
||||
|
||||
Button button_refresh{{8, 240, 72, 24}, "Refresh"};
|
||||
Button button_reset_pll{{88, 240, 72, 24}, "Reset PLL"};
|
||||
Button button_done{{168, 240, 64, 24}, "Done"};
|
||||
|
||||
void refresh_status();
|
||||
void reset_pll();
|
||||
};
|
||||
|
||||
#ifdef PRALINE
|
||||
/* SignalPathStatusView *************************************************/
|
||||
class SignalPathStatusView : public View {
|
||||
public:
|
||||
SignalPathStatusView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "Signal Path"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
void refresh_status();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "=== Signal Path Status ==="};
|
||||
|
||||
Text text_lbl_max_enable{{0, 20, 1114, 16}, "MAX2831:"};
|
||||
Text text_max_enable{{116, 20, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_max_mode{{0, 36, 114, 16}, "RX Mode:"};
|
||||
Text text_max_mode{{116, 36, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_rf_path{{0, 52, 114, 16}, "RF Path:"};
|
||||
Text text_rf_path{{116, 52, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_filter{{0, 68, 114, 16}, "Filter Band:"};
|
||||
Text text_filter{{116, 68, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_mixer{{0, 84, 114, 16}, "Mixer Enable:"};
|
||||
Text text_mixer{{116, 84, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_rf_amp{{0, 100, 114, 16}, "RF Amp:"};
|
||||
Text text_rf_amp{{116, 100, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_lna{{0, 116, 114, 16}, "LNA Gain:"};
|
||||
Text text_lna{{116, 116, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_vga{{0, 132, 114, 16}, "VGA Gain:"};
|
||||
Text text_vga{{116, 132, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_fpga_decim{{0, 148, 114, 16}, "FPGA Decim:"};
|
||||
Text text_fpga_decim{{116, 148, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_fpga_ctrl_dc_q{{0, 164, 114, 16}, "FPGA Ctrl:"};
|
||||
Text text_fpga_ctrl_dc_q{{116, 164, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_fpga_ctrl_qs{{0, 180, 114, 16}, ""};
|
||||
Text text_fpga_ctrl_qs{{116, 180, 124, 16}, "---"};
|
||||
|
||||
Text text_status{{0, 200, 240, 32}, ""};
|
||||
|
||||
Button button_refresh{{0, 280, 72, 24}, "Refresh"};
|
||||
Button button_toggle_q{{88, 280, 72, 24}, "Q Inv"};
|
||||
Button button_done{{176, 280, 64, 24}, "Done"};
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef PRALINE
|
||||
class GPIODebugView : public View {
|
||||
public:
|
||||
GPIODebugView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "GPIO Debug"; };
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
|
||||
// GPIO4 (LPF and RF Amp)
|
||||
Text text_lbl_gpio4{{0, 0, 240, 16}, "Pin Diag: GPIO4 (LPF|Amp|Mix)"};
|
||||
|
||||
Text text_lbl_dir4{{0, 18, 114, 16}, "DIR[4]:"};
|
||||
Text text_dir4{{116, 18, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_pin4{{0, 36, 114, 16}, "PIN[4] (read):"};
|
||||
Text text_pin4{{116, 36, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_set4{{0, 54, 114, 16}, "SET[4] (write):"};
|
||||
Text text_set4{{116, 54, 124, 16}, "---"};
|
||||
|
||||
// Bit 8 (LPF)
|
||||
Text text_lbl_lpf_bit{{0, 78, 240, 16}, "Bit 8 (LPF - GPIO4[8]):"};
|
||||
Text text_lpf_dir{{0, 96, 80, 16}, "DIR: ?"};
|
||||
Text text_lpf_pin{{82, 96, 78, 16}, "PIN: ?"};
|
||||
Text text_lpf_set{{162, 96, 78, 16}, "SET: ?"};
|
||||
|
||||
Button button_lpf_toggle{{8, 114, 110, 24}, "Toggle LPF"};
|
||||
Button button_lpf_on{{122, 114, 50, 24}, "ON"};
|
||||
Button button_lpf_off{{176, 114, 50, 24}, "OFF"};
|
||||
|
||||
// Bit 9 (RF Amp)
|
||||
Text text_lbl_amp_bit{{0, 146, 240, 16}, "Bit 9 (Amp - GPIO4[9]):"};
|
||||
Text text_amp_dir{{0, 164, 80, 16}, "DIR: ?"};
|
||||
Text text_amp_pin{{82, 164, 78, 16}, "PIN: ?"};
|
||||
Text text_amp_set{{162, 164, 78, 16}, "SET: ?"};
|
||||
|
||||
Button button_amp_toggle{{8, 182, 110, 24}, "Toggle Amp"};
|
||||
Button button_amp_on{{122, 182, 50, 24}, "ON"};
|
||||
Button button_amp_off{{176, 182, 50, 24}, "OFF"};
|
||||
|
||||
// GPIO3 (Mixer)
|
||||
Text text_lbl_gpio3{{0, 214, 240, 16}, "--- GPIO3 (Mixer) ---"};
|
||||
Text text_lbl_mix_bit{{0, 232, 240, 16}, "Bit 2 (MIX - GPIO3[2]):"};
|
||||
Text text_mix_dir{{0, 250, 80, 16}, "DIR: ?"};
|
||||
Text text_mix_pin{{82, 250, 78, 16}, "PIN: ?"};
|
||||
Text text_mix_set{{162, 250, 78, 16}, "SET: ?"};
|
||||
|
||||
// Controls
|
||||
Button button_refresh{{8, 280, 72, 24}, "Refresh"};
|
||||
Button button_done{{168, 280, 64, 24}, "Done"};
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef PRALINE
|
||||
/* RFFC5072StatusView *************************************************/
|
||||
class RFFC5072StatusView : public View {
|
||||
public:
|
||||
RFFC5072StatusView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "RFFC5072 Status"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
void refresh_status();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "=== RFFC5072 (1st IF) ==="};
|
||||
|
||||
Text text_lbl_lock{{0, 16, 114, 16}, "Lock Detect:"};
|
||||
Text text_lock{{116, 16, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_ctrl{{0, 32, 114, 16}, "Control:"};
|
||||
Text text_ctrl{{116, 32, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_enabled{{0, 48, 114, 16}, "Status:"};
|
||||
Text text_enabled{{116, 48, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_freq{{0, 64, 114, 16}, "LO Freq:"};
|
||||
Text text_freq{{116, 64, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_path{{0, 80, 114, 16}, "Path:"};
|
||||
Text text_path{{116, 80, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_mixer{{0, 96, 114, 16}, "Mixer:"};
|
||||
Text text_mixer{{116, 96, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_r0{{0, 112, 114, 16}, "Reg 0:"};
|
||||
Text text_r0{{116, 112, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_r1{{0, 128, 114, 16}, "Reg 1 (N):"};
|
||||
Text text_r1{{116, 128, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_r2{{0, 144, 114, 16}, "Reg 2:"};
|
||||
Text text_r2{{116, 144, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_n{{0, 160, 114, 16}, "N divider:"};
|
||||
Text text_n{{116, 160, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_lodiv{{0, 176, 114, 16}, "LO divider:"};
|
||||
Text text_lodiv{{116, 176, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_calc{{0, 192, 114, 16}, "Calc freq:"};
|
||||
Text text_calc{{116, 192, 124, 16}, "---"};
|
||||
|
||||
Text text_status{{0, 208, 240, 16}, ""};
|
||||
|
||||
Text text_lbl_regs_status{{0, 224, 48, 16}, "Regs:"};
|
||||
Text text_regs_status{{50, 224, 190, 16}, "---"};
|
||||
|
||||
Button button_refresh{{2, 280, 56, 24}, "Rfrsh"};
|
||||
Button button_done{{182, 280, 56, 24}, "Done"};
|
||||
};
|
||||
|
||||
#ifdef PRALINE
|
||||
/* RFFCTuningDebugView *************************************************/
|
||||
class RFFCTuningDebugView : public View {
|
||||
public:
|
||||
RFFCTuningDebugView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "RFFC Tuning Debug"; };
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "RFFC5072 Tuning Debug"};
|
||||
|
||||
Text text_lbl_called{{0, 18, 120, 16}, "Freq Set:"};
|
||||
Text text_called{{122, 18, 118, 16}, "NO"};
|
||||
|
||||
Text text_lbl_req{{0, 38, 120, 16}, "Requested:"};
|
||||
Text text_req{{122, 38, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_exp_n{{0, 56, 120, 16}, "Expected N:"};
|
||||
Text text_exp_n{{122, 56, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_act_n{{0, 74, 120, 16}, "Actual N:"};
|
||||
Text text_act_n{{122, 74, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_exp_div{{0, 92, 120, 16}, "Exp LO/Pres:"};
|
||||
Text text_exp_div{{122, 92, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_act_div{{0, 110, 120, 16}, "Act LO/Pres:"};
|
||||
Text text_act_div{{122, 110, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_calc{{0, 128, 120, 16}, "Calc LO freq:"};
|
||||
Text text_calc{{122, 128, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_calc_lo{{0, 146, 120, 16}, "Calc input:"};
|
||||
Text text_calc_lo{{122, 146, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_calc_vco{{0, 164, 120, 16}, "In Calc VCO:"};
|
||||
Text text_calc_vco{{122, 164, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_vco{{0, 182, 120, 16}, "Calc VCO:"};
|
||||
Text text_vco{{122, 182, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_n_q24{{0, 200, 120, 16}, "N (Q24):"};
|
||||
Text text_n_q24{{122, 200, 118, 16}, "---"};
|
||||
|
||||
Text text_status{{0, 224, 240, 48}, ""};
|
||||
|
||||
Button button_refresh{{8, 280, 72, 24}, "Refresh"};
|
||||
Button button_done{{168, 280, 64, 24}, "Done"};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef PRALINE
|
||||
/* MAX2831DebugView *************************************************/
|
||||
|
||||
class MAX2831DebugView : public View {
|
||||
public:
|
||||
MAX2831DebugView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "MAX2831 Debug"; };
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "MAX2831 (2nd IF) Debug"};
|
||||
|
||||
Text text_lbl_called{{0, 24, 120, 16}, "Freq Set:"};
|
||||
Text text_called{{122, 24, 118, 16}, "NO"};
|
||||
|
||||
Text text_lbl_valid{{0, 42, 120, 16}, "In Range:"};
|
||||
Text text_valid{{122, 42, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_req{{0, 60, 120, 16}, "Requested:"};
|
||||
Text text_req{{122, 60, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_calc_n{{0, 78, 120, 16}, "Calc N:"};
|
||||
Text text_calc_n{{122, 78, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_calc_frac{{0, 96, 120, 16}, "Calc Frac:"};
|
||||
Text text_calc_frac{{122, 96, 118, 16}, "---"};
|
||||
|
||||
Text text_spacer{{0, 114, 240, 16}, "--- Hardware Regs ---"};
|
||||
|
||||
Text text_lbl_r3{{0, 132, 120, 16}, "Reg 3:"};
|
||||
Text text_r3{{122, 132, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_r4{{0, 150, 120, 16}, "Reg 4:"};
|
||||
Text text_r4{{122, 150, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_act_n{{0, 168, 120, 16}, "Actual N:"};
|
||||
Text text_act_n{{122, 168, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_act_frac{{0, 186, 120, 16}, "Actual Frac:"};
|
||||
Text text_act_frac{{122, 186, 118, 16}, "---"};
|
||||
|
||||
Text text_lbl_calc_freq{{0, 204, 120, 16}, "Calc Freq:"};
|
||||
Text text_calc_freq{{122, 204, 118, 16}, "---"};
|
||||
|
||||
Text text_status{{0, 228, 240, 44}, ""};
|
||||
|
||||
Button button_refresh{{8, 280, 72, 24}, "Refresh"};
|
||||
Button button_done{{168, 280, 64, 24}, "Done"};
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef PRALINE
|
||||
class SystemDiagnosticsView : public View {
|
||||
public:
|
||||
SystemDiagnosticsView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "System Diagnostics"; };
|
||||
|
||||
private:
|
||||
void refresh();
|
||||
void read_gpio_states();
|
||||
void set_sample_rate(uint32_t rate);
|
||||
|
||||
Text text_title{{0, 0, 240, 16}, "System Diagnostics"};
|
||||
|
||||
// Sample Rate Section
|
||||
Text text_lbl_sample{{0, 24, 42, 16}, "Rate:"};
|
||||
Text text_sample_rate{{44, 24, 50, 16}, "---"};
|
||||
Text text_lbl_fpga_decode{{96, 24, 144, 16}, "DC:? Q:? QS:?"};
|
||||
|
||||
Button button_sample_2m{{2, 44, 56, 24}, "2 MSPS"};
|
||||
Button button_sample_4m{{62, 44, 56, 24}, "4 MSPS"};
|
||||
Button button_sample_8m{{122, 44, 56, 24}, "8 MSPS"};
|
||||
Button button_sample_20m{{182, 44, 56, 24}, "20 MSPS"};
|
||||
|
||||
// Baseband Filter Section
|
||||
Text text_lbl_bb_filter{{0, 76, 114, 16}, "BB Filter BW:"};
|
||||
Text text_bb_filter{{116, 76, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_reg8{{0, 94, 114, 16}, "MAX2831 R8:"};
|
||||
Text text_reg8{{116, 94, 124, 16}, "---"};
|
||||
|
||||
// GPIO States Section
|
||||
Text text_lbl_gpio{{0, 118, 240, 16}, "--- GPIO Pin States ---"};
|
||||
|
||||
Text text_lbl_lpf{{0, 136, 56, 16}, "LPF:"};
|
||||
Text text_gpio_lpf{{58, 136, 181, 16}, "---"};
|
||||
|
||||
Text text_lbl_mix{{0, 154, 56, 16}, "Mixer:"};
|
||||
Text text_gpio_mix{{58, 154, 181, 16}, "---"};
|
||||
|
||||
Text text_lbl_amp{{0, 172, 56, 16}, "RF Amp:"};
|
||||
Text text_gpio_amp{{58, 172, 181, 16}, "---"};
|
||||
|
||||
// FPGA Control Section
|
||||
Text text_lbl_fpga{{0, 196, 240, 16}, "--- FPGA Control ---"};
|
||||
|
||||
Text text_lbl_fpga_ctrl{{0, 214, 114, 16}, "FPGA Reg 1:"};
|
||||
Text text_fpga_ctrl{{116, 214, 124, 16}, "---"};
|
||||
|
||||
Text text_lbl_band{{0, 232, 48, 16}, "Band:"};
|
||||
Text text_band{{50, 232, 190, 16}, "---"};
|
||||
|
||||
Button button_toggle_q{{2, 252, 110, 24}, "Toggle Q Inv"};
|
||||
Button button_toggle_dc{{122, 252, 110, 24}, "Toggle DC Blk"};
|
||||
|
||||
// Control Buttons
|
||||
Button button_refresh{{2, 280, 72, 24}, "Refresh"};
|
||||
Button button_done{{168, 280, 64, 24}, "Done"};
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
class DebugPeripheralsMenuView : public BtnGridView {
|
||||
public:
|
||||
DebugPeripheralsMenuView(NavigationView& nav);
|
||||
|
||||
@@ -45,10 +45,14 @@ bool valid_firmware_file(std::filesystem::path::string_type path) {
|
||||
// test read of the whole file just to validate checksum (baseband flash code will re-read when flashing)
|
||||
auto result = firmware_file.open(path.c_str());
|
||||
if (!result.is_valid()) {
|
||||
uint64_t file_size = firmware_file.size();
|
||||
if (file_size > FLASH_ROM_SIZE) {
|
||||
// Firmware file is larger than the flash size for this device
|
||||
return false;
|
||||
}
|
||||
checksum = 0;
|
||||
for (uint32_t offset = 0; offset < FLASH_ROM_SIZE; offset += sizeof(read_buffer)) {
|
||||
for (uint64_t offset = 0; offset < FLASH_ROM_SIZE && offset < file_size; offset += sizeof(read_buffer)) {
|
||||
auto readResult = firmware_file.read(&read_buffer, sizeof(read_buffer));
|
||||
|
||||
if ((!readResult) || (readResult.value() != sizeof(read_buffer))) {
|
||||
// File was smaller than 1MB:
|
||||
// If version is such that the file SHOULD have been 1MB, call it a checksum error (otherwise say it's OK).
|
||||
|
||||
@@ -32,7 +32,9 @@
|
||||
#include "untar.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
#define FLASH_ROM_SIZE 1048576
|
||||
#include "../../flashsize.h"
|
||||
|
||||
#define FLASH_ROM_SIZE (FLASH_SIZE_MB * 1024 * 1024)
|
||||
#define FLASH_STARTING_ADDRESS 0x00000000
|
||||
#define FLASH_EXPECTED_CHECKSUM 0x00000000
|
||||
#define FLASH_CHECKSUM_ERROR 0xFFFFFFFF
|
||||
|
||||
@@ -65,7 +65,7 @@ class FreqManBaseView : public View {
|
||||
|
||||
OptionsField options_category{
|
||||
{3 * 8, 2},
|
||||
20 /* length */,
|
||||
19 /* length */,
|
||||
{}};
|
||||
|
||||
FreqManUIList freqlist_view{
|
||||
|
||||
@@ -171,7 +171,7 @@ void IQTrimView::update_range_controls(iq::TrimRange trim_range) {
|
||||
}
|
||||
|
||||
void IQTrimView::profile_capture() {
|
||||
power_buckets_ = {};
|
||||
power_buckets_.clear();
|
||||
iq::PowerBuckets buckets{
|
||||
.p = power_buckets_.data(),
|
||||
.size = power_buckets_.size()};
|
||||
|
||||
@@ -69,7 +69,7 @@ void GlassView::manage_beep_audio() {
|
||||
}
|
||||
}
|
||||
|
||||
void GlassView::get_max_power(const ChannelSpectrum& spectrum, uint8_t bin, uint8_t& max_power) {
|
||||
void GlassView::get_max_power(const ChannelSpectrum& spectrum, uint16_t bin, uint8_t& max_power) {
|
||||
if (mode == LOOKING_GLASS_SINGLEPASS) {
|
||||
// <20MHz spectrum mode
|
||||
if (bin < 120) {
|
||||
@@ -91,7 +91,7 @@ void GlassView::get_max_power(const ChannelSpectrum& spectrum, uint8_t bin, uint
|
||||
}
|
||||
}
|
||||
|
||||
rf::Frequency GlassView::get_freq_from_bin_pos(uint8_t pos) {
|
||||
rf::Frequency GlassView::get_freq_from_bin_pos(uint16_t pos) {
|
||||
rf::Frequency freq_at_pos = 0;
|
||||
if (mode == LOOKING_GLASS_SINGLEPASS) {
|
||||
// starting from the middle, minus 8 ignored bin on each side. Since pos is [-120,120] after the (pos - 120), it's divided by screen_width(240)/2 => 120
|
||||
@@ -101,7 +101,14 @@ rf::Frequency GlassView::get_freq_from_bin_pos(uint8_t pos) {
|
||||
return freq_at_pos;
|
||||
}
|
||||
|
||||
void GlassView::on_marker_change() {
|
||||
void GlassView::on_marker_change(int8_t delta) {
|
||||
if ((marker_pixel_index + delta) < 0)
|
||||
marker_pixel_index = marker_pixel_index + delta + screen_width;
|
||||
else if ((marker_pixel_index + delta) > screen_width)
|
||||
marker_pixel_index = marker_pixel_index + delta - screen_width;
|
||||
else
|
||||
marker_pixel_index = marker_pixel_index + delta;
|
||||
|
||||
marker = get_freq_from_bin_pos(marker_pixel_index);
|
||||
field_marker.set_text(to_string_short_freq(marker));
|
||||
plot_marker(marker_pixel_index); // Refresh marker on screen
|
||||
@@ -200,7 +207,7 @@ void GlassView::on_channel_spectrum(const ChannelSpectrum& spectrum) {
|
||||
baseband::spectrum_streaming_stop();
|
||||
// Convert bins of this spectrum slice into a representative max_power and when enough, into pixels
|
||||
// we actually need screen_width (240) of those bins
|
||||
for (uint8_t bin = 0; bin < bin_length; bin++) {
|
||||
for (uint16_t bin = 0; bin < bin_length; bin++) {
|
||||
get_max_power(spectrum, bin, max_power);
|
||||
if (max_power > range_max_power)
|
||||
range_max_power = max_power;
|
||||
@@ -208,7 +215,7 @@ void GlassView::on_channel_spectrum(const ChannelSpectrum& spectrum) {
|
||||
if (bin == 119) {
|
||||
uint8_t next_max_power = 0;
|
||||
get_max_power(spectrum, bin + 1, next_max_power);
|
||||
for (uint8_t it = 0; it < ignore_dc; it++) {
|
||||
for (uint16_t it = 0; it < ignore_dc; it++) {
|
||||
uint8_t med_max_power = (max_power + next_max_power) / 2; // due to the way process_bins works we have to keep resetting the color
|
||||
if (process_bins(&med_max_power) == true)
|
||||
return; // new line signaled, return
|
||||
@@ -285,7 +292,7 @@ void GlassView::on_range_changed() {
|
||||
max_power = 0;
|
||||
bins_hz_size = 0;
|
||||
|
||||
on_marker_change();
|
||||
on_marker_change(0);
|
||||
update_range_field();
|
||||
|
||||
// set the sample rate and bandwidth
|
||||
@@ -298,8 +305,8 @@ void GlassView::on_range_changed() {
|
||||
receiver_model.set_target_frequency(f_center); // tune rx for this slice
|
||||
}
|
||||
|
||||
void GlassView::plot_marker(uint8_t pos) {
|
||||
uint8_t shift_y = 0;
|
||||
void GlassView::plot_marker(uint16_t pos) {
|
||||
uint16_t shift_y = 0;
|
||||
if (live_frequency_view > 0) // plot one line down when in live view
|
||||
{
|
||||
shift_y = 16;
|
||||
@@ -381,9 +388,10 @@ GlassView::GlassView(
|
||||
&button_beep_squelch,
|
||||
&field_marker,
|
||||
&field_trigger,
|
||||
&button_marker_minus,
|
||||
&button_marker_plus,
|
||||
&button_jump,
|
||||
&button_rst,
|
||||
&field_rx_iq_phase_cal,
|
||||
&freq_stats});
|
||||
|
||||
load_presets(); // Load available presets from TXT files (or default).
|
||||
@@ -491,13 +499,7 @@ GlassView::GlassView(
|
||||
range_presets.set_selected_index(preset_index);
|
||||
|
||||
field_marker.on_encoder_change = [this](TextField&, EncoderEvent delta) {
|
||||
if ((marker_pixel_index + delta) < 0)
|
||||
marker_pixel_index = marker_pixel_index + delta + screen_width;
|
||||
else if ((marker_pixel_index + delta) > screen_width)
|
||||
marker_pixel_index = marker_pixel_index + delta - screen_width;
|
||||
else
|
||||
marker_pixel_index = marker_pixel_index + delta;
|
||||
on_marker_change();
|
||||
on_marker_change(delta);
|
||||
};
|
||||
|
||||
field_marker.on_select = [this](TextField&) {
|
||||
@@ -516,6 +518,14 @@ GlassView::GlassView(
|
||||
update_range_field();
|
||||
};
|
||||
|
||||
button_marker_minus.on_select = [this](Button&) {
|
||||
on_marker_change(-1);
|
||||
};
|
||||
|
||||
button_marker_plus.on_select = [this](Button&) {
|
||||
on_marker_change(1);
|
||||
};
|
||||
|
||||
button_jump.on_select = [this](Button&) {
|
||||
// Launch Audio with peak frequency.
|
||||
launch_audio(max_freq_hold);
|
||||
@@ -525,13 +535,6 @@ GlassView::GlassView(
|
||||
reset_live_view();
|
||||
};
|
||||
|
||||
field_rx_iq_phase_cal.set_range(0, hackrf_r9 ? 63 : 31); // max2839 has 6 bits [0..63], max2837 has 5 bits [0..31]
|
||||
field_rx_iq_phase_cal.set_value(get_spec_iq_phase_calibration_value()); // using accessor function of AnalogAudioView to read iq_phase_calibration_value from rx_audio.ini
|
||||
field_rx_iq_phase_cal.on_change = [this](int32_t v) {
|
||||
set_spec_iq_phase_calibration_value(v); // using accessor function of AnalogAudioView to write inside SPEC submenu, register value to max283x and save it to rx_audio.ini
|
||||
};
|
||||
set_spec_iq_phase_calibration_value(get_spec_iq_phase_calibration_value()); // initialize iq_phase_calibration in radio
|
||||
|
||||
display.scroll_set_area(109, screen_height - 1); // Restart scroll on the correct coordinates
|
||||
|
||||
// trigger:
|
||||
@@ -581,15 +584,6 @@ void GlassView::on_freqchg(int64_t freq) {
|
||||
on_range_changed();
|
||||
}
|
||||
|
||||
uint8_t GlassView::get_spec_iq_phase_calibration_value() { // define accessor functions inside AnalogAudioView to read & write real iq_phase_calibration_value
|
||||
return iq_phase_calibration_value;
|
||||
}
|
||||
|
||||
void GlassView::set_spec_iq_phase_calibration_value(uint8_t cal_value) { // define accessor functions
|
||||
iq_phase_calibration_value = cal_value;
|
||||
radio::set_rx_max283x_iq_phase_calibration(iq_phase_calibration_value);
|
||||
}
|
||||
|
||||
void GlassView::load_presets() {
|
||||
File presets_file;
|
||||
auto error = presets_file.open(looking_glass_dir / u"PRESETS.TXT");
|
||||
|
||||
@@ -66,9 +66,6 @@ class GlassView : public View {
|
||||
void on_hide() override;
|
||||
void focus() override;
|
||||
|
||||
uint8_t get_spec_iq_phase_calibration_value();
|
||||
void set_spec_iq_phase_calibration_value(uint8_t cal_value);
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
Gradient gradient{};
|
||||
@@ -80,11 +77,10 @@ class GlassView : public View {
|
||||
uint8_t filter_index = 0; // OFF
|
||||
uint8_t trigger = 32;
|
||||
uint8_t mode = LOOKING_GLASS_FASTSCAN;
|
||||
uint8_t live_frequency_view = 0; // Spectrum
|
||||
uint8_t live_frequency_integrate = 3; // Default (3 * old value + new_value) / 4
|
||||
uint8_t iq_phase_calibration_value{15}; // initial default RX IQ phase calibration value , used for both max2837 & max2839
|
||||
int32_t beep_squelch = 20; // range from -100 to +20, >=20 disabled
|
||||
bool beep_enabled = false; // activate on bip button click
|
||||
uint8_t live_frequency_view = 0; // Spectrum
|
||||
uint8_t live_frequency_integrate = 3; // Default (3 * old value + new_value) / 4
|
||||
int32_t beep_squelch = 20; // range from -100 to +20, >=20 disabled
|
||||
bool beep_enabled = false; // activate on bip button click
|
||||
app_settings::SettingsManager settings_{
|
||||
"rx_glass"sv,
|
||||
app_settings::Mode::RX,
|
||||
@@ -97,7 +93,6 @@ class GlassView : public View {
|
||||
{"scan_mode"sv, &mode},
|
||||
{"freq_view"sv, &live_frequency_view},
|
||||
{"freq_integrate"sv, &live_frequency_integrate},
|
||||
{"iq_phase_calibration"sv, &iq_phase_calibration_value}, // we are saving and restoring that CAL from Settings.
|
||||
{"beep_squelch"sv, &beep_squelch},
|
||||
{"beep_enabled"sv, &beep_enabled},
|
||||
}};
|
||||
@@ -116,9 +111,9 @@ class GlassView : public View {
|
||||
void update_min(int32_t v);
|
||||
void update_max(int32_t v);
|
||||
void update_range_field();
|
||||
void get_max_power(const ChannelSpectrum& spectrum, uint8_t bin, uint8_t& max_power);
|
||||
rf::Frequency get_freq_from_bin_pos(uint8_t pos);
|
||||
void on_marker_change();
|
||||
void get_max_power(const ChannelSpectrum& spectrum, uint16_t bin, uint8_t& max_power);
|
||||
rf::Frequency get_freq_from_bin_pos(uint16_t pos);
|
||||
void on_marker_change(int8_t delta);
|
||||
void retune();
|
||||
bool process_bins(uint8_t* powerlevel);
|
||||
void on_channel_spectrum(const ChannelSpectrum& spectrum);
|
||||
@@ -128,7 +123,7 @@ class GlassView : public View {
|
||||
void on_range_changed();
|
||||
void reset_live_view();
|
||||
void add_spectrum_pixel(uint8_t power);
|
||||
void plot_marker(uint8_t pos);
|
||||
void plot_marker(uint16_t pos);
|
||||
void load_presets();
|
||||
void populate_presets();
|
||||
void launch_audio(rf::Frequency center_freq);
|
||||
@@ -138,7 +133,7 @@ class GlassView : public View {
|
||||
rf::Frequency f_center_ini{0};
|
||||
|
||||
rf::Frequency marker{0};
|
||||
uint8_t marker_pixel_index{0};
|
||||
uint16_t marker_pixel_index{0};
|
||||
rf::Frequency marker_pixel_step{0};
|
||||
|
||||
// Size of one spectrum bin in Hz.
|
||||
@@ -173,8 +168,7 @@ class GlassView : public View {
|
||||
{{0, UI_POS_Y(0)}, "MIN: MAX: LNA VGA ", Theme::getInstance()->fg_light->foreground},
|
||||
{{0, 1 * 16}, "RANGE: FILTER: AMP:", Theme::getInstance()->fg_light->foreground},
|
||||
{{0, 2 * 16}, "P:", Theme::getInstance()->fg_light->foreground},
|
||||
{{0, 3 * 16}, "MARKER: MHz RXIQCAL", Theme::getInstance()->fg_light->foreground},
|
||||
//{{0, 4 * 16}, "RES: STEPS:", Theme::getInstance()->fg_light->foreground}};
|
||||
{{0, 3 * 16}, "MARKER( / ): MHz", Theme::getInstance()->fg_light->foreground},
|
||||
{{0, 4 * 16}, "RES: VOL:", Theme::getInstance()->fg_light->foreground}};
|
||||
|
||||
NumberField field_frequency_min{
|
||||
@@ -223,16 +217,16 @@ class GlassView : public View {
|
||||
""};
|
||||
|
||||
TextField field_marker{
|
||||
{7 * 8, 3 * 16, 9 * 8, 16},
|
||||
{12 * 8, 3 * 16, 9 * 8, 16},
|
||||
""};
|
||||
|
||||
NumberField field_rx_iq_phase_cal{
|
||||
{28 * 8, 3 * 16},
|
||||
2,
|
||||
{0, 63}, // 5 or 6 bits IQ CAL phase adjustment (range updated later)
|
||||
1,
|
||||
' ',
|
||||
};
|
||||
Button button_marker_minus{
|
||||
{7 * 8, 3 * 16 + 4, 1 * 8, 1 * 8},
|
||||
"-"};
|
||||
|
||||
Button button_marker_plus{
|
||||
{9 * 8, 3 * 16 + 4, 1 * 8, 1 * 8},
|
||||
"+"};
|
||||
|
||||
NumberField field_trigger{
|
||||
{4 * 8, 4 * 16},
|
||||
|
||||
@@ -350,6 +350,12 @@ MicTXView::MicTXView(
|
||||
&tx_button,
|
||||
&tx_icon});
|
||||
|
||||
// disable key repeat on select
|
||||
initial_switch_config_ = get_switches_repeat_config();
|
||||
SwitchesState config = initial_switch_config_;
|
||||
config[toUType(Switch::Sel)] = false;
|
||||
set_switches_repeat_config(config);
|
||||
|
||||
set_rxbw_options();
|
||||
set_rxbw_defaults(settings_.loaded());
|
||||
|
||||
@@ -640,6 +646,9 @@ MicTXView::MicTXView(
|
||||
}
|
||||
|
||||
MicTXView::~MicTXView() {
|
||||
// restore select key repeat mode
|
||||
set_switches_repeat_config(initial_switch_config_);
|
||||
|
||||
audio::input::stop();
|
||||
if (rx_enabled) { // Also turn off both (audio rx if enabled, and disable mic_loop to HP)
|
||||
rxaudio(false);
|
||||
|
||||
@@ -90,6 +90,9 @@ class MicTXView : public View {
|
||||
sampling_rate /* sampling rate */
|
||||
};
|
||||
|
||||
// structure used to control key repeat
|
||||
SwitchesState initial_switch_config_{};
|
||||
|
||||
enum Mic_Modulation : uint32_t {
|
||||
MIC_MOD_NFM = 0,
|
||||
MIC_MOD_WFM = 1,
|
||||
|
||||
@@ -1086,8 +1086,8 @@ void ReconView::on_statistics_update(const ChannelStatistics& statistics) {
|
||||
if (stepper < 0) stepper++;
|
||||
if (stepper > 0) stepper--;
|
||||
} // if( recon || stepper != 0 || index_stepper != 0 )
|
||||
} // if (frequency_list.size() > 0 )
|
||||
} /* on_statistics_updates */
|
||||
} // if (frequency_list.size() > 0 )
|
||||
} /* on_statistics_updates */
|
||||
}
|
||||
handle_retune();
|
||||
recon_redraw();
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
#include "ui_touch_calibration.hpp"
|
||||
#include "ui_text_editor.hpp"
|
||||
#include "ui_external_items_menu_loader.hpp"
|
||||
#include "ui_ss_viewer.hpp"
|
||||
#include "ui_fileman.hpp"
|
||||
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
@@ -309,13 +311,45 @@ SetFrequencyCorrectionModel SetRadioView::form_collect() {
|
||||
};
|
||||
}
|
||||
|
||||
/* SetTXLimitView ************************************/
|
||||
|
||||
SetTXLimitView::SetTXLimitView(NavigationView& nav) {
|
||||
add_children({
|
||||
&labels,
|
||||
&tx_gain_max_db,
|
||||
&tx_disable_switch,
|
||||
&tx_amp_disable_switch,
|
||||
&button_save,
|
||||
&button_cancel,
|
||||
});
|
||||
|
||||
tx_disable_switch.set_value(pmem::config_tx_disabled());
|
||||
tx_amp_disable_switch.set_value(pmem::config_tx_amp_disabled());
|
||||
tx_gain_max_db.set_value(pmem::config_tx_gain_max_db());
|
||||
|
||||
button_save.on_select = [&nav, this](Button&) {
|
||||
pmem::set_config_tx_disabled(tx_disable_switch.value());
|
||||
pmem::set_config_tx_amp_disabled(tx_amp_disable_switch.value());
|
||||
pmem::set_config_tx_gain_max_db(tx_gain_max_db.value());
|
||||
send_system_refresh();
|
||||
nav.pop();
|
||||
};
|
||||
|
||||
button_cancel.on_select = [&nav, this](Button&) {
|
||||
nav.pop();
|
||||
};
|
||||
}
|
||||
|
||||
void SetTXLimitView::focus() {
|
||||
button_save.focus();
|
||||
}
|
||||
|
||||
/* SetUIView *********************************************/
|
||||
|
||||
SetUIView::SetUIView(NavigationView& nav) {
|
||||
add_children({&checkbox_disable_touchscreen,
|
||||
&checkbox_bloff,
|
||||
&options_bloff,
|
||||
&checkbox_showsplash,
|
||||
&checkbox_showclock,
|
||||
&options_clockformat,
|
||||
&checkbox_guireturnflag,
|
||||
@@ -342,7 +376,6 @@ SetUIView::SetUIView(NavigationView& nav) {
|
||||
}
|
||||
|
||||
checkbox_disable_touchscreen.set_value(pmem::disable_touchscreen());
|
||||
checkbox_showsplash.set_value(pmem::config_splash());
|
||||
checkbox_showclock.set_value(!pmem::hide_clock());
|
||||
checkbox_guireturnflag.set_value(pmem::show_gui_return_icon());
|
||||
|
||||
@@ -381,7 +414,6 @@ SetUIView::SetUIView(NavigationView& nav) {
|
||||
pmem::set_clock_with_date(false);
|
||||
}
|
||||
|
||||
pmem::set_config_splash(checkbox_showsplash.value());
|
||||
pmem::set_clock_hidden(!checkbox_showclock.value());
|
||||
pmem::set_gui_return_icon(checkbox_guireturnflag.value());
|
||||
pmem::set_disable_touchscreen(checkbox_disable_touchscreen.value());
|
||||
@@ -1080,6 +1112,46 @@ void SetBatteryView::focus() {
|
||||
button_cancel.focus();
|
||||
}
|
||||
|
||||
/* SetSlpash *********************************************/
|
||||
|
||||
SetSplash::SetSplash(NavigationView& nav) {
|
||||
add_children({&checkbox_showsplash,
|
||||
&checkbox_randomsplash,
|
||||
&message,
|
||||
&button_picture_select,
|
||||
&button_save,
|
||||
&button_cancel});
|
||||
|
||||
checkbox_showsplash.set_value(pmem::config_splash());
|
||||
splash_bmp_exists = file_exists(splash_dot_bmp);
|
||||
checkbox_randomsplash.set_value(!splash_bmp_exists);
|
||||
message.hidden(splash_bmp_exists);
|
||||
|
||||
checkbox_randomsplash.on_select = [this](Checkbox&, bool v) {
|
||||
random_enabled = v;
|
||||
};
|
||||
|
||||
button_picture_select.on_select = [this, &nav](Button&) {
|
||||
auto ret = nav.push<FileManagerView>();
|
||||
ret->push_dir(splash_dir);
|
||||
};
|
||||
|
||||
button_save.on_select = [&nav, this](Button&) {
|
||||
if (random_enabled == true) delete_file(splash_dot_bmp);
|
||||
pmem::set_config_splash(checkbox_showsplash.value());
|
||||
send_system_refresh();
|
||||
nav.pop();
|
||||
};
|
||||
|
||||
button_cancel.on_select = [&nav, this](Button&) {
|
||||
nav.pop();
|
||||
};
|
||||
}
|
||||
|
||||
void SetSplash::focus() {
|
||||
button_save.focus();
|
||||
}
|
||||
|
||||
/* SettingsMenuView **************************************/
|
||||
|
||||
SettingsMenuView::SettingsMenuView(NavigationView& nav)
|
||||
@@ -1107,11 +1179,13 @@ void SettingsMenuView::on_populate() {
|
||||
{"Freq. Correct", ui::Color::dark_cyan(), &bitmap_icon_options_radio, [this]() { nav_.push<SetFrequencyCorrectionView>(); }},
|
||||
{"P.Memory Mgmt", ui::Color::dark_cyan(), &bitmap_icon_memory, [this]() { nav_.push<SetPersistentMemoryView>(); }},
|
||||
{"Radio", ui::Color::dark_cyan(), &bitmap_icon_options_radio, [this]() { nav_.push<SetRadioView>(); }},
|
||||
{"TX Limit", ui::Color::dark_cyan(), &bitmap_icon_options_radio, [this]() { nav_.push<SetTXLimitView>(); }},
|
||||
{"SD Card", ui::Color::dark_cyan(), &bitmap_icon_sdcard, [this]() { nav_.push<SetSDCardView>(); }},
|
||||
{"User Interface", ui::Color::dark_cyan(), &bitmap_icon_options_ui, [this]() { nav_.push<SetUIView>(); }},
|
||||
{"Display", ui::Color::dark_cyan(), &bitmap_icon_brightness, [this]() { nav_.push<SetDisplayView>(); }},
|
||||
{"Menu Color", ui::Color::dark_cyan(), &bitmap_icon_brightness, [this]() { nav_.push<SetMenuColorView>(); }},
|
||||
{"Theme", ui::Color::dark_cyan(), &bitmap_icon_setup, [this]() { nav_.push<SetThemeView>(); }},
|
||||
{"Splash settings", ui::Color::dark_cyan(), &bitmap_icon_file_image, [this]() { nav_.push<SetSplash>(); }},
|
||||
});
|
||||
|
||||
if (battery::BatteryManagement::isDetected()) add_item({"Battery", ui::Color::dark_cyan(), &bitmap_icon_batt_icon, [this]() { nav_.push<SetBatteryView>(); }});
|
||||
|
||||
@@ -264,6 +264,51 @@ class SetRadioView : public View {
|
||||
SetFrequencyCorrectionModel form_collect();
|
||||
};
|
||||
|
||||
class SetTXLimitView : public View {
|
||||
public:
|
||||
SetTXLimitView(NavigationView& nav);
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "TX Limit"; };
|
||||
|
||||
private:
|
||||
Labels labels{
|
||||
{{1 * 8, 1 * 16}, "Limits RF TX Gain", Theme::getInstance()->fg_light->foreground},
|
||||
{{1 * 8, 2 * 16}, "(This may affect", Theme::getInstance()->fg_light->foreground},
|
||||
{{1 * 8, 3 * 16}, "all applications.)", Theme::getInstance()->fg_light->foreground},
|
||||
{{2 * 8, 12 * 16}, "TX Max Gain:", Theme::getInstance()->fg_light->foreground},
|
||||
|
||||
};
|
||||
|
||||
Checkbox tx_disable_switch{
|
||||
{1 * 8, 6 * 16},
|
||||
23,
|
||||
"Disable TX"};
|
||||
|
||||
Checkbox tx_amp_disable_switch{
|
||||
{1 * 8, 8 * 16},
|
||||
23,
|
||||
"Disable TX Amp"};
|
||||
|
||||
NumberField tx_gain_max_db{
|
||||
{20 * 8, 12 * 16},
|
||||
6,
|
||||
{0, 47},
|
||||
1,
|
||||
' ',
|
||||
};
|
||||
|
||||
Button button_save{
|
||||
{UI_POS_X_CENTER(12) - UI_POS_WIDTH(8), UI_POS_Y_BOTTOM(4), UI_POS_WIDTH(12), UI_POS_HEIGHT(2)},
|
||||
"Save"};
|
||||
|
||||
Button button_cancel{
|
||||
{UI_POS_X_CENTER(16) + UI_POS_WIDTH(8), UI_POS_Y_BOTTOM(4), UI_POS_WIDTH(12), UI_POS_HEIGHT(2)},
|
||||
"Cancel",
|
||||
};
|
||||
};
|
||||
|
||||
using portapack::persistent_memory::backlight_timeout_t;
|
||||
|
||||
class SetUIView : public View {
|
||||
@@ -298,77 +343,72 @@ class SetUIView : public View {
|
||||
{"1 hour", backlight_timeout_t::Timeout3600Sec},
|
||||
}};
|
||||
|
||||
Checkbox checkbox_showsplash{
|
||||
{3 * 8, 6 * 16},
|
||||
20,
|
||||
"Show splash"};
|
||||
|
||||
Checkbox checkbox_showclock{
|
||||
{3 * 8, 8 * 16},
|
||||
{3 * 8, 6 * 16},
|
||||
20,
|
||||
"Show clock with:"};
|
||||
|
||||
OptionsField options_clockformat{
|
||||
{60, 9 * 16 + 8},
|
||||
{60, 7 * 16 + 8},
|
||||
20,
|
||||
{{"time only", 0},
|
||||
{"time and date", 1}}};
|
||||
|
||||
Checkbox checkbox_guireturnflag{
|
||||
{3 * 8, 11 * 16},
|
||||
{3 * 8, 9 * 16},
|
||||
20,
|
||||
"Back button in menu"};
|
||||
|
||||
Labels labels{
|
||||
{{3 * 8, 13 * 16}, "Show/Hide Status Icons", Theme::getInstance()->fg_light->foreground},
|
||||
{{3 * 8, 11 * 16}, "Show/Hide Status Icons", Theme::getInstance()->fg_light->foreground},
|
||||
};
|
||||
|
||||
ImageToggle toggle_camera{
|
||||
{2 * 8, 14 * 16 + 2, 16, 16},
|
||||
{2 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_camera};
|
||||
|
||||
ImageToggle toggle_sleep{
|
||||
{4 * 8, 14 * 16 + 2, 16, 16},
|
||||
{4 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_sleep};
|
||||
|
||||
ImageToggle toggle_stealth{
|
||||
{6 * 8, 14 * 16 + 2, 16, 16},
|
||||
{6 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_stealth};
|
||||
|
||||
ImageToggle toggle_converter{
|
||||
{8 * 8, 14 * 16 + 2, 16, 16},
|
||||
{8 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_upconvert};
|
||||
|
||||
ImageToggle toggle_bias_tee{
|
||||
{10 * 8, 14 * 16 + 2, 16, 16},
|
||||
{10 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_biast_off};
|
||||
|
||||
ImageToggle toggle_clock{
|
||||
{12 * 8, 14 * 16 + 2, 8, 16},
|
||||
{12 * 8, 12 * 16 + 2, 8, 16},
|
||||
&bitmap_icon_clk_ext};
|
||||
|
||||
ImageToggle toggle_mute{
|
||||
{13 * 8, 14 * 16 + 2, 16, 16},
|
||||
{13 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_speaker_and_headphones_mute};
|
||||
|
||||
ImageToggle toggle_speaker{
|
||||
{15 * 8, 14 * 16 + 2, 16, 16},
|
||||
{15 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_speaker_mute};
|
||||
|
||||
ImageToggle toggle_battery_icon{
|
||||
{17 * 8, 14 * 16 + 2, 16, 16},
|
||||
{17 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_batt_icon};
|
||||
|
||||
ImageToggle toggle_battery_text{
|
||||
{19 * 8, 14 * 16 + 2, 16, 16},
|
||||
{19 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_batt_text};
|
||||
|
||||
ImageToggle toggle_fake_brightness{
|
||||
{21 * 8, 14 * 16 + 2, 16, 16},
|
||||
{21 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_icon_brightness};
|
||||
|
||||
ImageToggle toggle_sd_card{
|
||||
{23 * 8, 14 * 16 + 2, 16, 16},
|
||||
{23 * 8, 12 * 16 + 2, 16, 16},
|
||||
&bitmap_sd_card_ok};
|
||||
|
||||
Button button_save{
|
||||
@@ -1024,6 +1064,43 @@ class SettingsMenuView : public BtnGridView {
|
||||
void on_populate() override;
|
||||
};
|
||||
|
||||
class SetSplash : public View {
|
||||
public:
|
||||
SetSplash(NavigationView& nav);
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override { return "Splash"; };
|
||||
|
||||
private:
|
||||
bool splash_bmp_exists = false;
|
||||
bool random_enabled = false;
|
||||
|
||||
Checkbox checkbox_showsplash{
|
||||
{3 * 8, 1 * 16},
|
||||
20,
|
||||
"Show splash"};
|
||||
|
||||
Checkbox checkbox_randomsplash{
|
||||
{3 * 8, 3 * 16},
|
||||
20,
|
||||
"Random splash on boot"};
|
||||
|
||||
Text message{{UI_POS_X(1), UI_POS_Y(6), UI_POS_WIDTH(26), UI_POS_HEIGHT(1)}, "Pick image to stop random."};
|
||||
|
||||
Button button_picture_select{
|
||||
{UI_POS_X_CENTER(8) - UI_POS_WIDTH(4), UI_POS_Y_BOTTOM(7), UI_POS_WIDTH(13), UI_POS_HEIGHT(2)},
|
||||
"Select pict."};
|
||||
|
||||
Button button_save{
|
||||
{UI_POS_X_CENTER(12) - UI_POS_WIDTH(8), UI_POS_Y_BOTTOM(4), UI_POS_WIDTH(12), UI_POS_HEIGHT(2)},
|
||||
"Save"};
|
||||
|
||||
Button button_cancel{
|
||||
{UI_POS_X_CENTER(16) + UI_POS_WIDTH(8), UI_POS_Y_BOTTOM(4), UI_POS_WIDTH(12), UI_POS_HEIGHT(2)},
|
||||
"Cancel"};
|
||||
};
|
||||
|
||||
} /* namespace ui */
|
||||
|
||||
#endif /*__UI_SETTINGS_H__*/
|
||||
|
||||
@@ -30,11 +30,10 @@
|
||||
#include "portapack.hpp"
|
||||
#include <cstring>
|
||||
#include <stdio.h>
|
||||
#include "rtc_time.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
namespace pmem = portapack::persistent_memory;
|
||||
|
||||
#include "string_format.hpp"
|
||||
#include "complex.hpp"
|
||||
|
||||
void SondeLogger::on_packet(const sonde::Packet& packet) {
|
||||
@@ -65,6 +64,8 @@ SondeView::SondeView(NavigationView& nav)
|
||||
&text_frame,
|
||||
&text_temp,
|
||||
&text_humid,
|
||||
&text_press,
|
||||
&text_vspeed,
|
||||
&geopos,
|
||||
&button_see_qr,
|
||||
&button_see_map});
|
||||
@@ -107,7 +108,7 @@ SondeView::SondeView(NavigationView& nav)
|
||||
|
||||
logger = std::make_unique<SondeLogger>();
|
||||
if (logger)
|
||||
logger->append(logs_dir / u"SONDE.TXT");
|
||||
logger->append(logs_dir / u"SONDE_" + to_string_timestamp(rtc_time::now()) + u".TXT");
|
||||
|
||||
if (pmem::beep_on_packets()) {
|
||||
audio::set_rate(audio::Rate::Hz_24000);
|
||||
@@ -155,7 +156,7 @@ void SondeView::on_packet(const sonde::Packet& packet) {
|
||||
sonde_id = packet.serial_number(); // used also as tag on the geomap
|
||||
text_serial.set(sonde_id);
|
||||
|
||||
text_timestamp.set(to_string_timestamp(packet.received_at()));
|
||||
text_timestamp.set(to_string_datetime(packet.received_at(), TimeFormat::YMDHMS));
|
||||
|
||||
text_voltage.set(unit_auto_scale(packet.battery_voltage(), 2, 2) + "V");
|
||||
|
||||
@@ -163,21 +164,42 @@ void SondeView::on_packet(const sonde::Packet& packet) {
|
||||
|
||||
temp_humid_info = packet.get_temp_humid();
|
||||
if (temp_humid_info.humid != 0) {
|
||||
double decimals = abs(get_decimals(temp_humid_info.humid, 10, true));
|
||||
text_humid.set(to_string_dec_int((int)temp_humid_info.humid) + "." + to_string_dec_uint(decimals, 1) + "%");
|
||||
text_humid.set(to_string_decimal(temp_humid_info.humid, 1) + "%");
|
||||
}
|
||||
|
||||
if (temp_humid_info.temp != 0) {
|
||||
double decimals = abs(get_decimals(temp_humid_info.temp, 10, true));
|
||||
text_temp.set(to_string_dec_int((int)temp_humid_info.temp) + "." + to_string_dec_uint(decimals, 1) + STR_DEGREES_C);
|
||||
text_temp.set(to_string_decimal(temp_humid_info.temp, 1) + STR_DEGREES_C);
|
||||
}
|
||||
|
||||
if (packet.get_pressure() != 0) {
|
||||
text_press.set(to_string_decimal(packet.get_pressure(), 1) + " hPa");
|
||||
}
|
||||
|
||||
gps_info = packet.get_GPS_data();
|
||||
|
||||
geopos.set_altitude(gps_info.alt);
|
||||
geopos.set_lat(gps_info.lat);
|
||||
geopos.set_lon(gps_info.lon);
|
||||
|
||||
if (last_timestamp_update_ != 0 && last_altitude_ != 0) {
|
||||
// calculate speeds
|
||||
float vspeed = 0;
|
||||
time_t currpackettime = rtc_time::rtcToUnixUTC(packet.received_at());
|
||||
int32_t time_diff = (currpackettime - last_timestamp_update_);
|
||||
if (time_diff >= 10) { // update only every 10 seconds
|
||||
vspeed = (static_cast<int>(gps_info.alt) - static_cast<int>(last_altitude_)) / (float)time_diff;
|
||||
last_timestamp_update_ = currpackettime;
|
||||
last_altitude_ = gps_info.alt;
|
||||
text_vspeed.set(to_string_decimal(vspeed, 1) + " m/s");
|
||||
}
|
||||
} else { // save first valid packet time + altitude
|
||||
last_timestamp_update_ = rtc_time::rtcToUnixUTC(packet.received_at());
|
||||
last_altitude_ = geopos.altitude();
|
||||
}
|
||||
if (gps_info.is_valid()) { // only update when valid, to prevent flashing
|
||||
geopos.set_altitude(gps_info.alt);
|
||||
geopos.set_lat(gps_info.lat);
|
||||
geopos.set_lon(gps_info.lon);
|
||||
if (geomap_view_) {
|
||||
geomap_view_->update_position(gps_info.lat, gps_info.lon, 400, gps_info.alt, 0);
|
||||
}
|
||||
}
|
||||
if (logger && logging) {
|
||||
logger->on_packet(packet);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "ui_rssi.hpp"
|
||||
#include "ui_qrcode.hpp"
|
||||
#include "ui_geomap.hpp"
|
||||
#include "string_format.hpp"
|
||||
|
||||
#include "event_m0.hpp"
|
||||
|
||||
@@ -94,32 +95,33 @@ class SondeView : public View {
|
||||
// AudioOutput audio_output { };
|
||||
|
||||
Labels labels{
|
||||
{{4 * 8, 2 * 16}, "Type:", Theme::getInstance()->fg_light->foreground},
|
||||
{{6 * 8, 3 * 16}, "ID:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 4 * 16}, "DateTime:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(4), UI_POS_Y(2)}, "Type:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(6), UI_POS_Y(3)}, "ID:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(4)}, "DateTime:", Theme::getInstance()->fg_light->foreground},
|
||||
|
||||
{{3 * 8, 5 * 16}, "Vbatt:", Theme::getInstance()->fg_light->foreground},
|
||||
{{3 * 8, 6 * 16}, "Frame:", Theme::getInstance()->fg_light->foreground},
|
||||
{{4 * 8, 7 * 16}, "Temp:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), 8 * 16}, "Humidity:", Theme::getInstance()->fg_light->foreground}};
|
||||
{{UI_POS_X(3), UI_POS_Y(5)}, "Vbatt:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(3), UI_POS_Y(6)}, "Frame:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(4), UI_POS_Y(7)}, "Temp:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(8)}, "Humidity:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(0), UI_POS_Y(9)}, "Pressure:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(2), UI_POS_Y(10)}, "VSpeed:", Theme::getInstance()->fg_light->foreground}};
|
||||
|
||||
RxFrequencyField field_frequency{
|
||||
{UI_POS_X(0), 0 * 8},
|
||||
{UI_POS_X(0), UI_POS_Y(0)},
|
||||
nav_};
|
||||
|
||||
RFAmpField field_rf_amp{
|
||||
{13 * 8, UI_POS_Y(0)}};
|
||||
|
||||
{UI_POS_X(13), UI_POS_Y(0)}};
|
||||
LNAGainField field_lna{
|
||||
{15 * 8, UI_POS_Y(0)}};
|
||||
{UI_POS_X(15), UI_POS_Y(0)}};
|
||||
|
||||
VGAGainField field_vga{
|
||||
{18 * 8, UI_POS_Y(0)}};
|
||||
{UI_POS_X(18), UI_POS_Y(0)}};
|
||||
|
||||
RSSI rssi{
|
||||
{21 * 8, 0, UI_POS_WIDTH_REMAINING(24), 4}};
|
||||
{UI_POS_X(21), UI_POS_Y(0), UI_POS_WIDTH_REMAINING(24), 4}};
|
||||
Channel channel{
|
||||
{21 * 8, 5, UI_POS_WIDTH_REMAINING(24), 4},
|
||||
{UI_POS_X(21), UI_POS_Y(0) + 5, UI_POS_WIDTH_REMAINING(24), 4},
|
||||
};
|
||||
|
||||
AudioVolumeField field_volume{
|
||||
@@ -136,47 +138,57 @@ class SondeView : public View {
|
||||
"CRC"};
|
||||
|
||||
Text text_signature{
|
||||
{9 * 8, 2 * 16, 10 * 8, 16},
|
||||
{UI_POS_X(9), UI_POS_Y(2), UI_POS_WIDTH_REMAINING(10), UI_POS_HEIGHT(1)},
|
||||
"..."};
|
||||
|
||||
Text text_serial{
|
||||
{9 * 8, 3 * 16, 11 * 8, 16},
|
||||
{UI_POS_X(9), UI_POS_Y(3), UI_POS_WIDTH_REMAINING(10), UI_POS_HEIGHT(1)},
|
||||
"..."};
|
||||
|
||||
Text text_timestamp{
|
||||
{9 * 8, 4 * 16, 11 * 8, 16},
|
||||
{UI_POS_X(9), UI_POS_Y(4), UI_POS_WIDTH_REMAINING(9), UI_POS_HEIGHT(1)},
|
||||
"..."};
|
||||
|
||||
Text text_voltage{
|
||||
{9 * 8, 5 * 16, 10 * 8, 16},
|
||||
{UI_POS_X(9), UI_POS_Y(5), UI_POS_WIDTH(10), UI_POS_HEIGHT(1)},
|
||||
"..."};
|
||||
|
||||
Text text_frame{
|
||||
{9 * 8, 6 * 16, 10 * 8, 16},
|
||||
{UI_POS_X(9), UI_POS_Y(6), UI_POS_WIDTH(10), UI_POS_HEIGHT(1)},
|
||||
"..."};
|
||||
|
||||
Text text_temp{
|
||||
{9 * 8, 7 * 16, 10 * 8, 16},
|
||||
{UI_POS_X(9), UI_POS_Y(7), UI_POS_WIDTH(10), UI_POS_HEIGHT(1)},
|
||||
"..."};
|
||||
|
||||
Text text_humid{
|
||||
{9 * 8, 8 * 16, 10 * 8, 16},
|
||||
{UI_POS_X(9), UI_POS_Y(8), UI_POS_WIDTH(10), UI_POS_HEIGHT(1)},
|
||||
"..."};
|
||||
|
||||
Text text_press{
|
||||
{UI_POS_X(9), UI_POS_Y(9), UI_POS_WIDTH(10), UI_POS_HEIGHT(1)},
|
||||
"..."};
|
||||
|
||||
Text text_vspeed{
|
||||
{UI_POS_X(9), UI_POS_Y(10), UI_POS_WIDTH(10), UI_POS_HEIGHT(1)},
|
||||
"..."};
|
||||
|
||||
GeoPos geopos{
|
||||
{0, 12 * 16},
|
||||
{UI_POS_X(0), UI_POS_Y(12)},
|
||||
GeoPos::alt_unit::METERS,
|
||||
GeoPos::spd_unit::HIDDEN};
|
||||
|
||||
Button button_see_qr{
|
||||
{UI_POS_X_CENTER(12) - UI_POS_WIDTH(8), UI_POS_Y_BOTTOM(4), 12 * 8, 3 * 16},
|
||||
{UI_POS_X_CENTER(12) - UI_POS_WIDTH(8), UI_POS_Y_BOTTOM(4), UI_POS_WIDTH(12), UI_POS_HEIGHT(3)},
|
||||
"See QR"};
|
||||
|
||||
Button button_see_map{
|
||||
{UI_POS_X_CENTER(12) + UI_POS_WIDTH(8), UI_POS_Y_BOTTOM(4), 12 * 8, 3 * 16},
|
||||
{UI_POS_X_CENTER(12) + UI_POS_WIDTH(8), UI_POS_Y_BOTTOM(4), UI_POS_WIDTH(12), UI_POS_HEIGHT(3)},
|
||||
"See on map"};
|
||||
|
||||
GeoMapView* geomap_view_{nullptr};
|
||||
time_t last_timestamp_update_{0};
|
||||
uint32_t last_altitude_{0};
|
||||
|
||||
MessageHandlerRegistration message_handler_packet{
|
||||
Message::ID::SondePacket,
|
||||
|
||||
@@ -27,8 +27,6 @@ namespace fs = std::filesystem;
|
||||
|
||||
namespace ui {
|
||||
|
||||
const std::filesystem::path splash_dot_bmp{u"/splash.bmp"};
|
||||
|
||||
ScreenshotViewer::ScreenshotViewer(
|
||||
NavigationView& nav,
|
||||
const std::filesystem::path& path)
|
||||
@@ -44,7 +42,6 @@ bool ScreenshotViewer::on_key(KeyEvent) {
|
||||
|
||||
void ScreenshotViewer::paint(Painter& painter) {
|
||||
File file{};
|
||||
|
||||
painter.fill_rectangle({0, 0, screen_width, screen_height}, Color::black());
|
||||
|
||||
auto show_invalid = [&]() {
|
||||
|
||||
@@ -28,11 +28,10 @@
|
||||
#include "ui_painter.hpp"
|
||||
#include "ui_widget.hpp"
|
||||
#include "file.hpp"
|
||||
#include "file_path.hpp"
|
||||
|
||||
namespace ui {
|
||||
|
||||
extern const std::filesystem::path splash_dot_bmp;
|
||||
|
||||
class ScreenshotViewer : public View {
|
||||
public:
|
||||
ScreenshotViewer(NavigationView& nav, const std::filesystem::path& path);
|
||||
@@ -49,7 +48,6 @@ class SplashViewer : public View {
|
||||
SplashViewer(NavigationView& nav, const std::filesystem::path& path);
|
||||
bool on_key(KeyEvent key) override;
|
||||
void paint(Painter& painter) override;
|
||||
void update_ss(void);
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
@@ -285,7 +285,7 @@ bool StandaloneView::on_encoder(const EncoderEvent event) {
|
||||
|
||||
bool StandaloneView::on_touch(const TouchEvent event) {
|
||||
if (get_application_information()->header_version > 1) {
|
||||
get_application_information()->OnTouchEvent(event.point.x(), event.point.y(), (uint32_t)event.type);
|
||||
return get_application_information()->OnTouchEvent(event.point.x(), event.point.y(), (uint32_t)event.type);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,10 @@
|
||||
#include "baseband_api.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "file_path.hpp"
|
||||
#include "ui_textentry.hpp"
|
||||
#include "../keeloq_keystore.hpp"
|
||||
#include "../keeloq_file.hpp"
|
||||
#include "../keeloq_common.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
@@ -56,6 +60,51 @@ void SubGhzDRecentEntryDetailView::update_data() {
|
||||
if (cnt != SD_NO_CNT) console.writeln("Cnt: " + to_string_dec_uint(cnt));
|
||||
|
||||
if (entry_.data != 0) console.writeln("Data: " + to_string_hex(entry_.data));
|
||||
|
||||
if (entry_.sensorType == FPS_RESTAURANT_PAGER) {
|
||||
uint8_t pager_addr = (entry_.data >> 5) & 0x0F;
|
||||
uint8_t func_code = (entry_.data >> 1) & 0x0F;
|
||||
console.writeln("Station: 0x" + to_string_hex(serial) + " (" + to_string_dec_uint(serial) + ")");
|
||||
console.writeln("Pager: " + to_string_dec_uint(pager_addr));
|
||||
if (func_code == 0x0D)
|
||||
console.writeln("Action: Buzz");
|
||||
else if (func_code == 0x0F)
|
||||
console.writeln("Action: Sync");
|
||||
else
|
||||
console.writeln("Action: 0x" + to_string_hex(func_code));
|
||||
}
|
||||
|
||||
if (entry_.sensorType == FPS_KEELOQ) {
|
||||
console.writeln("Fix: " + to_string_hex(fix));
|
||||
console.writeln("Encrypted: " + to_string_hex(encrypted));
|
||||
console.writeln("Manufacturer: " + mf_name);
|
||||
|
||||
if (hop != SD_NO_HOP) {
|
||||
console.writeln("Hop: " + to_string_hex(hop));
|
||||
|
||||
add_children({&button_save});
|
||||
|
||||
button_save.on_select = [this](const Button&) {
|
||||
keeloq_file_buffer.clear();
|
||||
|
||||
text_prompt(
|
||||
nav_,
|
||||
keeloq_file_buffer,
|
||||
64,
|
||||
ENTER_KEYBOARD_MODE_ALPHA,
|
||||
[this](std::string& buffer) {
|
||||
KeeloqData params{
|
||||
mf_name,
|
||||
serial,
|
||||
(uint16_t)cnt,
|
||||
btn};
|
||||
|
||||
ensure_directory(keeloq_remotes_dir);
|
||||
write_keeloq_file(keeloq_remotes_dir / buffer + ".KEELOQ", params);
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SubGhzDRecentEntryDetailView::SubGhzDRecentEntryDetailView(NavigationView& nav, const SubGhzDRecentEntry& entry)
|
||||
@@ -242,6 +291,10 @@ const char* SubGhzDView::getSensorTypeName(FPROTO_SUBGHZD_SENSOR type) {
|
||||
return "GangQi";
|
||||
case FPS_MARANTEC24:
|
||||
return "Marantec24";
|
||||
case FPS_HOLTEKHT6P20B:
|
||||
return "Holtek HT6P20B";
|
||||
case FPS_RESTAURANT_PAGER:
|
||||
return "Rest. Pager";
|
||||
case FPS_Invalid:
|
||||
default:
|
||||
return "Unknown";
|
||||
@@ -268,7 +321,14 @@ void RecentEntriesTable<ui::SubGhzDRecentEntries>::draw(
|
||||
line.reserve(30);
|
||||
|
||||
line = SubGhzDView::getSensorTypeName((FPROTO_SUBGHZD_SENSOR)entry.sensorType);
|
||||
line = line + " " + to_string_hex(entry.data << 32);
|
||||
if (entry.sensorType == FPS_RESTAURANT_PAGER) {
|
||||
uint8_t pgr = (entry.data >> 5) & 0x0F;
|
||||
uint8_t func = (entry.data >> 1) & 0x0F;
|
||||
line += " P:" + to_string_dec_uint(pgr) + (func == 0x0D ? " Buzz" : func == 0x0F ? " Sync"
|
||||
: "");
|
||||
} else {
|
||||
line = line + " " + to_string_hex(entry.data << 32);
|
||||
}
|
||||
line.resize(columns.at(0).second, ' ');
|
||||
std::string ageStr = to_string_dec_uint(entry.age);
|
||||
std::string bitsStr = to_string_dec_uint(entry.bits);
|
||||
@@ -301,6 +361,29 @@ void atomo_decrypt(uint8_t* buff) {
|
||||
}
|
||||
}
|
||||
|
||||
bool SubGhzDRecentEntryDetailView::keeloq_check_decrypt(uint32_t decrypt) {
|
||||
uint16_t end_serial = serial & 0xFF;
|
||||
|
||||
if ((decrypt >> 28 == btn) && (((((uint16_t)(decrypt >> 16)) & 0xFF) == end_serial) ||
|
||||
((((uint16_t)(decrypt >> 16)) & 0xFF) == 0))) {
|
||||
cnt = decrypt & 0xFFFF;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SubGhzDRecentEntryDetailView::keeloq_check_decrypt_centurion(uint32_t decrypt) {
|
||||
if ((decrypt >> 28 == btn) && ((((uint16_t)(decrypt >> 16)) & 0x3FF) == 0x1CE)) {
|
||||
cnt = decrypt & 0xFFFF;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const uint32_t came_twee_magic_numbers_xor[15] = {
|
||||
0x0E0E0E00,
|
||||
0x1D1D1D11,
|
||||
@@ -339,7 +422,7 @@ void SubGhzDRecentEntryDetailView::parseProtocol() {
|
||||
if (entry_.sensorType == FPS_CAMEATOMO) {
|
||||
entry_.data ^= 0xFFFFFFFFFFFFFFFF;
|
||||
entry_.data <<= 4;
|
||||
uint8_t pack[8] = {};
|
||||
uint8_t pack[8];
|
||||
pack[0] = (entry_.data >> 56);
|
||||
pack[1] = ((entry_.data >> 48) & 0xFF);
|
||||
pack[2] = ((entry_.data >> 40) & 0xFF);
|
||||
@@ -589,7 +672,57 @@ void SubGhzDRecentEntryDetailView::parseProtocol() {
|
||||
}
|
||||
|
||||
if (entry_.sensorType == FPS_KEELOQ) {
|
||||
// too many sub protocol versions, skipping. maybe in future when we'll have much more fw space
|
||||
uint64_t data_rev = FProtoGeneral::subghz_protocol_blocks_reverse_key(entry_.data, 64);
|
||||
|
||||
btn = data_rev >> 60;
|
||||
serial = (data_rev >> 32) & 0xFFFFFFF;
|
||||
fix = data_rev >> 32;
|
||||
encrypted = data_rev & 0xFFFFFFFF;
|
||||
|
||||
KeeloqKeystore keystore{};
|
||||
|
||||
const auto& keys = keystore.get_keys();
|
||||
|
||||
if (keys.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& key : keys) {
|
||||
switch (key.type) {
|
||||
case KEELOQ_SIMPLE_LEARNING: {
|
||||
uint32_t decrypted = keeloq_decrypt(encrypted, key.key);
|
||||
|
||||
if (keeloq_check_decrypt(decrypted)) {
|
||||
mf_name = key.mf_name;
|
||||
hop = decrypted;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case KEELOQ_NORMAL_LEARNING: {
|
||||
uint64_t man = keeloq_normal_learning(fix, key.key);
|
||||
uint32_t decrypted = keeloq_decrypt(encrypted, man);
|
||||
|
||||
if (key.mf_name == "Centurion" && keeloq_check_decrypt_centurion(decrypted)) {
|
||||
mf_name = "Centurion";
|
||||
hop = decrypted;
|
||||
|
||||
return;
|
||||
} else if (keeloq_check_decrypt(decrypted)) {
|
||||
mf_name = key.mf_name;
|
||||
hop = decrypted;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -756,5 +889,18 @@ void SubGhzDRecentEntryDetailView::parseProtocol() {
|
||||
btn = entry_.data & 0xf;
|
||||
return;
|
||||
}
|
||||
|
||||
if (entry_.sensorType == FPS_HOLTEKHT6P20B) {
|
||||
serial = entry_.data >> 8;
|
||||
btn = (entry_.data >> 4) & 0xF;
|
||||
return;
|
||||
}
|
||||
|
||||
if (entry_.sensorType == FPS_RESTAURANT_PAGER) {
|
||||
// 25-bit EV1527-variant: [sysid:16][pager:4][func:4][stop:1]
|
||||
serial = (entry_.data >> 9) & 0xFFFF; // System ID
|
||||
// btn/cnt left as SD_NO values; friendly output in update_data()
|
||||
return;
|
||||
}
|
||||
}
|
||||
} // namespace ui
|
||||
} // namespace ui
|
||||
|
||||
@@ -25,7 +25,11 @@
|
||||
|
||||
#define SD_NO_SERIAL 0xFFFFFFFF
|
||||
#define SD_NO_BTN 0xFF
|
||||
#define SD_NO_CNT 0xFF
|
||||
#define SD_NO_CNT 0xFFFFFFFF
|
||||
|
||||
#define SD_NO_HOP 0xFFFFFFFF
|
||||
#define SD_NO_FIX 0xFFFFFFFF
|
||||
#define SD_NO_ENCRYPTED 0xFFFFFFFF
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
@@ -191,6 +195,19 @@ class SubGhzDRecentEntryDetailView : public View {
|
||||
uint32_t cnt = SD_NO_CNT;
|
||||
uint32_t seed = 0;
|
||||
|
||||
// keeloq specific
|
||||
std::string keeloq_file_buffer{};
|
||||
|
||||
uint32_t hop = SD_NO_HOP;
|
||||
uint32_t fix = SD_NO_FIX;
|
||||
uint32_t encrypted = SD_NO_ENCRYPTED;
|
||||
|
||||
std::string mf_name = "Unknown";
|
||||
|
||||
bool keeloq_check_decrypt(uint32_t decrypt);
|
||||
bool keeloq_check_decrypt_centurion(uint32_t decrypt);
|
||||
// end keeloq specific
|
||||
|
||||
Text text_type{{UI_POS_X(0), 1 * 16, 15 * 8, 16}, "?"};
|
||||
Text text_id{{6 * 8, 2 * 16, 10 * 8, 16}, "?"};
|
||||
|
||||
@@ -207,6 +224,10 @@ class SubGhzDRecentEntryDetailView : public View {
|
||||
{screen_width - 96 - 4, screen_height - 32 - 12, 96, 32},
|
||||
"Done"};
|
||||
|
||||
Button button_save{
|
||||
{4, screen_height - 32 - 12, 96, 32},
|
||||
"Save"};
|
||||
|
||||
void parseProtocol();
|
||||
};
|
||||
|
||||
|
||||
@@ -612,7 +612,7 @@ void TextEditorView::open_file(const fs::path& path) {
|
||||
viewer.clear_file();
|
||||
delete_temp_file(path_);
|
||||
|
||||
path_ = {};
|
||||
path_ = "";
|
||||
file_dirty_ = false;
|
||||
has_temp_file_ = false;
|
||||
auto result = FileWrapper::open(
|
||||
|
||||
@@ -81,13 +81,13 @@ class TouchCalibrationView : public View {
|
||||
Color::black()};
|
||||
|
||||
Image image_calibrate_1{
|
||||
{240 - 32 - 16, (320 - 16) / 2 - 16, 32, 32},
|
||||
{screen_width - 32 - 16, (screen_height - 16) / 2 - 16, 32, 32},
|
||||
&bitmap_target_calibrate,
|
||||
Color::white(),
|
||||
Color::black()};
|
||||
|
||||
Image image_calibrate_2{
|
||||
{240 / 2 - 16, (320 - 16) - 32 - 16, 32, 32},
|
||||
{screen_width / 2 - 16, (screen_height - 16) - 32 - 16, 32, 32},
|
||||
&bitmap_target_calibrate,
|
||||
Color::white(),
|
||||
Color::black()};
|
||||
@@ -99,13 +99,13 @@ class TouchCalibrationView : public View {
|
||||
Color::black()};
|
||||
|
||||
Image image_verify_1{
|
||||
{240 - 32 - 16, (320 - 16) / 2 - 16, 32, 32},
|
||||
{screen_width - 32 - 16, (screen_height - 16) / 2 - 16, 32, 32},
|
||||
&bitmap_target_verify,
|
||||
Color::white(),
|
||||
Color::black()};
|
||||
|
||||
Image image_verify_2{
|
||||
{240 / 2 - 16, (320 - 16) - 32 - 16, 32, 32},
|
||||
{screen_width / 2 - 16, (screen_height - 16) - 32 - 16, 32, 32},
|
||||
&bitmap_target_verify,
|
||||
Color::white(),
|
||||
Color::black()};
|
||||
@@ -131,11 +131,11 @@ class TouchCalibrationView : public View {
|
||||
"Calibration failed. Retry?"};
|
||||
|
||||
Button button_cancel{
|
||||
{40, 200, 64, 24},
|
||||
{40, 200, UI_POS_WIDTH(8), 24},
|
||||
"Cancel"};
|
||||
|
||||
Button button_ok{
|
||||
{136, 200, 64, 24},
|
||||
{136, 200, UI_POS_WIDTH(8), 24},
|
||||
"OK"};
|
||||
|
||||
void on_frame_sync();
|
||||
|
||||
@@ -197,6 +197,10 @@ WeatherView::~WeatherView() {
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
uint16_t WeatherView::bcd_decode_short(uint32_t data) {
|
||||
return (data & 0xF) * 10 + ((data >> 4) & 0xF);
|
||||
}
|
||||
|
||||
const char* WeatherView::getWeatherSensorTypeName(FPROTO_WEATHER_SENSOR type) {
|
||||
switch (type) {
|
||||
case FPW_NexusTH:
|
||||
@@ -225,6 +229,8 @@ const char* WeatherView::getWeatherSensorTypeName(FPROTO_WEATHER_SENSOR type) {
|
||||
return "LaCrosse TX141THBv2";
|
||||
case FPW_OREGON2:
|
||||
return "Oregon2";
|
||||
case FPW_OREGON2B:
|
||||
return "Oregon2B";
|
||||
case FPW_OREGON3:
|
||||
return "Oregon3";
|
||||
case FPW_OREGONv1:
|
||||
@@ -299,7 +305,9 @@ WeatherRecentEntry WeatherView::process_data(const WeatherDataMessage* data) {
|
||||
WeatherRecentEntry ret = {};
|
||||
ret.sensorType = data->sensorType;
|
||||
int16_t i16 = 0;
|
||||
int32_t i32 = 0;
|
||||
uint16_t u16 = 0;
|
||||
|
||||
uint64_t u64 = 0;
|
||||
uint8_t u8 = 0;
|
||||
uint8_t channel_3021[] = {3, 0, 2, 1};
|
||||
@@ -442,12 +450,34 @@ WeatherRecentEntry WeatherView::process_data(const WeatherDataMessage* data) {
|
||||
ret.humidity = (data->decode_data >> 8) & 0xFF;
|
||||
break;
|
||||
case FPW_OREGON2:
|
||||
i16 = ((data->decode_data >> 4) & 0xF) * 10 + (((data->decode_data >> 4) >> 4) & 0xF);
|
||||
i16 *= 10;
|
||||
i16 += (data->decode_data >> 12) & 0xF;
|
||||
if (data->decode_data & 0xF) i16 = -i16;
|
||||
ret.temp = (float)i16 / 10.0;
|
||||
// todo fix missing parts.
|
||||
i32 = bcd_decode_short(data->decode_data >> 4);
|
||||
i32 *= 10;
|
||||
i32 += (data->decode_data >> 12) & 0xf;
|
||||
if (data->decode_data & 0xF) i32 = -i32;
|
||||
ret.temp = (float)i32 / 10.0;
|
||||
ret.battery_low = ((data->decode_data >> 32) & 0x4) ? 1 : 0;
|
||||
u8 = (data->decode_data >> 44) & 0xF;
|
||||
ret.channel = 1;
|
||||
while (u8 > 1) {
|
||||
ret.channel++;
|
||||
u8 >>= 1;
|
||||
}
|
||||
break;
|
||||
case FPW_OREGON2B:
|
||||
ret.humidity = bcd_decode_short(data->decode_data);
|
||||
u64 = data->decode_data >> 8;
|
||||
i32 = bcd_decode_short(u64 >> 4);
|
||||
i32 *= 10;
|
||||
i32 += (u64 >> 12) & 0xf;
|
||||
if (u64 & 0xF) i32 = -i32;
|
||||
ret.temp = (float)i32 / 10.0;
|
||||
ret.battery_low = ((data->decode_data >> 32) & 0x4) ? 1 : 0;
|
||||
u8 = (data->decode_data >> 44) & 0xF;
|
||||
ret.channel = 1;
|
||||
while (u8 > 1) {
|
||||
ret.channel++;
|
||||
u8 >>= 1;
|
||||
}
|
||||
break;
|
||||
case FPW_OREGON3:
|
||||
// todo check
|
||||
|
||||
@@ -114,6 +114,7 @@ class WeatherView : public View {
|
||||
|
||||
private:
|
||||
void on_tick_second();
|
||||
uint16_t bcd_decode_short(uint32_t data);
|
||||
void on_data(const WeatherDataMessage* data);
|
||||
WeatherRecentEntry process_data(const WeatherDataMessage* data);
|
||||
NavigationView& nav_;
|
||||
|
||||
@@ -52,12 +52,21 @@ static void send_message(const Message* const message) {
|
||||
creg::m0apptxevent::assert_event();
|
||||
|
||||
if constexpr (check_for_message_hang) {
|
||||
#ifdef PRALINE
|
||||
/* Timeout: ~3 seconds at typical clock speeds */
|
||||
auto count = 200'000'000u;
|
||||
#else
|
||||
auto count = UINT32_MAX;
|
||||
#endif
|
||||
while (shared_memory.baseband_message && --count)
|
||||
/* spin */;
|
||||
|
||||
if (count == 0)
|
||||
#ifdef PRALINE
|
||||
chDbgPanic("BB Msg Timeout");
|
||||
#else
|
||||
chDbgPanic("Baseband Send Fail");
|
||||
#endif
|
||||
} else {
|
||||
while (shared_memory.baseband_message)
|
||||
/* spin */;
|
||||
@@ -147,6 +156,19 @@ void set_sstv_data(const uint8_t vis_code, const uint32_t pixel_duration) {
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_sstvrx_data(const uint8_t code) {
|
||||
const SSTVRXConfigureMessage message{
|
||||
code};
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_sstvrx_phase_slant(const int16_t phase, const int16_t slant) {
|
||||
const SSTVRXPhaseSlantMessage message{
|
||||
phase,
|
||||
slant};
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_afsk(const uint32_t baudrate, const uint32_t word_length, const uint32_t trigger_value, const bool trigger_word) {
|
||||
const AFSKRxConfigureMessage message{
|
||||
baudrate,
|
||||
@@ -288,8 +310,8 @@ void set_fsk_data(const uint32_t stream_length, const uint32_t samples_per_bit,
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_pocsag() {
|
||||
const POCSAGConfigureMessage message{};
|
||||
void set_pocsag(int8_t baud_config) {
|
||||
const POCSAGConfigureMessage message{baud_config};
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
@@ -328,6 +350,11 @@ void set_noaaapt_config() {
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_flex_config() {
|
||||
const FlexConfigureMessage message{};
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_siggen_tone(const uint32_t tone) {
|
||||
const SigGenToneMessage message{
|
||||
TONES_F2D(tone, TONES_SAMPLERATE)};
|
||||
@@ -350,6 +377,41 @@ void set_subghzd_config(uint8_t modulation = 0, uint32_t sampling_rate = 0) {
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_moreserx_config(uint8_t mode) {
|
||||
const MorseRXConfigureMessage message{mode};
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_morsetx_config(uint8_t mode, uint32_t tone, float fm_delta) {
|
||||
const MorseTXConfigureMessage message{mode, tone, fm_delta};
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_morsetx_key(bool key_down) {
|
||||
const MorseTXkeyMessage message{key_down};
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_bitstream_config(uint32_t deviation, uint8_t mode) {
|
||||
const StreamTXConfigurationMessage message{deviation, mode};
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_rtty_config(uint16_t baud, uint16_t shift, uint8_t* payload, uint16_t payload_length) {
|
||||
RTTYDataMessage message{baud, shift};
|
||||
if (payload && payload_length > 0) {
|
||||
message.data_len = payload_length > message.max_len ? message.max_len : payload_length;
|
||||
for (size_t i = 0; i < message.data_len; ++i) {
|
||||
message.data[i] = payload[i];
|
||||
}
|
||||
}
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
void set_rtty_config(RTTYDataMessage& message) {
|
||||
send_message(&message);
|
||||
}
|
||||
|
||||
static bool baseband_image_running = false;
|
||||
|
||||
void run_image(const spi_flash::image_tag_t image_tag) {
|
||||
|
||||
@@ -74,13 +74,15 @@ void set_tone(const uint32_t index, const uint32_t delta, const uint32_t duratio
|
||||
void set_tones_config(const uint32_t bw, const uint32_t pre_silence, const uint16_t tone_count, const bool dual_tone, const bool audio_out);
|
||||
void kill_tone();
|
||||
void set_sstv_data(const uint8_t vis_code, const uint32_t pixel_duration);
|
||||
void set_sstvrx_data(const uint8_t code);
|
||||
void set_sstvrx_phase_slant(const int16_t phase, const int16_t slant);
|
||||
void set_audiotx_config(const uint32_t divider, const float deviation_hz, const float audio_gain, uint8_t audio_shift_bits_s16, uint8_t bits_per_sample, const uint32_t tone_key_delta, const bool am_enabled, const bool dsb_enabled, const bool usb_enabled, const bool lsb_enabled);
|
||||
void set_fifo_data(const int8_t* data);
|
||||
void set_pitch_rssi(int32_t avg, bool enabled);
|
||||
void set_afsk_data(const uint32_t afsk_samples_per_bit, const uint32_t afsk_phase_inc_mark, const uint32_t afsk_phase_inc_space, const uint8_t afsk_repeat, const uint32_t afsk_bw, const uint8_t symbol_count);
|
||||
void kill_afsk();
|
||||
void set_afsk(const uint32_t baudrate, const uint32_t word_length, const uint32_t trigger_value, const bool trigger_word);
|
||||
void set_fsk(const uint32_t samplesPerSymbol, const uint32_t syncWord, const uint8_t syncWordLength, const uint32_t preamble, const uint8_t preambleLength, uint16_t numDataBytes);
|
||||
void set_fsk(const uint8_t samplesPerSymbol, const uint32_t syncWord, const uint8_t syncWordLength, const uint32_t preamble, const uint8_t preambleLength, uint16_t numDataBytes);
|
||||
void set_aprs(const uint32_t baudrate);
|
||||
|
||||
void set_btlerx(uint8_t channel_number);
|
||||
@@ -91,7 +93,7 @@ void set_nrf(const uint32_t baudrate, const uint32_t word_length, const uint32_t
|
||||
void set_ook_data(const uint32_t stream_length, const uint32_t samples_per_bit, const uint8_t repeat, const uint32_t pause_symbols, const uint8_t de_bruijn_length = 0);
|
||||
void kill_ook();
|
||||
void set_fsk_data(const uint32_t stream_length, const uint32_t samples_per_bit, const uint32_t shift, const uint32_t progress_notice);
|
||||
void set_pocsag();
|
||||
void set_pocsag(int8_t baud_config = -1);
|
||||
void set_adsb();
|
||||
void set_jammer(const bool run, const jammer::JammerType type, const uint32_t speed);
|
||||
void set_rds_data(const uint16_t message_length);
|
||||
@@ -100,8 +102,15 @@ void set_siggen_tone(const uint32_t tone);
|
||||
void set_siggen_config(const uint32_t bw, const uint32_t shape, const uint32_t duration);
|
||||
void set_spectrum_painter_config(const uint16_t width, const uint16_t height, bool update, int32_t bw);
|
||||
void set_subghzd_config(uint8_t modulation, uint32_t sampling_rate);
|
||||
void set_moreserx_config(uint8_t mode);
|
||||
void set_morsetx_config(uint8_t mode, uint32_t tone, float fm_delta);
|
||||
void set_morsetx_key(bool key_down);
|
||||
void set_wefax_config(uint8_t lpm, uint8_t ioc);
|
||||
void set_noaaapt_config();
|
||||
void set_flex_config();
|
||||
void set_bitstream_config(uint32_t deviation, uint8_t mode); // mode 0 for am, 1 for 2fsk
|
||||
void set_rtty_config(uint16_t baud, uint16_t shift, uint8_t* payload = nullptr, uint16_t payload_length = 0); // baud*100
|
||||
void set_rtty_config(RTTYDataMessage& message);
|
||||
|
||||
void request_roger_beep();
|
||||
void request_rssi_beep();
|
||||
|
||||
@@ -415,6 +415,44 @@ static constexpr Bitmap bitmap_icon_adsb{
|
||||
{16, 16},
|
||||
bitmap_icon_adsb_data};
|
||||
|
||||
static constexpr uint8_t bitmap_icon_adulttoys_data[] = {
|
||||
0x00,
|
||||
0x00,
|
||||
0x30,
|
||||
0x0C,
|
||||
0x78,
|
||||
0x1E,
|
||||
0x7C,
|
||||
0x3E,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0xFC,
|
||||
0x3F,
|
||||
0xFC,
|
||||
0x3F,
|
||||
0xF8,
|
||||
0x1F,
|
||||
0xF0,
|
||||
0x0F,
|
||||
0xE0,
|
||||
0x07,
|
||||
0xC0,
|
||||
0x03,
|
||||
0x80,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
static constexpr Bitmap bitmap_icon_adulttoys{
|
||||
{16, 16},
|
||||
bitmap_icon_adulttoys_data};
|
||||
|
||||
static constexpr uint8_t bitmap_icon_ais_data[] = {
|
||||
0x00,
|
||||
0x01,
|
||||
@@ -4259,7 +4297,7 @@ static constexpr Bitmap bitmap_icon_tpms{
|
||||
{16, 16},
|
||||
bitmap_icon_tpms_data};
|
||||
|
||||
static constexpr uint8_t bitmap_icon_tranceivers_data[] = {
|
||||
static constexpr uint8_t bitmap_icon_transceivers_data[] = {
|
||||
0x80,
|
||||
0x01,
|
||||
0xC0,
|
||||
@@ -4293,9 +4331,9 @@ static constexpr uint8_t bitmap_icon_tranceivers_data[] = {
|
||||
0xFF,
|
||||
0xFF,
|
||||
};
|
||||
static constexpr Bitmap bitmap_icon_tranceivers{
|
||||
static constexpr Bitmap bitmap_icon_transceivers{
|
||||
{16, 16},
|
||||
bitmap_icon_tranceivers_data};
|
||||
bitmap_icon_transceivers_data};
|
||||
|
||||
static constexpr uint8_t bitmap_icon_transmit_data[] = {
|
||||
0x80,
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
#include "portapack_io.hpp"
|
||||
#include "portapack.hpp"
|
||||
|
||||
#include "hackrf_hal.hpp"
|
||||
using namespace hackrf::one;
|
||||
@@ -30,6 +31,14 @@ using namespace hackrf::one;
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
using namespace lpc43xx;
|
||||
|
||||
#ifdef PRALINE
|
||||
extern "C" {
|
||||
#include "fpga_bridge.h"
|
||||
}
|
||||
// Need access to ssp1_arbiter from radio namespace
|
||||
#include "radio.hpp"
|
||||
#endif
|
||||
|
||||
constexpr uint32_t si5351_vco_f = 800000000;
|
||||
|
||||
constexpr si5351::Inputs si5351_inputs{
|
||||
@@ -54,6 +63,12 @@ constexpr si5351::PLL si5351_pll_xtal_25m{
|
||||
.c = 1,
|
||||
};
|
||||
constexpr auto si5351_pll_a_xtal_reg = si5351_pll_xtal_25m.reg(0);
|
||||
#ifdef PRALINE
|
||||
static_assert(si5351_pll_xtal_25m.f_vco() == si5351_vco_f, "PLL XTAL frequency wrong");
|
||||
static_assert(si5351_pll_xtal_25m.p1() == 3584, "PLL XTAL P1 wrong");
|
||||
static_assert(si5351_pll_xtal_25m.p2() == 0, "PLL XTAL P2 wrong");
|
||||
static_assert(si5351_pll_xtal_25m.p3() == 1, "PLL XTAL P3 wrong");
|
||||
#endif
|
||||
|
||||
constexpr si5351::PLL si5351_pll_clkin_10m{
|
||||
.f_in = si5351_inputs.f_clkin_out(),
|
||||
@@ -64,10 +79,12 @@ constexpr si5351::PLL si5351_pll_clkin_10m{
|
||||
constexpr auto si5351c_pll_b_clkin_reg = si5351_pll_clkin_10m.reg(1);
|
||||
constexpr auto si5351a_pll_a_clkin_reg = si5351_pll_clkin_10m.reg(0);
|
||||
|
||||
#ifndef PRALINE
|
||||
static_assert(si5351_pll_xtal_25m.f_vco() == si5351_vco_f, "PLL XTAL frequency wrong");
|
||||
static_assert(si5351_pll_xtal_25m.p1() == 3584, "PLL XTAL P1 wrong");
|
||||
static_assert(si5351_pll_xtal_25m.p2() == 0, "PLL XTAL P2 wrong");
|
||||
static_assert(si5351_pll_xtal_25m.p3() == 1, "PLL XTAL P3 wrong");
|
||||
#endif
|
||||
|
||||
static_assert(si5351_pll_clkin_10m.f_vco() == si5351_vco_f, "PLL CLKIN frequency wrong");
|
||||
static_assert(si5351_pll_clkin_10m.p1() == 9728, "PLL CLKIN P1 wrong");
|
||||
@@ -101,6 +118,22 @@ constexpr si5351::MultisynthFractional si5351_ms_0_8m{
|
||||
};
|
||||
constexpr auto si5351c_ms_0_8m_reg = si5351_ms_0_8m.reg(clock_generator_output_og_codec);
|
||||
|
||||
#ifdef PRALINE
|
||||
// Verify compile-time values for 8 MHz config
|
||||
static_assert(si5351_ms_0_8m.p1() == 5888, "MS0 8MHz P1 should be 5888 (0x1700)");
|
||||
static_assert(si5351_ms_0_8m.p2() == 0, "MS0 8MHz P2 should be 0");
|
||||
static_assert(si5351_ms_0_8m.p3() == 1, "MS0 8MHz P3 should be 1");
|
||||
static_assert(si5351_ms_0_8m.f_out() == 8000000, "MS0 should output 8 MHz");
|
||||
|
||||
// Verify register array encoding
|
||||
static_assert(si5351c_ms_0_8m_reg[0] == 42, "MS0 base register should be 42");
|
||||
static_assert(si5351c_ms_0_8m_reg[1] == 0x00, "MS0 reg43 P3[15:8] should be 0x00");
|
||||
static_assert(si5351c_ms_0_8m_reg[2] == 0x01, "MS0 reg44 P3[7:0] should be 0x01");
|
||||
static_assert(si5351c_ms_0_8m_reg[3] == 0x10, "MS0 reg45 R_DIV should be 0x10");
|
||||
static_assert(si5351c_ms_0_8m_reg[4] == 0x17, "MS0 reg46 P1[15:8] should be 0x17");
|
||||
static_assert(si5351c_ms_0_8m_reg[5] == 0x00, "MS0 reg47 P1[7:0] should be 0x00");
|
||||
#endif
|
||||
|
||||
constexpr si5351::MultisynthFractional si5351_ms_group{
|
||||
.f_src = si5351_vco_f,
|
||||
.a = 80, /* Don't care */
|
||||
@@ -204,7 +237,11 @@ constexpr ClockControls si5351c_clock_control_common{{
|
||||
}};
|
||||
|
||||
constexpr ClockControls si5351a_clock_control_common{{
|
||||
#ifndef PRALINE
|
||||
{ClockControl::ClockCurrentDrive::_6mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off},
|
||||
#else
|
||||
{ClockControl::ClockCurrentDrive::_6mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Fractional, ClockControl::ClockPowerDown::Power_Off}, // CLK0: MUST be Fractional for 8 MHz!
|
||||
#endif
|
||||
{ClockControl::ClockCurrentDrive::_4mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Fractional, ClockControl::ClockPowerDown::Power_Off},
|
||||
{ClockControl::ClockCurrentDrive::_8mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off},
|
||||
{ClockControl::ClockCurrentDrive::_2mA, ClockControl::ClockSource::MS_Self, ClockControl::ClockInvert::Normal, ClockControl::MultiSynthSource::PLLA, ClockControl::MultiSynthMode::Integer, ClockControl::ClockPowerDown::Power_Off},
|
||||
@@ -244,8 +281,7 @@ static void portapack_tcxo_enable() {
|
||||
/* Delay >10ms at 96MHz clock speed for reference oscillator to start. */
|
||||
/* Delay an additional 1ms (arbitrary) for the clock generator to detect a signal. */
|
||||
volatile uint32_t delay = 240000 + 24000;
|
||||
while (delay--)
|
||||
;
|
||||
while (delay--);
|
||||
}
|
||||
|
||||
static void portapack_tcxo_disable() {
|
||||
@@ -256,9 +292,48 @@ static void portapack_tcxo_disable() {
|
||||
using namespace hackrf::one;
|
||||
|
||||
void ClockManager::init_clock_generator() {
|
||||
#ifdef PRALINE
|
||||
// PRALINE: Configure clock input mux GPIO
|
||||
// GPIO0_15 (clkin_ctrl) selects GP_CLKIN source:
|
||||
// 0 = P1 connector (external)
|
||||
// 1 = P22 (internal Si5351 CLK2)
|
||||
constexpr GPIO gpio_clkin_ctrl = gpio[GPIO0_15];
|
||||
gpio_clkin_ctrl.output();
|
||||
gpio_clkin_ctrl.write(1); // CLKIN_SIGNAL_P22 = 1 = internal Si5351 CLK2
|
||||
|
||||
// Also enable MCU clock gate (GPIO0_8)
|
||||
gpio_r9_mcu_clk_en.output();
|
||||
gpio_r9_mcu_clk_en.write(1);
|
||||
#else
|
||||
// HackRF One r9: GPIO0_8 (mcu_clk_en) gates Si5351 CLK2/CLK7 to GP_CLKIN
|
||||
if (hackrf_r9) {
|
||||
gpio_r9_mcu_clk_en.output();
|
||||
gpio_r9_mcu_clk_en.write(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
clock_generator.reset();
|
||||
clock_generator.set_crystal_internal_load_capacitance(CrystalInternalLoadCapacitance::XTAL_CL_8pF);
|
||||
clock_generator.enable_fanout();
|
||||
|
||||
#ifdef PRALINE
|
||||
/* PRALINE has Si5351A (NOT Si5351C like HackRF One OG).
|
||||
* Must use Si5351A configuration: PLLA only, no CLKIN support.
|
||||
*
|
||||
* IMPORTANT: Follow HackRF reference sequence:
|
||||
* 1. Set PLL input sources
|
||||
* 2. Configure PLL and multisynths
|
||||
* 3. Set clock control registers (AFTER multisynths!)
|
||||
* 4. Reset PLLs
|
||||
* 5. Enable outputs
|
||||
*/
|
||||
clock_generator.set_pll_input_sources(si5351a_pll_input_sources);
|
||||
|
||||
/* Skip MCU CLKIN setup and reference detection for PRALINE - not applicable */
|
||||
reference = Reference{ReferenceSource::Xtal, 0};
|
||||
|
||||
/* Clock control will be set AFTER multisynth configuration - see below */
|
||||
#else
|
||||
clock_generator.set_pll_input_sources(hackrf_r9
|
||||
? si5351a_pll_input_sources
|
||||
: si5351c_pll_input_sources);
|
||||
@@ -299,7 +374,62 @@ void ClockManager::init_clock_generator() {
|
||||
si5351_clock_control_common[7].ms_src(ref_pll),
|
||||
}};
|
||||
clock_generator.set_clock_control(si5351_clock_control);
|
||||
#endif
|
||||
|
||||
#ifdef PRALINE
|
||||
/* PRALINE uses Si5351A with:
|
||||
* CLK0 = AFE_CLK (codec/FPGA sample clock)
|
||||
* CLK1 = SCT_CLK (FPGA timing clock at 2x sample rate)
|
||||
* CLK4 = first IF (RFFC5072)
|
||||
* CLK5 = second IF (MAX2831)
|
||||
* Uses PLLA on XTAL only (no CLKIN support).
|
||||
*/
|
||||
|
||||
/* Step 1: Write PLL A configuration (800 MHz VCO from 25 MHz XTAL) */
|
||||
/* Use single-byte writes to debug I2C issues */
|
||||
{
|
||||
const auto& pll_regs = si5351_pll_a_xtal_reg;
|
||||
const uint8_t base_reg = pll_regs[0];
|
||||
for (size_t i = 1; i < pll_regs.size(); i++) {
|
||||
clock_generator.write_register(base_reg + i - 1, pll_regs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Step 2: Write multisynth configurations using single-byte writes */
|
||||
clock_generator.write_ms_single_byte(0, si5351_ms_0_8m); // MS0 = divider 50, r_div=1 for 8 MHz
|
||||
clock_generator.write_ms_single_byte(1, si5351_ms_16m); // MS1 = divider 50, r_div=0 for 16 MHz
|
||||
|
||||
/* CLK4 and CLK5 - use single-byte writes too */
|
||||
{
|
||||
const auto& ms4_regs = si5351c_ms_4_reg;
|
||||
const uint8_t base_reg = ms4_regs[0];
|
||||
for (size_t i = 1; i < ms4_regs.size(); i++) {
|
||||
clock_generator.write_register(base_reg + i - 1, ms4_regs[i]);
|
||||
}
|
||||
}
|
||||
{
|
||||
const auto& ms5_regs = si5351c_ms_5_reg;
|
||||
const uint8_t base_reg = ms5_regs[0];
|
||||
for (size_t i = 1; i < ms5_regs.size(); i++) {
|
||||
clock_generator.write_register(base_reg + i - 1, ms5_regs[i]);
|
||||
}
|
||||
}
|
||||
clock_generator.write(si5351a_ms6_7_off_reg); // MS6/7 off - short write is OK
|
||||
|
||||
/* Step 3: NOW set clock control registers (AFTER multisynths per HackRF reference) */
|
||||
const auto ref_pll = ClockControl::MultiSynthSource::PLLA;
|
||||
const ClockControls si5351_clock_control = ClockControls{{
|
||||
si5351a_clock_control_common[0].ms_src(ref_pll),
|
||||
si5351a_clock_control_common[1].ms_src(ref_pll),
|
||||
si5351a_clock_control_common[2].ms_src(ref_pll),
|
||||
si5351a_clock_control_common[3].ms_src(ref_pll),
|
||||
si5351a_clock_control_common[4].ms_src(ref_pll),
|
||||
si5351a_clock_control_common[5].ms_src(ref_pll),
|
||||
si5351a_clock_control_common[6].ms_src(ref_pll),
|
||||
si5351a_clock_control_common[7].ms_src(ref_pll),
|
||||
}};
|
||||
clock_generator.set_clock_control(si5351_clock_control);
|
||||
#else
|
||||
if (hackrf_r9) {
|
||||
const PLLReg pll_reg = (reference.source == ReferenceSource::Xtal)
|
||||
? si5351_pll_a_xtal_reg
|
||||
@@ -320,22 +450,45 @@ void ClockManager::init_clock_generator() {
|
||||
clock_generator.write(si5351c_ms_5_reg);
|
||||
clock_generator.write(si5351c_ms6_7_off_mcu_clkin_reg);
|
||||
}
|
||||
#endif
|
||||
|
||||
clock_generator.reset_plls();
|
||||
|
||||
// Wait for PLL(s) to lock.
|
||||
#ifdef PRALINE
|
||||
// PRALINE: Wait for PLLA to lock (0x20 = LOL_A bit)
|
||||
uint8_t device_status_mask = 0x20;
|
||||
uint32_t pll_timeout = 100000;
|
||||
while ((clock_generator.device_status() & device_status_mask) != 0 && pll_timeout > 0) {
|
||||
pll_timeout--;
|
||||
}
|
||||
// Store PLL lock status for debugging
|
||||
static volatile uint32_t pll_lock_timeout = pll_timeout;
|
||||
(void)pll_lock_timeout;
|
||||
|
||||
// CRITICAL: Add delay to ensure Si5351 writes complete before I2C bus stops
|
||||
chThdSleepMilliseconds(100);
|
||||
#else
|
||||
// Wait for PLL(s) to lock - with timeout to prevent hang
|
||||
uint8_t device_status_mask = hackrf_r9
|
||||
? 0x20
|
||||
: (ref_pll == ClockControl::MultiSynthSource::PLLB)
|
||||
? 0x40
|
||||
: 0x20;
|
||||
while ((clock_generator.device_status() & device_status_mask) != 0)
|
||||
;
|
||||
#ifndef PRALINE
|
||||
while ((clock_generator.device_status() & device_status_mask) != 0);
|
||||
#else
|
||||
uint32_t pll_timeout = 100000;
|
||||
while ((clock_generator.device_status() & device_status_mask) != 0 && pll_timeout > 0) {
|
||||
pll_timeout--;
|
||||
}
|
||||
#endif
|
||||
|
||||
clock_generator.set_clock_control(
|
||||
clock_generator_output_mcu_clkin,
|
||||
si5351_clock_control_common[clock_generator_output_mcu_clkin].ms_src(ref_pll).clk_pdn(ClockControl::ClockPowerDown::Power_On));
|
||||
clock_generator.enable_output(clock_generator_output_mcu_clkin);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t ClockManager::measure_gp_clkin_frequency() {
|
||||
@@ -377,8 +530,7 @@ ClockManager::Reference ClockManager::choose_reference() {
|
||||
if (hackrf_r9) {
|
||||
gpio_r9_clkin_en.write(1);
|
||||
volatile uint32_t delay = 240000 + 24000;
|
||||
while (delay--)
|
||||
;
|
||||
while (delay--);
|
||||
}
|
||||
const auto detected_reference = detect_reference_source();
|
||||
|
||||
@@ -403,6 +555,15 @@ void ClockManager::shutdown() {
|
||||
}
|
||||
|
||||
void ClockManager::enable_codec_clocks() {
|
||||
#ifdef PRALINE
|
||||
/* PRALINE: CLK0 (AFE_CLK) for codec/FPGA, CLK1 (SCT_CLK) for FPGA timing.
|
||||
* Reference hackrf_core.c shows PRALINE needs both CLK0 and CLK1. */
|
||||
clock_generator.enable_clock(clock_generator_output_og_codec); /* CLK0 */
|
||||
clock_generator.enable_clock(clock_generator_output_og_cpld); /* CLK1 */
|
||||
clock_generator.enable_output_mask(
|
||||
(1U << clock_generator_output_og_codec) |
|
||||
(1U << clock_generator_output_og_cpld));
|
||||
#else
|
||||
if (hackrf_r9) {
|
||||
clock_generator.enable_clock(clock_generator_output_r9_sgpio);
|
||||
} else {
|
||||
@@ -420,6 +581,7 @@ void ClockManager::enable_codec_clocks() {
|
||||
clock_generator.enable_output_mask(
|
||||
(1U << clock_generator_output_og_codec) | (1U << clock_generator_output_og_cpld) | (1U << clock_generator_output_og_sgpio));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ClockManager::disable_codec_clocks() {
|
||||
@@ -427,6 +589,14 @@ void ClockManager::disable_codec_clocks() {
|
||||
* be enabled for the output to come to rest at the state specified by
|
||||
* CLKx_DISABLE_STATE.
|
||||
*/
|
||||
#ifdef PRALINE
|
||||
/* PRALINE: CLK0 (AFE_CLK) and CLK1 (SCT_CLK) used for codec/FPGA */
|
||||
clock_generator.disable_output_mask(
|
||||
(1U << clock_generator_output_og_codec) |
|
||||
(1U << clock_generator_output_og_cpld));
|
||||
clock_generator.disable_clock(clock_generator_output_og_codec);
|
||||
clock_generator.disable_clock(clock_generator_output_og_cpld);
|
||||
#else
|
||||
if (hackrf_r9) {
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_r9_sgpio);
|
||||
clock_generator.disable_clock(clock_generator_output_r9_sgpio);
|
||||
@@ -437,9 +607,17 @@ void ClockManager::disable_codec_clocks() {
|
||||
clock_generator.disable_clock(clock_generator_output_og_cpld);
|
||||
clock_generator.disable_clock(clock_generator_output_og_sgpio);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ClockManager::enable_if_clocks() {
|
||||
#ifdef PRALINE
|
||||
/* PRALINE uses CLK4 (first IF) and CLK5 (second IF) like original HackRF One */
|
||||
clock_generator.enable_clock(clock_generator_output_og_first_if);
|
||||
clock_generator.enable_output_mask(1U << clock_generator_output_og_first_if);
|
||||
clock_generator.enable_clock(clock_generator_output_og_second_if);
|
||||
clock_generator.enable_output_mask(1U << clock_generator_output_og_second_if);
|
||||
#else
|
||||
if (hackrf_r9) {
|
||||
clock_generator.enable_clock(clock_generator_output_r9_if);
|
||||
clock_generator.enable_output_mask(1U << clock_generator_output_r9_if);
|
||||
@@ -449,9 +627,16 @@ void ClockManager::enable_if_clocks() {
|
||||
clock_generator.enable_clock(clock_generator_output_og_second_if);
|
||||
clock_generator.enable_output_mask(1U << clock_generator_output_og_second_if);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ClockManager::disable_if_clocks() {
|
||||
#ifdef PRALINE
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_og_first_if);
|
||||
clock_generator.disable_clock(clock_generator_output_og_first_if);
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_og_second_if);
|
||||
clock_generator.disable_clock(clock_generator_output_og_second_if);
|
||||
#else
|
||||
if (hackrf_r9) {
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_r9_if);
|
||||
clock_generator.disable_clock(clock_generator_output_r9_if);
|
||||
@@ -461,19 +646,41 @@ void ClockManager::disable_if_clocks() {
|
||||
clock_generator.disable_output_mask(1U << clock_generator_output_og_second_if);
|
||||
clock_generator.disable_clock(clock_generator_output_og_second_if);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ClockManager::set_sampling_frequency(const uint32_t frequency) {
|
||||
#ifdef PRALINE
|
||||
/* PRALINE: CLK0=AFE_CLK runs at sample rate (VCO/divider/2)
|
||||
* CLK1=SCT_CLK runs at 2x sample rate (VCO/divider/1)
|
||||
* Reference: hackrf_core.c sample_rate_frac_set() lines 580-582
|
||||
*/
|
||||
|
||||
/* PRALINE: Match HackRF USB sample_rate_frac_set()
|
||||
* Reference: hackrf_usb radio.c lines 29-91, hackrf_core.c lines 501-685 */
|
||||
|
||||
_base_band_frequency = frequency;
|
||||
|
||||
// Set FPGA decimation to 0 (no decimation) for direct passthrough
|
||||
fpga_debug_register_write(2, 0);
|
||||
radio::invalidate_spi_config();
|
||||
|
||||
// The following was originally from @kitty. Adopting for testing radio.
|
||||
clock_generator.set_ms_frequency(0, frequency * 2, si5351_vco_f, 1); // CLK0: r_div=1 (÷2)
|
||||
clock_generator.set_ms_frequency(1, frequency * 2, si5351_vco_f, 0); // CLK1: r_div=0 (÷1)
|
||||
#else
|
||||
/* Codec clock is at sampling frequency, CPLD and SGPIO clocks are at
|
||||
* twice the frequency, and derived from the MS0 synth. So it's only
|
||||
* necessary to change the MS0 synth frequency, and ensure the output
|
||||
* is divided by two.
|
||||
*/
|
||||
|
||||
if (hackrf_r9) {
|
||||
clock_generator.set_ms_frequency(clock_generator_output_r9_sgpio, frequency * 2, si5351_vco_f, 0);
|
||||
} else {
|
||||
clock_generator.set_ms_frequency(clock_generator_output_og_codec, frequency * 2, si5351_vco_f, 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ClockManager::set_reference_ppb(const int32_t ppb) {
|
||||
@@ -513,8 +720,15 @@ void ClockManager::start_frequency_monitor_measurement(const cgu::CLK_SEL clk_se
|
||||
|
||||
void ClockManager::wait_For_frequency_monitor_measurement_done() {
|
||||
// FREQ_MON mechanism fails to finish if there's no clock present on selected input?!
|
||||
while (LPC_CGU->FREQ_MON.MEAS == 1)
|
||||
;
|
||||
#ifndef PRALINE
|
||||
while (LPC_CGU->FREQ_MON.MEAS == 1);
|
||||
#else
|
||||
// PRALINE FIX: Add timeout to prevent infinite hang
|
||||
uint32_t timeout = 100000;
|
||||
while (LPC_CGU->FREQ_MON.MEAS == 1 && timeout > 0) {
|
||||
timeout--;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t ClockManager::get_frequency_monitor_measurement_in_hertz() {
|
||||
@@ -525,6 +739,35 @@ uint32_t ClockManager::get_frequency_monitor_measurement_in_hertz() {
|
||||
}
|
||||
|
||||
void ClockManager::start_audio_pll() {
|
||||
#ifdef PRALINE
|
||||
/* PRALINE: Use 12MHz XTAL for audio PLL
|
||||
* For 12MHz XTAL input, 48kHz audio rate, 256Fs MCLK:
|
||||
* Fout=12.288MHz, Fcco=491.52MHz
|
||||
* 12MHz * 1024 / 25 = 491.52MHz
|
||||
* MSEL=1024, NSEL=25, PSEL=20
|
||||
*/
|
||||
cgu::pll0audio::ctrl({
|
||||
.pd = 1,
|
||||
.bypass = 0,
|
||||
.directi = 0,
|
||||
.directo = 0,
|
||||
.clken = 0,
|
||||
.frm = 0,
|
||||
.autoblock = 1,
|
||||
.pllfract_req = 0,
|
||||
.sel_ext = 1,
|
||||
.mod_pd = 1,
|
||||
.clk_sel = cgu::CLK_SEL::XTAL,
|
||||
});
|
||||
|
||||
cgu::pll0audio::mdiv({
|
||||
.mdec = 22625UL, // MDEC for MSEL=1024
|
||||
});
|
||||
cgu::pll0audio::np_div({
|
||||
.pdec = 31, // PSEL=20
|
||||
.ndec = 69, // NDEC for NSEL=25
|
||||
});
|
||||
#else
|
||||
cgu::pll0audio::ctrl({
|
||||
.pd = 1,
|
||||
.bypass = 0,
|
||||
@@ -553,14 +796,24 @@ void ClockManager::start_audio_pll() {
|
||||
.pdec = 31,
|
||||
.ndec = 45,
|
||||
});
|
||||
#endif
|
||||
|
||||
cgu::pll0audio::frac({
|
||||
.pllfract_ctrl = 0,
|
||||
});
|
||||
|
||||
cgu::pll0audio::power_up();
|
||||
while (!cgu::pll0audio::is_locked())
|
||||
;
|
||||
#ifndef PRALINE
|
||||
while (!cgu::pll0audio::is_locked());
|
||||
#else
|
||||
// PRALINE FIX: Add timeout to prevent infinite hang if GP_CLKIN not present
|
||||
{
|
||||
uint32_t timeout = 100000;
|
||||
while (!cgu::pll0audio::is_locked() && timeout > 0) {
|
||||
timeout--;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
cgu::pll0audio::clock_enable();
|
||||
|
||||
set_base_audio_clock_divider(1);
|
||||
@@ -577,8 +830,7 @@ void ClockManager::set_base_audio_clock_divider(const size_t divisor) {
|
||||
void ClockManager::stop_audio_pll() {
|
||||
cgu::pll0audio::clock_disable();
|
||||
cgu::pll0audio::power_down();
|
||||
while (cgu::pll0audio::is_locked())
|
||||
;
|
||||
while (cgu::pll0audio::is_locked());
|
||||
}
|
||||
|
||||
void ClockManager::enable_clock_output(bool enable) {
|
||||
|
||||
@@ -70,8 +70,19 @@ class ClockManager {
|
||||
|
||||
void set_sampling_frequency(const uint32_t frequency);
|
||||
|
||||
uint32_t get_sampling_frequency() const {
|
||||
return _base_band_frequency;
|
||||
};
|
||||
|
||||
void set_reference_ppb(const int32_t ppb);
|
||||
|
||||
#ifdef PRALINE
|
||||
// Si5351 diagnostic methods
|
||||
uint8_t si5351_read_status() { return clock_generator.device_status(); }
|
||||
uint8_t si5351_read_register(uint8_t reg) { return clock_generator.read_register(reg); }
|
||||
void si5351_write_register(uint8_t reg, uint8_t value) { clock_generator.write_register(reg, value); }
|
||||
#endif
|
||||
|
||||
uint32_t get_frequency_monitor_measurement_in_hertz();
|
||||
|
||||
Reference get_reference() const;
|
||||
@@ -85,6 +96,8 @@ class ClockManager {
|
||||
si5351::Si5351& clock_generator;
|
||||
Reference reference;
|
||||
|
||||
uint32_t _base_band_frequency{20000000};
|
||||
|
||||
void set_gp_clkin_to_clkin_direct();
|
||||
|
||||
void start_frequency_monitor_measurement(const cgu::CLK_SEL clk_sel);
|
||||
|
||||
@@ -139,13 +139,11 @@ void runtime_error(uint8_t source) {
|
||||
led.off();
|
||||
|
||||
// wait for DFU button release if pressed, so we don't immediately jump into stack dump
|
||||
while (swizzled_switches() & (1 << (int)Switch::Dfu))
|
||||
;
|
||||
while (swizzled_switches() & (1 << (int)Switch::Dfu));
|
||||
|
||||
while (true) {
|
||||
volatile size_t n = 1000000U;
|
||||
while (n--)
|
||||
;
|
||||
while (n--);
|
||||
led.toggle();
|
||||
|
||||
// Stack dump will cover entire screen, so wait for DFU button press to attempt it
|
||||
@@ -225,8 +223,7 @@ void draw_stack_dump() {
|
||||
// Out of room on the screen or end of stack - allow Up/Down paging.
|
||||
// First wait for button release from previous press.
|
||||
// NOTE: can't call swizzle_switches() with interrupted enabled!
|
||||
while (swizzled_switches() & ((1 << (int)Switch::Right) | (1 << (int)Switch::Left) | (1 << (int)Switch::Down) | (1 << (int)Switch::Up) | (1 << (int)Switch::Sel) | (1 << (int)Switch::Dfu)))
|
||||
;
|
||||
while (swizzled_switches() & ((1 << (int)Switch::Right) | (1 << (int)Switch::Left) | (1 << (int)Switch::Down) | (1 << (int)Switch::Up) | (1 << (int)Switch::Sel) | (1 << (int)Switch::Dfu)));
|
||||
|
||||
painter.draw_string({border, portapack::display.height() - border - 8}, *Theme::getInstance()->bg_darkest_small, "Use UP/DOWN key");
|
||||
|
||||
|
||||
@@ -41,8 +41,7 @@ extern uint32_t __process_stack_end__;
|
||||
|
||||
inline uint32_t get_free_stack_space() {
|
||||
uint32_t* p;
|
||||
for (p = &__process_stack_base__; *p == CRT0_STACKS_FILL_PATTERN && p < &__process_stack_end__; p++)
|
||||
;
|
||||
for (p = &__process_stack_base__; *p == CRT0_STACKS_FILL_PATTERN && p < &__process_stack_end__; p++);
|
||||
auto stack_space_left = p - &__process_stack_base__;
|
||||
|
||||
return stack_space_left;
|
||||
|
||||
@@ -124,12 +124,12 @@ void EventDispatcher::request_stop() {
|
||||
|
||||
void EventDispatcher::set_display_sleep(const bool sleep) {
|
||||
// TODO: Distribute display sleep message more broadly, shut down data generation
|
||||
// on baseband side, since all that data is being discarded during sleep.
|
||||
// on baseband side, since all that data is being discarded during sleep. -- DON'T TODO it, sincethe stealth mode want to send with screen off!
|
||||
if (sleep) {
|
||||
portapack::backlight()->off();
|
||||
portapack::display.sleep();
|
||||
portapack::display.sleep(false); // when called the hw_sleep = true, the irq wont fire, so the EVT_MASK_LCD_FRAME_SYNC won't set.
|
||||
} else {
|
||||
portapack::display.wake();
|
||||
portapack::display.wake(true); // not important, command not affect if already hw waken up
|
||||
// Don't turn on backlight here.
|
||||
// Let frame sync handler turn on backlight after repaint.
|
||||
}
|
||||
@@ -180,12 +180,10 @@ void EventDispatcher::dispatch(const eventmask_t events) {
|
||||
/*if( events & EVT_MASK_LCD_FRAME_SYNC ) {
|
||||
blink_timer();
|
||||
}*/
|
||||
|
||||
if (events & EVT_MASK_LCD_FRAME_SYNC) {
|
||||
handle_lcd_frame_sync(!EventDispatcher::display_sleep);
|
||||
}
|
||||
if (!EventDispatcher::display_sleep) {
|
||||
if (events & EVT_MASK_LCD_FRAME_SYNC) {
|
||||
handle_lcd_frame_sync();
|
||||
}
|
||||
|
||||
if (events & EVT_MASK_ENCODER) {
|
||||
handle_encoder();
|
||||
}
|
||||
@@ -258,7 +256,9 @@ ui::Widget* EventDispatcher::touch_widget(ui::Widget* const w, ui::TouchEvent ev
|
||||
if (!w->hidden()) {
|
||||
// To achieve reverse depth ordering (last object drawn is
|
||||
// considered "top"), descend first.
|
||||
for (const auto child : w->children()) {
|
||||
auto& children = w->children();
|
||||
for (auto it = children.rbegin(); it != children.rend(); ++it) { // reverse, bc the lastly added will be "top" if overlaps
|
||||
const auto& child = *it;
|
||||
const auto touched_widget = touch_widget(child, event);
|
||||
if (touched_widget) {
|
||||
return touched_widget;
|
||||
@@ -328,17 +328,16 @@ ui::Widget* EventDispatcher::getFocusedWidget() {
|
||||
return context.focus_manager().focus_widget();
|
||||
}
|
||||
|
||||
void EventDispatcher::handle_lcd_frame_sync() {
|
||||
void EventDispatcher::handle_lcd_frame_sync(bool screen_on) {
|
||||
bool waiting_for_frame = this->waiting_for_frame;
|
||||
|
||||
DisplayFrameSyncMessage message;
|
||||
DisplayFrameSyncMessage message; // send framesync msg all the time, bc some apps relay on it
|
||||
message_map.send(&message);
|
||||
|
||||
static_cast<ui::SystemView*>(top_widget)->paint_overlay();
|
||||
painter.paint_widget_tree(top_widget);
|
||||
|
||||
portapack::backlight()->on();
|
||||
|
||||
if (screen_on) { // only draw when screen is on
|
||||
static_cast<ui::SystemView*>(top_widget)->paint_overlay();
|
||||
painter.paint_widget_tree(top_widget);
|
||||
portapack::backlight()->on();
|
||||
}
|
||||
if (waiting_for_frame)
|
||||
this->waiting_for_frame = false;
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ class EventDispatcher {
|
||||
void on_keyboard_event(ui::KeyboardEvent event);
|
||||
|
||||
// void blink_timer();
|
||||
void handle_lcd_frame_sync();
|
||||
void handle_lcd_frame_sync(bool screen_on);
|
||||
void handle_switches();
|
||||
void handle_encoder();
|
||||
void handle_touch();
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2025 Pezsma
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_adult_toys_controller.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::adult_toys_controller {
|
||||
|
||||
void initialize_app(::ui::NavigationView& nav) {
|
||||
nav.push<AdultToysView>();
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::adult_toys_controller
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_adult_toys_controller.application_information"), used)) application_information_t _application_information_adult_toys_controller = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::adult_toys_controller::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
|
||||
/*.app_name = */ "Adult Toys",
|
||||
/*.bitmap_data = */ {
|
||||
0x00,
|
||||
0x00,
|
||||
0x30,
|
||||
0x0C,
|
||||
0x78,
|
||||
0x1E,
|
||||
0x7C,
|
||||
0x3E,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0xFC,
|
||||
0x3F,
|
||||
0xFC,
|
||||
0x3F,
|
||||
0xF8,
|
||||
0x1F,
|
||||
0xF0,
|
||||
0x0F,
|
||||
0xE0,
|
||||
0x07,
|
||||
0xC0,
|
||||
0x03,
|
||||
0x80,
|
||||
0x01,
|
||||
0x00,
|
||||
0x00,
|
||||
},
|
||||
/*.icon_color = */ ui::Color::yellow().v,
|
||||
/*.menu_location = */ app_location_t::TX,
|
||||
/*.desired_menu_position = */ -1,
|
||||
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_btle_tx */ {'P', 'B', 'T', 'T'},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
}
|
||||
+373
@@ -0,0 +1,373 @@
|
||||
|
||||
#include "ui_adult_toys_controller.hpp"
|
||||
|
||||
#include "ui_modemsetup.hpp"
|
||||
#include "modems.hpp"
|
||||
#include "audio.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
using namespace modems;
|
||||
using namespace ui;
|
||||
|
||||
namespace ui::external_app::adult_toys_controller {
|
||||
|
||||
void AdultToysView::focus() {
|
||||
button_on.focus();
|
||||
}
|
||||
|
||||
AdultToysView::AdultToysView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
add_children({
|
||||
&button_on,
|
||||
&btn_adult,
|
||||
&btn_child,
|
||||
&btn_mode_decrease,
|
||||
&btn_mode_increase,
|
||||
&btn_pcknum_inc,
|
||||
&btn_pcknum_dec,
|
||||
&chk_mode_rnd,
|
||||
&chk_mode_play,
|
||||
&chk_mode_stop,
|
||||
&chk_mode_ncnt,
|
||||
&chk_mode_infinite,
|
||||
&field_frequency,
|
||||
&txt_selected_mode,
|
||||
&options_target,
|
||||
&labels,
|
||||
&message_num,
|
||||
&tx_view,
|
||||
&screen_message_1,
|
||||
&screen_message_2,
|
||||
&screen_message_3,
|
||||
&screen_message_4,
|
||||
&screen_message_5,
|
||||
&screen_message_6,
|
||||
&screen_message_7,
|
||||
&screen_message_8,
|
||||
&screen_message_9,
|
||||
&screen_message_10,
|
||||
});
|
||||
|
||||
btn_adult.on_select = [this](Button&) {
|
||||
start_screen = true;
|
||||
hidden_program(!start_screen);
|
||||
};
|
||||
|
||||
btn_child.on_select = [this](Button&) {
|
||||
nav_.pop();
|
||||
};
|
||||
|
||||
button_on.on_select = [this](Button&) {
|
||||
if (play_running || stop_running) {
|
||||
if (button_onstate) {
|
||||
button_onstate = false;
|
||||
stop();
|
||||
button_on.set_text(LanguageHelper::currentMessages[LANG_START]);
|
||||
} else {
|
||||
button_onstate = true;
|
||||
printCurrentModes();
|
||||
start();
|
||||
button_on.set_text(LanguageHelper::currentMessages[LANG_STOP]);
|
||||
}
|
||||
} // if play_running || stop_running
|
||||
};
|
||||
|
||||
btn_mode_decrease.on_select = [this](Button&) {
|
||||
if (toy_packet > 0) {
|
||||
toy_packet--;
|
||||
printCurrentModes();
|
||||
}
|
||||
};
|
||||
|
||||
btn_mode_increase.on_select = [this](Button&) {
|
||||
if (stop_running || play_running) {
|
||||
if (play_running && (toy_packet < max_plays - 1)) {
|
||||
toy_packet++;
|
||||
} else {
|
||||
if (stop_running && toy_packet < max_stops - 1) {
|
||||
toy_packet++;
|
||||
}
|
||||
}
|
||||
printCurrentModes();
|
||||
}
|
||||
};
|
||||
|
||||
btn_pcknum_inc.on_select = [this](Button&) {
|
||||
if (!button_onstate) {
|
||||
chk_mode_ncnt.set_value(true);
|
||||
if (n_message_set < n_message_max) {
|
||||
n_message_set++;
|
||||
} else {
|
||||
n_message_set = 0;
|
||||
}
|
||||
message_num.set_value(n_message_set);
|
||||
n_message_current = n_message_set;
|
||||
}
|
||||
};
|
||||
|
||||
btn_pcknum_dec.on_select = [this](Button&) {
|
||||
if (!button_onstate) {
|
||||
chk_mode_ncnt.set_value(true);
|
||||
if (n_message_set > 0) {
|
||||
n_message_set--;
|
||||
} else {
|
||||
n_message_set = n_message_max;
|
||||
}
|
||||
message_num.set_value(n_message_set);
|
||||
n_message_current = n_message_set;
|
||||
}
|
||||
};
|
||||
|
||||
message_num.on_change = [this](int32_t v) {
|
||||
if (!button_onstate) {
|
||||
chk_mode_ncnt.set_value(true);
|
||||
n_message_set = static_cast<uint16_t>(v);
|
||||
n_message_current = n_message_set;
|
||||
} else {
|
||||
if (!button_onstate) message_num.set_value(n_message_current);
|
||||
}
|
||||
};
|
||||
|
||||
chk_mode_rnd.on_select = [this](Checkbox&, bool v) {
|
||||
random_running = v;
|
||||
};
|
||||
|
||||
chk_mode_play.on_select = [this](Checkbox&, bool v) {
|
||||
play_running = v;
|
||||
if (play_running && stop_running) {
|
||||
toy_packet = 0;
|
||||
stop_running = false;
|
||||
chk_mode_stop.set_value(stop_running);
|
||||
}
|
||||
if (play_running) printCurrentModes();
|
||||
};
|
||||
|
||||
chk_mode_stop.on_select = [this](Checkbox&, bool v) {
|
||||
stop_running = v;
|
||||
if (play_running && stop_running) {
|
||||
toy_packet = 0;
|
||||
play_running = false;
|
||||
chk_mode_play.set_value(play_running);
|
||||
}
|
||||
if (stop_running) printCurrentModes();
|
||||
};
|
||||
|
||||
chk_mode_ncnt.on_select = [this](Checkbox&, bool v) {
|
||||
n_message_running = v;
|
||||
if (n_message_running && inf_message_running) {
|
||||
inf_message_running = false;
|
||||
chk_mode_infinite.set_value(inf_message_running);
|
||||
}
|
||||
};
|
||||
|
||||
chk_mode_infinite.on_select = [this](Checkbox&, bool v) {
|
||||
inf_message_running = v;
|
||||
if (n_message_running && inf_message_running) {
|
||||
n_message_running = false;
|
||||
chk_mode_ncnt.set_value(n_message_running);
|
||||
}
|
||||
};
|
||||
options_target.on_change = [this](size_t, int32_t i) {
|
||||
target = (uint8_t)i;
|
||||
};
|
||||
|
||||
chk_mode_infinite.set_value(true);
|
||||
chk_mode_play.set_value(true);
|
||||
}
|
||||
|
||||
void AdultToysView::hidden_program(bool hide) {
|
||||
options_target.hidden(hide);
|
||||
labels.hidden(hide);
|
||||
button_on.hidden(hide);
|
||||
btn_mode_decrease.hidden(hide);
|
||||
btn_mode_increase.hidden(hide);
|
||||
btn_pcknum_inc.hidden(hide);
|
||||
btn_pcknum_dec.hidden(hide);
|
||||
chk_mode_rnd.hidden(hide);
|
||||
chk_mode_play.hidden(hide);
|
||||
chk_mode_stop.hidden(hide);
|
||||
chk_mode_ncnt.hidden(hide);
|
||||
chk_mode_infinite.hidden(hide);
|
||||
field_frequency.hidden(hide);
|
||||
txt_selected_mode.hidden(hide);
|
||||
message_num.hidden(hide);
|
||||
tx_view.hidden(hide);
|
||||
btn_adult.hidden(!hide);
|
||||
btn_child.hidden(!hide);
|
||||
screen_message_1.hidden(!hide);
|
||||
screen_message_2.hidden(!hide);
|
||||
screen_message_3.hidden(!hide);
|
||||
screen_message_4.hidden(!hide);
|
||||
screen_message_5.hidden(!hide);
|
||||
screen_message_6.hidden(!hide);
|
||||
screen_message_7.hidden(!hide);
|
||||
screen_message_8.hidden(!hide);
|
||||
screen_message_9.hidden(!hide);
|
||||
screen_message_10.hidden(!hide);
|
||||
set_dirty();
|
||||
if (hide)
|
||||
btn_child.focus();
|
||||
else
|
||||
button_on.focus();
|
||||
}
|
||||
|
||||
void AdultToysView::on_show() {
|
||||
hidden_program(!start_screen);
|
||||
}
|
||||
|
||||
void AdultToysView::createPacket(bool regenerate) {
|
||||
if (regenerate) randomizeMac();
|
||||
randomChn();
|
||||
if (target == 1 || 1) { // now only lovespouse supported, in the future, need to separee them
|
||||
uint32_t mode = play_running ? plays[toy_packet].value : stops[toy_packet].value;
|
||||
|
||||
const uint8_t size = 22;
|
||||
uint8_t packet[size];
|
||||
uint8_t i = 0;
|
||||
|
||||
// 1. AD Flags
|
||||
packet[i++] = 2;
|
||||
packet[i++] = 0x01;
|
||||
packet[i++] = 0x1A;
|
||||
|
||||
// 2. Manufacturer Specific
|
||||
packet[i++] = 14;
|
||||
packet[i++] = 0xFF;
|
||||
packet[i++] = 0xFF;
|
||||
packet[i++] = 0x00;
|
||||
packet[i++] = 0x6D;
|
||||
packet[i++] = 0xB6;
|
||||
packet[i++] = 0x43;
|
||||
packet[i++] = 0xCE;
|
||||
packet[i++] = 0x97;
|
||||
packet[i++] = 0xFE;
|
||||
packet[i++] = 0x42;
|
||||
packet[i++] = 0x7C;
|
||||
packet[i++] = (mode >> 0x10) & 0xFF;
|
||||
packet[i++] = (mode >> 0x8) & 0xFF;
|
||||
packet[i++] = (mode >> 0x0) & 0xFF;
|
||||
|
||||
// 3. Service UUID List
|
||||
packet[i++] = 3;
|
||||
packet[i++] = 0x03;
|
||||
packet[i++] = 0x8F;
|
||||
packet[i++] = 0xAE;
|
||||
|
||||
std::string res = to_string_hex_array(packet, i);
|
||||
|
||||
memset(advertisementData, 0, sizeof(advertisementData));
|
||||
std::copy(res.begin(), res.end(), advertisementData);
|
||||
}
|
||||
}
|
||||
|
||||
AdultToysView::~AdultToysView() {
|
||||
stop();
|
||||
}
|
||||
|
||||
void AdultToysView::stop() {
|
||||
transmitter_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
void AdultToysView::start() {
|
||||
baseband::run_image(portapack::spi_flash::image_tag_btle_tx);
|
||||
transmitter_model.enable();
|
||||
on_tx_progress(true);
|
||||
}
|
||||
|
||||
void AdultToysView::reset() {
|
||||
stop();
|
||||
start();
|
||||
}
|
||||
|
||||
uint8_t AdultToysView::randomize(uint8_t max) {
|
||||
return static_cast<uint8_t>(rand() % max);
|
||||
}
|
||||
|
||||
void AdultToysView::printCurrentModes() {
|
||||
uint8_t max_val = play_running ? max_plays : max_stops;
|
||||
auto name = play_running ? plays[toy_packet].name : stops[toy_packet].name;
|
||||
std::string current = to_string_dec_uint(toy_packet + 1);
|
||||
std::string max_val_str = to_string_dec_uint(max_val);
|
||||
|
||||
std::string result_str = current;
|
||||
result_str += "/";
|
||||
result_str += max_val_str;
|
||||
result_str += " ";
|
||||
result_str += name;
|
||||
txt_selected_mode.set(result_str.c_str());
|
||||
}
|
||||
|
||||
uint64_t AdultToysView::get_freq_by_channel_number(uint8_t channel_number) {
|
||||
uint64_t freq_hz;
|
||||
|
||||
switch (channel_number) {
|
||||
case 37:
|
||||
freq_hz = 2'402'000'000ull;
|
||||
break;
|
||||
case 38:
|
||||
freq_hz = 2'426'000'000ull;
|
||||
break;
|
||||
case 39:
|
||||
freq_hz = 2'480'000'000ull;
|
||||
break;
|
||||
case 0 ... 10:
|
||||
freq_hz = 2'404'000'000ull + channel_number * 2'000'000ull;
|
||||
break;
|
||||
case 11 ... 36:
|
||||
freq_hz = 2'428'000'000ull + (channel_number - 11) * 2'000'000ull;
|
||||
break;
|
||||
default:
|
||||
freq_hz = UINT64_MAX;
|
||||
}
|
||||
|
||||
return freq_hz;
|
||||
}
|
||||
|
||||
void AdultToysView::randomizeMac() {
|
||||
const char hexDigits[] = "0123456789ABCDEF";
|
||||
// Generate 12 random hexadecimal characters
|
||||
for (int i = 0; i < 12; ++i) {
|
||||
int randomIndex = rand() % 16;
|
||||
mac[i] = hexDigits[randomIndex];
|
||||
}
|
||||
mac[12] = '\0'; // Null-terminate the string
|
||||
}
|
||||
|
||||
void AdultToysView::randomChn() {
|
||||
channel_number = 37 + rand() % (39 - 37 + 1);
|
||||
field_frequency.set_value(get_freq_by_channel_number(channel_number));
|
||||
}
|
||||
|
||||
void AdultToysView::on_tx_progress(const bool done) {
|
||||
if (!done) return;
|
||||
if (!button_onstate) return;
|
||||
bool regenerate = (counter++ % 600) == 0;
|
||||
if (random_running && regenerate) {
|
||||
toy_packet = randomize(play_running ? max_plays : max_stops);
|
||||
}
|
||||
createPacket(regenerate);
|
||||
printCurrentModes();
|
||||
|
||||
if (n_message_running) {
|
||||
if (n_message_current > 0) {
|
||||
n_message_current--;
|
||||
message_num.set_value(n_message_current);
|
||||
} else {
|
||||
stop();
|
||||
message_num.set_value(n_message_set);
|
||||
button_on.set_text(LanguageHelper::currentMessages[LANG_START]);
|
||||
button_onstate = false;
|
||||
n_message_current = n_message_set;
|
||||
return;
|
||||
}
|
||||
} // if n_message
|
||||
|
||||
baseband::set_btletx(channel_number, mac, advertisementData, pduType);
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::adult_toys_controller
|
||||
+245
@@ -0,0 +1,245 @@
|
||||
/*
|
||||
* Copyright (C) 2025 Pezsma
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
// Code from https://github.com/Next-Flip/Momentum-Apps/blob/89d493daa1ea0cb86906fa0042c41dd4edc22a6a/ble_spam/protocols/lovespouse.c#L93
|
||||
// Thanks for the work of the original creators!
|
||||
|
||||
#ifndef __UI_ADULT_TOYS_H__
|
||||
#define __UI_ADULT_TOYS_H__
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_language.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_transmitter.hpp"
|
||||
#include "ui_freq_field.hpp"
|
||||
#include "ui_record_view.hpp"
|
||||
#include "app_settings.hpp"
|
||||
#include "radio_state.hpp"
|
||||
#include "log_file.hpp"
|
||||
#include "utility.hpp"
|
||||
|
||||
using namespace ui;
|
||||
|
||||
namespace ui::external_app::adult_toys_controller {
|
||||
|
||||
enum PKT_TYPE {
|
||||
PKT_TYPE_INVALID_TYPE,
|
||||
PKT_TYPE_RAW,
|
||||
PKT_TYPE_DISCOVERY,
|
||||
PKT_TYPE_IBEACON,
|
||||
PKT_TYPE_ADV_IND,
|
||||
PKT_TYPE_ADV_DIRECT_IND,
|
||||
PKT_TYPE_ADV_NONCONN_IND,
|
||||
PKT_TYPE_ADV_SCAN_IND,
|
||||
PKT_TYPE_SCAN_REQ,
|
||||
PKT_TYPE_SCAN_RSP,
|
||||
PKT_TYPE_CONNECT_REQ,
|
||||
PKT_TYPE_LL_DATA,
|
||||
PKT_TYPE_LL_CONNECTION_UPDATE_REQ,
|
||||
PKT_TYPE_LL_CHANNEL_MAP_REQ,
|
||||
PKT_TYPE_LL_TERMINATE_IND,
|
||||
PKT_TYPE_LL_ENC_REQ,
|
||||
PKT_TYPE_LL_ENC_RSP,
|
||||
PKT_TYPE_LL_START_ENC_REQ,
|
||||
PKT_TYPE_LL_START_ENC_RSP,
|
||||
PKT_TYPE_LL_UNKNOWN_RSP,
|
||||
PKT_TYPE_LL_FEATURE_REQ,
|
||||
PKT_TYPE_LL_FEATURE_RSP,
|
||||
PKT_TYPE_LL_PAUSE_ENC_REQ,
|
||||
PKT_TYPE_LL_PAUSE_ENC_RSP,
|
||||
PKT_TYPE_LL_VERSION_IND,
|
||||
PKT_TYPE_LL_REJECT_IND,
|
||||
PKT_TYPE_NUM_PKT_TYPE
|
||||
};
|
||||
|
||||
class AdultToysView : public ui::View {
|
||||
public:
|
||||
AdultToysView(NavigationView& nav);
|
||||
~AdultToysView();
|
||||
|
||||
void focus() override;
|
||||
void on_show() override;
|
||||
|
||||
std::string title() const override {
|
||||
return "Adult Toys";
|
||||
};
|
||||
|
||||
struct LovespouseMode {
|
||||
uint32_t value;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
TxRadioState radio_state_{
|
||||
2'402'000'000 /* frequency */,
|
||||
4'000'000 /* bandwidth */,
|
||||
4'000'000 /* sampling rate */
|
||||
};
|
||||
|
||||
TxFrequencyField field_frequency{
|
||||
{UI_POS_X(0), UI_POS_Y(0)},
|
||||
nav_};
|
||||
|
||||
TransmitterView2 tx_view{
|
||||
{UI_POS_X(11), UI_POS_Y(0)},
|
||||
/*short_ui*/ true};
|
||||
|
||||
app_settings::SettingsManager settings_{
|
||||
"tx_adult_toys", app_settings::Mode::TX};
|
||||
|
||||
OptionsField options_target{
|
||||
{UI_POS_X(6), UI_POS_Y(1)},
|
||||
11,
|
||||
{{"LoveSpouse", 1}}};
|
||||
|
||||
Button btn_adult{{UI_POS_X(0), UI_POS_Y_BOTTOM(4), UI_POS_WIDTH(10), UI_POS_HEIGHT(3)}, "adult"};
|
||||
|
||||
Button btn_child{{UI_POS_X_RIGHT(10), UI_POS_Y_BOTTOM(4), UI_POS_WIDTH(10), UI_POS_HEIGHT(3)}, "child"};
|
||||
|
||||
Button button_on{
|
||||
{UI_POS_X(0), UI_POS_Y(3), UI_POS_WIDTH(12), UI_POS_HEIGHT(2)},
|
||||
LanguageHelper::currentMessages[LANG_START]};
|
||||
|
||||
Button btn_mode_decrease{
|
||||
{UI_POS_X(0), UI_POS_Y(13), UI_POS_WIDTH(3), UI_POS_HEIGHT(2)},
|
||||
"<-"};
|
||||
|
||||
Button btn_mode_increase{
|
||||
{UI_POS_X_RIGHT(3), UI_POS_Y(13), UI_POS_WIDTH(3), UI_POS_HEIGHT(2)},
|
||||
"->"};
|
||||
|
||||
Text txt_selected_mode{{UI_POS_X_CENTER(22), UI_POS_Y(13.5), UI_POS_WIDTH(22), UI_POS_HEIGHT(1)}, ""};
|
||||
|
||||
Button btn_pcknum_inc{
|
||||
{UI_POS_X(7), UI_POS_Y(9), UI_POS_WIDTH(2), UI_POS_HEIGHT(1.5)},
|
||||
"+"};
|
||||
|
||||
Button btn_pcknum_dec{
|
||||
{UI_POS_X(0), UI_POS_Y(9), UI_POS_WIDTH(2), UI_POS_HEIGHT(1.5)},
|
||||
"-"};
|
||||
|
||||
NumberField message_num{{UI_POS_X(3), UI_POS_Y(9.2)}, 3, {0, 999}, 1, ' ', true};
|
||||
|
||||
Checkbox chk_mode_rnd{{UI_POS_X_RIGHT(15), UI_POS_Y(3)}, 12, "Random Msg.", false};
|
||||
Checkbox chk_mode_play{{UI_POS_X_RIGHT(15), UI_POS_Y(5)}, 10, "Play Mode", false};
|
||||
Checkbox chk_mode_stop{{UI_POS_X_RIGHT(15), UI_POS_Y(7)}, 10, "Stop Mode", false};
|
||||
Checkbox chk_mode_ncnt{{UI_POS_X_RIGHT(15), UI_POS_Y(9)}, 7, "N Msg.", false};
|
||||
Checkbox chk_mode_infinite{{UI_POS_X_RIGHT(15), UI_POS_Y(11)}, 10, "Inf. Msg.", false};
|
||||
|
||||
Text screen_message_1{{0, 0, UI_POS_MAXWIDTH, UI_POS_HEIGHT(1)}, "The application is intended"};
|
||||
Text screen_message_2{{0, 25, UI_POS_MAXWIDTH, UI_POS_HEIGHT(1)}, "for controlling Love Spouse"};
|
||||
Text screen_message_3{{0, 50, UI_POS_MAXWIDTH, UI_POS_HEIGHT(1)}, "auxiliary tools/devices."};
|
||||
Text screen_message_4{{0, 75, UI_POS_MAXWIDTH, UI_POS_HEIGHT(1)}, "It is only for use by adults."};
|
||||
Text screen_message_5{{0, 100, UI_POS_MAXWIDTH, UI_POS_HEIGHT(1)}, "Are you an adult?"};
|
||||
|
||||
Text screen_message_6{{0, 140, UI_POS_MAXWIDTH, UI_POS_HEIGHT(1)}, "To use the application, "};
|
||||
Text screen_message_7{{0, 165, UI_POS_MAXWIDTH, UI_POS_HEIGHT(1)}, "I assume full responsibility"};
|
||||
Text screen_message_8{{0, 190, UI_POS_MAXWIDTH, UI_POS_HEIGHT(1)}, "for the \"I do not assume"};
|
||||
Text screen_message_9{{0, 215, UI_POS_MAXWIDTH, UI_POS_HEIGHT(1)}, "responsibility\"."};
|
||||
Text screen_message_10{{UI_POS_X_RIGHT(16), 230, UI_POS_WIDTH(16), UI_POS_HEIGHT(1)}, "(The developer)"};
|
||||
|
||||
Labels labels{
|
||||
{{UI_POS_X(0), UI_POS_Y(1)}, "Type:", Theme::getInstance()->fg_light->foreground}};
|
||||
|
||||
bool button_onstate{false};
|
||||
bool play_running{false};
|
||||
bool stop_running{false};
|
||||
bool random_running{false};
|
||||
bool n_message_running{false};
|
||||
bool inf_message_running{false};
|
||||
bool start_screen{false};
|
||||
|
||||
uint8_t target = 1; // lovespouse
|
||||
|
||||
char mac[13] = "010203040506";
|
||||
uint8_t channel_number = 37;
|
||||
char advertisementData[63] = {"03032CFE06162CFED5A59E020AB4\0"};
|
||||
|
||||
PKT_TYPE pduType = {PKT_TYPE_DISCOVERY};
|
||||
|
||||
uint8_t toy_packet = 0;
|
||||
uint16_t n_message_max = 999;
|
||||
uint16_t n_message_set = 0;
|
||||
uint16_t n_message_current = 0;
|
||||
static const size_t max_plays = 27;
|
||||
static const size_t max_stops = 3;
|
||||
|
||||
uint16_t counter = 599;
|
||||
|
||||
void createPacket(bool regenerate);
|
||||
void start();
|
||||
void stop();
|
||||
void reset();
|
||||
void printCurrentModes();
|
||||
void on_tx_progress(const bool done);
|
||||
void hidden_program(bool hide);
|
||||
void randomizeMac();
|
||||
void randomChn();
|
||||
uint8_t randomize(uint8_t max);
|
||||
uint64_t get_freq_by_channel_number(uint8_t channel_number);
|
||||
|
||||
MessageHandlerRegistration message_handler_tx_progress{
|
||||
Message::ID::TXProgress,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const TXProgressMessage*>(p);
|
||||
this->on_tx_progress(message.done);
|
||||
}};
|
||||
|
||||
LovespouseMode plays[max_plays] = {
|
||||
{0xE49C6C, "Classic 1"},
|
||||
{0xE7075E, "Classic 2"},
|
||||
{0xE68E4F, "Classic 3"},
|
||||
{0xE1313B, "Classic 4"},
|
||||
{0xE0B82A, "Classic 5"},
|
||||
{0xE32318, "Classic 6"},
|
||||
{0xE2AA09, "Classic 7"},
|
||||
{0xED5DF1, "Classic 8"},
|
||||
{0xECD4E0, "Classic 9"},
|
||||
{0xD41F5D, "Independent 1-1"},
|
||||
{0xD7846F, "Independent 1-2"},
|
||||
{0xD60D7E, "Independent 1-3"},
|
||||
{0xD1B20A, "Independent 1-4"},
|
||||
{0xD0B31B, "Independent 1-5"},
|
||||
{0xD3A029, "Independent 1-6"},
|
||||
{0xD22938, "Independent 1-7"},
|
||||
{0xDDDEC0, "Independent 1-8"},
|
||||
{0xDC57D1, "Independent 1-9"},
|
||||
{0xA4982E, "Independent 2-1"},
|
||||
{0xA7031C, "Independent 2-2"},
|
||||
{0xA68A0D, "Independent 2-3"},
|
||||
{0xA13579, "Independent 2-4"},
|
||||
{0xA0BC68, "Independent 2-5"},
|
||||
{0xA3275A, "Independent 2-6"},
|
||||
{0xA2AE4B, "Independent 2-7"},
|
||||
{0xAD59B3, "Independent 2-8"},
|
||||
{0xACD0A2, "Independent 2-9"},
|
||||
};
|
||||
|
||||
LovespouseMode stops[max_stops] = {
|
||||
{0xE5157D, "Classic Stop"},
|
||||
{0xD5964C, "Independent 1 Stop"},
|
||||
{0xA5113F, "Independent 2 Stop"},
|
||||
};
|
||||
};
|
||||
}; // namespace ui::external_app::adult_toys_controller
|
||||
|
||||
#endif // ui_adult_toys_controller_hpp
|
||||
+2
-2
@@ -34,7 +34,7 @@ using namespace portapack;
|
||||
#include <cmath>
|
||||
#include <array>
|
||||
|
||||
namespace ui {
|
||||
namespace ui::external_app::analogtv {
|
||||
namespace tv {
|
||||
|
||||
/* TimeScopeView******************************************************/
|
||||
@@ -235,4 +235,4 @@ void TVWidget::on_audio_spectrum() {
|
||||
}
|
||||
|
||||
} /* namespace tv */
|
||||
} /* namespace ui */
|
||||
} // namespace ui::external_app::analogtv
|
||||
+2
-2
@@ -33,7 +33,7 @@
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
namespace ui {
|
||||
namespace ui::external_app::analogtv {
|
||||
namespace tv {
|
||||
|
||||
class TimeScopeView : public View {
|
||||
@@ -167,6 +167,6 @@ class TVWidget : public View {
|
||||
};
|
||||
|
||||
} /* namespace tv */
|
||||
} /* namespace ui */
|
||||
} // namespace ui::external_app::analogtv
|
||||
|
||||
#endif /*__UI_TV_H__*/
|
||||
+38
-25
@@ -62,19 +62,24 @@ AppManagerView::AppManagerView(NavigationView& nav)
|
||||
auto app_name = get_app_info(menu_view.highlighted_index(), true);
|
||||
auto app_id = get_app_info(menu_view.highlighted_index(), false);
|
||||
|
||||
info += "Hidden:";
|
||||
if (!app_name.empty()) {
|
||||
info += "Hidden:";
|
||||
|
||||
if (is_blacklisted(app_name)) {
|
||||
info += "Yes ";
|
||||
} else {
|
||||
info += "No ";
|
||||
if (is_blacklisted(app_name)) {
|
||||
info += "Yes ";
|
||||
} else {
|
||||
info += "No ";
|
||||
}
|
||||
}
|
||||
|
||||
info += "Autostart:";
|
||||
if (is_autostart_app(app_id)) {
|
||||
info += "Yes";
|
||||
} else {
|
||||
info += "No";
|
||||
if (!app_id.empty()) {
|
||||
info += "Autostart:";
|
||||
|
||||
if (is_autostart_app(app_id)) {
|
||||
info += "Yes";
|
||||
} else {
|
||||
info += "No";
|
||||
}
|
||||
}
|
||||
|
||||
if (info.empty()) {
|
||||
@@ -82,6 +87,8 @@ AppManagerView::AppManagerView(NavigationView& nav)
|
||||
}
|
||||
|
||||
text_app_info.set(info);
|
||||
button_hide_unhide.set_focusable(!app_name.empty());
|
||||
button_set_cancel_autostart.set_focusable(!app_id.empty());
|
||||
};
|
||||
|
||||
button_hide_unhide.on_select = [this](Button&) {
|
||||
@@ -120,27 +127,23 @@ void AppManagerView::refresh_list() {
|
||||
};
|
||||
|
||||
for (auto& app : NavigationView::appList) {
|
||||
if (app.id == nullptr) continue;
|
||||
|
||||
app_list_index++;
|
||||
|
||||
menu_view.add_item({app.displayName + std::string(is_autostart_app(app.id) ? padding(app.displayName) : ""),
|
||||
menu_view.add_item({app.displayName + std::string((app.id != nullptr && is_autostart_app(app.id)) ? padding(app.displayName) : ""),
|
||||
app.iconColor,
|
||||
app.icon,
|
||||
[this, app_id = std::string(app.id)](KeyEvent) {
|
||||
[this, app_id = std::string(app.id != nullptr ? app.id : "")](KeyEvent) {
|
||||
button_hide_unhide.focus();
|
||||
}});
|
||||
}
|
||||
|
||||
ExternalItemsMenuLoader::load_all_external_items_callback([this, &index, &padding](ui::AppInfoConsole& app) {
|
||||
if (app.appCallName == nullptr) return;
|
||||
|
||||
app_list_index++;
|
||||
|
||||
menu_view.add_item({app.appFriendlyName + std::string(is_autostart_app(app.appCallName) ? padding(app.appFriendlyName) : ""),
|
||||
menu_view.add_item({app.appFriendlyName + std::string((app.appCallName != nullptr && is_autostart_app(app.appCallName)) ? padding(app.appFriendlyName) : ""),
|
||||
ui::Color::light_grey(),
|
||||
&bitmap_icon_sdcard,
|
||||
[this, app_id = std::string(app.appCallName)](KeyEvent) {
|
||||
[this, app_id = std::string(app.appCallName != nullptr ? app.appCallName : "")](KeyEvent) {
|
||||
button_hide_unhide.focus();
|
||||
}});
|
||||
});
|
||||
@@ -156,19 +159,29 @@ void AppManagerView::hide_app() {
|
||||
std::vector<std::string> blacklist;
|
||||
get_blacklist(blacklist);
|
||||
|
||||
blacklist.push_back(get_app_info(menu_view.highlighted_index(), true));
|
||||
auto app_name = get_app_info(menu_view.highlighted_index(), true);
|
||||
if (app_name.empty()) return;
|
||||
|
||||
blacklist.push_back(app_name);
|
||||
write_blacklist(blacklist);
|
||||
}
|
||||
|
||||
void AppManagerView::unhide_app() {
|
||||
std::vector<std::string> blacklist;
|
||||
get_blacklist(blacklist);
|
||||
blacklist.erase(std::remove(blacklist.begin(), blacklist.end(), get_app_info(menu_view.highlighted_index(), true)), blacklist.end());
|
||||
|
||||
auto app_name = get_app_info(menu_view.highlighted_index(), true);
|
||||
if (app_name.empty()) return;
|
||||
|
||||
blacklist.erase(std::remove(blacklist.begin(), blacklist.end(), app_name), blacklist.end());
|
||||
write_blacklist(blacklist);
|
||||
}
|
||||
|
||||
void AppManagerView::hide_unhide_app() {
|
||||
if (is_blacklisted(get_app_info(menu_view.highlighted_index(), true)))
|
||||
auto app_name = get_app_info(menu_view.highlighted_index(), true);
|
||||
if (app_name.empty()) return;
|
||||
|
||||
if (is_blacklisted(app_name))
|
||||
unhide_app();
|
||||
else
|
||||
hide_app();
|
||||
@@ -218,6 +231,7 @@ void AppManagerView::set_auto_start() {
|
||||
if (app_index >= app_list_index) return;
|
||||
|
||||
auto id_aka_app_call_name = get_app_info(app_index, false);
|
||||
if (id_aka_app_call_name.empty()) return;
|
||||
|
||||
autostart_app = id_aka_app_call_name;
|
||||
|
||||
@@ -234,6 +248,7 @@ void AppManagerView::set_unset_autostart_app() {
|
||||
if (app_index >= app_list_index) return;
|
||||
|
||||
auto id_aka_friendly_name = get_app_info(app_index, false);
|
||||
if (id_aka_friendly_name.empty()) return;
|
||||
|
||||
if (is_autostart_app(id_aka_friendly_name))
|
||||
unset_auto_start();
|
||||
@@ -254,17 +269,15 @@ std::string AppManagerView::get_app_info(uint16_t index, bool is_display_name) {
|
||||
std::string result;
|
||||
|
||||
for (auto& app : NavigationView::appList) {
|
||||
if (app.id == nullptr) continue;
|
||||
if (current_index == index) {
|
||||
return is_display_name ? std::string(app.displayName) : std::string(app.id);
|
||||
return is_display_name ? std::string(app.displayName != nullptr ? app.displayName : "") : std::string(app.id != nullptr ? app.id : "");
|
||||
}
|
||||
current_index++;
|
||||
}
|
||||
|
||||
ExternalItemsMenuLoader::load_all_external_items_callback([¤t_index, &index, &result, &is_display_name](ui::AppInfoConsole& app) {
|
||||
if (app.appCallName == nullptr) return;
|
||||
if (current_index == index) {
|
||||
result = is_display_name ? app.appFriendlyName : app.appCallName;
|
||||
result = is_display_name ? (app.appFriendlyName != nullptr ? app.appFriendlyName : "") : (app.appCallName != nullptr ? app.appCallName : "");
|
||||
}
|
||||
current_index++;
|
||||
});
|
||||
|
||||
+75
-127
@@ -24,25 +24,25 @@ constexpr uint32_t BLUE_TEAM_ADDRESS = BATTLESHIP_BASE_ADDRESS + 2;
|
||||
|
||||
BattleshipView::BattleshipView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
CELL_SIZE = screen_width / GRID_SIZE;
|
||||
baseband::run_image(portapack::spi_flash::image_tag_pocsag2);
|
||||
|
||||
add_children({&text_title, &text_subtitle,
|
||||
&rect_radio_settings, &label_radio, &button_frequency,
|
||||
//&rect_radio_settings, &rect_audio_settings, &rect_team_selection,
|
||||
&label_radio, &button_frequency,
|
||||
&label_rf_amp, &checkbox_rf_amp,
|
||||
&label_lna, &field_lna,
|
||||
&label_vga, &field_vga,
|
||||
&label_tx_gain, &field_tx_gain,
|
||||
&rect_audio_settings, &label_audio,
|
||||
&label_audio,
|
||||
&checkbox_sound, &label_volume, &field_volume,
|
||||
&rect_team_selection, &label_team,
|
||||
&label_team,
|
||||
&button_red_team, &button_blue_team,
|
||||
&rssi, &text_status, &text_score,
|
||||
&rssi,
|
||||
&button_rotate, &button_place, &button_fire, &button_menu});
|
||||
|
||||
// Hide in-game elements
|
||||
rssi.hidden(true);
|
||||
text_status.hidden(true);
|
||||
text_score.hidden(true);
|
||||
button_rotate.hidden(true);
|
||||
button_place.hidden(true);
|
||||
button_fire.hidden(true);
|
||||
@@ -151,8 +151,8 @@ BattleshipView::BattleshipView(NavigationView& nav)
|
||||
field_tx_gain.set_parent_rect({185, 118, 32, 16});
|
||||
checkbox_sound.set_parent_rect({17, 187, 80, 24});
|
||||
field_volume.set_parent_rect({165, 187, 32, 16});
|
||||
button_red_team.set_parent_rect({25, 242, 85, 45});
|
||||
button_blue_team.set_parent_rect({130, 242, 85, 45});
|
||||
// button_red_team.set_parent_rect({25, 242, 85, 45});
|
||||
// button_blue_team.set_parent_rect({130, 242, 85, 45});
|
||||
|
||||
// Make menu elements focusable
|
||||
button_frequency.set_focusable(true);
|
||||
@@ -191,11 +191,42 @@ void BattleshipView::init_game() {
|
||||
enemy_grid[y][x] = CellState::EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
setup_ships();
|
||||
update_score();
|
||||
}
|
||||
|
||||
void BattleshipView::show_hide_menu(bool menu_vis) {
|
||||
text_title.hidden(!menu_vis);
|
||||
text_subtitle.hidden(!menu_vis);
|
||||
// rect_radio_settings.hidden(!menu_vis); rect_audio_settings.hidden(!menu_vis); rect_team_selection.hidden(!menu_vis);
|
||||
label_radio.hidden(!menu_vis);
|
||||
button_frequency.hidden(!menu_vis);
|
||||
label_rf_amp.hidden(!menu_vis);
|
||||
checkbox_rf_amp.hidden(!menu_vis);
|
||||
label_lna.hidden(!menu_vis);
|
||||
field_lna.hidden(!menu_vis);
|
||||
label_vga.hidden(!menu_vis);
|
||||
field_vga.hidden(!menu_vis);
|
||||
label_tx_gain.hidden(!menu_vis);
|
||||
field_tx_gain.hidden(!menu_vis);
|
||||
label_audio.hidden(!menu_vis);
|
||||
checkbox_sound.hidden(!menu_vis);
|
||||
label_volume.hidden(!menu_vis);
|
||||
field_volume.hidden(!menu_vis);
|
||||
label_team.hidden(!menu_vis);
|
||||
button_red_team.hidden(!menu_vis);
|
||||
button_blue_team.hidden(!menu_vis);
|
||||
rssi.hidden(menu_vis);
|
||||
button_rotate.hidden(menu_vis);
|
||||
button_place.hidden(menu_vis);
|
||||
button_menu.hidden(menu_vis);
|
||||
|
||||
// button_rotate.set_focusable(false); //no need, since can't focus on hidden
|
||||
// button_place.set_focusable(false);
|
||||
// button_menu.set_focusable(false);
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
void BattleshipView::reset_game() {
|
||||
transmitter_model.disable();
|
||||
receiver_model.disable();
|
||||
@@ -221,50 +252,7 @@ void BattleshipView::reset_game() {
|
||||
update_score();
|
||||
|
||||
// Toggle visibility
|
||||
bool menu_vis = true;
|
||||
bool game_vis = false;
|
||||
|
||||
text_title.hidden(!menu_vis);
|
||||
text_subtitle.hidden(!menu_vis);
|
||||
rect_radio_settings.hidden(!menu_vis);
|
||||
label_radio.hidden(!menu_vis);
|
||||
button_frequency.hidden(!menu_vis);
|
||||
label_rf_amp.hidden(!menu_vis);
|
||||
checkbox_rf_amp.hidden(!menu_vis);
|
||||
label_lna.hidden(!menu_vis);
|
||||
field_lna.hidden(!menu_vis);
|
||||
label_vga.hidden(!menu_vis);
|
||||
field_vga.hidden(!menu_vis);
|
||||
label_tx_gain.hidden(!menu_vis);
|
||||
field_tx_gain.hidden(!menu_vis);
|
||||
rect_audio_settings.hidden(!menu_vis);
|
||||
label_audio.hidden(!menu_vis);
|
||||
checkbox_sound.hidden(!menu_vis);
|
||||
label_volume.hidden(!menu_vis);
|
||||
field_volume.hidden(!menu_vis);
|
||||
rect_team_selection.hidden(!menu_vis);
|
||||
label_team.hidden(!menu_vis);
|
||||
button_red_team.hidden(!menu_vis);
|
||||
button_blue_team.hidden(!menu_vis);
|
||||
|
||||
rssi.hidden(!game_vis);
|
||||
text_status.hidden(!game_vis);
|
||||
text_score.hidden(!game_vis);
|
||||
button_rotate.hidden(!game_vis);
|
||||
button_place.hidden(!game_vis);
|
||||
button_fire.hidden(!game_vis);
|
||||
button_menu.hidden(!game_vis);
|
||||
|
||||
// Restore focusability
|
||||
button_frequency.set_focusable(menu_vis);
|
||||
checkbox_rf_amp.set_focusable(menu_vis);
|
||||
field_lna.set_focusable(menu_vis);
|
||||
field_vga.set_focusable(menu_vis);
|
||||
field_tx_gain.set_focusable(menu_vis);
|
||||
checkbox_sound.set_focusable(menu_vis);
|
||||
field_volume.set_focusable(menu_vis);
|
||||
button_red_team.set_focusable(menu_vis);
|
||||
button_blue_team.set_focusable(menu_vis);
|
||||
show_hide_menu(true);
|
||||
|
||||
button_frequency.focus();
|
||||
set_dirty();
|
||||
@@ -283,45 +271,10 @@ void BattleshipView::start_team(bool red) {
|
||||
game_state = GameState::PLACING_SHIPS;
|
||||
|
||||
// Toggle visibility
|
||||
bool menu_vis = false;
|
||||
bool game_vis = true;
|
||||
|
||||
text_title.hidden(!menu_vis);
|
||||
text_subtitle.hidden(!menu_vis);
|
||||
rect_radio_settings.hidden(!menu_vis);
|
||||
label_radio.hidden(!menu_vis);
|
||||
button_frequency.hidden(!menu_vis);
|
||||
label_rf_amp.hidden(!menu_vis);
|
||||
checkbox_rf_amp.hidden(!menu_vis);
|
||||
label_lna.hidden(!menu_vis);
|
||||
field_lna.hidden(!menu_vis);
|
||||
label_vga.hidden(!menu_vis);
|
||||
field_vga.hidden(!menu_vis);
|
||||
label_tx_gain.hidden(!menu_vis);
|
||||
field_tx_gain.hidden(!menu_vis);
|
||||
rect_audio_settings.hidden(!menu_vis);
|
||||
label_audio.hidden(!menu_vis);
|
||||
checkbox_sound.hidden(!menu_vis);
|
||||
label_volume.hidden(!menu_vis);
|
||||
field_volume.hidden(!menu_vis);
|
||||
rect_team_selection.hidden(!menu_vis);
|
||||
label_team.hidden(!menu_vis);
|
||||
button_red_team.hidden(!menu_vis);
|
||||
button_blue_team.hidden(!menu_vis);
|
||||
|
||||
rssi.hidden(!game_vis);
|
||||
text_status.hidden(true);
|
||||
text_score.hidden(true);
|
||||
button_rotate.hidden(false);
|
||||
button_place.hidden(false);
|
||||
button_menu.hidden(false);
|
||||
show_hide_menu(false);
|
||||
|
||||
current_status = "Place carrier (5)";
|
||||
|
||||
button_rotate.set_focusable(false);
|
||||
button_place.set_focusable(false);
|
||||
button_menu.set_focusable(false);
|
||||
|
||||
focus();
|
||||
is_transmitting = true;
|
||||
configure_radio_rx();
|
||||
@@ -382,7 +335,7 @@ void BattleshipView::configure_radio_rx() {
|
||||
}
|
||||
|
||||
void BattleshipView::paint(Painter& painter) {
|
||||
painter.fill_rectangle({0, 0, 240, 320}, Color::black());
|
||||
painter.fill_rectangle({0, 0, UI_POS_MAXWIDTH, UI_POS_MAXHEIGHT}, Color::black());
|
||||
|
||||
if (game_state == GameState::MENU) {
|
||||
draw_menu_screen(painter);
|
||||
@@ -426,24 +379,21 @@ void BattleshipView::paint(Painter& painter) {
|
||||
}
|
||||
|
||||
Color team_color = is_red_team ? Color::red() : Color::blue();
|
||||
painter.fill_rectangle({0, 5, 240, 16}, team_color);
|
||||
painter.fill_rectangle({0, 5, screen_width, 16}, team_color);
|
||||
|
||||
auto style_white = Style{
|
||||
.font = ui::font::fixed_8x16,
|
||||
.background = team_color,
|
||||
.foreground = Color::white()};
|
||||
painter.draw_string({85, 5}, style_white, is_red_team ? "RED TEAM" : "BLUE TEAM");
|
||||
painter.draw_string({UI_POS_X_CENTER(9), 5}, style_white, is_red_team ? "RED TEAM" : "BLUE TEAM");
|
||||
|
||||
auto style_status = Style{
|
||||
.font = ui::font::fixed_8x16,
|
||||
.background = Color::black(),
|
||||
.foreground = Color::white()};
|
||||
painter.fill_rectangle({0, 21, 240, 16}, Color::black());
|
||||
painter.draw_string({10, 21}, style_status, current_status);
|
||||
|
||||
if (game_state != GameState::MENU) {
|
||||
painter.draw_string({170, 21}, style_status, current_score);
|
||||
}
|
||||
painter.fill_rectangle({0, 21, screen_width, 16}, Color::black());
|
||||
painter.draw_string({5, 21}, style_status, current_status);
|
||||
painter.draw_string({170, 21}, style_status, current_score);
|
||||
|
||||
if (game_state == GameState::PLACING_SHIPS) {
|
||||
draw_grid(painter, GRID_OFFSET_X, GRID_OFFSET_Y + 5, my_grid, true);
|
||||
@@ -452,35 +402,35 @@ void BattleshipView::paint(Painter& painter) {
|
||||
}
|
||||
} else if (game_state == GameState::MY_TURN) {
|
||||
draw_grid(painter, GRID_OFFSET_X, GRID_OFFSET_Y + 5, enemy_grid, false, true);
|
||||
painter.draw_string({10, GRID_OFFSET_Y + GRID_SIZE * CELL_SIZE + 10}, style_status,
|
||||
"Enemy ships: " + to_string_dec_uint(enemy_ships_remaining));
|
||||
painter.draw_string({0, GRID_OFFSET_Y + GRID_SIZE * CELL_SIZE + 10}, style_status,
|
||||
"Enemy: " + to_string_dec_uint(enemy_ships_remaining));
|
||||
} else if (game_state == GameState::OPPONENT_TURN || game_state == GameState::WAITING_FOR_OPPONENT) {
|
||||
draw_grid(painter, GRID_OFFSET_X, GRID_OFFSET_Y + 5, my_grid, true);
|
||||
painter.draw_string({10, GRID_OFFSET_Y + GRID_SIZE * CELL_SIZE + 10}, style_status,
|
||||
"Your ships: " + to_string_dec_uint(ships_remaining));
|
||||
painter.draw_string({0, GRID_OFFSET_Y + GRID_SIZE * CELL_SIZE + 10}, style_status,
|
||||
"You: " + to_string_dec_uint(ships_remaining));
|
||||
} else if (game_state == GameState::GAME_OVER) {
|
||||
painter.draw_string({50, 150}, style_status, "Game Over!");
|
||||
painter.draw_string({UI_POS_X_CENTER(11), 150}, style_status, "Game Over!");
|
||||
painter.draw_string({30, 170}, style_status, current_status);
|
||||
}
|
||||
}
|
||||
|
||||
void BattleshipView::draw_menu_screen(Painter& painter) {
|
||||
painter.draw_hline({12, 38}, 216, Color::dark_cyan());
|
||||
painter.draw_hline({12, 20 + 16}, screen_width - 24, Color::dark_cyan());
|
||||
|
||||
painter.fill_rectangle({13, 41, 214, 116}, Color::dark_grey());
|
||||
painter.draw_hline({12, 40}, 216, Color::cyan());
|
||||
painter.draw_hline({12, 157}, 216, Color::cyan());
|
||||
painter.fill_rectangle({13, 59, screen_width - 26, 116}, Color::dark_grey());
|
||||
painter.draw_hline({12, 58}, screen_width - 24, Color::cyan());
|
||||
painter.draw_hline({12, 157}, screen_width - 24, Color::cyan());
|
||||
|
||||
painter.fill_rectangle({13, 165, 214, 43}, Color::dark_grey());
|
||||
painter.draw_hline({12, 164}, 216, Color::cyan());
|
||||
painter.draw_hline({12, 208}, 216, Color::cyan());
|
||||
painter.fill_rectangle({13, 165, screen_width - 24, 57}, Color::dark_grey());
|
||||
painter.draw_hline({12, 164}, screen_width - 24, Color::cyan());
|
||||
painter.draw_hline({12, 223}, screen_width - 24, Color::cyan());
|
||||
|
||||
painter.fill_rectangle({13, 218, 214, 73}, Color::dark_grey());
|
||||
painter.draw_hline({12, 217}, 216, Color::cyan());
|
||||
painter.draw_hline({12, 291}, 216, Color::cyan());
|
||||
painter.fill_rectangle({13, 232, screen_width - 26, 67}, Color::dark_grey());
|
||||
painter.draw_hline({12, 232}, screen_width - 24, Color::cyan());
|
||||
painter.draw_hline({12, 300}, screen_width - 24, Color::cyan());
|
||||
|
||||
// Radio status indicator
|
||||
Point indicator_pos{220, 53};
|
||||
Point indicator_pos{UI_POS_MAXWIDTH - 20, 59};
|
||||
if (is_transmitting) {
|
||||
painter.fill_rectangle({indicator_pos, {6, 6}}, Color::red());
|
||||
painter.draw_rectangle({indicator_pos.x() - 1, indicator_pos.y() - 1, 8, 8}, Color::light_grey());
|
||||
@@ -490,7 +440,7 @@ void BattleshipView::draw_menu_screen(Painter& painter) {
|
||||
}
|
||||
}
|
||||
|
||||
void BattleshipView::draw_grid(Painter& painter, uint8_t grid_x, uint8_t grid_y, const std::array<std::array<CellState, GRID_SIZE>, GRID_SIZE>& grid, bool show_ships, bool is_offense_grid) {
|
||||
void BattleshipView::draw_grid(Painter& painter, uint16_t grid_x, uint16_t grid_y, const std::array<std::array<CellState, GRID_SIZE>, GRID_SIZE>& grid, bool show_ships, bool is_offense_grid) {
|
||||
painter.fill_rectangle({grid_x, grid_y, GRID_SIZE * CELL_SIZE, GRID_SIZE * CELL_SIZE},
|
||||
Color::dark_blue());
|
||||
|
||||
@@ -501,26 +451,24 @@ void BattleshipView::draw_grid(Painter& painter, uint8_t grid_x, uint8_t grid_y,
|
||||
GRID_SIZE * CELL_SIZE, Color::grey());
|
||||
}
|
||||
|
||||
for (uint8_t y = 0; y < GRID_SIZE; y++) {
|
||||
for (uint8_t x = 0; x < GRID_SIZE; x++) {
|
||||
draw_cell(painter, grid_x + x * CELL_SIZE + 1, grid_y + y * CELL_SIZE + 1,
|
||||
grid[y][x], show_ships, is_offense_grid,
|
||||
is_cursor_at(x, y, is_offense_grid));
|
||||
for (uint16_t y = 0; y < GRID_SIZE; y++) {
|
||||
for (uint16_t x = 0; x < GRID_SIZE; x++) {
|
||||
draw_cell(painter, grid_x + x * CELL_SIZE + 1, grid_y + y * CELL_SIZE + 1, grid[y][x], show_ships, is_offense_grid, is_cursor_at(x, y, is_offense_grid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BattleshipView::draw_cell(Painter& painter, uint8_t cell_x, uint8_t cell_y, CellState state, bool show_ships, bool is_offense_grid, bool is_cursor) {
|
||||
void BattleshipView::draw_cell(Painter& painter, uint16_t cell_x, uint16_t cell_y, CellState state, bool show_ships, bool is_offense_grid, bool is_cursor) {
|
||||
Color cell_color = Color::dark_blue();
|
||||
bool should_fill = false;
|
||||
|
||||
if (game_state == GameState::PLACING_SHIPS && !is_offense_grid && current_ship_index < 5) {
|
||||
uint8_t ship_size = my_ships[current_ship_index].size();
|
||||
for (uint8_t i = 0; i < ship_size; i++) {
|
||||
uint8_t preview_x = placing_horizontal ? cursor_x + i : cursor_x;
|
||||
uint8_t preview_y = placing_horizontal ? cursor_y : cursor_y + i;
|
||||
uint8_t grid_x = (cell_x - 1) / CELL_SIZE;
|
||||
uint8_t grid_y = (cell_y - GRID_OFFSET_Y - 6) / CELL_SIZE;
|
||||
uint16_t preview_x = placing_horizontal ? cursor_x + i : cursor_x;
|
||||
uint16_t preview_y = placing_horizontal ? cursor_y : cursor_y + i;
|
||||
uint16_t grid_x = (cell_x - 1) / CELL_SIZE;
|
||||
uint16_t grid_y = (cell_y - GRID_OFFSET_Y - 6) / CELL_SIZE;
|
||||
if (grid_x == preview_x && grid_y == preview_y && preview_x < GRID_SIZE && preview_y < GRID_SIZE) {
|
||||
return;
|
||||
}
|
||||
@@ -597,8 +545,8 @@ void BattleshipView::draw_ship_preview(Painter& painter) {
|
||||
uint8_t y = placing_horizontal ? cursor_y : cursor_y + i;
|
||||
|
||||
if (x < GRID_SIZE && y < GRID_SIZE) {
|
||||
uint8_t cell_x = GRID_OFFSET_X + x * CELL_SIZE + 1;
|
||||
uint8_t cell_y = GRID_OFFSET_Y + 5 + y * CELL_SIZE + 1;
|
||||
uint16_t cell_x = GRID_OFFSET_X + x * CELL_SIZE + 1;
|
||||
uint16_t cell_y = GRID_OFFSET_Y + 5 + y * CELL_SIZE + 1;
|
||||
|
||||
Color preview_color = can_place ? Color::green() : Color::red();
|
||||
|
||||
|
||||
+26
-25
@@ -23,12 +23,9 @@
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace ui::external_app::battleship {
|
||||
#define GRID_SIZE 10
|
||||
|
||||
constexpr uint8_t GRID_SIZE = 10;
|
||||
constexpr uint8_t CELL_SIZE = 24;
|
||||
constexpr uint8_t GRID_OFFSET_X = 0;
|
||||
constexpr uint8_t GRID_OFFSET_Y = 32;
|
||||
namespace ui::external_app::battleship {
|
||||
|
||||
enum class ShipType : uint8_t {
|
||||
CARRIER = 5,
|
||||
@@ -103,6 +100,10 @@ class BattleshipView : public View {
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
uint16_t CELL_SIZE = 24;
|
||||
uint16_t GRID_OFFSET_X = 0;
|
||||
uint16_t GRID_OFFSET_Y = 32;
|
||||
|
||||
RxRadioState rx_radio_state_{
|
||||
433920000 /* frequency */,
|
||||
1750000 /* bandwidth */,
|
||||
@@ -163,11 +164,11 @@ class BattleshipView : public View {
|
||||
uint32_t last_address{0};
|
||||
|
||||
// UI Elements - Menu/Settings Screen
|
||||
Text text_title{{60, 2, 120, 24}, "BATTLESHIP"};
|
||||
Text text_subtitle{{40, 20, 160, 16}, "Naval Combat Game"};
|
||||
Text text_title{{UI_POS_X_CENTER(11), 2, UI_POS_WIDTH(11), 16}, "BATTLESHIP"};
|
||||
Text text_subtitle{{UI_POS_X_CENTER(18), 24, UI_POS_WIDTH(18), 16}, "Naval Combat Game"};
|
||||
|
||||
Rectangle rect_radio_settings{{12, 40, 216, 118}, Color::dark_grey()};
|
||||
Text label_radio{{17, 45, 100, 16}, "RADIO SETUP"};
|
||||
// Rectangle rect_radio_settings{{12, 40, 216, 118}, Color::dark_grey()};
|
||||
Text label_radio{{UI_POS_X_CENTER(12), 45, UI_POS_WIDTH(12), 16}, "RADIO SETUP"};
|
||||
ButtonWithEncoder button_frequency{{17, 65, 11 * 8, 20}, ""};
|
||||
|
||||
// Radio controls
|
||||
@@ -183,25 +184,24 @@ class BattleshipView : public View {
|
||||
Text label_tx_gain{{155, 118, 25, 16}, "TX:"};
|
||||
NumberField field_tx_gain{{185, 118}, 2, {0, 47}, 8, ' '};
|
||||
|
||||
Rectangle rect_audio_settings{{12, 164, 216, 45}, Color::dark_grey()};
|
||||
Text label_audio{{17, 169, 80, 16}, "AUDIO"};
|
||||
Checkbox checkbox_sound{{17, 187}, 8, "Sound On", true};
|
||||
// Rectangle rect_audio_settings{{12, 164, 216, 45}, Color::dark_grey()};
|
||||
Text label_audio{{UI_POS_X_CENTER(6), 155, UI_POS_WIDTH(6), 16}, "AUDIO"};
|
||||
Checkbox checkbox_sound{{17, 177}, 8, "Sound On", true};
|
||||
Text label_volume{{110, 187, 50, 16}, "Volume:"};
|
||||
AudioVolumeField field_volume{{165, 187}};
|
||||
AudioVolumeField field_volume{{165, 177}};
|
||||
|
||||
Rectangle rect_team_selection{{12, 217, 216, 75}, Color::dark_grey()};
|
||||
Text label_team{{17, 222, 110, 16}, "SELECT TEAM"};
|
||||
Button button_red_team{{25, 242, 85, 45}, "RED\nTEAM"};
|
||||
Button button_blue_team{{130, 242, 85, 45}, "BLUE\nTEAM"};
|
||||
// Rectangle rect_team_selection{{12, 217, 216, 75}, Color::dark_grey()};
|
||||
Text label_team{{17, 220, 8 * 12, 16}, "SELECT TEAM"};
|
||||
Button button_red_team{{UI_POS_X_CENTER(10) - UI_POS_WIDTH(7), 237, UI_POS_WIDTH(10), 45}, "RED\nTEAM"};
|
||||
Button button_blue_team{{UI_POS_X_CENTER(10) + UI_POS_WIDTH(7), 237, UI_POS_WIDTH(10), 45}, "BLUE\nTEAM"};
|
||||
|
||||
// In-game UI elements
|
||||
RSSI rssi{{21 * 8, 0, 6 * 8, 4}};
|
||||
Text text_status{{10, 16, 220, 16}, ""};
|
||||
RSSI rssi{{UI_POS_X_RIGHT(6), 0, 6 * 8, 4}};
|
||||
Text text_score{{170, 16, 60, 16}, ""};
|
||||
Button button_rotate{{10, 265, 65, 32}, "Rotate"};
|
||||
Button button_place{{82, 265, 65, 32}, "Place"};
|
||||
Button button_fire{{82, 265, 65, 32}, "Fire!"};
|
||||
Button button_menu{{155, 265, 65, 32}, "Menu"};
|
||||
Button button_rotate{{5, UI_POS_Y_BOTTOM(3), 65, 32}, "Rotate"};
|
||||
Button button_place{{UI_POS_X_CENTER(6), UI_POS_Y_BOTTOM(3), 65, 32}, "Place"};
|
||||
Button button_fire{{UI_POS_X_RIGHT(17), UI_POS_Y_BOTTOM(3), 65, 32}, "Fire!"};
|
||||
Button button_menu{{UI_POS_X_RIGHT(8), UI_POS_Y_BOTTOM(3), 65, 32}, "Menu"};
|
||||
|
||||
// Methods
|
||||
void init_game();
|
||||
@@ -209,8 +209,8 @@ class BattleshipView : public View {
|
||||
void start_team(bool red);
|
||||
void setup_ships();
|
||||
void draw_menu_screen(Painter& painter);
|
||||
void draw_grid(Painter& painter, uint8_t grid_x, uint8_t grid_y, const std::array<std::array<CellState, GRID_SIZE>, GRID_SIZE>& grid, bool show_ships, bool is_offense_grid = false);
|
||||
void draw_cell(Painter& painter, uint8_t cell_x, uint8_t cell_y, CellState state, bool show_ships, bool is_offense_grid, bool is_cursor);
|
||||
void draw_grid(Painter& painter, uint16_t grid_x, uint16_t grid_y, const std::array<std::array<CellState, GRID_SIZE>, GRID_SIZE>& grid, bool show_ships, bool is_offense_grid = false);
|
||||
void draw_cell(Painter& painter, uint16_t cell_x, uint16_t cell_y, CellState state, bool show_ships, bool is_offense_grid, bool is_cursor);
|
||||
void draw_ship_preview(Painter& painter);
|
||||
void place_ship();
|
||||
bool can_place_ship(uint8_t x, uint8_t y, uint8_t size, bool horizontal);
|
||||
@@ -218,6 +218,7 @@ class BattleshipView : public View {
|
||||
void process_shot(uint8_t x, uint8_t y);
|
||||
void update_score();
|
||||
bool is_cursor_at(uint8_t x, uint8_t y, bool is_offense_grid);
|
||||
void show_hide_menu(bool menu_vis);
|
||||
|
||||
void send_message(const GameMessage& msg);
|
||||
void process_message(const std::string& message);
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
*/
|
||||
|
||||
#include "bht.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
namespace ui::external_app::bht_tx {
|
||||
|
||||
|
||||
+1
-1
@@ -207,7 +207,7 @@ class BHTView : public View {
|
||||
"Scan"};
|
||||
|
||||
Checkbox checkbox_flashing{
|
||||
{16 * 8, 25 * 8},
|
||||
{UI_POS_X(16), 25 * 8},
|
||||
8,
|
||||
"Flashing"};
|
||||
NumberField field_speed{
|
||||
|
||||
+147
-133
@@ -41,6 +41,19 @@ void game_timer_check() {
|
||||
|
||||
BlackjackView::BlackjackView(NavigationView& nav)
|
||||
: nav_{nav}, game_timer{} {
|
||||
// Initialize screen dimensions dynamically
|
||||
screen_w = ui::screen_width;
|
||||
screen_h = ui::screen_height;
|
||||
|
||||
// Scale card size based on screen
|
||||
if (screen_w <= 240) {
|
||||
card_width = 50;
|
||||
card_height = 65;
|
||||
} else if (screen_w >= 400) {
|
||||
card_width = 70;
|
||||
card_height = 90;
|
||||
}
|
||||
|
||||
add_children({&dummy});
|
||||
current_instance = this;
|
||||
game_timer.attach(&game_timer_check, 1.0 / 60.0);
|
||||
@@ -59,7 +72,7 @@ void BlackjackView::paint(Painter& painter) {
|
||||
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
init_deck();
|
||||
}
|
||||
}
|
||||
@@ -70,7 +83,7 @@ void BlackjackView::frame_sync() {
|
||||
}
|
||||
|
||||
void BlackjackView::clear_screen() {
|
||||
painter.fill_rectangle({0, 0, screen_width, screen_height}, Color::black());
|
||||
painter.fill_rectangle({0, 0, screen_w, screen_h}, Color::black());
|
||||
}
|
||||
|
||||
void BlackjackView::init_deck() {
|
||||
@@ -267,22 +280,24 @@ void BlackjackView::draw_menu_static() {
|
||||
|
||||
painter.draw_string({UI_POS_X_CENTER(10), 20}, style_title, "BLACKJACK");
|
||||
|
||||
// Draw rules
|
||||
painter.draw_string({UI_POS_X_CENTER(12), 55}, style_rules, "-- RULES --");
|
||||
painter.draw_string({UI_POS_X_CENTER(16), 75}, style_text, "Get close to 21");
|
||||
painter.draw_string({UI_POS_X_CENTER(19), 90}, style_text, "without going over");
|
||||
painter.draw_string({UI_POS_X_CENTER(18), 110}, style_text, "Dealer hits on 16");
|
||||
painter.draw_string({UI_POS_X_CENTER(19), 125}, style_text, "Dealer stays on 17");
|
||||
painter.draw_string({UI_POS_X_CENTER(19), 145}, style_text, "Blackjack pays 1:1");
|
||||
// Draw rules - adjust Y positions for smaller screens
|
||||
int rules_y = (screen_h > 300) ? 55 : 45;
|
||||
painter.draw_string({UI_POS_X_CENTER(12), rules_y}, style_rules, "-- RULES --");
|
||||
painter.draw_string({UI_POS_X_CENTER(16), rules_y + 20}, style_text, "Get close to 21");
|
||||
painter.draw_string({UI_POS_X_CENTER(19), rules_y + 35}, style_text, "without going over");
|
||||
painter.draw_string({UI_POS_X_CENTER(18), rules_y + 55}, style_text, "Dealer hits on 16");
|
||||
painter.draw_string({UI_POS_X_CENTER(19), rules_y + 70}, style_text, "Dealer stays on 17");
|
||||
painter.draw_string({UI_POS_X_CENTER(19), rules_y + 90}, style_text, "Blackjack pays 1:1");
|
||||
|
||||
// Controls
|
||||
painter.draw_string({UI_POS_X_CENTER(15), 175}, style_rules, "-- CONTROLS --");
|
||||
painter.draw_string({UI_POS_X_CENTER(18), 195}, style_text, "SELECT: Start/Hit");
|
||||
painter.draw_string({UI_POS_X_CENTER(12), 210}, style_text, "LEFT: Stats");
|
||||
painter.draw_string({UI_POS_X_CENTER(17), 225}, style_text, "RIGHT: Exit/Stay");
|
||||
int controls_y = (screen_h > 300) ? 175 : 155;
|
||||
painter.draw_string({UI_POS_X_CENTER(15), controls_y}, style_rules, "-- CONTROLS --");
|
||||
painter.draw_string({UI_POS_X_CENTER(18), controls_y + 20}, style_text, "SELECT: Start/Hit");
|
||||
painter.draw_string({UI_POS_X_CENTER(12), controls_y + 35}, style_text, "LEFT: Stats");
|
||||
painter.draw_string({UI_POS_X_CENTER(17), controls_y + 50}, style_text, "RIGHT: Exit/Stay");
|
||||
|
||||
// Draw high score
|
||||
painter.draw_string({UI_POS_X_CENTER(17), 250}, style_text, "High Score: $" + std::to_string(high_score));
|
||||
// Draw high score at bottom
|
||||
painter.draw_string({UI_POS_X_CENTER(17), screen_h - 70}, style_text, "High Score: $" + std::to_string(high_score));
|
||||
}
|
||||
|
||||
void BlackjackView::draw_menu() {
|
||||
@@ -293,10 +308,10 @@ void BlackjackView::draw_menu() {
|
||||
|
||||
if (blink_state) {
|
||||
auto style = *ui::Theme::getInstance()->fg_yellow;
|
||||
painter.draw_string({UI_POS_X_CENTER(17), 280}, style, "* PRESS SELECT *");
|
||||
painter.draw_string({UI_POS_X_CENTER(17), screen_h - 40}, style, "* PRESS SELECT *");
|
||||
} else {
|
||||
// Clear just the text area
|
||||
painter.fill_rectangle({UI_POS_X_CENTER(17), 278, 130, 20}, Color::black());
|
||||
painter.fill_rectangle({UI_POS_X_CENTER(17), screen_h - 42, 130, 20}, Color::black());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -310,27 +325,29 @@ void BlackjackView::draw_stats() {
|
||||
|
||||
painter.draw_string({UI_POS_X_CENTER(11), 30}, style_title, "STATISTICS");
|
||||
|
||||
painter.draw_string({30, 80}, style_text, "Wins:");
|
||||
int stats_x = (screen_w > 300) ? 50 : 30;
|
||||
|
||||
painter.draw_string({stats_x, 80}, style_text, "Wins:");
|
||||
painter.draw_string({UI_POS_X_CENTER(5), 80}, style_value, std::to_string(wins));
|
||||
|
||||
painter.draw_string({30, 100}, style_text, "Losses:");
|
||||
painter.draw_string({stats_x, 100}, style_text, "Losses:");
|
||||
painter.draw_string({UI_POS_X_CENTER(5), 100}, style_value, std::to_string(losses));
|
||||
|
||||
// Win percentage
|
||||
uint32_t total = wins + losses;
|
||||
if (total > 0) {
|
||||
uint32_t win_pct = (wins * 100) / total;
|
||||
painter.draw_string({30, 120}, style_text, "Win %:");
|
||||
painter.draw_string({stats_x, 120}, style_text, "Win %:");
|
||||
painter.draw_string({UI_POS_X_CENTER(5), 120}, style_value, std::to_string(win_pct) + "%");
|
||||
}
|
||||
|
||||
painter.draw_string({30, 160}, style_text, "High Score:");
|
||||
painter.draw_string({stats_x, 160}, style_text, "High Score:");
|
||||
painter.draw_string({UI_POS_X_CENTER(5), 160}, style_value, "$" + std::to_string(high_score));
|
||||
|
||||
painter.draw_string({30, 180}, style_text, "Cash:");
|
||||
painter.draw_string({stats_x, 180}, style_text, "Cash:");
|
||||
painter.draw_string({UI_POS_X_CENTER(5), 180}, style_value, "$" + std::to_string(cash));
|
||||
|
||||
painter.draw_string({40, 250}, style_text, "SELECT: Back");
|
||||
painter.draw_string({UI_POS_X_CENTER(12), screen_h - 70}, style_text, "SELECT: Back");
|
||||
}
|
||||
|
||||
void BlackjackView::draw_betting() {
|
||||
@@ -343,7 +360,7 @@ void BlackjackView::draw_betting() {
|
||||
auto style_title = *ui::Theme::getInstance()->fg_green;
|
||||
auto style_text = *ui::Theme::getInstance()->fg_light;
|
||||
|
||||
painter.draw_string({70, 40}, style_title, "PLACE BET");
|
||||
painter.draw_string({UI_POS_X_CENTER(10), 40}, style_title, "PLACE BET");
|
||||
painter.draw_string({30, 80}, style_text, "Cash: $" + std::to_string(cash));
|
||||
|
||||
painter.draw_string({30, 140}, style_text, "ENCODER: +/- $10");
|
||||
@@ -373,7 +390,7 @@ void BlackjackView::draw_game() {
|
||||
|
||||
auto style = *ui::Theme::getInstance()->fg_green;
|
||||
painter.draw_string({10, 10}, style, "Cash: $" + std::to_string(cash));
|
||||
painter.draw_string({140, 10}, style, "Bet: $" + std::to_string(bet));
|
||||
painter.draw_string({screen_w - 80, 10}, style, "Bet: $" + std::to_string(bet));
|
||||
|
||||
// Draw dealer hand with value next to label
|
||||
auto style_value = *ui::Theme::getInstance()->fg_yellow;
|
||||
@@ -385,16 +402,18 @@ void BlackjackView::draw_game() {
|
||||
draw_hand(10, 65, dealer_cards, dealer_card_count, true);
|
||||
|
||||
// Draw player hand with value next to label
|
||||
painter.draw_string({10, 165}, *ui::Theme::getInstance()->fg_light, "You:");
|
||||
int player_y = (screen_h > 300) ? 165 : 145;
|
||||
painter.draw_string({10, player_y}, *ui::Theme::getInstance()->fg_light, "You:");
|
||||
int player_value = calculate_hand_value(player_cards, player_card_count);
|
||||
painter.draw_string({50, 165}, style_value, "(" + std::to_string(player_value) + ")");
|
||||
draw_hand(10, 185, player_cards, player_card_count, false);
|
||||
painter.draw_string({50, player_y}, style_value, "(" + std::to_string(player_value) + ")");
|
||||
draw_hand(10, player_y + 20, player_cards, player_card_count, false);
|
||||
|
||||
// Draw controls or result
|
||||
int controls_y = screen_h - 50;
|
||||
if (game_state == GameState::PLAYING) {
|
||||
auto style_text = *ui::Theme::getInstance()->fg_light;
|
||||
painter.draw_string({30, 290}, style_text, "SELECT: Hit");
|
||||
painter.draw_string({130, 290}, style_text, "RIGHT: Stay");
|
||||
painter.draw_string({30, controls_y}, style_text, "SELECT: Hit");
|
||||
painter.draw_string({screen_w - 100, controls_y}, style_text, "RIGHT: Stay");
|
||||
} else if (game_state == GameState::GAME_OVER) {
|
||||
const Style* style_result = ui::Theme::getInstance()->fg_yellow;
|
||||
std::string result;
|
||||
@@ -416,14 +435,14 @@ void BlackjackView::draw_game() {
|
||||
}
|
||||
|
||||
// Draw result
|
||||
painter.draw_string({UI_POS_X_CENTER(result.length()), 270}, *style_result, result);
|
||||
painter.draw_string({UI_POS_X_CENTER(result.length()), controls_y - 20}, *style_result, result);
|
||||
|
||||
// Draw compact bet selector in top right area
|
||||
// Draw compact bet selector
|
||||
auto style_bet = *ui::Theme::getInstance()->fg_cyan;
|
||||
painter.draw_string({140, 25}, style_bet, "Next: $" + std::to_string(bet));
|
||||
painter.draw_string({screen_w - 100, 25}, style_bet, "Next: $" + std::to_string(bet));
|
||||
|
||||
// Show controls
|
||||
painter.draw_string({10, 290}, *ui::Theme::getInstance()->fg_light, "SELECT: Deal ENC: +/-");
|
||||
painter.draw_string({10, controls_y}, *ui::Theme::getInstance()->fg_light, "SELECT: Deal ENC: +/-");
|
||||
}
|
||||
|
||||
last_player_count = player_card_count;
|
||||
@@ -432,109 +451,106 @@ void BlackjackView::draw_game() {
|
||||
last_bet = bet;
|
||||
} else if (game_state == GameState::GAME_OVER && bet != last_bet) {
|
||||
// Only update the bet display when it changes
|
||||
painter.fill_rectangle({140, 25, 90, 16}, Color::black());
|
||||
painter.draw_string({140, 25}, *ui::Theme::getInstance()->fg_cyan, "Next: $" + std::to_string(bet));
|
||||
painter.fill_rectangle({screen_w - 100, 25, 90, 16}, Color::black());
|
||||
painter.draw_string({screen_w - 100, 25}, *ui::Theme::getInstance()->fg_cyan, "Next: $" + std::to_string(bet));
|
||||
last_bet = bet;
|
||||
}
|
||||
}
|
||||
|
||||
void BlackjackView::draw_suit_symbol(int x, int y, uint8_t suit, Color color, bool large) {
|
||||
if (large) {
|
||||
// Large suit symbols for center of card
|
||||
// Scale large symbols based on card size
|
||||
int scale = card_width / 60;
|
||||
|
||||
switch (suit) {
|
||||
case 0: // Spades
|
||||
// Top curve
|
||||
painter.fill_rectangle({x + 9, y + 4, 2, 2}, color);
|
||||
painter.fill_rectangle({x + 8, y + 5, 4, 2}, color);
|
||||
painter.fill_rectangle({x + 7, y + 6, 6, 2}, color);
|
||||
painter.fill_rectangle({x + 6, y + 7, 8, 2}, color);
|
||||
painter.fill_rectangle({x + 5, y + 8, 10, 2}, color);
|
||||
painter.fill_rectangle({x + 4, y + 9, 12, 2}, color);
|
||||
painter.fill_rectangle({x + 3, y + 10, 14, 2}, color);
|
||||
painter.fill_rectangle({x + 2, y + 11, 16, 2}, color);
|
||||
painter.fill_rectangle({x + 1, y + 12, 18, 2}, color);
|
||||
painter.fill_rectangle({x + 0, y + 13, 20, 3}, color);
|
||||
painter.fill_rectangle({x + 1, y + 16, 18, 2}, color);
|
||||
painter.fill_rectangle({x + 2, y + 17, 16, 1}, color);
|
||||
painter.fill_rectangle({x + 3, y + 18, 14, 1}, color);
|
||||
// Draw using scaled rectangles
|
||||
painter.fill_rectangle({x + 9 * scale, y + 4 * scale, 2 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 8 * scale, y + 5 * scale, 4 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 7 * scale, y + 6 * scale, 6 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 6 * scale, y + 7 * scale, 8 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 5 * scale, y + 8 * scale, 10 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 4 * scale, y + 9 * scale, 12 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 3 * scale, y + 10 * scale, 14 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 2 * scale, y + 11 * scale, 16 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 1 * scale, y + 12 * scale, 18 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 0 * scale, y + 13 * scale, 20 * scale, 3 * scale}, color);
|
||||
painter.fill_rectangle({x + 1 * scale, y + 16 * scale, 18 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 2 * scale, y + 17 * scale, 16 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 3 * scale, y + 18 * scale, 14 * scale, 1 * scale}, color);
|
||||
// Stem
|
||||
painter.fill_rectangle({x + 9, y + 19, 2, 4}, color);
|
||||
painter.fill_rectangle({x + 8, y + 22, 4, 1}, color);
|
||||
painter.fill_rectangle({x + 7, y + 23, 6, 1}, color);
|
||||
painter.fill_rectangle({x + 6, y + 24, 8, 1}, color);
|
||||
painter.fill_rectangle({x + 9 * scale, y + 19 * scale, 2 * scale, 4 * scale}, color);
|
||||
painter.fill_rectangle({x + 8 * scale, y + 22 * scale, 4 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 7 * scale, y + 23 * scale, 6 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 6 * scale, y + 24 * scale, 8 * scale, 1 * scale}, color);
|
||||
break;
|
||||
|
||||
case 1: // Hearts
|
||||
// Left bump
|
||||
painter.fill_rectangle({x + 3, y + 5, 4, 2}, color);
|
||||
painter.fill_rectangle({x + 2, y + 6, 6, 2}, color);
|
||||
painter.fill_rectangle({x + 1, y + 7, 8, 3}, color);
|
||||
painter.fill_rectangle({x + 0, y + 9, 9, 3}, color);
|
||||
// Right bump
|
||||
painter.fill_rectangle({x + 13, y + 5, 4, 2}, color);
|
||||
painter.fill_rectangle({x + 12, y + 6, 6, 2}, color);
|
||||
painter.fill_rectangle({x + 11, y + 7, 8, 3}, color);
|
||||
painter.fill_rectangle({x + 11, y + 9, 9, 3}, color);
|
||||
// Body
|
||||
painter.fill_rectangle({x + 1, y + 11, 18, 3}, color);
|
||||
painter.fill_rectangle({x + 2, y + 14, 16, 2}, color);
|
||||
painter.fill_rectangle({x + 3, y + 16, 14, 2}, color);
|
||||
painter.fill_rectangle({x + 4, y + 18, 12, 1}, color);
|
||||
painter.fill_rectangle({x + 5, y + 19, 10, 1}, color);
|
||||
painter.fill_rectangle({x + 6, y + 20, 8, 1}, color);
|
||||
painter.fill_rectangle({x + 7, y + 21, 6, 1}, color);
|
||||
painter.fill_rectangle({x + 8, y + 22, 4, 1}, color);
|
||||
painter.fill_rectangle({x + 9, y + 23, 2, 1}, color);
|
||||
// Draw using scaled rectangles
|
||||
painter.fill_rectangle({x + 3 * scale, y + 5 * scale, 4 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 2 * scale, y + 6 * scale, 6 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 1 * scale, y + 7 * scale, 8 * scale, 3 * scale}, color);
|
||||
painter.fill_rectangle({x + 0 * scale, y + 9 * scale, 9 * scale, 3 * scale}, color);
|
||||
painter.fill_rectangle({x + 13 * scale, y + 5 * scale, 4 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 12 * scale, y + 6 * scale, 6 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 11 * scale, y + 7 * scale, 8 * scale, 3 * scale}, color);
|
||||
painter.fill_rectangle({x + 11 * scale, y + 9 * scale, 9 * scale, 3 * scale}, color);
|
||||
painter.fill_rectangle({x + 1 * scale, y + 11 * scale, 18 * scale, 3 * scale}, color);
|
||||
painter.fill_rectangle({x + 2 * scale, y + 14 * scale, 16 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 3 * scale, y + 16 * scale, 14 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 4 * scale, y + 18 * scale, 12 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 5 * scale, y + 19 * scale, 10 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 6 * scale, y + 20 * scale, 8 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 7 * scale, y + 21 * scale, 6 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 8 * scale, y + 22 * scale, 4 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 9 * scale, y + 23 * scale, 2 * scale, 1 * scale}, color);
|
||||
break;
|
||||
|
||||
case 2: // Diamonds
|
||||
painter.fill_rectangle({x + 10, y + 3, 1, 1}, color);
|
||||
painter.fill_rectangle({x + 9, y + 4, 3, 1}, color);
|
||||
painter.fill_rectangle({x + 8, y + 5, 5, 1}, color);
|
||||
painter.fill_rectangle({x + 7, y + 6, 7, 1}, color);
|
||||
painter.fill_rectangle({x + 6, y + 7, 9, 1}, color);
|
||||
painter.fill_rectangle({x + 5, y + 8, 11, 1}, color);
|
||||
painter.fill_rectangle({x + 4, y + 9, 13, 1}, color);
|
||||
painter.fill_rectangle({x + 3, y + 10, 15, 1}, color);
|
||||
painter.fill_rectangle({x + 2, y + 11, 17, 1}, color);
|
||||
painter.fill_rectangle({x + 1, y + 12, 19, 1}, color);
|
||||
painter.fill_rectangle({x + 0, y + 13, 21, 1}, color);
|
||||
painter.fill_rectangle({x + 1, y + 14, 19, 1}, color);
|
||||
painter.fill_rectangle({x + 2, y + 15, 17, 1}, color);
|
||||
painter.fill_rectangle({x + 3, y + 16, 15, 1}, color);
|
||||
painter.fill_rectangle({x + 4, y + 17, 13, 1}, color);
|
||||
painter.fill_rectangle({x + 5, y + 18, 11, 1}, color);
|
||||
painter.fill_rectangle({x + 6, y + 19, 9, 1}, color);
|
||||
painter.fill_rectangle({x + 7, y + 20, 7, 1}, color);
|
||||
painter.fill_rectangle({x + 8, y + 21, 5, 1}, color);
|
||||
painter.fill_rectangle({x + 9, y + 22, 3, 1}, color);
|
||||
painter.fill_rectangle({x + 10, y + 23, 1, 1}, color);
|
||||
// Draw using scaled rectangles
|
||||
painter.fill_rectangle({x + 10 * scale, y + 3 * scale, 1 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 9 * scale, y + 4 * scale, 3 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 8 * scale, y + 5 * scale, 5 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 7 * scale, y + 6 * scale, 7 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 6 * scale, y + 7 * scale, 9 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 5 * scale, y + 8 * scale, 11 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 4 * scale, y + 9 * scale, 13 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 3 * scale, y + 10 * scale, 15 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 2 * scale, y + 11 * scale, 17 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 1 * scale, y + 12 * scale, 19 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 0 * scale, y + 13 * scale, 21 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 1 * scale, y + 14 * scale, 19 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 2 * scale, y + 15 * scale, 17 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 3 * scale, y + 16 * scale, 15 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 4 * scale, y + 17 * scale, 13 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 5 * scale, y + 18 * scale, 11 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 6 * scale, y + 19 * scale, 9 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 7 * scale, y + 20 * scale, 7 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 8 * scale, y + 21 * scale, 5 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 9 * scale, y + 22 * scale, 3 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 10 * scale, y + 23 * scale, 1 * scale, 1 * scale}, color);
|
||||
break;
|
||||
|
||||
case 3: // Clubs
|
||||
// Center circle
|
||||
painter.fill_rectangle({x + 8, y + 8, 5, 1}, color);
|
||||
painter.fill_rectangle({x + 7, y + 9, 7, 3}, color);
|
||||
painter.fill_rectangle({x + 8, y + 12, 5, 1}, color);
|
||||
// Left circle
|
||||
painter.fill_rectangle({x + 3, y + 11, 4, 1}, color);
|
||||
painter.fill_rectangle({x + 2, y + 12, 6, 3}, color);
|
||||
painter.fill_rectangle({x + 3, y + 15, 4, 1}, color);
|
||||
// Right circle
|
||||
painter.fill_rectangle({x + 14, y + 11, 4, 1}, color);
|
||||
painter.fill_rectangle({x + 13, y + 12, 6, 3}, color);
|
||||
painter.fill_rectangle({x + 14, y + 15, 4, 1}, color);
|
||||
// Connect circles
|
||||
painter.fill_rectangle({x + 6, y + 13, 9, 2}, color);
|
||||
// Stem
|
||||
painter.fill_rectangle({x + 9, y + 16, 3, 4}, color);
|
||||
painter.fill_rectangle({x + 8, y + 19, 5, 1}, color);
|
||||
painter.fill_rectangle({x + 7, y + 20, 7, 1}, color);
|
||||
painter.fill_rectangle({x + 6, y + 21, 9, 1}, color);
|
||||
// Draw using scaled rectangles
|
||||
painter.fill_rectangle({x + 8 * scale, y + 8 * scale, 5 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 7 * scale, y + 9 * scale, 7 * scale, 3 * scale}, color);
|
||||
painter.fill_rectangle({x + 8 * scale, y + 12 * scale, 5 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 3 * scale, y + 11 * scale, 4 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 2 * scale, y + 12 * scale, 6 * scale, 3 * scale}, color);
|
||||
painter.fill_rectangle({x + 3 * scale, y + 15 * scale, 4 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 14 * scale, y + 11 * scale, 4 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 13 * scale, y + 12 * scale, 6 * scale, 3 * scale}, color);
|
||||
painter.fill_rectangle({x + 14 * scale, y + 15 * scale, 4 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 6 * scale, y + 13 * scale, 9 * scale, 2 * scale}, color);
|
||||
painter.fill_rectangle({x + 9 * scale, y + 16 * scale, 3 * scale, 4 * scale}, color);
|
||||
painter.fill_rectangle({x + 8 * scale, y + 19 * scale, 5 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 7 * scale, y + 20 * scale, 7 * scale, 1 * scale}, color);
|
||||
painter.fill_rectangle({x + 6 * scale, y + 21 * scale, 9 * scale, 1 * scale}, color);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// Small suit symbols
|
||||
// Small suit symbols remain the same
|
||||
switch (suit) {
|
||||
case 0: // Spades - small
|
||||
painter.fill_rectangle({x + 2, y + 1, 3, 3}, color);
|
||||
@@ -569,18 +585,15 @@ void BlackjackView::draw_suit_symbol(int x, int y, uint8_t suit, Color color, bo
|
||||
}
|
||||
|
||||
void BlackjackView::draw_card(int x, int y, uint8_t card, bool hidden) {
|
||||
const int width = 60;
|
||||
const int height = 80;
|
||||
|
||||
// Draw card background
|
||||
painter.fill_rectangle({x, y, width, height}, Color::white());
|
||||
painter.draw_rectangle({x, y, width, height}, Color::black());
|
||||
painter.draw_rectangle({x + 1, y + 1, width - 2, height - 2}, Color::grey()); // Inner border
|
||||
painter.fill_rectangle({x, y, card_width, card_height}, Color::white());
|
||||
painter.draw_rectangle({x, y, card_width, card_height}, Color::black());
|
||||
painter.draw_rectangle({x + 1, y + 1, card_width - 2, card_height - 2}, Color::grey());
|
||||
|
||||
if (hidden) {
|
||||
// Draw card back pattern - diagonal lines
|
||||
for (int i = 4; i < width - 4; i += 6) {
|
||||
for (int j = 4; j < height - 4; j += 6) {
|
||||
for (int i = 4; i < card_width - 4; i += 6) {
|
||||
for (int j = 4; j < card_height - 4; j += 6) {
|
||||
painter.fill_rectangle({x + i, y + j, 3, 3}, Color::blue());
|
||||
painter.fill_rectangle({x + i + 3, y + j + 3, 3, 3}, Color::red());
|
||||
}
|
||||
@@ -606,22 +619,23 @@ void BlackjackView::draw_card(int x, int y, uint8_t card, bool hidden) {
|
||||
draw_suit_symbol(suit_x, y + 4, suit, suit_color, false);
|
||||
|
||||
// Draw value in bottom-right corner
|
||||
int bottom_x = (value_str == "10") ? x + width - 24 : x + width - 16;
|
||||
painter.draw_string({bottom_x, y + height - 18}, card_style, value_str);
|
||||
int bottom_x = (value_str == "10") ? x + card_width - 24 : x + card_width - 16;
|
||||
painter.draw_string({bottom_x, y + card_height - 18}, card_style, value_str);
|
||||
|
||||
// Draw small suit symbol in bottom-right
|
||||
draw_suit_symbol(x + width - 10, y + height - 16, suit, suit_color, false);
|
||||
draw_suit_symbol(x + card_width - 10, y + card_height - 16, suit, suit_color, false);
|
||||
|
||||
// Draw large suit symbol in center
|
||||
draw_suit_symbol(x + 20, y + 28, suit, suit_color, true);
|
||||
int center_x = x + (card_width - 20) / 2;
|
||||
int center_y = y + (card_height - 25) / 2;
|
||||
draw_suit_symbol(center_x, center_y, suit, suit_color, true);
|
||||
}
|
||||
}
|
||||
|
||||
void BlackjackView::draw_hand(int x, int y, uint8_t* cards, uint8_t count, bool is_dealer) {
|
||||
// Calculate total width needed
|
||||
const int card_width = 60;
|
||||
const int overlap = 40; // Amount of overlap when cards need to fit
|
||||
const int max_width = screen_width - 10 - x; // Available width on screen
|
||||
const int overlap = card_width * 2 / 3; // Amount of overlap when cards need to fit
|
||||
const int max_width = screen_w - 10 - x; // Available width on screen
|
||||
|
||||
int spacing;
|
||||
if (count == 1) {
|
||||
@@ -651,7 +665,7 @@ bool BlackjackView::on_key(const KeyEvent key) {
|
||||
switch (game_state) {
|
||||
case GameState::MENU:
|
||||
if (cash < 10) {
|
||||
cash = 100; // Reset if broke - maybe should provide https://gamblersanonymous.org/ link if they also lost their wife and house
|
||||
cash = 100; // Reset if broke
|
||||
wins = 0;
|
||||
losses = 0;
|
||||
}
|
||||
@@ -724,4 +738,4 @@ bool BlackjackView::on_encoder(const EncoderEvent delta) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::blackjack
|
||||
} // namespace ui::external_app::blackjack
|
||||
@@ -77,6 +77,12 @@ class BlackjackView : public View {
|
||||
NavigationView& nav_;
|
||||
bool initialized = false;
|
||||
|
||||
// Screen dimensions (set dynamically)
|
||||
int screen_w = 0;
|
||||
int screen_h = 0;
|
||||
int card_width = 60;
|
||||
int card_height = 80;
|
||||
|
||||
// Game variables
|
||||
static constexpr uint8_t MAX_CARDS_IN_HAND = 11; // Maximum possible cards before bust
|
||||
uint8_t deck[52];
|
||||
@@ -141,7 +147,7 @@ class BlackjackView : public View {
|
||||
{"highscore"sv, &high_score}}};
|
||||
|
||||
Button dummy{
|
||||
{screen_width, 0, 0, 0},
|
||||
{0, 0, 0, 0},
|
||||
""};
|
||||
|
||||
MessageHandlerRegistration message_handler_frame_sync{
|
||||
@@ -153,4 +159,4 @@ class BlackjackView : public View {
|
||||
|
||||
} // namespace ui::external_app::blackjack
|
||||
|
||||
#endif /* __UI_BLACKJACK_H__ */
|
||||
#endif /* __UI_BLACKJACK_H__ */
|
||||
+1
-1
@@ -132,7 +132,7 @@ void BLESpamView::reset() {
|
||||
}
|
||||
|
||||
void BLESpamView::randomChn() {
|
||||
channel_number = 37 + std::rand() % (39 - 37 + 1);
|
||||
channel_number = 37 + rand() % (39 - 37 + 1);
|
||||
field_frequency.set_value(get_freq_by_channel_number(channel_number));
|
||||
}
|
||||
|
||||
|
||||
+12
-12
@@ -20,13 +20,13 @@ void initialize_app(ui::NavigationView& nav) {
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_breakout.application_information"), used)) application_information_t _application_information_breakout = {
|
||||
(uint8_t*)0x00000000,
|
||||
ui::external_app::breakout::initialize_app,
|
||||
CURRENT_HEADER_VERSION,
|
||||
VERSION_MD5,
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::breakout::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
|
||||
"Breakout",
|
||||
{
|
||||
/*.app_name = */ "Breakout",
|
||||
/*.bitmap_data = */ {
|
||||
0x00,
|
||||
0x00,
|
||||
0x7F,
|
||||
@@ -60,11 +60,11 @@ __attribute__((section(".external_app.app_breakout.application_information"), us
|
||||
0xF7,
|
||||
0xF7,
|
||||
},
|
||||
ui::Color::green().v,
|
||||
app_location_t::GAMES,
|
||||
-1,
|
||||
/*.icon_color = */ ui::Color::green().v,
|
||||
/*.menu_location = */ app_location_t::GAMES,
|
||||
/*.desired_menu_position = */ -1,
|
||||
|
||||
{0, 0, 0, 0},
|
||||
0x00000000,
|
||||
/*.m4_app_tag = */ {'P', 'A', 'B', 'P'}, // This is the audio beep baseband tag!
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
} // namespace ui::external_app::breakout
|
||||
}
|
||||
+280
-11
@@ -7,6 +7,12 @@
|
||||
*/
|
||||
|
||||
#include "ui_breakout.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "audio.hpp"
|
||||
#include "portapack.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
|
||||
namespace ui::external_app::breakout {
|
||||
|
||||
@@ -92,6 +98,37 @@ void BreakoutView::init_game() {
|
||||
game_state = STATE_MENU;
|
||||
menu_blink_state = true;
|
||||
menu_blink_counter = 0;
|
||||
|
||||
// Play startup sound
|
||||
if (sound_enabled) {
|
||||
baseband::request_audio_beep(262, 24000, 150); // C4 -
|
||||
chThdSleepMilliseconds(200);
|
||||
baseband::request_audio_beep(262, 24000, 150); // C4
|
||||
chThdSleepMilliseconds(200);
|
||||
baseband::request_audio_beep(392, 24000, 150); // G4
|
||||
chThdSleepMilliseconds(200);
|
||||
baseband::request_audio_beep(392, 24000, 150); // G4
|
||||
chThdSleepMilliseconds(200);
|
||||
baseband::request_audio_beep(440, 24000, 150); // A4
|
||||
chThdSleepMilliseconds(200);
|
||||
baseband::request_audio_beep(440, 24000, 150); // A4
|
||||
chThdSleepMilliseconds(200);
|
||||
baseband::request_audio_beep(392, 24000, 300); // G4
|
||||
chThdSleepMilliseconds(350);
|
||||
baseband::request_audio_beep(349, 24000, 150); // F4
|
||||
chThdSleepMilliseconds(200);
|
||||
baseband::request_audio_beep(349, 24000, 150); // F4
|
||||
chThdSleepMilliseconds(200);
|
||||
baseband::request_audio_beep(330, 24000, 150); // E4
|
||||
chThdSleepMilliseconds(200);
|
||||
baseband::request_audio_beep(330, 24000, 150); // E4
|
||||
chThdSleepMilliseconds(200);
|
||||
baseband::request_audio_beep(294, 24000, 150); // D4
|
||||
chThdSleepMilliseconds(200);
|
||||
baseband::request_audio_beep(294, 24000, 150); // D4
|
||||
chThdSleepMilliseconds(200);
|
||||
baseband::request_audio_beep(262, 24000, 400); // C4
|
||||
}
|
||||
}
|
||||
|
||||
void BreakoutView::init_level() {
|
||||
@@ -126,6 +163,34 @@ void BreakoutView::draw_screen() {
|
||||
draw_level();
|
||||
}
|
||||
|
||||
void BreakoutView::draw_menu_volume_bar() {
|
||||
// Clear the entire volume area first to handle bar shrinking
|
||||
painter.fill_rectangle({40, 259, 220, 40}, Color::black());
|
||||
|
||||
// Draw volume label
|
||||
auto style = *ui::Theme::getInstance()->fg_light;
|
||||
painter.draw_string({40, 260}, style, "Volume:");
|
||||
|
||||
// Draw volume bar background
|
||||
painter.draw_rectangle({100, 259, 102, 10}, Color::grey());
|
||||
|
||||
// Draw volume level
|
||||
int bar_width = (volume_level * 100) / 99;
|
||||
if (bar_width > 0) {
|
||||
painter.fill_rectangle({101, 260, bar_width, 8}, Color::green());
|
||||
}
|
||||
|
||||
// Draw percentage
|
||||
painter.draw_string({210, 260}, style, std::to_string(volume_level) + "%");
|
||||
|
||||
// Draw sound status
|
||||
if (sound_enabled) {
|
||||
painter.draw_string({UI_POS_X_CENTER(11), 280}, *ui::Theme::getInstance()->fg_green, "Sound: ON");
|
||||
} else {
|
||||
painter.draw_string({UI_POS_X_CENTER(11), 280}, *ui::Theme::getInstance()->fg_red, "Sound: OFF");
|
||||
}
|
||||
}
|
||||
|
||||
void BreakoutView::draw_borders() {
|
||||
rect(0, GAME_AREA_TOP - 1, SCREEN_WIDTH, GAME_AREA_TOP, COLOR_BORDER);
|
||||
}
|
||||
@@ -166,6 +231,22 @@ void BreakoutView::draw_level() {
|
||||
painter.draw_string({80, 30}, style, "Level: " + std::to_string(level));
|
||||
}
|
||||
|
||||
void BreakoutView::adjust_volume(int delta) {
|
||||
volume_level += delta;
|
||||
if (volume_level < 0) volume_level = 0;
|
||||
if (volume_level > 99) volume_level = 99;
|
||||
|
||||
// Update the actual audio volume using decibel conversion
|
||||
// Map 0-99 to roughly -60dB to 0dB range
|
||||
int db = (volume_level - 99) * 60 / 99; // Maps 0->-60dB, 99->0dB
|
||||
audio::headphone::set_volume(volume_t::decibel(db));
|
||||
|
||||
// If we're in the menu, redraw the volume bar
|
||||
if (game_state == STATE_MENU) {
|
||||
draw_menu_volume_bar();
|
||||
}
|
||||
}
|
||||
|
||||
void BreakoutView::move_paddle_left() {
|
||||
if (paddle_x > 0) {
|
||||
fillrect(paddle_x, PADDLE_Y, paddle_x + PADDLE_WIDTH, PADDLE_Y + PADDLE_HEIGHT, COLOR_BACKGROUND);
|
||||
@@ -231,19 +312,23 @@ void BreakoutView::update_game() {
|
||||
if (ball_x < 0) {
|
||||
ball_x = 0;
|
||||
ball_dx = -ball_dx;
|
||||
play_wall_hit();
|
||||
} else if (ball_x > SCREEN_WIDTH - BALL_SIZE) {
|
||||
ball_x = SCREEN_WIDTH - BALL_SIZE;
|
||||
ball_dx = -ball_dx;
|
||||
play_wall_hit();
|
||||
}
|
||||
|
||||
if (ball_y < GAME_AREA_TOP) {
|
||||
ball_y = GAME_AREA_TOP;
|
||||
ball_dy = -ball_dy;
|
||||
play_wall_hit();
|
||||
}
|
||||
|
||||
// Bottom edge - lose life
|
||||
if (ball_y > GAME_AREA_BOTTOM) {
|
||||
lives--;
|
||||
play_death_sound(); // Play death sound
|
||||
draw_lives();
|
||||
if (lives <= 0) {
|
||||
handle_game_over();
|
||||
@@ -262,6 +347,8 @@ void BreakoutView::update_game() {
|
||||
ball_y = PADDLE_Y - BALL_SIZE;
|
||||
ball_dy = -ball_dy;
|
||||
|
||||
play_paddle_hit();
|
||||
|
||||
// Add some angle based on hit position
|
||||
float hit_position = (ball_x + (BALL_SIZE / 2)) - paddle_x;
|
||||
float angle = (hit_position / PADDLE_WIDTH) - 0.5f;
|
||||
@@ -301,6 +388,8 @@ bool BreakoutView::check_brick_collision(int row, int col) {
|
||||
score += (5 - row) * 10;
|
||||
draw_score();
|
||||
|
||||
play_brick_hit();
|
||||
|
||||
ball_dy = -ball_dy;
|
||||
return true;
|
||||
}
|
||||
@@ -314,6 +403,8 @@ bool BreakoutView::check_level_complete() {
|
||||
|
||||
void BreakoutView::next_level() {
|
||||
level++;
|
||||
play_level_complete();
|
||||
chThdSleepMilliseconds(500); // Give time for sound to play
|
||||
init_level();
|
||||
draw_screen();
|
||||
}
|
||||
@@ -322,9 +413,11 @@ void BreakoutView::handle_game_over() {
|
||||
game_state = STATE_GAME_OVER;
|
||||
gameover_blink_state = true;
|
||||
gameover_blink_counter = 0;
|
||||
play_game_over();
|
||||
}
|
||||
|
||||
void BreakoutView::show_menu() {
|
||||
// Only draw the static parts once
|
||||
if (menu_blink_counter == 0) {
|
||||
cls();
|
||||
background(COLOR_BACKGROUND);
|
||||
@@ -338,23 +431,30 @@ void BreakoutView::show_menu() {
|
||||
painter.draw_string({UI_POS_X_CENTER(20), 130}, style_cyan, "ROTARY: MOVE PADDLE");
|
||||
painter.draw_string({UI_POS_X_CENTER(21), 160}, style_cyan, "SELECT: START/LAUNCH");
|
||||
painter.draw_string({UI_POS_X_CENTER(25), 190}, style_blue, "========================");
|
||||
|
||||
// Volume adjustment instructions
|
||||
painter.draw_string({UI_POS_X_CENTER(24), 220}, style_cyan, "Press UP/DOWN for Volume");
|
||||
|
||||
// Draw volume control at bottom
|
||||
draw_menu_volume_bar();
|
||||
}
|
||||
|
||||
auto style_red = *ui::Theme::getInstance()->fg_red;
|
||||
|
||||
// Only flash the "PRESS SELECT" text
|
||||
if (++menu_blink_counter >= 30) {
|
||||
menu_blink_counter = 0;
|
||||
menu_blink_counter = 1; // Keep it at 1 so we don't redraw everything
|
||||
menu_blink_state = !menu_blink_state;
|
||||
|
||||
painter.fill_rectangle({UI_POS_X_CENTER(17), 228, 128, 20}, Color::black());
|
||||
auto style_red = *ui::Theme::getInstance()->fg_red;
|
||||
painter.fill_rectangle({UI_POS_X_CENTER(17), 238, 128, 20}, Color::black());
|
||||
|
||||
if (menu_blink_state) {
|
||||
painter.draw_string({UI_POS_X_CENTER(17), 230}, style_red, "* PRESS SELECT *");
|
||||
painter.draw_string({UI_POS_X_CENTER(17), 240}, style_red, "* PRESS SELECT *");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BreakoutView::show_game_over() {
|
||||
// Only draw the static parts once
|
||||
if (gameover_blink_counter == 0) {
|
||||
cls();
|
||||
background(COLOR_BACKGROUND);
|
||||
@@ -366,12 +466,12 @@ void BreakoutView::show_game_over() {
|
||||
painter.draw_string({UI_POS_X_CENTER(11), 150}, style_yellow, "SCORE: " + std::to_string(score));
|
||||
}
|
||||
|
||||
auto style_green = *ui::Theme::getInstance()->fg_green;
|
||||
|
||||
// Only flash the "PRESS SELECT" text
|
||||
if (++gameover_blink_counter >= 30) {
|
||||
gameover_blink_counter = 0;
|
||||
gameover_blink_counter = 1; // Keep it at 1 so we don't redraw everything
|
||||
gameover_blink_state = !gameover_blink_state;
|
||||
|
||||
auto style_green = *ui::Theme::getInstance()->fg_green;
|
||||
painter.fill_rectangle({UI_POS_X_CENTER(13), 198, 96, 20}, Color::black());
|
||||
|
||||
if (gameover_blink_state) {
|
||||
@@ -385,17 +485,169 @@ void BreakoutView::reset_game() {
|
||||
score = 0;
|
||||
lives = 3;
|
||||
game_state = STATE_PLAYING;
|
||||
|
||||
dummy.focus();
|
||||
|
||||
init_level();
|
||||
draw_screen();
|
||||
}
|
||||
|
||||
// Sound effect implementations with timing control
|
||||
void BreakoutView::play_paddle_hit() {
|
||||
if (sound_enabled) {
|
||||
uint32_t current_time = chTimeNow();
|
||||
if (current_time - last_sound_time >= min_sound_interval) {
|
||||
baseband::request_beep_stop(); // Stop any previous sound
|
||||
chThdSleepMilliseconds(5); // Small delay
|
||||
baseband::request_audio_beep(440, 24000, 40); // 440Hz A4, 40ms
|
||||
last_sound_time = current_time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BreakoutView::play_brick_hit() {
|
||||
if (sound_enabled) {
|
||||
uint32_t current_time = chTimeNow();
|
||||
if (current_time - last_sound_time >= min_sound_interval) {
|
||||
baseband::request_beep_stop(); // Stop any previous sound
|
||||
chThdSleepMilliseconds(5); // Small delay
|
||||
// Higher pitch that varies with remaining bricks
|
||||
uint32_t freq = 880 + ((25 - brick_count) * 20); // Gets higher as bricks are destroyed
|
||||
baseband::request_audio_beep(freq, 24000, 30);
|
||||
last_sound_time = current_time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BreakoutView::play_wall_hit() {
|
||||
if (sound_enabled) {
|
||||
uint32_t current_time = chTimeNow();
|
||||
if (current_time - last_sound_time >= min_sound_interval) {
|
||||
baseband::request_beep_stop(); // Stop any previous sound
|
||||
chThdSleepMilliseconds(5); // Small delay
|
||||
baseband::request_audio_beep(220, 24000, 120); // 220Hz A3, 120ms
|
||||
last_sound_time = current_time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BreakoutView::play_death_sound() {
|
||||
if (sound_enabled) {
|
||||
baseband::request_audio_beep(493, 24000, 150); // B4
|
||||
chThdSleepMilliseconds(180);
|
||||
baseband::request_audio_beep(466, 24000, 150); // Bb4
|
||||
chThdSleepMilliseconds(180);
|
||||
baseband::request_audio_beep(440, 24000, 150); // A4
|
||||
chThdSleepMilliseconds(180);
|
||||
baseband::request_audio_beep(415, 24000, 150); // Ab4
|
||||
chThdSleepMilliseconds(180);
|
||||
baseband::request_audio_beep(392, 24000, 150); // G4
|
||||
chThdSleepMilliseconds(180);
|
||||
baseband::request_audio_beep(369, 24000, 150); // Gb4
|
||||
chThdSleepMilliseconds(180);
|
||||
baseband::request_audio_beep(349, 24000, 150); // F4
|
||||
chThdSleepMilliseconds(180);
|
||||
baseband::request_audio_beep(329, 24000, 150); // E4
|
||||
chThdSleepMilliseconds(180);
|
||||
baseband::request_audio_beep(293, 24000, 150); // D4
|
||||
chThdSleepMilliseconds(180);
|
||||
baseband::request_audio_beep(261, 24000, 150); // C4
|
||||
chThdSleepMilliseconds(180);
|
||||
baseband::request_audio_beep(196, 24000, 200); // G3
|
||||
chThdSleepMilliseconds(230);
|
||||
baseband::request_audio_beep(130, 24000, 300); // C3
|
||||
}
|
||||
}
|
||||
|
||||
void BreakoutView::play_game_over() {
|
||||
if (sound_enabled) {
|
||||
// First phrase
|
||||
baseband::request_audio_beep(392, 24000, 300); // G4
|
||||
chThdSleepMilliseconds(350);
|
||||
baseband::request_audio_beep(392, 24000, 150); // G4
|
||||
chThdSleepMilliseconds(200);
|
||||
baseband::request_audio_beep(392, 24000, 150); // G4
|
||||
chThdSleepMilliseconds(200);
|
||||
baseband::request_audio_beep(311, 24000, 500); // Eb4 - long
|
||||
chThdSleepMilliseconds(600);
|
||||
|
||||
// Second phrase
|
||||
baseband::request_audio_beep(349, 24000, 300); // F4
|
||||
chThdSleepMilliseconds(350);
|
||||
baseband::request_audio_beep(349, 24000, 150); // F4
|
||||
chThdSleepMilliseconds(200);
|
||||
baseband::request_audio_beep(349, 24000, 150); // F4
|
||||
chThdSleepMilliseconds(200);
|
||||
baseband::request_audio_beep(294, 24000, 500); // D4 - long
|
||||
chThdSleepMilliseconds(600);
|
||||
|
||||
// Final phrase - slower and more dramatic
|
||||
baseband::request_audio_beep(262, 24000, 200); // C4
|
||||
chThdSleepMilliseconds(250);
|
||||
baseband::request_audio_beep(247, 24000, 200); // B3
|
||||
chThdSleepMilliseconds(250);
|
||||
baseband::request_audio_beep(233, 24000, 200); // Bb3
|
||||
chThdSleepMilliseconds(250);
|
||||
baseband::request_audio_beep(220, 24000, 200); // A3
|
||||
chThdSleepMilliseconds(250);
|
||||
baseband::request_audio_beep(196, 24000, 200); // G3
|
||||
chThdSleepMilliseconds(250);
|
||||
baseband::request_audio_beep(175, 24000, 200); // F3
|
||||
chThdSleepMilliseconds(250);
|
||||
baseband::request_audio_beep(131, 24000, 600); // C3
|
||||
}
|
||||
}
|
||||
|
||||
void BreakoutView::play_level_complete() {
|
||||
if (sound_enabled) {
|
||||
baseband::request_beep_stop(); // Stop any previous sound
|
||||
chThdSleepMilliseconds(10);
|
||||
baseband::request_audio_beep(1047, 24000, 300); // 1047Hz C6, 300ms
|
||||
}
|
||||
}
|
||||
|
||||
BreakoutView::BreakoutView(NavigationView& nav)
|
||||
: nav_{nav}, bricks{} { // Add bricks{} here
|
||||
: nav_{nav}, bricks{} {
|
||||
// Initialize audio system for beeps FIRST
|
||||
baseband::run_prepared_image(portapack::memory::map::m4_code.base()); // Load the audio beep baseband
|
||||
|
||||
add_children({&dummy});
|
||||
|
||||
// Initialize audio
|
||||
audio::set_rate(audio::Rate::Hz_24000);
|
||||
audio::output::start();
|
||||
|
||||
// Set initial volume to 80% and ensure sound is ON
|
||||
volume_level = 80;
|
||||
sound_enabled = true; // Make sure this is explicitly set to ON
|
||||
|
||||
// Set the actual volume
|
||||
int db = (volume_level - 99) * 60 / 99; // Maps to roughly -12dB for 80%
|
||||
audio::headphone::set_volume(volume_t::decibel(db));
|
||||
|
||||
attach(1.0 / 60.0);
|
||||
}
|
||||
|
||||
BreakoutView::~BreakoutView() {
|
||||
// Clean shutdown
|
||||
baseband::request_beep_stop();
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
audio::output::stop();
|
||||
}
|
||||
|
||||
void BreakoutView::on_show() {
|
||||
// Nothing needed here, initialization done in constructor
|
||||
}
|
||||
|
||||
void BreakoutView::on_hide() {
|
||||
// Additional cleanup
|
||||
baseband::request_beep_stop();
|
||||
audio::output::stop();
|
||||
}
|
||||
|
||||
void BreakoutView::focus() {
|
||||
dummy.focus();
|
||||
}
|
||||
|
||||
void BreakoutView::paint(Painter& painter) {
|
||||
@@ -403,7 +655,7 @@ void BreakoutView::paint(Painter& painter) {
|
||||
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
init_game();
|
||||
}
|
||||
}
|
||||
@@ -433,16 +685,33 @@ bool BreakoutView::on_key(const KeyEvent key) {
|
||||
} else if (game_state == STATE_PLAYING && ball_attached) {
|
||||
launch_ball();
|
||||
} else if (game_state == STATE_GAME_OVER) {
|
||||
reset_game();
|
||||
// Return to menu after game over
|
||||
game_state = STATE_MENU;
|
||||
menu_blink_counter = 0;
|
||||
init_game();
|
||||
}
|
||||
} else if (key == KeyEvent::Left && game_state == STATE_PLAYING) {
|
||||
move_paddle_left();
|
||||
} else if (key == KeyEvent::Right && game_state == STATE_PLAYING) {
|
||||
move_paddle_right();
|
||||
} else if (key == KeyEvent::Up && game_state == STATE_MENU) {
|
||||
// Only adjust volume in menu
|
||||
adjust_volume(5);
|
||||
if (!sound_enabled) sound_enabled = true;
|
||||
set_dirty();
|
||||
} else if (key == KeyEvent::Down && game_state == STATE_MENU) {
|
||||
// Only adjust volume in menu
|
||||
adjust_volume(-5);
|
||||
set_dirty();
|
||||
}
|
||||
|
||||
set_dirty();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BreakoutView::on_touch(const TouchEvent event) {
|
||||
(void)event; // Intentionally unused - touch disabled to avoid nav bar issues
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::breakout
|
||||
+21
-1
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "event_m0.hpp"
|
||||
#include "message.hpp"
|
||||
#include "irq_controls.hpp"
|
||||
@@ -56,15 +57,18 @@ enum {
|
||||
class BreakoutView : public View {
|
||||
public:
|
||||
BreakoutView(NavigationView& nav);
|
||||
~BreakoutView();
|
||||
void on_show() override;
|
||||
void on_hide() override;
|
||||
|
||||
std::string title() const override { return "Breakout"; }
|
||||
|
||||
void focus() override { dummy.focus(); }
|
||||
void focus() override;
|
||||
void paint(Painter& painter) override;
|
||||
void frame_sync();
|
||||
bool on_encoder(const EncoderEvent event) override;
|
||||
bool on_key(KeyEvent key) override;
|
||||
bool on_touch(const TouchEvent event) override;
|
||||
|
||||
void cls();
|
||||
void background(int color);
|
||||
@@ -81,6 +85,7 @@ class BreakoutView : public View {
|
||||
void draw_lives();
|
||||
void draw_level();
|
||||
void draw_borders();
|
||||
void draw_menu_volume_bar();
|
||||
void move_paddle_left();
|
||||
void move_paddle_right();
|
||||
void launch_ball();
|
||||
@@ -96,6 +101,15 @@ class BreakoutView : public View {
|
||||
void check_game_timer();
|
||||
void attach(double delay_sec);
|
||||
void detach();
|
||||
void adjust_volume(int delta);
|
||||
|
||||
// Sound effect methods
|
||||
void play_paddle_hit();
|
||||
void play_brick_hit();
|
||||
void play_wall_hit();
|
||||
void play_death_sound();
|
||||
void play_game_over();
|
||||
void play_level_complete();
|
||||
|
||||
private:
|
||||
const Color pp_colors[9] = {
|
||||
@@ -147,6 +161,12 @@ class BreakoutView : public View {
|
||||
double game_update_timeout = 0;
|
||||
uint32_t game_update_counter = 0;
|
||||
|
||||
// Audio control
|
||||
bool sound_enabled = true;
|
||||
int volume_level = 80; // 0-99
|
||||
uint32_t last_sound_time = 0;
|
||||
uint32_t min_sound_interval = 20; // Minimum ms between sounds
|
||||
|
||||
Button dummy{
|
||||
{screen_width, 0, 0, 0},
|
||||
""};
|
||||
|
||||
+1
-1
@@ -125,7 +125,7 @@ void DinoGameView::paint(Painter& painter) {
|
||||
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
init_game();
|
||||
}
|
||||
}
|
||||
|
||||
+13
-13
@@ -204,11 +204,11 @@ void spawn_entity(uint8_t type, uint8_t x, uint8_t y) {
|
||||
|
||||
void spawn_random_entity(uint8_t type) {
|
||||
if (num_entities >= MAX_ENTITIES) return;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
uint8_t spawn_x, spawn_y;
|
||||
do {
|
||||
spawn_x = std::rand() % LEVEL_WIDTH;
|
||||
spawn_y = std::rand() % LEVEL_HEIGHT;
|
||||
spawn_x = rand() % LEVEL_WIDTH;
|
||||
spawn_y = rand() % LEVEL_HEIGHT;
|
||||
} while (get_block_at(spawn_x, spawn_y) == 0xF ||
|
||||
(spawn_x == (uint8_t)player.pos.x && spawn_y == (uint8_t)player.pos.y));
|
||||
|
||||
@@ -227,9 +227,9 @@ void remove_entity(uint8_t index) {
|
||||
bool spawned = false;
|
||||
|
||||
while (!spawned && attempts < 50) {
|
||||
std::srand(LPC_RTC->CTIME0 + attempts);
|
||||
uint8_t spawn_x = std::rand() % LEVEL_WIDTH;
|
||||
uint8_t spawn_y = std::rand() % LEVEL_HEIGHT;
|
||||
srand(LPC_RTC->CTIME0 + attempts);
|
||||
uint8_t spawn_x = rand() % LEVEL_WIDTH;
|
||||
uint8_t spawn_y = rand() % LEVEL_HEIGHT;
|
||||
|
||||
int16_t dx = (int16_t)spawn_x - (int16_t)player.pos.x;
|
||||
int16_t dy = (int16_t)spawn_y - (int16_t)player.pos.y;
|
||||
@@ -270,9 +270,9 @@ void initialize_level() {
|
||||
uint8_t attempts = 0;
|
||||
|
||||
while (initial_enemies < 2 && num_entities < MAX_ENTITIES && attempts < 50) {
|
||||
std::srand(LPC_RTC->CTIME0 + attempts);
|
||||
int8_t offset_x = (std::rand() % 11) - 5;
|
||||
int8_t offset_y = (std::rand() % 11) - 5;
|
||||
srand(LPC_RTC->CTIME0 + attempts);
|
||||
int8_t offset_x = (rand() % 11) - 5;
|
||||
int8_t offset_y = (rand() % 11) - 5;
|
||||
|
||||
if (abs(offset_x) < 3 && abs(offset_y) < 3) {
|
||||
attempts++;
|
||||
@@ -307,10 +307,10 @@ void initialize_level() {
|
||||
|
||||
attempts = 0;
|
||||
while (num_entities < MIN_ENTITIES && attempts < 100) {
|
||||
std::srand(LPC_RTC->CTIME0 + attempts + 100);
|
||||
srand(LPC_RTC->CTIME0 + attempts + 100);
|
||||
|
||||
uint8_t spawn_x = std::rand() % LEVEL_WIDTH;
|
||||
uint8_t spawn_y = std::rand() % LEVEL_HEIGHT;
|
||||
uint8_t spawn_x = rand() % LEVEL_WIDTH;
|
||||
uint8_t spawn_y = rand() % LEVEL_HEIGHT;
|
||||
|
||||
int16_t dx = (int16_t)spawn_x - (int16_t)player.pos.x;
|
||||
int16_t dy = (int16_t)spawn_y - (int16_t)player.pos.y;
|
||||
@@ -1045,7 +1045,7 @@ void DoomView::on_show() {
|
||||
void DoomView::paint(Painter& painter) {
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
scene = 0;
|
||||
up = down = left = right = fired = false;
|
||||
jogging = view_height = 0;
|
||||
|
||||
+1
-1
@@ -118,7 +118,7 @@ class ERTAppView : public View {
|
||||
|
||||
// Prevent painting of region covered entirely by a child.
|
||||
// TODO: Add flag to View that specifies view does not need to be cleared before painting.
|
||||
void paint(Painter&) override{};
|
||||
void paint(Painter&) override {};
|
||||
|
||||
void focus() override;
|
||||
|
||||
|
||||
+152
-75
@@ -1,259 +1,313 @@
|
||||
set(EXTCPPSRC
|
||||
|
||||
#afsk_rx
|
||||
#afsk_rx 16 byte
|
||||
external/afsk_rx/main.cpp
|
||||
external/afsk_rx/ui_afsk_rx.cpp
|
||||
|
||||
#calculator
|
||||
#calculator 632 bytes
|
||||
external/calculator/main.cpp
|
||||
external/calculator/ui_calculator.cpp
|
||||
|
||||
#font_viewer
|
||||
#font_viewer 8 byte?!
|
||||
external/font_viewer/main.cpp
|
||||
external/font_viewer/ui_font_viewer.cpp
|
||||
|
||||
#blespam
|
||||
#blespam 336 bytes - array initializers?
|
||||
external/blespam/main.cpp
|
||||
external/blespam/ui_blespam.cpp
|
||||
|
||||
#analogtv
|
||||
#analogtv 552 bytes
|
||||
external/analogtv/main.cpp
|
||||
external/analogtv/analog_tv_app.cpp
|
||||
external/analogtv/ui_tv.cpp
|
||||
|
||||
#nrf_rx
|
||||
#nrf_rx 40 byte
|
||||
external/nrf_rx/main.cpp
|
||||
external/nrf_rx/ui_nrf_rx.cpp
|
||||
|
||||
#coasterp
|
||||
#coasterp 0 byte
|
||||
external/coasterp/main.cpp
|
||||
external/coasterp/ui_coasterp.cpp
|
||||
|
||||
#lge
|
||||
#lge 120 byte
|
||||
external/lge/main.cpp
|
||||
external/lge/lge_app.cpp
|
||||
external/lge/rfm69.cpp
|
||||
|
||||
#lcr
|
||||
#lcr - 460 byte flash
|
||||
external/lcr/main.cpp
|
||||
external/lcr/ui_lcr.cpp
|
||||
|
||||
#jammer
|
||||
#jammer 144 byte
|
||||
external/jammer/main.cpp
|
||||
external/jammer/ui_jammer.cpp
|
||||
|
||||
#gpssim
|
||||
#gpssim 160 byte
|
||||
external/gpssim/main.cpp
|
||||
external/gpssim/gps_sim_app.cpp
|
||||
|
||||
#spainter
|
||||
#spainter 464 byte
|
||||
external/spainter/main.cpp
|
||||
external/spainter/ui_spectrum_painter.cpp
|
||||
external/spainter/ui_spectrum_painter_text.cpp
|
||||
external/spainter/ui_spectrum_painter_image.cpp
|
||||
|
||||
#keyfob
|
||||
#keyfob 216 byte
|
||||
external/keyfob/main.cpp
|
||||
external/keyfob/ui_keyfob.cpp
|
||||
external/keyfob/ui_keyfob.hpp
|
||||
|
||||
#tetris
|
||||
#tetris 88 byte
|
||||
external/tetris/main.cpp
|
||||
external/tetris/ui_tetris.cpp
|
||||
|
||||
#extsensors
|
||||
|
||||
#extsensors 192 byte
|
||||
external/extsensors/main.cpp
|
||||
external/extsensors/ui_extsensors.cpp
|
||||
external/extsensors/ui_extsensors.hpp
|
||||
|
||||
#foxhunt
|
||||
#foxhunt 0
|
||||
external/foxhunt/main.cpp
|
||||
external/foxhunt/ui_foxhunt_rx.cpp
|
||||
external/foxhunt/ui_foxhunt_rx.hpp
|
||||
|
||||
#audio_test
|
||||
#audio_test 192 byte
|
||||
external/audio_test/main.cpp
|
||||
external/audio_test/ui_audio_test.cpp
|
||||
|
||||
#wardrivemap
|
||||
#wardrivemap 64 byte
|
||||
external/wardrivemap/main.cpp
|
||||
external/wardrivemap/ui_wardrivemap.cpp
|
||||
|
||||
#tpmsrx
|
||||
#tpmsrx 920 byte- possible shared part with baseband
|
||||
external/tpmsrx/main.cpp
|
||||
external/tpmsrx/tpms_app.cpp
|
||||
|
||||
#protoview
|
||||
#tpmstx 800 bytes - TPMS transmit with editable fields
|
||||
external/tpmstx/main.cpp
|
||||
external/tpmstx/tpms_tx_app.cpp
|
||||
|
||||
#protoview 8 byte
|
||||
external/protoview/main.cpp
|
||||
external/protoview/ui_protoview.cpp
|
||||
|
||||
#adsbtx
|
||||
#adsbtx 3544 byte - adsb shared part
|
||||
external/adsbtx/main.cpp
|
||||
external/adsbtx/ui_adsb_tx.cpp
|
||||
|
||||
#morse_tx
|
||||
external/morse_tx/main.cpp
|
||||
external/morse_tx/ui_morse.cpp
|
||||
#morse_tx 768 bytes -- disabled because of the new morse tx app with more functions
|
||||
#external/morse_tx/main.cpp
|
||||
#external/morse_tx/ui_morse.cpp
|
||||
|
||||
#sstvtx
|
||||
#sstvtx 456 bytes
|
||||
external/sstvtx/main.cpp
|
||||
external/sstvtx/ui_sstvtx.cpp
|
||||
|
||||
#random
|
||||
#sstvrx
|
||||
external/sstvrx/main.cpp
|
||||
external/sstvrx/ui_sstvrx.cpp
|
||||
|
||||
#random 464 bytes.
|
||||
external/random_password/main.cpp
|
||||
external/random_password/ui_random_password.cpp
|
||||
external/random_password/sha512.cpp
|
||||
external/random_password/sha512.h
|
||||
|
||||
#acars
|
||||
external/acars_rx/main.cpp
|
||||
external/acars_rx/acars_app.cpp
|
||||
#external/acars_rx/main.cpp
|
||||
#external/acars_rx/acars_app.cpp
|
||||
|
||||
#wefax_rx
|
||||
#wefax_rx 192 bytes
|
||||
external/wefax_rx/main.cpp
|
||||
external/wefax_rx/ui_wefax_rx.cpp
|
||||
|
||||
|
||||
#noaaapt_rx
|
||||
#noaaapt_rx 72 bytes
|
||||
external/noaaapt_rx/main.cpp
|
||||
external/noaaapt_rx/ui_noaaapt_rx.cpp
|
||||
|
||||
|
||||
|
||||
#shoppingcart_lock
|
||||
#shoppingcart_lock 272 bytes
|
||||
external/shoppingcart_lock/main.cpp
|
||||
external/shoppingcart_lock/shoppingcart_lock.cpp
|
||||
|
||||
#ookbrute
|
||||
|
||||
#ookbrute 80 byte
|
||||
external/ookbrute/main.cpp
|
||||
external/ookbrute/ui_ookbrute.cpp
|
||||
|
||||
#ook_editor
|
||||
#ook_editor 1808 bytes
|
||||
external/ook_editor/main.cpp
|
||||
external/ook_editor/ui_ook_editor.cpp
|
||||
|
||||
#cvs_spam
|
||||
#cvs_spam 24 byte
|
||||
external/cvs_spam/main.cpp
|
||||
external/cvs_spam/cvs_spam.cpp
|
||||
|
||||
#flippertx
|
||||
#flippertx 712 bytes
|
||||
external/flippertx/main.cpp
|
||||
external/flippertx/ui_flippertx.cpp
|
||||
|
||||
#remote
|
||||
#remote 1664 bytes
|
||||
external/remote/main.cpp
|
||||
external/remote/ui_remote.cpp
|
||||
|
||||
#mcu_temperature
|
||||
#mcu_temperature 112
|
||||
external/mcu_temperature/main.cpp
|
||||
external/mcu_temperature/mcu_temperature.cpp
|
||||
|
||||
#fmradio
|
||||
#fmradio 640
|
||||
external/fmradio/main.cpp
|
||||
external/fmradio/ui_fmradio.cpp
|
||||
|
||||
#tuner
|
||||
#tuner 384
|
||||
external/tuner/main.cpp
|
||||
external/tuner/ui_tuner.cpp
|
||||
|
||||
#metronome
|
||||
#metronome 696 bytes
|
||||
external/metronome/main.cpp
|
||||
external/metronome/ui_metronome.cpp
|
||||
|
||||
#app_manager
|
||||
#app_manager 40 bytes
|
||||
external/app_manager/main.cpp
|
||||
external/app_manager/ui_app_manager.cpp
|
||||
|
||||
#hopper
|
||||
#hopper 472 bytes
|
||||
external/hopper/main.cpp
|
||||
external/hopper/ui_hopper.cpp
|
||||
|
||||
# whip calculator
|
||||
# whip calculator 48 bytes
|
||||
external/antenna_length/main.cpp
|
||||
external/antenna_length/ui_whipcalc.cpp
|
||||
|
||||
# wav viewer
|
||||
# wav viewer 1232 bytes
|
||||
external/wav_view/main.cpp
|
||||
external/wav_view/ui_view_wav.cpp
|
||||
|
||||
# wipe sdcard
|
||||
|
||||
# wipe sdcard 16 byte
|
||||
external/sd_wipe/main.cpp
|
||||
external/sd_wipe/ui_sd_wipe.cpp
|
||||
|
||||
# playlist editor
|
||||
# playlist editor 232 bytes
|
||||
external/playlist_editor/main.cpp
|
||||
external/playlist_editor/ui_playlist_editor.cpp
|
||||
|
||||
#snake
|
||||
#snake 240 bytes
|
||||
external/snake/main.cpp
|
||||
external/snake/ui_snake.cpp
|
||||
|
||||
#stopwatch
|
||||
|
||||
#stopwatch 0
|
||||
external/stopwatch/main.cpp
|
||||
external/stopwatch/ui_stopwatch.cpp
|
||||
|
||||
#breakout
|
||||
#breakout 1144 bytes
|
||||
external/breakout/main.cpp
|
||||
external/breakout/ui_breakout.cpp
|
||||
|
||||
#dinogame
|
||||
#dinogame 0
|
||||
external/dinogame/main.cpp
|
||||
external/dinogame/ui_dinogame.cpp
|
||||
|
||||
#doom
|
||||
#doom 224
|
||||
external/doom/main.cpp
|
||||
external/doom/ui_doom.cpp
|
||||
|
||||
#debug_pmem
|
||||
#debug_pmem 944 byte
|
||||
external/debug_pmem/main.cpp
|
||||
external/debug_pmem/ui_debug_pmem.cpp
|
||||
|
||||
#scanner
|
||||
#scanner 520 byte
|
||||
external/scanner/main.cpp
|
||||
external/scanner/ui_scanner.cpp
|
||||
|
||||
#level
|
||||
#level 24 byte
|
||||
external/level/main.cpp
|
||||
external/level/ui_level.cpp
|
||||
|
||||
#gfxEQ
|
||||
#gfxEQ 80 byte
|
||||
external/gfxeq/main.cpp
|
||||
external/gfxeq/ui_gfxeq.cpp
|
||||
external/gfxeq/ui_gfxeq.cpp
|
||||
|
||||
#detector_rx
|
||||
#waterfall designer
|
||||
external/waterfall_designer/main.cpp
|
||||
external/waterfall_designer/ui_waterfall_designer.cpp
|
||||
|
||||
#detector_rx 168 byte
|
||||
external/detector_rx/main.cpp
|
||||
external/detector_rx/ui_detector_rx.cpp
|
||||
|
||||
#space_invaders
|
||||
#space_invaders 0 byte
|
||||
external/spaceinv/main.cpp
|
||||
external/spaceinv/ui_spaceinv.cpp
|
||||
|
||||
#blackjack
|
||||
#blackjack 24 byte
|
||||
external/blackjack/main.cpp
|
||||
external/blackjack/ui_blackjack.cpp
|
||||
|
||||
#battleship
|
||||
#battleship 256 byte
|
||||
external/battleship/main.cpp
|
||||
external/battleship/ui_battleship.cpp
|
||||
|
||||
#ert
|
||||
#ert 3040 bytes - has common with baseband, could be renamed the namespace, so both could have it, but not kept in fw.
|
||||
external/ert/main.cpp
|
||||
external/ert/ert_app.cpp
|
||||
|
||||
#epirb_rx
|
||||
#epirb_rx 168 byte flash
|
||||
external/epirb_rx/main.cpp
|
||||
external/epirb_rx/ui_epirb_rx.cpp
|
||||
|
||||
#soundboard
|
||||
#soundboard 272byte - 1236 bytes
|
||||
external/soundboard/main.cpp
|
||||
external/soundboard/soundboard_app.cpp
|
||||
|
||||
#game2048
|
||||
#game2048 - 168 byte flash
|
||||
external/game2048/main.cpp
|
||||
external/game2048/ui_game2048.cpp
|
||||
|
||||
#bht_tx
|
||||
#bht_tx - 3920 byte flash, unknown
|
||||
external/bht_tx/main.cpp
|
||||
external/bht_tx/ui_bht_tx.cpp
|
||||
external/bht_tx/bht.cpp
|
||||
|
||||
#morse_practice - 80 byte flash - bc of array initializers
|
||||
external/morse_practice/main.cpp
|
||||
external/morse_practice/ui_morse_practice.cpp
|
||||
|
||||
#adult_toys_controller 144 bytes
|
||||
external/adult_toys_controller/main.cpp
|
||||
external/adult_toys_controller/ui_adult_toys_controller.cpp
|
||||
|
||||
#flex_rx
|
||||
external/flex_rx/main.cpp
|
||||
external/flex_rx/ui_flex_rx.cpp
|
||||
|
||||
#subcarrx
|
||||
external/subcarrx/main.cpp
|
||||
external/subcarrx/ui_subcar.cpp
|
||||
|
||||
#siggen
|
||||
external/siggen/main.cpp
|
||||
external/siggen/ui_siggen.cpp
|
||||
|
||||
#morse_radio
|
||||
external/morse_radio/main.cpp
|
||||
external/morse_radio/ui_morse_radio.cpp
|
||||
|
||||
#morseradiotx
|
||||
external/morseradiotx/main.cpp
|
||||
external/morseradiotx/ui_morse_radiotx.cpp
|
||||
|
||||
external/keeloqtx/main.cpp
|
||||
external/keeloqtx/ui_keeloqtx.cpp
|
||||
#rtty_rx
|
||||
external/rtty_rx/main.cpp
|
||||
external/rtty_rx/ui_rtty_rx.cpp
|
||||
external/rtty_rx/baudot.cpp
|
||||
|
||||
#rtty_tx
|
||||
external/rtty_tx/main.cpp
|
||||
external/rtty_tx/ui_rtty_tx.cpp
|
||||
external/rtty_tx/baudot.cpp
|
||||
)
|
||||
|
||||
set(EXTAPPLIST
|
||||
@@ -261,8 +315,8 @@ set(EXTAPPLIST
|
||||
calculator
|
||||
font_viewer
|
||||
blespam
|
||||
nrf_rx
|
||||
analogtv
|
||||
nrf_rx
|
||||
coasterp
|
||||
lge
|
||||
lcr
|
||||
@@ -275,19 +329,21 @@ set(EXTAPPLIST
|
||||
foxhunt_rx
|
||||
audio_test
|
||||
wardrivemap
|
||||
cvs_spam
|
||||
tpmsrx
|
||||
tpmstx
|
||||
protoview
|
||||
adsbtx
|
||||
morse_tx
|
||||
#morse_tx
|
||||
sstvtx
|
||||
sstvrx
|
||||
random_password
|
||||
# acars_rx
|
||||
ookbrute
|
||||
ook_editor
|
||||
# acars_rx --not working
|
||||
wefax_rx
|
||||
noaaapt_rx
|
||||
shoppingcart_lock
|
||||
ookbrute
|
||||
ook_editor
|
||||
cvs_spam
|
||||
flippertx
|
||||
remote
|
||||
mcu_temperature
|
||||
@@ -309,6 +365,7 @@ set(EXTAPPLIST
|
||||
scanner
|
||||
level
|
||||
gfxeq
|
||||
waterfall_designer
|
||||
detector_rx
|
||||
spaceinv
|
||||
blackjack
|
||||
@@ -318,4 +375,24 @@ set(EXTAPPLIST
|
||||
soundboard
|
||||
game2048
|
||||
bht_tx
|
||||
morse_practice
|
||||
adult_toys_controller
|
||||
flex_rx
|
||||
subcarrx
|
||||
siggen
|
||||
morse_radio
|
||||
morseradiotx
|
||||
keeloqtx
|
||||
rtty_rx
|
||||
rtty_tx
|
||||
)
|
||||
|
||||
# sdusb has type conflicts with PRALINE (HackRF Pro) - add only for non-PRALINE builds
|
||||
if(NOT BOARD STREQUAL "PRALINE")
|
||||
list(APPEND EXTCPPSRC
|
||||
external/sdusb/main.cpp
|
||||
external/sdusb/ui_sd_over_usb.cpp
|
||||
)
|
||||
list(APPEND EXTAPPLIST sdusb)
|
||||
endif()
|
||||
|
||||
|
||||
+97
-3
@@ -83,9 +83,21 @@ MEMORY
|
||||
ram_external_app_epirb_rx (rwx) : org = 0xADEA0000, len = 32k
|
||||
ram_external_app_soundboard (rwx) : org = 0xADEB0000, len = 32k
|
||||
ram_external_app_game2048 (rwx) : org = 0xADEC0000, len = 32k
|
||||
ram_external_app_bht_tx (rwx) : org = 0xADED0000, len = 32k
|
||||
|
||||
|
||||
ram_external_app_bht_tx (rwx) : org = 0xADED0000, len = 32k
|
||||
ram_external_app_morse_practice (rwx) : org = 0xADEE0000, len = 32k
|
||||
ram_external_app_adult_toys_controller (rwx) : org = 0xADEF0000, len = 32k
|
||||
ram_external_app_flex_rx (rwx) : org = 0xADF00000, len = 32k
|
||||
ram_external_app_sstvrx (rwx) : org = 0xADF10000, len = 32k
|
||||
ram_external_app_subcarrx (rwx) : org = 0xADF20000, len = 32k
|
||||
ram_external_app_siggen (rwx) : org = 0xADF30000, len = 32k
|
||||
ram_external_app_sdusb (rwx) : org = 0xADF40000, len = 32k
|
||||
ram_external_app_morse_radio (rwx) : org = 0xADF50000, len = 32k
|
||||
ram_external_app_waterfall_designer (rwx) : org = 0xADF60000, len = 32k
|
||||
ram_external_app_morseradiotx (rwx) : org = 0xADF70000, len = 32k
|
||||
ram_external_app_keeloqtx (rwx) : org = 0xADF80000, len = 32k
|
||||
ram_external_app_rtty_rx (rwx) : org = 0xADF90000, len = 32k
|
||||
ram_external_app_rtty_tx (rwx) : org = 0xADFA0000, len = 32k
|
||||
ram_external_app_tpmstx (rwx) : org = 0xADFB0000, len = 32k
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
@@ -204,6 +216,12 @@ SECTIONS
|
||||
*(*ui*external_app*tpmsrx*);
|
||||
} > ram_external_app_tpmsrx
|
||||
|
||||
.external_app_tpmstx : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_tpmstx.application_information));
|
||||
*(*ui*external_app*tpmstx*);
|
||||
} > ram_external_app_tpmstx
|
||||
|
||||
.external_app_protoview : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_protoview.application_information));
|
||||
@@ -396,6 +414,12 @@ SECTIONS
|
||||
*(*ui*external_app*gfxeq*);
|
||||
} > ram_external_app_gfxeq
|
||||
|
||||
.external_app_waterfall_designer : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_waterfall_designer.application_information));
|
||||
*(*ui*external_app*waterfall_designer*);
|
||||
} > ram_external_app_waterfall_designer
|
||||
|
||||
.external_app_detector_rx : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_detector_rx.application_information));
|
||||
@@ -458,5 +482,75 @@ SECTIONS
|
||||
} > ram_external_app_bht_tx
|
||||
|
||||
|
||||
.external_app_morse_practice : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_morse_practice.application_information));
|
||||
*(*ui*external_app*morse_practice*);
|
||||
} > ram_external_app_morse_practice
|
||||
|
||||
.external_app_adult_toys_controller : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_adult_toys_controller.application_information));
|
||||
*(*ui*external_app*adult_toys_controller*);
|
||||
} > ram_external_app_adult_toys_controller
|
||||
|
||||
.external_app_flex_rx : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_flex_rx.application_information));
|
||||
*(*ui*external_app*flex_rx*);
|
||||
} > ram_external_app_flex_rx
|
||||
|
||||
.external_app_sstvrx : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_sstvrx.application_information));
|
||||
*(*ui*external_app*sstvrx*);
|
||||
} > ram_external_app_sstvrx
|
||||
|
||||
.external_app_subcarrx : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_subcarrx.application_information));
|
||||
*(*ui*external_app*subcarrx*);
|
||||
} > ram_external_app_subcarrx
|
||||
|
||||
.external_app_siggen : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_siggen.application_information));
|
||||
*(*ui*external_app*siggen*);
|
||||
} > ram_external_app_siggen
|
||||
|
||||
.external_app_sdusb : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_sdusb.application_information));
|
||||
*(*ui*external_app*sdusb*);
|
||||
} > ram_external_app_sdusb
|
||||
|
||||
.external_app_morse_radio : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_morse_radio.application_information));
|
||||
*(*ui*external_app*morse_radio*);
|
||||
} > ram_external_app_morse_radio
|
||||
|
||||
.external_app_morseradiotx : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_morseradiotx.application_information));
|
||||
*(*ui*external_app*morseradiotx*);
|
||||
} > ram_external_app_morseradiotx
|
||||
|
||||
.external_app_keeloqtx : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_keeloqtx.application_information));
|
||||
*(*ui*external_app*keeloqtx*);
|
||||
} > ram_external_app_keeloqtx
|
||||
.external_app_rtty_rx : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_rtty_rx.application_information));
|
||||
*(*ui*external_app*rtty_rx*);
|
||||
} > ram_external_app_rtty_rx
|
||||
|
||||
.external_app_rtty_tx : ALIGN(4) SUBALIGN(4)
|
||||
{
|
||||
KEEP(*(.external_app.app_rtty_tx.application_information));
|
||||
*(*ui*external_app*rtty_tx*);
|
||||
} > ram_external_app_rtty_tx
|
||||
}
|
||||
|
||||
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright (C) 2025 HTotoo
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_flex_rx.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::flex_rx {
|
||||
void initialize_app(ui::NavigationView& nav) {
|
||||
nav.push<FlexAppView>();
|
||||
}
|
||||
} // namespace ui::external_app::flex_rx
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_flex_rx.application_information"), used)) application_information_t _application_information_flex_rx = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::flex_rx::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
|
||||
/*.app_name = */ "FLEX RX",
|
||||
/*.bitmap_data = */ {
|
||||
0x00,
|
||||
0x00,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0x02,
|
||||
0x40,
|
||||
0xFA,
|
||||
0x5F,
|
||||
0x02,
|
||||
0x40,
|
||||
0xF2,
|
||||
0x4F,
|
||||
0x02,
|
||||
0x40,
|
||||
0xE2,
|
||||
0x47,
|
||||
0x02,
|
||||
0x40,
|
||||
0xC2,
|
||||
0x43,
|
||||
0x02,
|
||||
0x40,
|
||||
0x82,
|
||||
0x41,
|
||||
0x02,
|
||||
0x40,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
},
|
||||
/*.icon_color = */ ui::Color::orange().v,
|
||||
/*.menu_location = */ app_location_t::RX,
|
||||
/*.desired_menu_position = */ -1,
|
||||
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_flex */ {'P', 'F', 'L', 'X'},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
#include "ui_flex_rx.hpp"
|
||||
|
||||
#include "baseband_api.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "memory_map.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
|
||||
namespace ui::external_app::flex_rx {
|
||||
|
||||
FlexAppView::FlexAppView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
// Load baseband image for FLEX decoding
|
||||
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
|
||||
|
||||
add_children({&field_frequency,
|
||||
&field_rf_amp,
|
||||
&field_lna,
|
||||
&field_vga,
|
||||
&rssi,
|
||||
&console});
|
||||
|
||||
// Restore saved frequency
|
||||
field_frequency.set_value(frequency_value);
|
||||
receiver_model.set_target_frequency(frequency_value);
|
||||
|
||||
// Frequency change callback
|
||||
field_frequency.updated = [this](rf::Frequency f) {
|
||||
update_freq(f);
|
||||
};
|
||||
|
||||
// Configure receiver
|
||||
receiver_model.set_sampling_rate(3072000);
|
||||
receiver_model.set_baseband_bandwidth(1750000);
|
||||
receiver_model.enable();
|
||||
receiver_model.set_squelch_level(0);
|
||||
|
||||
// Initialize FLEX baseband
|
||||
baseband::set_flex_config();
|
||||
|
||||
console.writeln("Ready");
|
||||
}
|
||||
|
||||
FlexAppView::~FlexAppView() {
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
void FlexAppView::focus() {
|
||||
field_frequency.focus();
|
||||
}
|
||||
|
||||
// Redraw all messages to console
|
||||
void FlexAppView::redraw_console() {
|
||||
console.clear(true);
|
||||
bool first = true;
|
||||
for (const auto& msg : messages) {
|
||||
if (!first) {
|
||||
console.writeln(""); // Blank line between messages
|
||||
}
|
||||
first = false;
|
||||
console.writeln(msg);
|
||||
}
|
||||
}
|
||||
|
||||
// Add message to log with automatic line wrapping
|
||||
void FlexAppView::log_message(const std::string& message) {
|
||||
const size_t chars_per_line = screen_width / 8;
|
||||
// Console height accounts for status bar and controls row
|
||||
const size_t console_lines = (screen_height - 2 * 16) / 16;
|
||||
|
||||
messages.push_back(message);
|
||||
|
||||
// Calculate total lines used (messages + blank lines between them)
|
||||
size_t total_lines = 0;
|
||||
for (size_t i = 0; i < messages.size(); i++) {
|
||||
if (i > 0) total_lines++; // Count blank line separator
|
||||
size_t msg_lines = (messages[i].length() + chars_per_line - 1) / chars_per_line;
|
||||
if (msg_lines == 0) msg_lines = 1;
|
||||
total_lines += msg_lines;
|
||||
}
|
||||
|
||||
// If console would overflow, remove oldest messages and redraw
|
||||
if (total_lines > console_lines) {
|
||||
while (total_lines > console_lines && !messages.empty()) {
|
||||
const auto& oldest = messages.front();
|
||||
size_t oldest_lines = (oldest.length() + chars_per_line - 1) / chars_per_line;
|
||||
if (oldest_lines == 0) oldest_lines = 1;
|
||||
total_lines -= oldest_lines;
|
||||
if (messages.size() > 1) total_lines--; // Remove separator line too
|
||||
messages.erase(messages.begin());
|
||||
}
|
||||
redraw_console();
|
||||
} else {
|
||||
// Just append new message
|
||||
if (messages.size() > 1) {
|
||||
console.writeln(""); // Blank line before new message
|
||||
}
|
||||
console.writeln(message);
|
||||
}
|
||||
}
|
||||
|
||||
// Update frequency and save for persistence
|
||||
void FlexAppView::update_freq(rf::Frequency f) {
|
||||
frequency_value = f;
|
||||
receiver_model.set_target_frequency(f);
|
||||
}
|
||||
|
||||
// Handle decoded FLEX packet from baseband
|
||||
void FlexAppView::on_packet(const FlexPacketMessage* message) {
|
||||
log_message(message->packet.message);
|
||||
}
|
||||
|
||||
// Handle stats message (currently unused)
|
||||
void FlexAppView::on_stats(const FlexStatsMessage*) {
|
||||
}
|
||||
|
||||
// Debug handler - uncomment to see baseband debug messages
|
||||
void FlexAppView::on_debug(const FlexDebugMessage* message) {
|
||||
(void)message; // Suppress unused parameter warning
|
||||
// std::string text = "DBG: ";
|
||||
// text += message->text;
|
||||
// text += " " + to_string_hex(message->val1, 8);
|
||||
// text += " " + to_string_hex(message->val2, 8);
|
||||
// log_message(text);
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::flex_rx
|
||||
@@ -0,0 +1,97 @@
|
||||
#ifndef __UI_FLEX_RX_H__
|
||||
#define __UI_FLEX_RX_H__
|
||||
|
||||
#include "ui_widget.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "ui_freq_field.hpp"
|
||||
#include "ui_rssi.hpp"
|
||||
#include "app_settings.hpp"
|
||||
#include "radio_state.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ui::external_app::flex_rx {
|
||||
|
||||
class FlexAppView : public View {
|
||||
public:
|
||||
FlexAppView(NavigationView& nav);
|
||||
~FlexAppView();
|
||||
|
||||
void focus() override;
|
||||
std::string title() const override { return "FLEX RX"; };
|
||||
|
||||
private:
|
||||
NavigationView& nav_;
|
||||
|
||||
// Saved settings
|
||||
rf::Frequency frequency_value{931740000}; // Default FLEX frequency
|
||||
|
||||
RxRadioState radio_state_{};
|
||||
|
||||
// Message storage for console redraw
|
||||
static constexpr size_t MAX_MESSAGES = 20;
|
||||
std::vector<std::string> messages{};
|
||||
|
||||
// Helper methods
|
||||
void log_message(const std::string& message);
|
||||
void redraw_console();
|
||||
void update_freq(rf::Frequency f);
|
||||
|
||||
// UI Elements - Row 0, dynamically positioned
|
||||
RxFrequencyField field_frequency{
|
||||
{UI_POS_X(0), UI_POS_Y(0)},
|
||||
nav_};
|
||||
|
||||
RFAmpField field_rf_amp{
|
||||
{UI_POS_X(13), UI_POS_Y(0)}};
|
||||
LNAGainField field_lna{
|
||||
{UI_POS_X(15), UI_POS_Y(0)}};
|
||||
VGAGainField field_vga{
|
||||
{UI_POS_X(18), UI_POS_Y(0)}};
|
||||
|
||||
RSSI rssi{
|
||||
{UI_POS_X(21), 0, UI_POS_WIDTH(9), 4}};
|
||||
|
||||
// Message display area (below controls, account for status bar)
|
||||
Console console{
|
||||
{0, 1 * 16, screen_width, screen_height - 2 * 16}};
|
||||
|
||||
// Persistent settings manager
|
||||
app_settings::SettingsManager settings_{
|
||||
"rx_flex",
|
||||
app_settings::Mode::RX,
|
||||
{{"frequency", &frequency_value}}};
|
||||
|
||||
// Message handlers
|
||||
void on_packet(const FlexPacketMessage* message);
|
||||
void on_stats(const FlexStatsMessage* message);
|
||||
void on_debug(const FlexDebugMessage* message);
|
||||
|
||||
// Message handler registrations
|
||||
MessageHandlerRegistration message_handler_packet{
|
||||
Message::ID::FlexPacket,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *static_cast<const FlexPacketMessage*>(p);
|
||||
this->on_packet(&message);
|
||||
}};
|
||||
|
||||
MessageHandlerRegistration message_handler_stats{
|
||||
Message::ID::FlexStats,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *static_cast<const FlexStatsMessage*>(p);
|
||||
this->on_stats(&message);
|
||||
}};
|
||||
|
||||
MessageHandlerRegistration message_handler_debug{
|
||||
Message::ID::FlexDebug,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *static_cast<const FlexDebugMessage*>(p);
|
||||
this->on_debug(&message);
|
||||
}};
|
||||
};
|
||||
|
||||
} // namespace ui::external_app::flex_rx
|
||||
|
||||
#endif /*__UI_FLEX_RX_H__*/
|
||||
@@ -80,7 +80,7 @@ bool FlipperTxView::on_file_changed(std::filesystem::path new_file_path) {
|
||||
return false;
|
||||
}
|
||||
preset = submeta.value().preset;
|
||||
if (preset != FLIPPER_PRESET_OOK) {
|
||||
if (preset != FLIPPER_PRESET_OOK && preset != FLIPPER_PRESET_2FSK) {
|
||||
field_filename.set_text("File: err, not supp. preset");
|
||||
return false;
|
||||
}
|
||||
@@ -108,8 +108,13 @@ void FlipperTxView::stop() {
|
||||
bool FlipperTxView::start() {
|
||||
if (filename.empty()) return false;
|
||||
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
|
||||
transmitter_model.set_sampling_rate(OOK_SAMPLERATE);
|
||||
transmitter_model.enable();
|
||||
button_startstop.set_text(LanguageHelper::currentMessages[LANG_STOP]);
|
||||
uint8_t mode = 0;
|
||||
if (preset == FLIPPER_PRESET_2FSK)
|
||||
mode = 1;
|
||||
baseband::set_bitstream_config(FM_DEVIATION, mode);
|
||||
// start thread
|
||||
replay_thread = std::make_unique<FlipperPlayThread>(
|
||||
filename,
|
||||
|
||||
@@ -28,6 +28,8 @@ using namespace ui;
|
||||
namespace ui::external_app::flippertx {
|
||||
|
||||
#define OOK_SAMPLERATE 2280000U
|
||||
#define FM_DEVIATION 60000U
|
||||
|
||||
class FlipperPlayThread;
|
||||
class FlipperTxView : public View {
|
||||
public:
|
||||
@@ -79,7 +81,7 @@ class FlipperTxView : public View {
|
||||
void on_tx_progress(const bool done);
|
||||
bool on_file_changed(std::filesystem::path new_file_path);
|
||||
|
||||
std::filesystem::path filename = {};
|
||||
std::filesystem::path filename = "";
|
||||
FlipperProto proto = FLIPPER_PROTO_UNSUPPORTED;
|
||||
FlipperPreset preset = FLIPPER_PRESET_UNK;
|
||||
uint16_t te = 0; // for binraw
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ Game2048View::Game2048View(NavigationView& nav)
|
||||
|
||||
void Game2048View::on_show() {
|
||||
if (!initialized) {
|
||||
std::srand(LPC_RTC->CTIME0);
|
||||
srand(LPC_RTC->CTIME0);
|
||||
reset_game();
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ gfxEQView::gfxEQView(NavigationView& nav)
|
||||
audio::set_rate(audio::Rate::Hz_48000);
|
||||
audio::output::start();
|
||||
receiver_model.set_headphone_volume(receiver_model.headphone_volume()); // WM8731 hack
|
||||
//
|
||||
receiver_model.enable();
|
||||
|
||||
receiver_model.set_target_frequency(frequency_value); // Retune to actual freq
|
||||
|
||||
+9
-7
@@ -46,6 +46,7 @@ class gfxEQView : public View {
|
||||
NavigationView& nav_;
|
||||
|
||||
uint32_t current_theme{0};
|
||||
|
||||
const std::array<ColorTheme, 20> themes{
|
||||
ColorTheme{Color(255, 0, 255), Color(255, 255, 255)},
|
||||
ColorTheme{Color(0, 255, 0), Color(255, 0, 0)},
|
||||
@@ -68,13 +69,14 @@ class gfxEQView : public View {
|
||||
ColorTheme{Color(64, 64, 64), Color(255, 0, 0)},
|
||||
ColorTheme{Color(255, 192, 0), Color(0, 64, 128)}};
|
||||
|
||||
ButtonWithEncoder button_frequency{{UI_POS_X(0), UI_POS_Y(0) + 4, 11 * 8, 1 * 8}, ""};
|
||||
RFAmpField field_rf_amp{{13 * 8, UI_POS_Y(0)}};
|
||||
LNAGainField field_lna{{15 * 8, UI_POS_Y(0)}};
|
||||
VGAGainField field_vga{{18 * 8, UI_POS_Y(0)}};
|
||||
Button button_mood{{21 * 8, 0, 6 * 8, 16}, "MOOD"};
|
||||
AudioVolumeField field_volume{{screen_width - 2 * 8, UI_POS_Y(0)}};
|
||||
GraphEq gr{{2, UI_POS_DEFAULT_HEIGHT, UI_POS_MAXWIDTH - 4, UI_POS_HEIGHT_REMAINING(2)}, false};
|
||||
// Widgets with positions using UI_POS macros
|
||||
ButtonWithEncoder button_frequency{{UI_POS_X(0), UI_POS_Y(0) + 4, UI_POS_WIDTH(11), UI_POS_HEIGHT(1)}, ""};
|
||||
RFAmpField field_rf_amp{{UI_POS_X(12), UI_POS_Y(0) + 4}};
|
||||
LNAGainField field_lna{{UI_POS_X(14), UI_POS_Y(0) + 4}};
|
||||
VGAGainField field_vga{{UI_POS_X(17), UI_POS_Y(0) + 4}};
|
||||
Button button_mood{{UI_POS_X(21), UI_POS_Y(0) + 4, UI_POS_WIDTH(4), UI_POS_HEIGHT(1)}, "MOOD"};
|
||||
AudioVolumeField field_volume{{UI_POS_X_RIGHT(2), UI_POS_Y(0) + 4}};
|
||||
GraphEq gr{{2, UI_POS_Y(1) + 8, UI_POS_MAXWIDTH, UI_POS_Y_BOTTOM(1) - 28}, false};
|
||||
|
||||
rf::Frequency frequency_value{93100000};
|
||||
|
||||
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2026 lifegame1lu111
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_keeloqtx.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::ui_keeloqtx {
|
||||
void initialize_app(ui::NavigationView& nav) {
|
||||
nav.push<KeeloqTXView>();
|
||||
}
|
||||
} // namespace ui::external_app::ui_keeloqtx
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_keeloqtx.application_information"), used)) application_information_t _application_information_keeloqtx = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::ui_keeloqtx::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
/*.app_name = */ "KeeLoq TX",
|
||||
/*.bitmap_data = */ {
|
||||
0x20,
|
||||
0x00,
|
||||
0x20,
|
||||
0x00,
|
||||
0x20,
|
||||
0x00,
|
||||
0x20,
|
||||
0x00,
|
||||
0xE0,
|
||||
0x07,
|
||||
0xF0,
|
||||
0x0F,
|
||||
0x30,
|
||||
0x0C,
|
||||
0x30,
|
||||
0x0C,
|
||||
0xF0,
|
||||
0x0F,
|
||||
0xF0,
|
||||
0x0F,
|
||||
0x70,
|
||||
0x0D,
|
||||
0xB0,
|
||||
0x0E,
|
||||
0x70,
|
||||
0x0D,
|
||||
0xB0,
|
||||
0x0E,
|
||||
0xF0,
|
||||
0x0F,
|
||||
0xE0,
|
||||
0x07,
|
||||
},
|
||||
/*.icon_color = */ ui::Color::yellow().v,
|
||||
/*.menu_location = */ app_location_t::TX,
|
||||
/*.desired_menu_position = */ -1,
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_ook */ {'P', 'O', 'O', 'K'},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
#include "ui_keeloqtx.hpp"
|
||||
#include "ui_fileman.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "../../keeloq_common.hpp"
|
||||
#include "../../baseband/fprotos/fprotogeneral.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
using namespace ui;
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace ui::external_app::ui_keeloqtx {
|
||||
|
||||
void KeeloqTXView::focus() {
|
||||
button_open.focus();
|
||||
}
|
||||
|
||||
void KeeloqTXView::update_hop() {
|
||||
hop = data.btn << 28 | (data.serial & 0x3FF) << 16 | data.counter;
|
||||
|
||||
if (data.mf_name == "Aprimatic") {
|
||||
uint32_t apri_serial = data.serial;
|
||||
uint8_t apr1 = 0;
|
||||
|
||||
for (uint16_t i = 1; i != 0b10000000000; i <<= 1) {
|
||||
if (apri_serial & i) apr1++;
|
||||
}
|
||||
|
||||
apri_serial &= 0b00001111111111;
|
||||
|
||||
if (apr1 % 2 == 0) {
|
||||
apri_serial |= 0b110000000000;
|
||||
}
|
||||
|
||||
hop = data.btn << 28 | (apri_serial & 0xFFF) << 16 | data.counter;
|
||||
} else if (
|
||||
data.mf_name == "DTM_Neo" || data.mf_name == "FAAC_RC,XT" || data.mf_name == "Mutanco_Mutancode" || data.mf_name == "Came_Space" || data.mf_name == "Genius_Bravo" || data.mf_name == "GSN" || data.mf_name == "Rosh" || data.mf_name == "Rossi" || data.mf_name == "Peccinin" || data.mf_name == "Steelmate" || data.mf_name == "Cardin_S449") {
|
||||
hop = data.btn << 28 | (data.serial & 0xFFF) << 16 | data.counter;
|
||||
} else if (
|
||||
data.mf_name == "NICE_Smilo" || data.mf_name == "NICE_MHOUSE" || data.mf_name == "JCM_Tech") {
|
||||
hop = data.btn << 28 | (data.serial & 0xFF) << 16 | data.counter;
|
||||
} else if (data.mf_name == "Merlin") {
|
||||
hop = data.btn << 28 | (0x000) << 16 | data.counter;
|
||||
} else if (data.mf_name == "Centurion") {
|
||||
hop = data.btn << 28 | (0x1CE) << 16 | data.counter;
|
||||
} else if (data.mf_name == "Monarch") {
|
||||
hop = data.btn << 28 | (0x100) << 16 | data.counter;
|
||||
} else if (data.mf_name == "Dea_Mio") {
|
||||
uint8_t first_disc_num = (data.serial >> 8) & 0xF;
|
||||
uint8_t result_disc = (0xC + (first_disc_num % 4));
|
||||
|
||||
uint32_t dea_serial = (data.serial & 0xFF) | (((uint32_t)result_disc) << 8);
|
||||
|
||||
hop = data.btn << 28 | (dea_serial & 0xFFF) << 16 | data.counter;
|
||||
}
|
||||
|
||||
text_hop.set(to_string_hex(hop));
|
||||
}
|
||||
|
||||
void KeeloqTXView::update_payload() {
|
||||
uint64_t encrypt = 0;
|
||||
|
||||
switch (current_key.type) {
|
||||
case KEELOQ_SIMPLE_LEARNING: {
|
||||
encrypt = keeloq_encrypt(hop, current_key.key);
|
||||
|
||||
break;
|
||||
}
|
||||
case KEELOQ_NORMAL_LEARNING: {
|
||||
uint64_t man = keeloq_normal_learning(fix, current_key.key);
|
||||
|
||||
encrypt = keeloq_encrypt(hop, man);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
payload = (uint64_t)fix << 32 | encrypt;
|
||||
|
||||
uint64_t preview_payload = FProtoGeneral::subghz_protocol_blocks_reverse_key(payload, 64);
|
||||
|
||||
text_payload.set(to_string_hex(preview_payload));
|
||||
encode_data();
|
||||
}
|
||||
|
||||
void KeeloqTXView::encode_data() {
|
||||
std::string fragments{};
|
||||
|
||||
for (uint32_t i = 0; i < 64; ++i) {
|
||||
fragments += keeloq_fragments[bit(payload, i)];
|
||||
}
|
||||
|
||||
encoded_data = KEELOQ_HEADER + fragments + "1001";
|
||||
|
||||
if (data.mf_name == "Sommer") {
|
||||
pause_duration = 28;
|
||||
} else {
|
||||
pause_duration = 39;
|
||||
}
|
||||
}
|
||||
|
||||
KeeloqTXView::KeeloqTXView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
baseband::run_image(portapack::spi_flash::image_tag_ook);
|
||||
|
||||
add_children({&labels,
|
||||
&text_mf_name,
|
||||
&text_serial,
|
||||
&text_fix,
|
||||
&text_hop,
|
||||
&field_counter,
|
||||
&field_button,
|
||||
&field_repeat,
|
||||
&text_payload,
|
||||
&button_open,
|
||||
&text_status,
|
||||
&progressbar,
|
||||
&tx_view});
|
||||
|
||||
field_counter.on_change = [this](uint32_t value) {
|
||||
data.counter = (uint16_t)value;
|
||||
|
||||
update_hop();
|
||||
update_payload();
|
||||
};
|
||||
|
||||
field_button.on_change = [this](uint32_t value) {
|
||||
data.btn = (uint8_t)value;
|
||||
|
||||
fix &= 0xFFFFFFF;
|
||||
fix |= data.btn << 28;
|
||||
|
||||
text_fix.set(to_string_hex(fix));
|
||||
|
||||
update_hop();
|
||||
update_payload();
|
||||
};
|
||||
|
||||
field_repeat.on_change = [this](uint32_t value) {
|
||||
repeat = value;
|
||||
};
|
||||
|
||||
field_repeat.set_value(4, true);
|
||||
|
||||
tx_view.on_edit_frequency = [this, &nav]() {
|
||||
auto new_view = nav.push<FrequencyKeypadView>(transmitter_model.target_frequency());
|
||||
new_view->on_changed = [this](rf::Frequency f) {
|
||||
transmitter_model.set_target_frequency(f);
|
||||
};
|
||||
};
|
||||
|
||||
tx_view.on_start = [this]() {
|
||||
start_tx();
|
||||
};
|
||||
|
||||
tx_view.on_stop = [this]() {
|
||||
baseband::kill_ook();
|
||||
stop_tx();
|
||||
};
|
||||
|
||||
button_open.on_select = [this](const Button&) {
|
||||
auto open_view = nav_.push<FileLoadView>(".KEELOQ");
|
||||
|
||||
ensure_directory(keeloq_remotes_dir);
|
||||
open_view->push_dir(keeloq_remotes_dir);
|
||||
open_view->on_changed = [this](fs::path path) {
|
||||
nav_.set_on_pop([this, path]() {
|
||||
if (!read_keeloq_file(path, data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
file_path = path;
|
||||
|
||||
for (const auto& key : keystore.get_keys()) {
|
||||
if (key.mf_name == data.mf_name) {
|
||||
current_key = key;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fix = data.btn << 28 | data.serial;
|
||||
|
||||
update_hop();
|
||||
|
||||
text_mf_name.set(data.mf_name);
|
||||
text_serial.set(to_string_hex(data.serial));
|
||||
text_fix.set(to_string_hex(fix));
|
||||
|
||||
field_counter.set_value(data.counter, false);
|
||||
field_button.set_value(data.btn, false);
|
||||
|
||||
update_payload();
|
||||
|
||||
field_counter.focus();
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
void KeeloqTXView::start_tx() {
|
||||
size_t bitstream_length = encoders::make_bitstream(encoded_data);
|
||||
|
||||
progressbar.set_max(repeat);
|
||||
tx_view.set_transmitting(true);
|
||||
|
||||
transmitter_model.enable();
|
||||
|
||||
baseband::set_ook_data(
|
||||
bitstream_length,
|
||||
OOK_SAMPLERATE * (400.0 / 1000000.0),
|
||||
repeat,
|
||||
pause_duration);
|
||||
}
|
||||
|
||||
void KeeloqTXView::stop_tx() {
|
||||
transmitter_model.disable();
|
||||
text_status.set("Ready");
|
||||
progressbar.set_value(0);
|
||||
tx_view.set_transmitting(false);
|
||||
|
||||
data.counter += 1;
|
||||
|
||||
field_counter.set_value(data.counter, false);
|
||||
|
||||
update_hop();
|
||||
update_payload();
|
||||
|
||||
write_keeloq_file(file_path, data);
|
||||
}
|
||||
|
||||
void KeeloqTXView::on_tx_progress(uint32_t progress, bool done) {
|
||||
if (!done) {
|
||||
text_status.set(to_string_dec_uint(progress + 1) + "/" + to_string_dec_uint(repeat));
|
||||
progressbar.set_value(progress + 1);
|
||||
} else {
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
stop_tx();
|
||||
}
|
||||
}
|
||||
|
||||
KeeloqTXView::~KeeloqTXView() {
|
||||
transmitter_model.disable();
|
||||
baseband::shutdown();
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::ui_keeloqtx
|
||||
@@ -0,0 +1,129 @@
|
||||
#ifndef __KEELOQTX__
|
||||
#define __KEELOQTX__
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_transmitter.hpp"
|
||||
#include "transmitter_model.hpp"
|
||||
#include "file_path.hpp"
|
||||
#include "app_settings.hpp"
|
||||
#include "radio_state.hpp"
|
||||
#include "encoders.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "../../keeloq_file.hpp"
|
||||
#include "../../keeloq_keystore.hpp"
|
||||
|
||||
#define KEELOQ_HEADER "101010101010101010101010000000000"
|
||||
|
||||
namespace ui::external_app::ui_keeloqtx {
|
||||
|
||||
class KeeloqTXView : public View {
|
||||
public:
|
||||
KeeloqTXView(NavigationView& nav);
|
||||
~KeeloqTXView();
|
||||
|
||||
void focus() override;
|
||||
|
||||
std::string title() const override {
|
||||
return "KeeLoqTX";
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string keeloq_fragments[2] = {"110", "100"};
|
||||
|
||||
NavigationView& nav_;
|
||||
|
||||
TxRadioState radio_state_{
|
||||
433920000,
|
||||
1750000,
|
||||
OOK_SAMPLERATE};
|
||||
|
||||
app_settings::SettingsManager settings_{
|
||||
"tx_keeloq", app_settings::Mode::TX};
|
||||
|
||||
std::filesystem::path file_path{};
|
||||
|
||||
KeeloqKeystore keystore{};
|
||||
KeeloqKey current_key{};
|
||||
KeeloqData data{};
|
||||
|
||||
uint32_t fix = 0;
|
||||
uint32_t hop = 0;
|
||||
uint64_t payload = 0;
|
||||
|
||||
void update_hop();
|
||||
|
||||
Labels labels{
|
||||
{{UI_POS_X(1), UI_POS_Y(0)}, "Manufacturer:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(1), UI_POS_Y(1)}, "Serial:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(1), UI_POS_Y(2)}, "Fix:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(1), UI_POS_Y(3)}, "Hop:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(1), UI_POS_Y(4)}, "Counter:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(1), UI_POS_Y(5)}, "Button:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(1), UI_POS_Y(6)}, "Repeat:", Theme::getInstance()->fg_light->foreground},
|
||||
{{UI_POS_X(2), UI_POS_Y(8)}, "Payload:", Theme::getInstance()->fg_light->foreground},
|
||||
};
|
||||
|
||||
Text text_mf_name{{UI_POS_X(15), UI_POS_Y(0), 128, 16}, ""};
|
||||
Text text_serial{{UI_POS_X(9), UI_POS_Y(1), 64, 16}, "00000000"};
|
||||
Text text_fix{{UI_POS_X(6), UI_POS_Y(2), 64, 16}, "00000000"};
|
||||
Text text_hop{{UI_POS_X(6), UI_POS_Y(3), 64, 16}, "00000000"};
|
||||
|
||||
NumberField field_counter{
|
||||
{UI_POS_X(10), UI_POS_Y(4)},
|
||||
5,
|
||||
{0, 65535},
|
||||
1,
|
||||
' '};
|
||||
NumberField field_button{
|
||||
{UI_POS_X(9), UI_POS_Y(5)},
|
||||
2,
|
||||
{0, 15},
|
||||
1,
|
||||
' '};
|
||||
NumberField field_repeat{
|
||||
{UI_POS_X(10), UI_POS_Y(6)},
|
||||
3,
|
||||
{0, 100},
|
||||
1,
|
||||
' '};
|
||||
|
||||
Text text_payload{{UI_POS_X(2), UI_POS_Y(9), 128, 16}, "0000000000000000"};
|
||||
|
||||
void update_payload();
|
||||
|
||||
Button button_open{{UI_POS_X(0), UI_POS_Y(11), screen_width, 32}, "Open file"};
|
||||
|
||||
Text text_status{{UI_POS_X(2), UI_POS_Y_BOTTOM(7), 128, 16}, "Ready"};
|
||||
|
||||
ProgressBar progressbar{
|
||||
{UI_POS_X(2), UI_POS_Y_BOTTOM(7) + 20, UI_POS_WIDTH_REMAINING(4), 16}};
|
||||
|
||||
TransmitterView tx_view{
|
||||
(int16_t)UI_POS_Y_BOTTOM(4),
|
||||
50000,
|
||||
9};
|
||||
|
||||
std::string encoded_data{};
|
||||
|
||||
void encode_data();
|
||||
|
||||
uint32_t repeat = 4;
|
||||
uint32_t pause_duration = 0;
|
||||
|
||||
void start_tx();
|
||||
void stop_tx();
|
||||
|
||||
void update_progress();
|
||||
void on_tx_progress(uint32_t progress, bool done);
|
||||
|
||||
MessageHandlerRegistration message_handler_tx_progress{
|
||||
Message::ID::TXProgress,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const TXProgressMessage*>(p);
|
||||
this->on_tx_progress(message.progress, message.done);
|
||||
}};
|
||||
};
|
||||
|
||||
} // namespace ui::external_app::ui_keeloqtx
|
||||
|
||||
#endif
|
||||
@@ -24,6 +24,8 @@
|
||||
#include "crc.hpp"
|
||||
#include "portapack_shared_memory.hpp"
|
||||
|
||||
namespace ui::external_app::lge {
|
||||
|
||||
uint32_t RFM69::gen_frame(std::vector<uint8_t>& payload) {
|
||||
CRC<16> crc{0x1021, 0x1D0F, 0xFFFF};
|
||||
std::vector<uint8_t> frame{};
|
||||
@@ -74,3 +76,5 @@ uint32_t RFM69::gen_frame(std::vector<uint8_t>& payload) {
|
||||
// Copy for baseband
|
||||
return frame.size();
|
||||
}
|
||||
|
||||
} /* namespace ui::external_app::lge */
|
||||
@@ -28,6 +28,8 @@
|
||||
|
||||
#include "utility.hpp"
|
||||
|
||||
namespace ui::external_app::lge {
|
||||
|
||||
class RFM69 {
|
||||
public:
|
||||
RFM69(const uint8_t num_preamble, const uint16_t sync_word, const bool CRC, const bool manchester)
|
||||
@@ -54,4 +56,6 @@ class RFM69 {
|
||||
bool manchester_{false};
|
||||
};
|
||||
|
||||
} /* namespace ui::external_app::lge */
|
||||
|
||||
#endif /*__RFM69_H__*/
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2025 Pezsma
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_morse_practice.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::morse_practice {
|
||||
|
||||
void initialize_app(NavigationView& nav) {
|
||||
nav.push<MorsePracticeView>();
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::morse_practice
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_morse_practice.application_information"), used))
|
||||
application_information_t _application_information_morse_practice = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::morse_practice::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
|
||||
/*.app_name = */ "Morse P",
|
||||
/*.bitmap_data = */ {
|
||||
0x00,
|
||||
0x00,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xBB,
|
||||
0xD0,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0x0B,
|
||||
0xE1,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xEB,
|
||||
0xD0,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0x70,
|
||||
0x00,
|
||||
0x30,
|
||||
0x00,
|
||||
0x10,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
},
|
||||
/*.icon_color = */ ui::Color::yellow().v,
|
||||
/*.menu_location = */ app_location_t::GAMES,
|
||||
/*.desired_menu_position = */ -1,
|
||||
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_none */ {'P', 'A', 'B', 'P'},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
|
||||
} // extern "C"
|
||||
@@ -0,0 +1,363 @@
|
||||
#ifndef __MORSEDECODER_HPP__
|
||||
#define __MORSEDECODER_HPP__
|
||||
|
||||
/*
|
||||
* Copyright (C) 2025 Pezsma
|
||||
*
|
||||
* 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 <cstdint>
|
||||
#include <string>
|
||||
#include "string_format.hpp"
|
||||
|
||||
namespace ui::external_app::morse_practice {
|
||||
|
||||
class MorseRingBuffer {
|
||||
public:
|
||||
MorseRingBuffer()
|
||||
: head_(0), tail_(0), count_(0) {}
|
||||
|
||||
void push_back(const uint32_t& value) {
|
||||
data_[head_] = value;
|
||||
head_ = (head_ + 1) % 40;
|
||||
if (count_ < 40) {
|
||||
count_++;
|
||||
} else {
|
||||
// overwrite oldest element
|
||||
tail_ = (tail_ + 1) % 40;
|
||||
}
|
||||
}
|
||||
|
||||
void pop_front() {
|
||||
if (count_ > 0) {
|
||||
tail_ = (tail_ + 1) % 40;
|
||||
count_--;
|
||||
}
|
||||
}
|
||||
|
||||
size_t size() const { return count_; }
|
||||
bool empty() const { return count_ == 0; }
|
||||
const uint32_t& front() const { return data_[tail_]; }
|
||||
// Access by index (0 = oldest)
|
||||
uint32_t operator[](size_t idx) const {
|
||||
return data_[(tail_ + idx) % 40];
|
||||
}
|
||||
// Convert to vector-like access for sorting etc.
|
||||
void copy_to_array(uint32_t* out) const {
|
||||
for (size_t i = 0; i < count_; ++i)
|
||||
out[i] = (*this)[i];
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t data_[40];
|
||||
size_t head_;
|
||||
size_t tail_;
|
||||
size_t count_;
|
||||
};
|
||||
|
||||
class MorseDecoder {
|
||||
public:
|
||||
struct DecodeResult {
|
||||
std::string text = "";
|
||||
double confidence = 0.0;
|
||||
|
||||
bool isValid() const {
|
||||
return !text.empty();
|
||||
}
|
||||
};
|
||||
|
||||
struct MorseEntry {
|
||||
std::string code;
|
||||
std::string letter;
|
||||
};
|
||||
|
||||
MorseDecoder() {}
|
||||
|
||||
DecodeResult
|
||||
handleInput(int32_t duration_ms) {
|
||||
DecodeResult result = {"", 0.0};
|
||||
|
||||
if (duration_ms < 5 && duration_ms > -5) return result;
|
||||
|
||||
if (duration_ms > 0) {
|
||||
pulse_history_.push_back(duration_ms);
|
||||
double dah_prob = getDahProbability(duration_ms);
|
||||
current_sequence_ += (dah_prob > 0.5) ? '-' : '.';
|
||||
last_confidence_ = (dah_prob > 0.5) ? dah_prob : (1.0 - dah_prob);
|
||||
last_sequence_ = current_sequence_;
|
||||
|
||||
} else {
|
||||
uint32_t gap_duration = -duration_ms;
|
||||
pulse_gaps_.push_back(gap_duration);
|
||||
|
||||
if (gap_duration >= getInterCharThreshold() && !current_sequence_.empty()) {
|
||||
result.text = lookupMorse(current_sequence_);
|
||||
|
||||
result.confidence = (result.text[0] != '{') ? last_confidence_ : 0.0;
|
||||
if (gap_duration >= getInterWordThreshold()) {
|
||||
result.text += " ";
|
||||
}
|
||||
current_sequence_ = "";
|
||||
}
|
||||
}
|
||||
|
||||
updateLearning();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
inline double getInterElementThreshold() { return time_unit_ms_ * 0.8; }
|
||||
inline double getInterCharThreshold() { return time_unit_ms_ * 2.5; }
|
||||
inline double getInterWordThreshold() { return time_unit_ms_ * 6.0; }
|
||||
|
||||
inline double getCurrentTimeUnit() { return time_unit_ms_; }
|
||||
inline std::string getLastSequence() { return last_sequence_; }
|
||||
|
||||
private:
|
||||
std::string current_sequence_ = "";
|
||||
std::string last_sequence_ = "";
|
||||
double time_unit_ms_ = 119.0;
|
||||
double last_confidence_ = 0.0;
|
||||
MorseRingBuffer pulse_history_{};
|
||||
MorseRingBuffer pulse_gaps_{};
|
||||
|
||||
std::string lookupMorse(const std::string& seq) {
|
||||
for (size_t i = 0; i < morse_table_size_; i++) {
|
||||
if (seq == morse_table_[i].code)
|
||||
return morse_table_[i].letter;
|
||||
}
|
||||
return "{" + seq + "}"; // not found
|
||||
}
|
||||
|
||||
double getDahProbability(uint32_t duration_ms) {
|
||||
double start_interp = 1.5 * time_unit_ms_;
|
||||
double end_interp = 2.5 * time_unit_ms_;
|
||||
|
||||
if (duration_ms <= start_interp) return 0.0;
|
||||
if (duration_ms >= end_interp) return 1.0;
|
||||
return ((double)(duration_ms)-start_interp) / (end_interp - start_interp);
|
||||
}
|
||||
|
||||
size_t findDecisionBoundary(uint32_t* sorted_data, size_t sorted_data_size) {
|
||||
if (sorted_data_size < 4) return 0;
|
||||
|
||||
size_t best_split_index = 0;
|
||||
uint32_t max_diff = 0;
|
||||
|
||||
for (size_t i = 1; i < sorted_data_size; ++i) {
|
||||
uint32_t diff = sorted_data[i] - sorted_data[i - 1];
|
||||
if (diff > sorted_data[i - 1] * 0.5 && diff > max_diff) {
|
||||
max_diff = diff;
|
||||
best_split_index = i;
|
||||
}
|
||||
}
|
||||
return best_split_index;
|
||||
}
|
||||
|
||||
bool calculatePulseUnit(double& unit, double& confidence) {
|
||||
if (pulse_history_.size() < 10) return false;
|
||||
uint32_t sorted_pulses[pulse_history_.size()];
|
||||
pulse_history_.copy_to_array(sorted_pulses);
|
||||
sort_uint32(sorted_pulses, pulse_history_.size());
|
||||
|
||||
size_t split_index = findDecisionBoundary(sorted_pulses, pulse_history_.size());
|
||||
if (split_index == 0 || split_index < 3 || (pulse_history_.size() - split_index) < 2) {
|
||||
return false;
|
||||
}
|
||||
double dit_sum = sum_uint32_range(sorted_pulses, 0, split_index);
|
||||
double dah_sum = sum_uint32_range(sorted_pulses, split_index, pulse_history_.size());
|
||||
|
||||
double avg_dit = dit_sum / split_index;
|
||||
double avg_dah = dah_sum / (pulse_history_.size() - split_index);
|
||||
if (avg_dah <= avg_dit) return false;
|
||||
|
||||
double ratio = avg_dah / avg_dit;
|
||||
if (ratio > 1.5 && ratio < 5.0) {
|
||||
unit = avg_dit;
|
||||
double tmpabs = ratio - 3.0;
|
||||
if (tmpabs < 0) tmpabs *= -1;
|
||||
tmpabs /= 3.0;
|
||||
tmpabs = 1.0 - tmpabs;
|
||||
if (tmpabs < 0) tmpabs = 0;
|
||||
confidence = tmpabs; // 0..1
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool calculateGapUnit(double& unit, double& confidence) {
|
||||
if (pulse_gaps_.size() < 10) return false;
|
||||
double threshold = getInterElementThreshold();
|
||||
double valid_gaps[pulse_gaps_.size()];
|
||||
size_t valid_count = 0;
|
||||
for (size_t i = 0; i < pulse_gaps_.size(); i++) {
|
||||
double gap = pulse_gaps_[i];
|
||||
if (gap <= threshold) {
|
||||
valid_gaps[valid_count++] = gap;
|
||||
}
|
||||
}
|
||||
if (valid_count < 2) {
|
||||
return false;
|
||||
}
|
||||
double sum = sum_double_range(valid_gaps, 0, valid_count);
|
||||
size_t count_to_average = valid_count;
|
||||
|
||||
if (count_to_average > 0) {
|
||||
unit = sum / count_to_average;
|
||||
confidence = 0.8;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
double sum_uint32_range(const uint32_t* data, size_t start, size_t end) {
|
||||
double sum = 0.0;
|
||||
for (size_t i = start; i < end; i++) {
|
||||
sum += data[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
double sum_double_range(const double* data, size_t start, size_t end) {
|
||||
double sum = 0.0;
|
||||
for (size_t i = start; i < end; i++) {
|
||||
sum += data[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
void sort_uint32(uint32_t* data, size_t size) {
|
||||
if (size < 2)
|
||||
return;
|
||||
|
||||
for (size_t i = 1; i < size; i++) {
|
||||
uint32_t key = data[i];
|
||||
size_t j = i;
|
||||
|
||||
while (j > 0 && data[j - 1] > key) {
|
||||
data[j] = data[j - 1];
|
||||
j--;
|
||||
}
|
||||
|
||||
data[j] = key;
|
||||
}
|
||||
}
|
||||
|
||||
double clamp_double(double value, double min_val, double max_val) {
|
||||
if (value < min_val)
|
||||
return min_val;
|
||||
else if (value > max_val)
|
||||
return max_val;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
void updateLearning() {
|
||||
double pulse_unit = -1.0, pulse_confidence = 0.0;
|
||||
double gap_unit = -1.0, gap_confidence = 0.0;
|
||||
|
||||
bool pulse_success = calculatePulseUnit(pulse_unit, pulse_confidence);
|
||||
bool gap_success = calculateGapUnit(gap_unit, gap_confidence);
|
||||
|
||||
double new_time_unit = -1.0;
|
||||
if (pulse_success && pulse_confidence > 0.5) {
|
||||
new_time_unit = pulse_unit;
|
||||
} else if (pulse_success && gap_success) {
|
||||
gap_confidence = 0.2;
|
||||
double total_confidence = pulse_confidence + gap_confidence;
|
||||
new_time_unit = (pulse_unit * pulse_confidence + gap_unit * gap_confidence) / total_confidence;
|
||||
} else if (gap_success) {
|
||||
new_time_unit = gap_unit;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
double max_change = time_unit_ms_ * 0.25;
|
||||
new_time_unit = clamp_double(new_time_unit, time_unit_ms_ - max_change, time_unit_ms_ + max_change);
|
||||
double DEFAULT_TIME_UNIT = 160.0;
|
||||
double BASE_LEARNING_RATE = 0.05;
|
||||
double MAX_LEARNING_RATE = 0.25;
|
||||
double tudeltaabs = new_time_unit - DEFAULT_TIME_UNIT;
|
||||
if (tudeltaabs < 0) tudeltaabs *= -1;
|
||||
double deviation_from_default = tudeltaabs / DEFAULT_TIME_UNIT;
|
||||
double tpp = deviation_from_default * 2.0;
|
||||
if (tpp > 1) tpp = 1;
|
||||
double learning_factor = BASE_LEARNING_RATE + (MAX_LEARNING_RATE - BASE_LEARNING_RATE) * tpp;
|
||||
|
||||
time_unit_ms_ = (time_unit_ms_ * (1.0 - learning_factor)) + (new_time_unit * learning_factor);
|
||||
}
|
||||
|
||||
size_t morse_table_size_ = 50;
|
||||
MorseEntry morse_table_[50] = {
|
||||
{".-", "A"},
|
||||
{"-...", "B"},
|
||||
{"-.-.", "C"},
|
||||
{"-..", "D"},
|
||||
{".", "E"},
|
||||
{"..-.", "F"},
|
||||
{"--.", "G"},
|
||||
{"....", "H"},
|
||||
{"..", "I"},
|
||||
{".---", "J"},
|
||||
{"-.-", "K"},
|
||||
{".-..", "L"},
|
||||
{"--", "M"},
|
||||
{"-.", "N"},
|
||||
{"---", "O"},
|
||||
{".--.", "P"},
|
||||
{"--.-", "Q"},
|
||||
{".-.", "R"},
|
||||
{"...", "S"},
|
||||
{"-", "T"},
|
||||
{"..-", "U"},
|
||||
{"...-", "V"},
|
||||
{".--", "W"},
|
||||
{"-..-", "X"},
|
||||
{"-.--", "Y"},
|
||||
{"--..", "Z"},
|
||||
{".----", "1"},
|
||||
{"..---", "2"},
|
||||
{"...--", "3"},
|
||||
{"....-", "4"},
|
||||
{".....", "5"},
|
||||
{"-....", "6"},
|
||||
{"--...", "7"},
|
||||
{"---..", "8"},
|
||||
{"----.", "9"},
|
||||
{"-----", "0"},
|
||||
{".-.-.-", "."},
|
||||
{"..--..", "?"},
|
||||
{"-.-.--", "!"},
|
||||
{"--..--", ","},
|
||||
{"-...-", "="},
|
||||
{"-..-.", "/"},
|
||||
{".--.-.", "@"},
|
||||
{"---...", ":"},
|
||||
{"-....-", "-"},
|
||||
{".----.", "'"},
|
||||
{".-..-.", "\""},
|
||||
{"-.--.", "("},
|
||||
{"-.--.-", ")"},
|
||||
{".-.-.", "+"}};
|
||||
};
|
||||
|
||||
} // namespace ui::external_app::morse_practice
|
||||
|
||||
#endif // __MORSEDECODER_HPP__
|
||||
@@ -0,0 +1,152 @@
|
||||
#include "ui_morse_practice.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
|
||||
namespace ui::external_app::morse_practice {
|
||||
|
||||
MorsePracticeView::MorsePracticeView(ui::NavigationView& nav)
|
||||
: nav_(nav) {
|
||||
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
|
||||
add_children({&btn_tt,
|
||||
&txt_last,
|
||||
&btn_clear,
|
||||
&console_text,
|
||||
&field_volume});
|
||||
|
||||
initial_switch_config_ = get_switches_repeat_config();
|
||||
|
||||
SwitchesState config = initial_switch_config_;
|
||||
config[toUType(Switch::Sel)] = false;
|
||||
set_switches_repeat_config(config);
|
||||
|
||||
audio::set_rate(audio::Rate::Hz_24000);
|
||||
|
||||
btn_tt.on_select = [this](Button&) {
|
||||
if (button_touch) {
|
||||
button_touch = false;
|
||||
return;
|
||||
}
|
||||
button_was_selected = true;
|
||||
onPress();
|
||||
};
|
||||
btn_tt.on_touch_press = [this](Button&) {
|
||||
button_touch = true;
|
||||
button_was_selected = false;
|
||||
onPress();
|
||||
};
|
||||
btn_tt.on_touch_release = [this](Button&) {
|
||||
button_touch = true;
|
||||
button_was_selected = false;
|
||||
onRelease();
|
||||
};
|
||||
btn_clear.on_select = [this](Button&) {
|
||||
console_text.clear(true);
|
||||
txt_last.set("");
|
||||
};
|
||||
audio::output::start();
|
||||
auto vol = field_volume.value();
|
||||
field_volume.set_value(0);
|
||||
field_volume.set_value(vol);
|
||||
}
|
||||
|
||||
MorsePracticeView::~MorsePracticeView() {
|
||||
set_switches_repeat_config(initial_switch_config_);
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
audio::output::stop();
|
||||
}
|
||||
|
||||
void MorsePracticeView::on_show() {
|
||||
console_text.write("Morse Practice ready\n");
|
||||
start_time = 0;
|
||||
end_time = 0;
|
||||
}
|
||||
|
||||
void MorsePracticeView::focus() {
|
||||
btn_tt.focus();
|
||||
}
|
||||
|
||||
void MorsePracticeView::onPress() {
|
||||
start_time = chTimeNow();
|
||||
if (end_time != 0) {
|
||||
int64_t gap_delta = (chTimeNow() - end_time);
|
||||
auto result = morse_decoder_.handleInput(-gap_delta);
|
||||
if (result.isValid()) {
|
||||
writeCharToConsole(result.text, result.confidence);
|
||||
}
|
||||
}
|
||||
end_time = 0;
|
||||
decode_timeout_calc = false;
|
||||
baseband::request_audio_beep(1000, 24000, 2000);
|
||||
}
|
||||
|
||||
void MorsePracticeView::onRelease() {
|
||||
end_time = chTimeNow();
|
||||
if (start_time != 0) {
|
||||
int32_t press_delta = (end_time - start_time);
|
||||
auto result = morse_decoder_.handleInput(press_delta);
|
||||
if (result.isValid()) {
|
||||
writeCharToConsole(result.text, result.confidence);
|
||||
}
|
||||
}
|
||||
start_time = 0;
|
||||
decode_timeout_calc = true;
|
||||
baseband::request_beep_stop();
|
||||
}
|
||||
|
||||
void MorsePracticeView::writeCharToConsole(const std::string& ch, double confidence) {
|
||||
if (ch.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
txt_last.set(morse_decoder_.getLastSequence().c_str());
|
||||
|
||||
last_color_id = color_id;
|
||||
std::string color = "";
|
||||
|
||||
if (ch == " ") {
|
||||
color_id = 0;
|
||||
} else if (ch[0] == '{') { // no match
|
||||
color_id = 0;
|
||||
} else {
|
||||
if (confidence < 0.8)
|
||||
color_id = 1;
|
||||
else if (confidence < 0.9)
|
||||
color_id = 2;
|
||||
else
|
||||
color_id = 3;
|
||||
}
|
||||
color = arr_color[color_id];
|
||||
last_color_id = color_id;
|
||||
console_text.write(color + ch);
|
||||
}
|
||||
|
||||
inline bool MorsePracticeView::tx_button_held() {
|
||||
const auto switches_state = get_switches_state();
|
||||
return switches_state[(size_t)ui::KeyEvent::Select];
|
||||
}
|
||||
|
||||
void MorsePracticeView::on_framesync() {
|
||||
if (button_was_selected && !button_touch && !tx_button_held()) {
|
||||
button_was_selected = false;
|
||||
onRelease();
|
||||
}
|
||||
|
||||
if (end_time != 0 && decode_timeout_calc) {
|
||||
int64_t gap_delta = (chTimeNow() - end_time);
|
||||
|
||||
if (gap_delta >= morse_decoder_.getInterCharThreshold()) {
|
||||
auto result = morse_decoder_.handleInput(-(int32_t)gap_delta);
|
||||
if (result.isValid()) {
|
||||
writeCharToConsole(result.text, result.confidence);
|
||||
}
|
||||
}
|
||||
if (gap_delta >= morse_decoder_.getInterWordThreshold()) {
|
||||
writeCharToConsole(" ", 1.0);
|
||||
end_time = 0;
|
||||
decode_timeout_calc = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::morse_practice
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2025 Pezsma
|
||||
*
|
||||
* 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 __MORSE_PRACTICE_H__
|
||||
#define __MORSE_PRACTICE_H__
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_widget.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "ui_language.hpp"
|
||||
#include "ui_painter.hpp"
|
||||
#include "ui_receiver.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "morsedecoder.hpp"
|
||||
#include "irq_controls.hpp"
|
||||
#include "radio_state.hpp"
|
||||
#include "portapack.hpp"
|
||||
#include "message.hpp"
|
||||
#include "volume.hpp"
|
||||
#include "audio.hpp"
|
||||
#include "baseband_api.hpp"
|
||||
#include "external_app.hpp"
|
||||
#include <ch.h>
|
||||
|
||||
namespace ui::external_app::morse_practice {
|
||||
|
||||
class MorsePracticeView : public ui::View {
|
||||
public:
|
||||
MorsePracticeView(ui::NavigationView& nav);
|
||||
~MorsePracticeView();
|
||||
|
||||
std::string title() const override { return "Morse Practice"; }
|
||||
void focus() override;
|
||||
void on_show() override;
|
||||
|
||||
private:
|
||||
void onPress();
|
||||
void onRelease();
|
||||
void on_framesync();
|
||||
void writeCharToConsole(const std::string& ch, double confidence);
|
||||
bool tx_button_held();
|
||||
|
||||
ui::NavigationView& nav_;
|
||||
MorseDecoder morse_decoder_{};
|
||||
|
||||
int64_t start_time = 0;
|
||||
int64_t end_time = 0;
|
||||
|
||||
ui::Button btn_tt{{UI_POS_X_CENTER(12), UI_POS_Y(3), UI_POS_WIDTH(12), UI_POS_HEIGHT(3)}, "KEY"};
|
||||
ui::Text txt_last{{UI_POS_X(0), UI_POS_Y(6), UI_POS_MAXWIDTH, UI_POS_HEIGHT(1)}, ""};
|
||||
ui::Button btn_clear{{UI_POS_X(0), UI_POS_Y_BOTTOM(2), UI_POS_WIDTH(6), UI_POS_HEIGHT(1)}, "CLR"};
|
||||
ui::Console console_text{{UI_POS_X(0), UI_POS_Y(7), UI_POS_MAXWIDTH, UI_POS_HEIGHT_REMAINING(10)}};
|
||||
AudioVolumeField field_volume{{UI_POS_X_RIGHT(2), UI_POS_Y(0)}};
|
||||
|
||||
uint8_t last_color_id = 255;
|
||||
uint8_t color_id = 255;
|
||||
std::string arr_color[4] = {STR_COLOR_WHITE, STR_COLOR_RED, STR_COLOR_YELLOW, STR_COLOR_GREEN};
|
||||
|
||||
bool button_touch = false;
|
||||
bool button_was_selected = false;
|
||||
bool decode_timeout_calc = false;
|
||||
SwitchesState initial_switch_config_{};
|
||||
|
||||
MessageHandlerRegistration message_handler_framesync{
|
||||
Message::ID::DisplayFrameSync,
|
||||
[this](const Message* const p) {
|
||||
(void)p;
|
||||
this->on_framesync();
|
||||
}};
|
||||
};
|
||||
|
||||
} // namespace ui::external_app::morse_practice
|
||||
|
||||
#endif // __MORSE_PRACTICE_H__
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2026 Pezsma
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "ui.hpp"
|
||||
#include "ui_morse_radio.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "external_app.hpp"
|
||||
|
||||
namespace ui::external_app::morse_radio {
|
||||
|
||||
void initialize_app(NavigationView& nav) {
|
||||
nav.push<MorseRadioView>();
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::morse_radio
|
||||
|
||||
extern "C" {
|
||||
|
||||
__attribute__((section(".external_app.app_morse_radio.application_information"), used))
|
||||
application_information_t _application_information_morse_radio = {
|
||||
/*.memory_location = */ (uint8_t*)0x00000000,
|
||||
/*.externalAppEntry = */ ui::external_app::morse_radio::initialize_app,
|
||||
/*.header_version = */ CURRENT_HEADER_VERSION,
|
||||
/*.app_version = */ VERSION_MD5,
|
||||
|
||||
/*.app_name = */ "Morse",
|
||||
/*.bitmap_data = */ {
|
||||
0x00,
|
||||
0x00,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xBB,
|
||||
0xD0,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0x0B,
|
||||
0xE1,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xEB,
|
||||
0xD0,
|
||||
0xFF,
|
||||
0xFF,
|
||||
0xFE,
|
||||
0x7F,
|
||||
0x70,
|
||||
0x00,
|
||||
0x30,
|
||||
0x00,
|
||||
0x10,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
},
|
||||
/*.icon_color = */ ui::Color::yellow().v,
|
||||
/*.menu_location = */ app_location_t::RX,
|
||||
/*.desired_menu_position = */ -1,
|
||||
|
||||
/*.m4_app_tag = portapack::spi_flash::image_tag_morse_radio */ {'P', 'M', 'R', 'S'},
|
||||
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,378 @@
|
||||
#ifndef __MORSEDECODER_HPP__
|
||||
#define __MORSEDECODER_HPP__
|
||||
|
||||
/*
|
||||
* Copyright (C) 2025 Pezsma
|
||||
*
|
||||
* 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 <cstdint>
|
||||
#include <string>
|
||||
#include "string_format.hpp"
|
||||
|
||||
namespace ui::external_app::morse_radio {
|
||||
|
||||
class MorseRingBuffer {
|
||||
public:
|
||||
MorseRingBuffer()
|
||||
: head_(0), tail_(0), count_(0) {}
|
||||
|
||||
void push_back(const uint32_t& value) {
|
||||
data_[head_] = value;
|
||||
head_ = (head_ + 1) % 40;
|
||||
if (count_ < 40) {
|
||||
count_++;
|
||||
} else {
|
||||
// overwrite oldest element
|
||||
tail_ = (tail_ + 1) % 40;
|
||||
}
|
||||
}
|
||||
|
||||
void pop_front() {
|
||||
if (count_ > 0) {
|
||||
tail_ = (tail_ + 1) % 40;
|
||||
count_--;
|
||||
}
|
||||
}
|
||||
|
||||
size_t size() const { return count_; }
|
||||
bool empty() const { return count_ == 0; }
|
||||
const uint32_t& front() const { return data_[tail_]; }
|
||||
// Access by index (0 = oldest)
|
||||
uint32_t operator[](size_t idx) const {
|
||||
return data_[(tail_ + idx) % 40];
|
||||
}
|
||||
// Convert to vector-like access for sorting etc.
|
||||
void copy_to_array(uint32_t* out) const {
|
||||
for (size_t i = 0; i < count_; ++i)
|
||||
out[i] = (*this)[i];
|
||||
}
|
||||
|
||||
void clear() {
|
||||
head_ = 0;
|
||||
tail_ = 0;
|
||||
count_ = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t data_[40];
|
||||
size_t head_;
|
||||
size_t tail_;
|
||||
size_t count_;
|
||||
};
|
||||
|
||||
class MorseDecoder {
|
||||
public:
|
||||
struct DecodeResult {
|
||||
std::string text = "";
|
||||
double confidence = 0.0;
|
||||
|
||||
bool isValid() const {
|
||||
return !text.empty();
|
||||
}
|
||||
};
|
||||
|
||||
struct MorseEntry {
|
||||
std::string code;
|
||||
std::string letter;
|
||||
};
|
||||
|
||||
MorseDecoder() {}
|
||||
|
||||
void resetLearning() {
|
||||
time_unit_ms_ = 119.0;
|
||||
current_sequence_ = "";
|
||||
last_sequence_ = "";
|
||||
last_confidence_ = 0.0;
|
||||
pulse_history_.clear();
|
||||
pulse_gaps_.clear();
|
||||
}
|
||||
|
||||
DecodeResult
|
||||
handleInput(int32_t duration_ms) {
|
||||
DecodeResult result = {"", 0.0};
|
||||
|
||||
if (duration_ms < 5 && duration_ms > -5) return result;
|
||||
|
||||
if (duration_ms > 0) {
|
||||
pulse_history_.push_back(duration_ms);
|
||||
double dah_prob = getDahProbability(duration_ms);
|
||||
current_sequence_ += (dah_prob > 0.5) ? '-' : '.';
|
||||
last_confidence_ = (dah_prob > 0.5) ? dah_prob : (1.0 - dah_prob);
|
||||
last_sequence_ = current_sequence_;
|
||||
|
||||
} else {
|
||||
uint32_t gap_duration = -duration_ms;
|
||||
pulse_gaps_.push_back(gap_duration);
|
||||
|
||||
if (gap_duration >= getInterCharThreshold() && !current_sequence_.empty()) {
|
||||
result.text = lookupMorse(current_sequence_);
|
||||
|
||||
result.confidence = (result.text[0] != '{') ? last_confidence_ : 0.0;
|
||||
if (gap_duration >= getInterWordThreshold()) {
|
||||
result.text += " ";
|
||||
}
|
||||
current_sequence_ = "";
|
||||
}
|
||||
}
|
||||
|
||||
updateLearning();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
inline double getInterElementThreshold() { return time_unit_ms_ * 0.8; }
|
||||
inline double getInterCharThreshold() { return time_unit_ms_ * 2.5; }
|
||||
inline double getInterWordThreshold() { return time_unit_ms_ * 6.0; }
|
||||
|
||||
inline double getCurrentTimeUnit() { return time_unit_ms_; }
|
||||
inline std::string getLastSequence() { return last_sequence_; }
|
||||
|
||||
private:
|
||||
std::string current_sequence_ = "";
|
||||
std::string last_sequence_ = "";
|
||||
double time_unit_ms_ = 119.0;
|
||||
double last_confidence_ = 0.0;
|
||||
MorseRingBuffer pulse_history_{};
|
||||
MorseRingBuffer pulse_gaps_{};
|
||||
|
||||
std::string lookupMorse(const std::string& seq) {
|
||||
for (size_t i = 0; i < morse_table_size_; i++) {
|
||||
if (seq == morse_table_[i].code)
|
||||
return morse_table_[i].letter;
|
||||
}
|
||||
return "{" + seq + "}"; // not found
|
||||
}
|
||||
|
||||
double getDahProbability(uint32_t duration_ms) {
|
||||
double start_interp = 1.5 * time_unit_ms_;
|
||||
double end_interp = 2.5 * time_unit_ms_;
|
||||
|
||||
if (duration_ms <= start_interp) return 0.0;
|
||||
if (duration_ms >= end_interp) return 1.0;
|
||||
return ((double)(duration_ms)-start_interp) / (end_interp - start_interp);
|
||||
}
|
||||
|
||||
size_t findDecisionBoundary(uint32_t* sorted_data, size_t sorted_data_size) {
|
||||
if (sorted_data_size < 4) return 0;
|
||||
|
||||
size_t best_split_index = 0;
|
||||
uint32_t max_diff = 0;
|
||||
|
||||
for (size_t i = 1; i < sorted_data_size; ++i) {
|
||||
uint32_t diff = sorted_data[i] - sorted_data[i - 1];
|
||||
if (diff > sorted_data[i - 1] * 0.5 && diff > max_diff) {
|
||||
max_diff = diff;
|
||||
best_split_index = i;
|
||||
}
|
||||
}
|
||||
return best_split_index;
|
||||
}
|
||||
|
||||
bool calculatePulseUnit(double& unit, double& confidence) {
|
||||
if (pulse_history_.size() < 10) return false;
|
||||
uint32_t sorted_pulses[pulse_history_.size()];
|
||||
pulse_history_.copy_to_array(sorted_pulses);
|
||||
sort_uint32(sorted_pulses, pulse_history_.size());
|
||||
|
||||
size_t split_index = findDecisionBoundary(sorted_pulses, pulse_history_.size());
|
||||
if (split_index == 0 || split_index < 3 || (pulse_history_.size() - split_index) < 2) {
|
||||
return false;
|
||||
}
|
||||
double dit_sum = sum_uint32_range(sorted_pulses, 0, split_index);
|
||||
double dah_sum = sum_uint32_range(sorted_pulses, split_index, pulse_history_.size());
|
||||
|
||||
double avg_dit = dit_sum / split_index;
|
||||
double avg_dah = dah_sum / (pulse_history_.size() - split_index);
|
||||
if (avg_dah <= avg_dit) return false;
|
||||
|
||||
double ratio = avg_dah / avg_dit;
|
||||
if (ratio > 1.5 && ratio < 5.0) {
|
||||
unit = avg_dit;
|
||||
double tmpabs = ratio - 3.0;
|
||||
if (tmpabs < 0) tmpabs *= -1;
|
||||
tmpabs /= 3.0;
|
||||
tmpabs = 1.0 - tmpabs;
|
||||
if (tmpabs < 0) tmpabs = 0;
|
||||
confidence = tmpabs; // 0..1
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool calculateGapUnit(double& unit, double& confidence) {
|
||||
if (pulse_gaps_.size() < 10) return false;
|
||||
double threshold = getInterElementThreshold();
|
||||
double valid_gaps[pulse_gaps_.size()];
|
||||
size_t valid_count = 0;
|
||||
for (size_t i = 0; i < pulse_gaps_.size(); i++) {
|
||||
double gap = pulse_gaps_[i];
|
||||
if (gap <= threshold) {
|
||||
valid_gaps[valid_count++] = gap;
|
||||
}
|
||||
}
|
||||
if (valid_count < 2) {
|
||||
return false;
|
||||
}
|
||||
double sum = sum_double_range(valid_gaps, 0, valid_count);
|
||||
size_t count_to_average = valid_count;
|
||||
|
||||
if (count_to_average > 0) {
|
||||
unit = sum / count_to_average;
|
||||
confidence = 0.8;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
double sum_uint32_range(const uint32_t* data, size_t start, size_t end) {
|
||||
double sum = 0.0;
|
||||
for (size_t i = start; i < end; i++) {
|
||||
sum += data[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
double sum_double_range(const double* data, size_t start, size_t end) {
|
||||
double sum = 0.0;
|
||||
for (size_t i = start; i < end; i++) {
|
||||
sum += data[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
void sort_uint32(uint32_t* data, size_t size) {
|
||||
if (size < 2)
|
||||
return;
|
||||
|
||||
for (size_t i = 1; i < size; i++) {
|
||||
uint32_t key = data[i];
|
||||
size_t j = i;
|
||||
|
||||
while (j > 0 && data[j - 1] > key) {
|
||||
data[j] = data[j - 1];
|
||||
j--;
|
||||
}
|
||||
|
||||
data[j] = key;
|
||||
}
|
||||
}
|
||||
|
||||
double clamp_double(double value, double min_val, double max_val) {
|
||||
if (value < min_val)
|
||||
return min_val;
|
||||
else if (value > max_val)
|
||||
return max_val;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
void updateLearning() {
|
||||
double pulse_unit = -1.0, pulse_confidence = 0.0;
|
||||
double gap_unit = -1.0, gap_confidence = 0.0;
|
||||
|
||||
bool pulse_success = calculatePulseUnit(pulse_unit, pulse_confidence);
|
||||
bool gap_success = calculateGapUnit(gap_unit, gap_confidence);
|
||||
|
||||
double new_time_unit = -1.0;
|
||||
if (pulse_success && pulse_confidence > 0.5) {
|
||||
new_time_unit = pulse_unit;
|
||||
} else if (pulse_success && gap_success) {
|
||||
gap_confidence = 0.2;
|
||||
double total_confidence = pulse_confidence + gap_confidence;
|
||||
new_time_unit = (pulse_unit * pulse_confidence + gap_unit * gap_confidence) / total_confidence;
|
||||
} else if (gap_success) {
|
||||
new_time_unit = gap_unit;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
double max_change = time_unit_ms_ * 0.25;
|
||||
new_time_unit = clamp_double(new_time_unit, time_unit_ms_ - max_change, time_unit_ms_ + max_change);
|
||||
double DEFAULT_TIME_UNIT = 160.0;
|
||||
double BASE_LEARNING_RATE = 0.05;
|
||||
double MAX_LEARNING_RATE = 0.25;
|
||||
double tudeltaabs = new_time_unit - DEFAULT_TIME_UNIT;
|
||||
if (tudeltaabs < 0) tudeltaabs *= -1;
|
||||
double deviation_from_default = tudeltaabs / DEFAULT_TIME_UNIT;
|
||||
double tpp = deviation_from_default * 2.0;
|
||||
if (tpp > 1) tpp = 1;
|
||||
double learning_factor = BASE_LEARNING_RATE + (MAX_LEARNING_RATE - BASE_LEARNING_RATE) * tpp;
|
||||
|
||||
time_unit_ms_ = (time_unit_ms_ * (1.0 - learning_factor)) + (new_time_unit * learning_factor);
|
||||
}
|
||||
|
||||
size_t morse_table_size_ = 50;
|
||||
MorseEntry morse_table_[50] = {
|
||||
{".-", "A"},
|
||||
{"-...", "B"},
|
||||
{"-.-.", "C"},
|
||||
{"-..", "D"},
|
||||
{".", "E"},
|
||||
{"..-.", "F"},
|
||||
{"--.", "G"},
|
||||
{"....", "H"},
|
||||
{"..", "I"},
|
||||
{".---", "J"},
|
||||
{"-.-", "K"},
|
||||
{".-..", "L"},
|
||||
{"--", "M"},
|
||||
{"-.", "N"},
|
||||
{"---", "O"},
|
||||
{".--.", "P"},
|
||||
{"--.-", "Q"},
|
||||
{".-.", "R"},
|
||||
{"...", "S"},
|
||||
{"-", "T"},
|
||||
{"..-", "U"},
|
||||
{"...-", "V"},
|
||||
{".--", "W"},
|
||||
{"-..-", "X"},
|
||||
{"-.--", "Y"},
|
||||
{"--..", "Z"},
|
||||
{".----", "1"},
|
||||
{"..---", "2"},
|
||||
{"...--", "3"},
|
||||
{"....-", "4"},
|
||||
{".....", "5"},
|
||||
{"-....", "6"},
|
||||
{"--...", "7"},
|
||||
{"---..", "8"},
|
||||
{"----.", "9"},
|
||||
{"-----", "0"},
|
||||
{".-.-.-", "."},
|
||||
{"..--..", "?"},
|
||||
{"-.-.--", "!"},
|
||||
{"--..--", ","},
|
||||
{"-...-", "="},
|
||||
{"-..-.", "/"},
|
||||
{".--.-.", "@"},
|
||||
{"---...", ":"},
|
||||
{"-....-", "-"},
|
||||
{".----.", "'"},
|
||||
{".-..-.", "\""},
|
||||
{"-.--.", "("},
|
||||
{"-.--.-", ")"},
|
||||
{".-.-.", "+"}};
|
||||
};
|
||||
|
||||
} // namespace ui::external_app::morse_radio
|
||||
|
||||
#endif // __MORSEDECODER_HPP__
|
||||
@@ -0,0 +1,282 @@
|
||||
#include "ui_morse_radio.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
|
||||
namespace ui::external_app::morse_radio {
|
||||
|
||||
MorseRadioView::MorseRadioView(ui::NavigationView& nav)
|
||||
: nav_(nav) {
|
||||
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
|
||||
add_children({&rssi,
|
||||
&field_rf_amp,
|
||||
&field_lna,
|
||||
&field_vga,
|
||||
&field_volume,
|
||||
&field_frequency,
|
||||
&txt_last,
|
||||
&txt_speed,
|
||||
&txt_freq,
|
||||
&txt_clip,
|
||||
&options_mode,
|
||||
&btn_clear,
|
||||
&console_text,
|
||||
&labels,
|
||||
&chk_log,
|
||||
&field_squelch});
|
||||
field_frequency.set_step(100);
|
||||
|
||||
btn_clear.on_select = [this](Button&) {
|
||||
console_text.clear(true);
|
||||
txt_last.set("");
|
||||
time_stamp = false;
|
||||
if (logger && save_log)
|
||||
logger->init_daily_log(logs_dir);
|
||||
};
|
||||
|
||||
field_squelch.on_change = [this](int32_t v) {
|
||||
receiver_model.set_squelch_level(v);
|
||||
};
|
||||
|
||||
options_mode.on_change = [this](size_t, int32_t mode) {
|
||||
audio::output::stop();
|
||||
receiver_model.disable();
|
||||
morse_decoder_.resetLearning();
|
||||
if (mode == MORSE_NFM) {
|
||||
receiver_model.set_am_configuration(4);
|
||||
receiver_model.set_modulation(ReceiverModel::Mode::NarrowbandFMAudio);
|
||||
field_squelch.set_style(Theme::getInstance()->option_active);
|
||||
field_squelch.set_focusable(true);
|
||||
field_squelch.set_value(receiver_model.squelch_level());
|
||||
audio::set_rate(audio::Rate::Hz_24000);
|
||||
} else {
|
||||
audio::set_rate(audio::Rate::Hz_12000);
|
||||
receiver_model.set_modulation(ReceiverModel::Mode::AMAudio);
|
||||
if (mode == MORSE_AM_CW || mode == MORSE_AM_DSB)
|
||||
receiver_model.set_am_configuration(7);
|
||||
else if (mode == MORSE_AM_USB)
|
||||
receiver_model.set_am_configuration(9);
|
||||
else // LSB
|
||||
receiver_model.set_am_configuration(10);
|
||||
field_squelch.set_style(Theme::getInstance()->fg_dark);
|
||||
field_squelch.set_focusable(false);
|
||||
}
|
||||
baseband::set_moreserx_config(mode);
|
||||
saved_mode = mode;
|
||||
|
||||
audio::output::start();
|
||||
receiver_model.set_headphone_volume(receiver_model.headphone_volume()); // WM8731 hack.
|
||||
|
||||
receiver_model.set_sampling_rate(3072000);
|
||||
receiver_model.set_baseband_bandwidth(1750000);
|
||||
receiver_model.enable();
|
||||
};
|
||||
options_mode.set_selected_index(saved_mode);
|
||||
|
||||
logger = std::make_unique<MorseLogger>();
|
||||
chk_log.on_select = [this](Checkbox&, bool save) {
|
||||
save_log = save;
|
||||
if (logger && save_log)
|
||||
logger->init_daily_log(logs_dir);
|
||||
};
|
||||
}
|
||||
|
||||
void MorseLogger::init_daily_log(const std::filesystem::path& log_dir) {
|
||||
auto now = rtc_time::now();
|
||||
std::string pattern = "morse_";
|
||||
uint16_t y = now.year();
|
||||
pattern += (char)('0' + (y / 1000) % 10);
|
||||
pattern += (char)('0' + (y / 100) % 10);
|
||||
pattern += (char)('0' + (y / 10) % 10);
|
||||
pattern += (char)('0' + (y % 10));
|
||||
|
||||
uint8_t m = now.month();
|
||||
pattern += (char)('0' + (m / 10) % 10);
|
||||
pattern += (char)('0' + (m % 10));
|
||||
|
||||
uint8_t d = now.day();
|
||||
pattern += (char)('0' + (d / 10) % 10);
|
||||
pattern += (char)('0' + (d % 10));
|
||||
|
||||
pattern += "_???.TXT";
|
||||
|
||||
auto full_pattern_path = log_dir / pattern;
|
||||
auto final_path = next_filename_matching_pattern(full_pattern_path);
|
||||
if (!final_path.empty()) {
|
||||
this->append(final_path);
|
||||
}
|
||||
}
|
||||
|
||||
void MorseLogger::radio_set_log(const std::string& morse_mode) {
|
||||
int64_t freq = receiver_model.target_frequency();
|
||||
std::string header = "Freq:" + to_string_rounded_freq(freq, 4);
|
||||
header += "MHz, ";
|
||||
header += "RX MODE:" + morse_mode;
|
||||
header += "\r\nMessage:";
|
||||
log_file.write_raw(header);
|
||||
}
|
||||
|
||||
bool MorseLogger::on_packet(const std::string& content, bool time, const std::string& morse_mode) {
|
||||
if (!time) {
|
||||
log_file.write_raw_no_newline("\r\n\r\n");
|
||||
auto timestamp = to_string_datetime(rtc_time::now(), YMDHMS);
|
||||
log_file.write_raw("[" + timestamp + "] ");
|
||||
radio_set_log(morse_mode);
|
||||
char_count = 0;
|
||||
time = true;
|
||||
}
|
||||
|
||||
if (content.empty()) return time;
|
||||
std::string s;
|
||||
for (char c : content) {
|
||||
s = c;
|
||||
if ((char_count >= 35 && c == ' ') || (char_count >= 47)) {
|
||||
log_file.write_raw_no_newline("\r\n");
|
||||
|
||||
if (c != ' ') {
|
||||
log_file.write_raw_no_newline(s);
|
||||
char_count = 1;
|
||||
} else {
|
||||
char_count = 0;
|
||||
}
|
||||
} else {
|
||||
log_file.write_raw_no_newline(s);
|
||||
char_count++;
|
||||
}
|
||||
}
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
MorseRadioView::~MorseRadioView() {
|
||||
receiver_model.disable();
|
||||
baseband::shutdown();
|
||||
audio::output::stop();
|
||||
}
|
||||
|
||||
void MorseRadioView::focus() {
|
||||
field_frequency.focus();
|
||||
txt_clip.set_style(Theme::getInstance()->fg_red);
|
||||
txt_clip.hidden(true);
|
||||
}
|
||||
|
||||
void MorseRadioView::check_for_timeout() {
|
||||
uint64_t now = chTimeNow();
|
||||
if (last_activity_time == 0) {
|
||||
last_activity_time = now;
|
||||
return;
|
||||
}
|
||||
uint64_t quiet_duration = now - last_activity_time;
|
||||
if (quiet_duration >= 60000) {
|
||||
morse_decoder_.resetLearning();
|
||||
time_stamp = false;
|
||||
last_activity_time = now;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t MorseRadioView::ProcessSignal(int32_t sig_time_us) {
|
||||
int8_t sign = (sig_time_us > 0) ? 1 : ((sig_time_us < 0) ? -1 : 0);
|
||||
int32_t result = 0;
|
||||
|
||||
if (last_sign_ == 0) {
|
||||
last_sign_ = sign;
|
||||
accumulator_us_ = sig_time_us;
|
||||
long_pause_sent_ = false;
|
||||
return 0;
|
||||
}
|
||||
if (sign == last_sign_) {
|
||||
accumulator_us_ += sig_time_us;
|
||||
|
||||
if (sign < 0) {
|
||||
int32_t threshold_us = morse_decoder_.getInterWordThreshold() * 1000;
|
||||
if (!long_pause_sent_ && accumulator_us_ <= -threshold_us) {
|
||||
result = accumulator_us_ / 1000;
|
||||
long_pause_sent_ = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// state change
|
||||
if (!long_pause_sent_) {
|
||||
result = accumulator_us_ / 1000;
|
||||
} else {
|
||||
result = 0;
|
||||
}
|
||||
accumulator_us_ = sig_time_us;
|
||||
last_sign_ = sign;
|
||||
long_pause_sent_ = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void MorseRadioView::on_data(const MorseRXDataMessage* message) {
|
||||
int32_t r;
|
||||
|
||||
txt_clip.hidden(!message->clipped);
|
||||
|
||||
for (uint8_t i = 0; i <= message->state_cnt; ++i) {
|
||||
r = ProcessSignal(message->state_durations[i]);
|
||||
auto result = morse_decoder_.handleInput((r != 0) ? r : 0);
|
||||
if (result.isValid()) {
|
||||
last_activity_time = chTimeNow(); // start reset timer on valid input
|
||||
writeCharToConsole(result.text, result.confidence);
|
||||
if (logger && save_log) {
|
||||
time_stamp = logger->on_packet(result.text, time_stamp, options_mode.selected_index_name());
|
||||
}
|
||||
float dah_time = morse_decoder_.getCurrentTimeUnit() * 3.0f;
|
||||
if (dah_time > 0) {
|
||||
uint16_t wpm = (uint16_t)(3600.0f / (dah_time + 18.0f) + 0.5f);
|
||||
txt_speed.set(to_string_dec_uint(wpm));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MorseRadioView::on_freq(const MorseRXfreqMessage* message) {
|
||||
std::string ret = " ";
|
||||
uint32_t freq = message->measured_frequency;
|
||||
if (freq < 301) {
|
||||
ret = "<";
|
||||
freq = 300;
|
||||
}
|
||||
if (freq > 2299) {
|
||||
freq = 2300;
|
||||
ret = ">";
|
||||
}
|
||||
if (freq < 400 || freq > 1400)
|
||||
txt_freq.set_style(Theme::getInstance()->fg_red);
|
||||
else if (freq <= 580 || freq >= 1220)
|
||||
txt_freq.set_style(Theme::getInstance()->fg_yellow);
|
||||
else
|
||||
txt_freq.set_style(Theme::getInstance()->fg_green);
|
||||
ret += to_string_dec_uint(freq);
|
||||
txt_freq.set(ret);
|
||||
}
|
||||
|
||||
void MorseRadioView::writeCharToConsole(const std::string& ch, double confidence) {
|
||||
if (ch.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
txt_last.set(morse_decoder_.getLastSequence().c_str());
|
||||
|
||||
last_color_id = color_id;
|
||||
std::string color = "";
|
||||
|
||||
if (ch == " ") {
|
||||
color_id = 0;
|
||||
} else if (ch[0] == '{') { // no match
|
||||
color_id = 0;
|
||||
} else {
|
||||
if (confidence < 0.8)
|
||||
color_id = 1;
|
||||
else if (confidence < 0.9)
|
||||
color_id = 2;
|
||||
else
|
||||
color_id = 3;
|
||||
}
|
||||
color = arr_color[color_id];
|
||||
last_color_id = color_id;
|
||||
console_text.write(color + ch);
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::morse_radio
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user