mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-16 00:17:03 +03:00
Compare commits
121 Commits
I2S-4MFlas
...
I2S-4MFlas
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c76bbc3524 | ||
|
|
9619b1d792 | ||
|
|
0bbd5a064f | ||
|
|
986521fd4a | ||
|
|
406a56a3a3 | ||
|
|
c9455f70ff | ||
|
|
b5b76480e4 | ||
|
|
e6744deab8 | ||
|
|
94baf86989 | ||
|
|
0c856a37c1 | ||
|
|
d5f28375ce | ||
|
|
7ea5a93647 | ||
|
|
ca38a14420 | ||
|
|
9ebe717e74 | ||
|
|
12347bdb29 | ||
|
|
a42c9ff860 | ||
|
|
e67413697c | ||
|
|
c4b797e54f | ||
|
|
9971fb0ff3 | ||
|
|
8280bc4903 | ||
|
|
adc6a86725 | ||
|
|
61f58f9a52 | ||
|
|
e3650413f5 | ||
|
|
750ffbf464 | ||
|
|
65f52a23bc | ||
|
|
da411bf1c8 | ||
|
|
0a319269c2 | ||
|
|
b0ce38bf14 | ||
|
|
767b677947 | ||
|
|
724818390b | ||
|
|
105e800cc1 | ||
|
|
ab09f009f7 | ||
|
|
9c179adf85 | ||
|
|
719b289659 | ||
|
|
eb7df4a5e9 | ||
|
|
9a54239323 | ||
|
|
b790156be0 | ||
|
|
f87b3adec2 | ||
|
|
35d42f2096 | ||
|
|
d2d0cadeed | ||
|
|
cd76619e96 | ||
|
|
781699362f | ||
|
|
c4dbf60cb6 | ||
|
|
3dd7b4b02c | ||
|
|
83c1a2b8e0 | ||
|
|
e8021c38f0 | ||
|
|
71bb57f1eb | ||
|
|
7eb4b218e3 | ||
|
|
953d1657f9 | ||
|
|
b21a143196 | ||
|
|
898f1d92ed | ||
|
|
f6fd11783c | ||
|
|
f33cb569ce | ||
|
|
f5d6f26c01 | ||
|
|
8df6b853e6 | ||
|
|
f7c0107d40 | ||
|
|
5068309d25 | ||
|
|
506a5aaf7a | ||
|
|
fe409730e0 | ||
|
|
4d6cfaca1c | ||
|
|
69e61ce451 | ||
|
|
60bd591bf8 | ||
|
|
3ea26a0c6f | ||
|
|
53fa83b2dd | ||
|
|
90f53db953 | ||
|
|
b413780048 | ||
|
|
456f16fc79 | ||
|
|
04e2917351 | ||
|
|
dc9e1191a2 | ||
|
|
72a8fb2249 | ||
|
|
f409a9ee28 | ||
|
|
b85cf98cdf | ||
|
|
e85c967220 | ||
|
|
ce21ff1b76 | ||
|
|
7c71fb6a65 | ||
|
|
bb22d4ea02 | ||
|
|
e0e749fb5b | ||
|
|
c650bc7658 | ||
|
|
a76ce3f344 | ||
|
|
1d059be001 | ||
|
|
32195b50ba | ||
|
|
a7539a5332 | ||
|
|
450ebae399 | ||
|
|
d238063c49 | ||
|
|
58f2e4488b | ||
|
|
b83e2722c0 | ||
|
|
96a3f8aab0 | ||
|
|
66b88d186a | ||
|
|
bb185d76dc | ||
|
|
f4c0a91e84 | ||
|
|
2ecf2e6098 | ||
|
|
f32e4de84b | ||
|
|
55303ec1b3 | ||
|
|
effc574e50 | ||
|
|
3941a26b67 | ||
|
|
b47074e668 | ||
|
|
822de92df1 | ||
|
|
6bd778c7c6 | ||
|
|
28ecad4652 | ||
|
|
ddd6bddde7 | ||
|
|
f4e899fc60 | ||
|
|
c61ff05081 | ||
|
|
c4df0c93f9 | ||
|
|
fae09ba29e | ||
|
|
fd0c38c49f | ||
|
|
a83f14113e | ||
|
|
7f0b411dac | ||
|
|
3350a8dbc7 | ||
|
|
a2eddb5411 | ||
|
|
65ff5f7c2a | ||
|
|
5ed2f6d03e | ||
|
|
d8bd588982 | ||
|
|
e4481a95f9 | ||
|
|
992f5c361c | ||
|
|
08c7ccdf28 | ||
|
|
0002256630 | ||
|
|
b3ee25e3be | ||
|
|
d53ae66547 | ||
|
|
26708ea51a | ||
|
|
9c711d73f5 | ||
|
|
d0ac871a3b |
90
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
90
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: How to Submit an Issue for the squeezelite-esp32 Project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
To help us resolve your issue as quickly as possible, please follow these guidelines when submitting an issue. Providing all the necessary information will save both your time and ours.
|
||||
|
||||
### Describe the bug
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
### Preliminary Information
|
||||
|
||||
1. **Firmware Version**: Specify the version of the firmware you are using.
|
||||
2. **Plugin Version**: Mention the version of the plugin installed on your LMS (Logitech Media Server).
|
||||
|
||||
### Hardware Details
|
||||
|
||||
Please describe your hardware setup:
|
||||
|
||||
- **ESP32 Module**: For example, ESP32 WROVER, ESP32-S3, etc.
|
||||
- **Board Type**: If applicable, e.g., ESP32 audio kit, etc.
|
||||
- **DAC Chip**: Specify the DAC chip you are using.
|
||||
- **Additional Hardware**: Include details about any other hardware like rotary controls, buttons, screens (SPI, I2C), Ethernet, IO expansion, etc.
|
||||
|
||||
### NVS Settings
|
||||
|
||||
Follow these steps to share your NVS settings:
|
||||
|
||||
1. Open the web UI of your device.
|
||||
2. Click on the "Credit" tab.
|
||||
3. Enable the "Show NVS Editor" checkbox. This allows you to view or change the NVS configuration even when not in recovery mode.
|
||||
4. Navigate to the "NVS Editor" tab.
|
||||
5. Scroll to the bottom and click "Download Config".
|
||||
6. Share the downloaded content here.
|
||||
|
||||
<details>
|
||||
<pre><code>
|
||||
Your log content here
|
||||
</code></pre>
|
||||
</details>
|
||||
|
||||
|
||||
### Logs
|
||||
|
||||
To share logs:
|
||||
|
||||
1. Connect your player to a computer using a USB cable. Use a built-in Serial-USB adapter if your player has one, or an external USB adapter otherwise.
|
||||
2. Go to the [web installer](https://sle118.github.io/squeezelite-esp32-installer/).
|
||||
3. Click "Connect to Device".
|
||||
4. Select the appropriate serial port.
|
||||
5. Click "Logs And Console".
|
||||
6. Download the logs and share them here. Please remove any sensitive information like Wi-Fi passwords or MAC addresses.
|
||||
- **If the problem occurs soon after booting**: Share the full log until the issue occurs.
|
||||
- **If the problem occurs later during playback**: Trim the logs to include information just before and after the problem occurs.
|
||||
|
||||
#### Example Log
|
||||
|
||||
Here's an example log for reference. Make sure to obfuscate sensitive information like Wi-Fi passwords, MAC addresses, and change IP addresses to something more generic.
|
||||
|
||||
<details>
|
||||
<pre><code>
|
||||
=== START OF LOG ===
|
||||
Example of log from the console
|
||||
rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
|
||||
configsip: 0, SPIWP:0xee
|
||||
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
|
||||
mode:DIO, clock div:1
|
||||
...
|
||||
I (1041) cpu_start: Application information:
|
||||
I (1044) cpu_start: Project name: Squeezelite-ESP32
|
||||
I (1050) cpu_start: App version: I2S-4MFlash-1336
|
||||
I (1055) cpu_start: Compile time: Aug 12 2023 01:20:18
|
||||
I (1062) cpu_start: ELF file SHA256: 34241d6e99fd1d6b...
|
||||
I (1068) cpu_start: ESP-IDF: v4.3.5-dirty
|
||||
...
|
||||
I (1133) heap_init: At 40094A8C len 0000B574 (45 KiB): IRAM
|
||||
I (1139) spiram: Adding pool of 4066K of external SPI memory to heap allocator
|
||||
=== END OF LOG ===
|
||||
</code></pre>
|
||||
</details>
|
||||
|
||||
### Issue Description
|
||||
|
||||
1. **Observed Behavior**: Describe what you think is wrong.
|
||||
2. **Expected Behavior**: Describe what you expect should happen.
|
||||
3. **Steps to Reproduce**: Provide a step-by-step guide on how to replicate the issue.
|
||||
11
.github/workflows/Platform_build.yml
vendored
11
.github/workflows/Platform_build.yml
vendored
@@ -34,14 +34,15 @@ jobs:
|
||||
uses: einaregilsson/build-number@v3
|
||||
with:
|
||||
token: ${{secrets.github_token}}
|
||||
|
||||
- name: Set build flags
|
||||
id: build_flags
|
||||
run: |
|
||||
git config --global --add safe.directory /__w/squeezelite-esp32/squeezelite-esp32
|
||||
[ ${{github.event.inputs.ui_build}} ] && ui_build_option="--ui_build" || ui_build_option=""
|
||||
[ ${{github.event.inputs.release_build}} ] && release_build_option="--force" || release_build_option=""
|
||||
echo "ui_build_option=$ui_build_option" >> $GITHUB_ENV
|
||||
echo "release_build_option=$release_build_option" >> $GITHUB_ENV
|
||||
[ ${{github.event.inputs.release_build}} ] && release_build_option="--force" || release_build_option=""
|
||||
echo "ui_build_option=$ui_build_option" >> "$GITHUB_OUTPUT"
|
||||
echo "release_build_option=$release_build_option" >> "$GITHUB_OUTPUT"
|
||||
echo "Dumping environment"
|
||||
env
|
||||
. /opt/esp/python_env/idf4.3_py3.8_env/bin/activate
|
||||
@@ -49,7 +50,7 @@ jobs:
|
||||
# --mock - to mock the compilation part - this is to be used for testing only
|
||||
# --force - to force a release build even if the last commit message doesn't contain the word "release"
|
||||
# --ui_build - to force a ui_build even if the last commit message doesn't contain "[ui-build]"
|
||||
build_tools.py build_flags $ui_build_option $release_build_option
|
||||
build_tools.py build_flags $ui_build_option $release_build_option
|
||||
- name: Show Build Flags
|
||||
run: |
|
||||
echo "Running with the following options"
|
||||
@@ -196,7 +197,7 @@ jobs:
|
||||
release_name: ${{ env.name }}
|
||||
body: ${{ env.description }}
|
||||
draft: false
|
||||
prerelease: true
|
||||
prerelease: false
|
||||
- name: Upload Release Asset - Squeezelite binary file
|
||||
if: ${{ needs.bootstrap.outputs.release_flag == 1 && needs.bootstrap.outputs.mock == 0 }}
|
||||
id: upload-release-asset
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -8,3 +8,6 @@
|
||||
[submodule "components/wifi-manager/UML-State-Machine-in-C"]
|
||||
path = components/wifi-manager/UML-State-Machine-in-C
|
||||
url = https://github.com/kiishor/UML-State-Machine-in-C
|
||||
[submodule "components/wifi-manager/webapp/src/bootswatch"]
|
||||
path = components/wifi-manager/webapp/src/bootswatch
|
||||
url = https://github.com/thomaspark/bootswatch.git
|
||||
|
||||
33
CHANGELOG
Normal file
33
CHANGELOG
Normal file
@@ -0,0 +1,33 @@
|
||||
2023-10-27
|
||||
- fix vorbis (and opus) memory leak
|
||||
|
||||
2023-10-25
|
||||
- fix vorbis codec close
|
||||
|
||||
2023-10-23
|
||||
- fix Spotify track insertion
|
||||
- [WEB] Allow running without LMS with option "Audio/Disable Squeezelite"
|
||||
|
||||
2023-10.07
|
||||
- catchup with official cspot
|
||||
|
||||
2023-10-06
|
||||
- fix cspot PREV on first track, NEXT on last track and normal ending
|
||||
- use DMA_AUTO for SPI
|
||||
- cspot share same time log
|
||||
|
||||
2023-10-06
|
||||
- Fix bootswatch bug that caused difficult to read UI ( issue #319)
|
||||
|
||||
2023-10-02
|
||||
- update cspot
|
||||
|
||||
2023-09-29
|
||||
- sleep mechanism
|
||||
- spotify can store credentials so that zeroconf is optional and players are always registered
|
||||
- add battery to led_vu (see credits)
|
||||
- spdif can do 24 bits (see credits)
|
||||
- rmt fixes
|
||||
- airplay & spotify artwork fixes
|
||||
- airplay stability improvments
|
||||
- fix UI text color
|
||||
@@ -25,7 +25,11 @@ ENV GCC_TOOLS_BASE=/opt/esp/tools/xtensa-esp32-elf/esp-2021r2-patch3-8.4.0/xtens
|
||||
# pushd components/wifi-manager/webapp/ && npm install && npm run-script build && popd
|
||||
#
|
||||
# to run the docker with netwotrk port published on the host:
|
||||
# (windows)
|
||||
# docker run --rm -p 5000:5000/tcp -v %cd%:/project -w /project -it sle118/squeezelite-esp32-idfv435
|
||||
# (linux)
|
||||
# docker run --rm -p 5000:5000/tcp -v `pwd`:/project -w /project -it sle118/squeezelite-esp32-idfv435
|
||||
|
||||
|
||||
ARG IDF_CLONE_URL=https://github.com/espressif/esp-idf.git
|
||||
ARG IDF_CLONE_BRANCH_OR_TAG=master
|
||||
|
||||
75
README.md
75
README.md
@@ -1,13 +1,14 @@
|
||||
[](https://github.com/sle118/squeezelite-esp32/actions/workflows/Platform_build.yml)
|
||||
# Squeezelite-esp32
|
||||
|
||||
## Forewords
|
||||
**More and more people seems to use this without a LMS server, just for BT, AirPlay or Spotify. It's fine but understand that squeezeliteESP32 is primarily a Logitech Media Server player and has been designed around that concept. All the others are add-ons stitched to it, so other modes have their shortcomings. So please make sure you read [this](#Additional-configuration-notes-from-the-Web-UI) before opening an issue**
|
||||
## What is this?
|
||||
Squeezelite-esp32 is an audio software suite made to run on espressif's esp32 and esp32-s3 wifi (b/g/n) and bluetooth chipsets. It offers the following capabilities
|
||||
|
||||
- Stream your local music and connect to all major on-line music providers (Spotify, Deezer, Tidal, Qobuz) using [Logitech Media Server - a.k.a LMS](https://forums.slimdevices.com/) and enjoy multi-room audio synchronization. LMS can be extended by numerous plugins and can be controlled using a Web browser or dedicated applications (iPhone, Android). It can also send audio to UPnP, Sonos, ChromeCast and AirPlay speakers/devices.
|
||||
- Stream from a **Bluetooth** device (iPhone, Android)
|
||||
- Stream from an **AirPlay** controller (iPhone, iTunes ...) and enjoy synchronization multiroom as well (although it's AirPlay 1 only)
|
||||
- Stream directly from **Spotify** using SpotifyConnect (thanks to [cspot](https://github.com/feelfreelinux/cspot))
|
||||
- Stream directly from **Spotify** using SpotifyConnect (thanks to [cspot](https://github.com/feelfreelinux/cspot)) - please read carefully [this](#spotify)
|
||||
|
||||
Depending on the hardware connected to the esp32, you can send audio to a local DAC, to SPDIF or to a Bluetooth speaker. The bare minimum required hardware is a WROVER module with 4MB of Flash and 4MB of PSRAM (https://www.espressif.com/en/products/modules/esp32). With that module standalone, just apply power and you can stream to a Bluetooth speaker. You can also send audio to most I2S DAC as well as to SPDIF receivers using just a cable or an optical transducer.
|
||||
|
||||
@@ -69,7 +70,7 @@ Please note that when sending to a Bluetooth speaker (source), only 44.1 kHz can
|
||||
Most DAC will work out-of-the-box with simply an I2S connection, but some require specific commands to be sent using I2C. See DAC option below to understand how to send these dedicated commands. There is build-in support for TAS575x, TAS5780, TAS5713 and AC101 DAC.
|
||||
|
||||
### Raw WROOM esp32-s3 module
|
||||
The esp32-s3 based modules like [this]@(https://www.espressif.com/sites/default/files/documentation/esp32-s3-wroom-1_wroom-1u_datasheet_en.pdf) are also supported but requires esp-idf 4.4. It is not yet part of official releases, but it compiles & runs. The s3 does not have bluetooth audio. Note that CPU performances are greatly enhanced.
|
||||
The esp32-s3 based modules like [this](https://www.espressif.com/sites/default/files/documentation/esp32-s3-wroom-1_wroom-1u_datasheet_en.pdf) are also supported but requires esp-idf 4.4. It is not yet part of official releases, but it compiles & runs. The s3 does not have bluetooth audio. Note that CPU performances are greatly enhanced.
|
||||
|
||||
### SqueezeAMP
|
||||
This is the main hardware companion of Squeezelite-esp32 and has been developped together. Details on capabilities can be found [here](https://forums.slimdevices.com/showthread.php?110926-pre-ANNOUNCE-SqueezeAMP-and-SqueezeliteESP32) and [here](https://github.com/philippe44/SqueezeAMP).
|
||||
@@ -82,6 +83,8 @@ NB: You can use the pre-build binaries SqueezeAMP4MBFlash which has all the hard
|
||||
- dac_config: `model=TAS57xx,bck=33,ws=25,do=32,sda=27,scl=26,mute=14:0`
|
||||
- spdif_config: `bck=33,ws=25,do=15`
|
||||
|
||||
The IR can be used as a wake-up signal using (setting `sleep_config` with `wake=0:0`). It's a pull-up so it stays at 1 when not receiving anything which means it cannot be used in conjuction with other wake-up IOs. See [Sleeping](#sleeping) for more details regarding the limitation of waking-up upon multiple inputs.
|
||||
|
||||
### MuseLuxe
|
||||
This portable battery-powered [speaker](https://raspiaudio.com/produit/esp-muse-luxe) is compatible with squeezelite-esp32 for which there is a dedicated build supplied with every update. If you want to rebuild, use the `squeezelite-esp32-Muse-sdkconfig.defaults` configuration file.
|
||||
|
||||
@@ -184,7 +187,7 @@ bck=<gpio>,ws=<gpio>,do=<gpio>[,mck=0|1|2][,mute=<gpio>[:0|1][,model=TAS57xx|TAS
|
||||
```
|
||||
if "model" is not set or is not recognized, then default "I2S" is used. The option "mck" is used for some codecs that require a master clock (although they should not). By default GPIO0 is used as MCLK and only recent builds (post mid-2023) can use 1 or 2. Also be aware that this cannot coexit with RMII Ethernet (see ethernet section below). I2C parameters are optional and only needed if your DAC requires an I2C control (See 'dac_controlset' below). Note that "i2c" parameters are decimal, hex notation is not allowed.
|
||||
|
||||
So far, TAS57xx, TAS5713, AC101, WM8978 and ES8388 are recognized models where the proper init sequence/volume/power controls are sent. For other codecs that might require an I2C commands, please use the parameter "dac_controlset" that allows definition of simple commands to be sent over i2c for init, power, speakder and headset on and off using a JSON syntax:
|
||||
So far, TAS57xx, TAS5713, AC101, WM8978 and ES8388 are recognized models where the proper init sequence/volume/power controls are sent. For other codecs that might require an I2C commands, please use the parameter "dac_controlset" that allows definition of simple commands to be sent over i2c for init, power, speaker and headset on and off using a JSON syntax:
|
||||
```json
|
||||
{ <command>: [ {"reg":<register>,"val":<value>,"mode":<nothing>|"or"|"and"}, ... {{"reg":<register>,"val":<value>,"mode":<nothing>|"or"|"and"} ],
|
||||
<command>: [ {"reg":<register>,"val":<value>,"mode":<nothing>|"or"|"and"}, ... {{"reg":<register>,"val":<value>,"mode":<nothing>|"or"|"and"} ],
|
||||
@@ -194,6 +197,8 @@ Where `<command>` is one of init, poweron, poweroff, speakeron, speakeroff, head
|
||||
|
||||
This is standard JSON notation, so if you are not familiar with it, Google is your best friend. Be aware that the '...' means you can have as many entries as you want, it's not part of the syntax. Every section is optional, but it does not make sense to set i2c in the 'dac_config' parameter and not setting anything here. The parameter 'mode' allows to *or* the register with the value or to *and* it. Don't set 'mode' if you simply want to write. The 'val parameter can be an array [v1, v2,...] to write a serie of bytes in a single i2c burst (in that case 'mode' is ignored). **Note that all values must be decimal**. You can use a validator like [this](https://jsonlint.com) to verify your syntax
|
||||
|
||||
The 'power' command is used when powering on/off the DAC after the idle period (see -C option of squeezelite) and the 'speaker/headset' commands are sent when switching between speakers and headsets (see headset jack detection).
|
||||
|
||||
NB: For named configurations ((SqueezeAMP, Muse ... all except I2S), all this is ignored. For know codecs, the built-in sequences can be overwritten using dac_controlset
|
||||
|
||||
**Please note that you can not use the same GPIO or port as the I2C.**
|
||||
@@ -211,7 +216,7 @@ bck=<gpio>,ws=<gpio>,do=<gpio>
|
||||
```
|
||||
NB: For named configurations, this is ignored
|
||||
|
||||
To optimize speed, a bit-manipulation trick is used and as a result, the bit depth is limited to 20 bits, even in 32 bits mode. As said before, this is more than enough for any human ear. In theory, it could be extended up to 23 bits but I don't see the need. Now, you can also get SPDIF using a specialized chip that offers a I2S interface like a DAC but spits out SPDIF (optical and coax). Refers to DAC chapter then.
|
||||
The maximum bit depth is 24 bits, even in 32 bits mode (this a SPDIF limitation - thank @UrbanLienert for theupdate from 20 to 24 bit). Now, you can also get SPDIF using a specialized chip that offers a I2S interface like a DAC but spits out SPDIF (optical and coax). Refers to DAC chapter then.
|
||||
|
||||
If you want coax, you can also use a poor-man's trick to generate signal from a 3.3V GPIO. All that does is dividing the 3.3V to generate a 0.6V peak-to-peak and then remove DC
|
||||
```
|
||||
@@ -227,7 +232,7 @@ Ground -------------------------- coax signal ground
|
||||
The NVS parameter "display_config" sets the parameters for an optional display. It can be I2C (see [here](#i2c) for shared bus) or SPI (see [here](#spi) for shared bus) Syntax is
|
||||
```
|
||||
I2C,width=<pixels>,height=<pixels>[address=<i2c_address>][,reset=<gpio>][,HFlip][,VFlip][driver=SSD1306|SSD1326[:1|4]|SSD1327|SH1106]
|
||||
SPI,width=<pixels>,height=<pixels>,cs=<gpio>[,back=<gpio>][,reset=<gpio>][,speed=<speed>][,HFlip][,VFlip][driver=SSD1306|SSD1322|SSD1326[:1|4]|SSD1327|SH1106|SSD1675|ST7735[:x=<offset>][:y=<offset>]|ST7789|ILI9341[:16|18][,rotate]]
|
||||
SPI,width=<pixels>,height=<pixels>,cs=<gpio>[,back=<gpio>][,reset=<gpio>][,speed=<speed>][,HFlip][,VFlip][driver=SSD1306|SSD1322|SSD1326[:1|4]|SSD1327|SH1106|SSD1675|ST7735|ST7789[:x=<offset>][:y=<offset>]|ILI9341[:16|18][,rotate]]
|
||||
```
|
||||
- back: a LED backlight used by some older devices (ST7735). It is PWM controlled for brightness
|
||||
- reset: some display have a reset pin that is should normally be pulled up if unused. Most displays require reset and will not initialize well otherwise.
|
||||
@@ -272,6 +277,8 @@ GPIO can be set to GND provide or Vcc at boot. This is convenient to power devic
|
||||
|
||||
The `<amp>` parameter can use used to assign a GPIO that will be set to active level (default 1) when playback starts. It will be reset when squeezelite becomes idle. The idle timeout is set on the squeezelite command line through `-C <timeout>`
|
||||
|
||||
The `<power>` parameter can use used to assign a GPIO that will be set to active level (default 1) when player is powered on and reset when powered off (in LMS, does not apply to AirPlay, Spotify or BT).
|
||||
|
||||
If you have an audio jack that supports insertion (use :0 or :1 to set the level when inserted), you can specify which GPIO it's connected to. Using the parameter jack_mutes_amp allows to mute the amp when headset (e.g.) is inserted.
|
||||
|
||||
You can set the Green and Red status led as well with their respective active state (:0 or :1) or specific the chipset if you use addressable RGB led.
|
||||
@@ -281,7 +288,7 @@ The `<ir>` parameter set the GPIO associated to an IR receiver. No need to add p
|
||||
Syntax is:
|
||||
|
||||
```
|
||||
<gpio>=Vcc|GND|amp[:1|0]|ir[:nec|rc5]|jack[:0|1]|green[:0|1|ws2812]|red[:0|1|ws2812]|spkfault[:0|1][,<repeated sequence for next GPIO>]
|
||||
<gpio>=Vcc|GND|amp[:1|0]|power[:1:0]|ir[:nec|rc5]|jack[:0|1]|green[:0|1|ws2812]|red[:0|1|ws2812]|spkfault[:0|1][,<repeated sequence for next GPIO>]
|
||||
```
|
||||
You can define the defaults for jack, spkfault leds at compile time but nvs parameter takes precedence except for named configurations ((SqueezeAMP, Muse ...) where these are forced at runtime.
|
||||
**Note that gpio 36 and 39 are input only and cannot use interrupt. When set to jack or speaker fault, a 100ms polling checks their value but that's expensive**
|
||||
@@ -391,9 +398,11 @@ ACTRLS_NONE, ACTRLS_POWER, ACTRLS_VOLUP, ACTRLS_VOLDOWN, ACTRLS_TOGGLE, ACTRLS_P
|
||||
ACTRLS_PAUSE, ACTRLS_STOP, ACTRLS_REW, ACTRLS_FWD, ACTRLS_PREV, ACTRLS_NEXT,
|
||||
BCTRLS_UP, BCTRLS_DOWN, BCTRLS_LEFT, BCTRLS_RIGHT,
|
||||
BCTRLS_PS1, BCTRLS_PS2, BCTRLS_PS3, BCTRLS_PS4, BCTRLS_PS5, BCTRLS_PS6, BCTRLS_PS7, BCTRLS_PS8, BCTRLS_PS9, BCTRLS_PS10,
|
||||
KNOB_LEFT, KNOB_RIGHT, KNOB_PUSH,
|
||||
KNOB_LEFT, KNOB_RIGHT, KNOB_PUSH,
|
||||
ACTRLS_SLEEP,
|
||||
```
|
||||
|
||||
Note that ACTRLS_SLEEP is not an actual button that can be sent to LMS, but it's a hook to activate deep sleep mode (see [Sleeping](#sleeping)).
|
||||
|
||||
One you've created such a string, use it to fill a new NVS parameter with any name below 16(?) characters. You can have as many of these configs as you can. Then set the config parameter "actrls_config" with the name of your default config
|
||||
|
||||
For example a config named "buttons" :
|
||||
@@ -502,7 +511,36 @@ channel=0..7,scale=<scale>,cells=<1..3>[,atten=<0|1|2|3>]
|
||||
```
|
||||
NB: Set parameter to empty to disable battery reading. For named configurations (SqueezeAMP, Muse ...), this is ignored (except for SqueezeAMP where number of cells is required)
|
||||
|
||||
# Configuration
|
||||
### Sleeping
|
||||
The esp32 can be put in deep sleep mode to save some power. How much really depends on the connected periperals, so best is to do your own measures. Waking-up from deep sleep is the equivalent of a reboot, but as the chip takes a few seconds to connect, it's still an efficient process.
|
||||
|
||||
The esp32 can enter deep sleep after an audio inactivity timeout, after a button has been pressed, after a GPIO is set to a given level (there is a subtle difference, see below) or if the battery reaches a threashold. It wakes up only on some GPIO events. Note that *all* GPIO are isolated when sleeping (unless they are set with the `rtc`option) so you can not assume anything about their value, except that they will not drain current. The `rtc` option allows to keep some GPIO (from the RTC domain only) either pulled up or down. This can be useful if you want to keep some periperal active, for example a GPIO expander whose interrupt will be used to wake-up the system.
|
||||
|
||||
The NVS parameter `sleep_config` is mostly used for setting sleep conditions
|
||||
```
|
||||
[delay=<mins>][,sleep=<gpio>[:0|1]][,wake=<gpio>[:0|1][|<gpio>[:0|1]...][,rtc=<gpio>[:0|1][|<gpio>[:0|1]...][,batt=<voltage>][,spurious=<mins>]
|
||||
```
|
||||
- delay: inactivity in **minutes** before going to sleep
|
||||
- spurious: when using IR, wake-up can be triggered by any activity on the allocated GPIO, hence other remotes may cause unwanted wake-up. This sets (in **minutes** - default is 1) an inactivity delay after which sleep resumes.
|
||||
- sleep: GPIO that will put the system into sleep and it can be a level 0 or 1.
|
||||
- wake: **list** of GPIOs that with cause it to wake up (reboot) with their respective values. In such list, GPIO's are separated by an actual '|'.
|
||||
- batt: threshold in **volts** under which the system will enter into sleep.
|
||||
|
||||
The battery voltage is measured every 10 seconds and 30 values are averaged before producing a result. The result must be 3 times below the threshold to enter sleep, so it takes a total of 10\*30\*3 = 15 minutes.
|
||||
|
||||
Be mindful that if the same GPIO is used to go to sleep and wakeup with the *same* level (in other word it's a transition/edge that triggers the action) the above will not work and the esp32 will immediately restart. In such case, you case use a button definition. The benefit of buttons is that not only can you re-use one actual button (e.g. 'stop') to make it the sleep trigger (using a long-press or a shift-press) but by selecting the ACTRLS_SLEEP action upon 'release', you can got to sleep upon release (1-0-1 transition) but also wake up upon another press (0 level applied on GPIO) because you only go to sleep *after* the GPIO returned to 1.
|
||||
|
||||
Please see [buttons](#buttons) for detailed syntax.
|
||||
|
||||
The option to use multiple GPIOs is very limited on esp32 and the esp-idf 4.3.x we are using: it is only possible to wake-up when **any** of the defined GPIO is set to 1. The fact that you can specify different levels in the wake list is irrelevant for now, it's just a provision for future upgrades to more recent versions of esp-idf.
|
||||
|
||||
**Only the following GPIOs can be used to wake-up the esp32**
|
||||
- ESP32: 0, 2, 4, 12-15, 25-27, 32-39;
|
||||
- ESP32-S3: 0-21.
|
||||
|
||||
Some have asked for a soft power on/off option. Although this is not built-in, it's easy to create yours as long as the regulator/power supply of the board can be controlled by Vcc or GND. Depending on how it is active, add a pull-up/down resistor to the regulator's control and connect it also to one GPIO of the esp32. Then using set_GPIO, set that GPIO to Vcc or GND. Use a hardware button that forces the regulator on with a pull- up/down and once the esp32 has booted, it will force the GPIO to the desired value maintaining the board on by software. To power it off by software, just use the deep sleep option which will suspend all GPIO hence switching off the regulator.
|
||||
|
||||
# Software configuration
|
||||
|
||||
## Setup WiFi
|
||||
- Boot the esp, look for a new wifi access point showing up and connect to it. Default build ssid and passwords are "squeezelite"/"squeezelite".
|
||||
@@ -523,6 +561,15 @@ At this point, the device should have disabled its built-in access point and sho
|
||||
- The toggle switch should be set to 'ON' to ensure that squeezelite is active after booting (you might have to fiddle with it a few times)
|
||||
- You can enable accessto NVS parameters under 'credits'
|
||||
|
||||
## Spotify
|
||||
By default, SqueezeESP32 will use ZeroConf to advertise its Spotify capabilties. This means that until at least one local Spotify Connect application controllers discovers and connects to it, SqueezeESP32 will not be registered to Spotify servers. As a consequence, Spotify's WebAPI will not be able to see it (for example, Home Assistant services will miss it). Once you are connected to it using for example Spotify Desktop app, it will be registered and displayed everywhere.
|
||||
|
||||
If you want the player to be registered at start-up, you need to disable the ZeroConf option using the WebUI or `cspot_config::ZeroConf`. In that mode, the first time you run SqueezeESP32, it will be in ZeroConf mode and when you connect to it using a controller for the firt time, it receives and store credentials that will be used next time (after reboot).
|
||||
|
||||
Set ZeroConf to 1 will always force ZeroConf mode to be used.
|
||||
|
||||
The ZeroConf mode consumes less memory as it uses the built-in HTTP and mDNS servers to broadcast its capabilities. A Spotify controller will then discover these and trigger the SqueezeESP32 Spotify stack (cspot) to start. When the controller disconnects, the stack is shut down. In non-ZeroConf mode, the stack starts immediately (providing stored credentials are valid) and always run - a disconnect will not shut it down.
|
||||
|
||||
## Monitor
|
||||
In addition of the esp-idf serial link monitor option, you can also enable a telnet server (see NVS parameters) where you'll have access to a ton of logs of what's happening inside the WROVER.
|
||||
|
||||
@@ -616,5 +663,11 @@ If you have already cloned the repository and you are getting compile errors on
|
||||
- stack consumption can be very high with some codec variants, so set NONTHREADSAFE_PSEUDOSTACK and GLOBAL_STACK_SIZE=48000 and unset VAR_ARRAYS in config.h
|
||||
- libmad has been patched to avoid using a lot of stack and is not provided here. There is an issue with sync detection in 1.15.1b from where the original stack patch was done but since a few fixes have been made wrt sync detection. This 1.15.1b-10 found on debian fixes the issue where mad thinks it has reached sync but has not and so returns a wrong sample rate. It comes at the expense of 8KB (!) of code where a simple check in squeezelite/mad.c that next_frame[0] is 0xff and next_frame[1] & 0xf0 is 0xf0 does the trick ...
|
||||
|
||||
# Hardware tips
|
||||
There is a possibility to have a software on/off where a temporary switch can power-up the esp32 which then will auto-sustain its power. Depending on the selected hardware, it a can also include a power-off by using a long press on the same button.
|
||||
|
||||
The auto-power is simply acheived by using `setGPIO` and forcing a GPIO to Vcc or GND and the sustain on/off requires a button creation whose longpress is an ACTRLS_SLEEP action (see also the [Sleeping](#sleeping) section). Credits [Renber78](http://github.com/Renber78) for schedmatics below
|
||||
|
||||

|
||||
|
||||
# Footnotes
|
||||
(1) SPDIF is made by tricking the I2S bus but this consumes a fair bit of CPU as it multiplies by four the throughput on the i2s bus. To optimize some computation, the parity of the spdif frames must always be 0, so at least one bit has to be available to force it. As SPDIF samples are 20+4 bits length maximum, the LSB is used for that purpose, so the bit 24 is randomly toggling. It does not matter for 16 bits samples but it has been chosen to truncate the last 4 bits for 24 bits samples. I'm sure that some smart dude can further optimize spdif_convert() and use the user bit instead. You're welcome to do a PR but, as said above, I (philippe44) am not interested by 24 bits mental illness :-) and I've already made an effort to provide 20 bits which already way more what's needed :-)
|
||||
|
||||
BIN
Soft Power.png
Normal file
BIN
Soft Power.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
@@ -297,6 +297,12 @@ CONFIG_AUDIO_CONTROLS=""
|
||||
CONFIG_AMP_GPIO=-1
|
||||
# end of AMP configuration
|
||||
|
||||
#
|
||||
# POWER configuration
|
||||
#
|
||||
CONFIG_POWER_GPIO=-1
|
||||
# end of POWER configuration
|
||||
|
||||
#
|
||||
# Audio JACK
|
||||
#
|
||||
@@ -942,7 +948,7 @@ CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y
|
||||
CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=y
|
||||
# CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set
|
||||
CONFIG_FREERTOS_INTERRUPT_BACKTRACE=y
|
||||
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1
|
||||
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=2
|
||||
# CONFIG_FREERTOS_ASSERT_FAIL_ABORT is not set
|
||||
CONFIG_FREERTOS_ASSERT_DISABLE=y
|
||||
CONFIG_FREERTOS_ISR_STACKSIZE=2096
|
||||
|
||||
@@ -264,6 +264,12 @@ CONFIG_CSPOT_SINK=y
|
||||
#
|
||||
# end of Display Screen
|
||||
|
||||
#
|
||||
# POWER configuration
|
||||
#
|
||||
CONFIG_POWER_GPIO=-1
|
||||
# end of POWER configuration
|
||||
|
||||
#
|
||||
# Various I/O
|
||||
#
|
||||
@@ -901,7 +907,7 @@ CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y
|
||||
CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=y
|
||||
# CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set
|
||||
CONFIG_FREERTOS_INTERRUPT_BACKTRACE=y
|
||||
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1
|
||||
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=2
|
||||
# CONFIG_FREERTOS_ASSERT_FAIL_ABORT is not set
|
||||
CONFIG_FREERTOS_ASSERT_DISABLE=y
|
||||
CONFIG_FREERTOS_ISR_STACKSIZE=2096
|
||||
|
||||
@@ -288,6 +288,12 @@ CONFIG_AUDIO_CONTROLS=""
|
||||
CONFIG_AMP_GPIO=-1
|
||||
# end of AMP configuration
|
||||
|
||||
#
|
||||
# POWER configuration
|
||||
#
|
||||
CONFIG_POWER_GPIO=-1
|
||||
# end of POWER configuration
|
||||
|
||||
#
|
||||
# Compiler options
|
||||
#
|
||||
@@ -912,7 +918,7 @@ CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION=y
|
||||
CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY=y
|
||||
# CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK is not set
|
||||
CONFIG_FREERTOS_INTERRUPT_BACKTRACE=y
|
||||
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=1
|
||||
CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS=2
|
||||
# CONFIG_FREERTOS_ASSERT_FAIL_ABORT is not set
|
||||
CONFIG_FREERTOS_ASSERT_DISABLE=y
|
||||
CONFIG_FREERTOS_ISR_STACKSIZE=2096
|
||||
|
||||
@@ -289,10 +289,8 @@ struct GDS_Device* ST77xx_Detect(char *Driver, struct GDS_Device* Device) {
|
||||
struct PrivateSpace* Private = (struct PrivateSpace*) Device->Private;
|
||||
Private->Model = Model;
|
||||
|
||||
if (Model == ST7735) {
|
||||
sscanf(Driver, "%*[^:]%*[^x]%*[^=]=%hu", &Private->Offset.Height);
|
||||
sscanf(Driver, "%*[^:]%*[^y]%*[^=]=%hu", &Private->Offset.Width);
|
||||
}
|
||||
sscanf(Driver, "%*[^:]%*[^x]%*[^=]=%hu", &Private->Offset.Height);
|
||||
sscanf(Driver, "%*[^:]%*[^y]%*[^=]=%hu", &Private->Offset.Width);
|
||||
|
||||
if (Depth == 18) {
|
||||
Device->Mode = GDS_RGB666;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "platform_config.h"
|
||||
#include "tools.h"
|
||||
#include "display.h"
|
||||
#include "services.h"
|
||||
#include "gds.h"
|
||||
#include "gds_default_if.h"
|
||||
#include "gds_draw.h"
|
||||
@@ -73,7 +74,9 @@ static const char *known_drivers[] = {"SH1106",
|
||||
"ILI9341",
|
||||
NULL
|
||||
};
|
||||
|
||||
static void displayer_task(void *args);
|
||||
static void display_sleep(void);
|
||||
|
||||
struct GDS_Device *display;
|
||||
extern GDS_DetectFunc SSD1306_Detect, SSD132x_Detect, SH1106_Detect, SSD1675_Detect, SSD1322_Detect, SSD1351_Detect, ST77xx_Detect, ILI9341_Detect;
|
||||
@@ -174,11 +177,21 @@ void display_init(char *welcome) {
|
||||
if (height <= 64 && width > height * 2) displayer.artwork.offset = width - height - ARTWORK_BORDER;
|
||||
PARSE_PARAM(displayer.metadata_config, "artwork", ':', displayer.artwork.fit);
|
||||
}
|
||||
|
||||
// and finally register ourselves to power off upon deep sleep
|
||||
services_sleep_setsuspend(display_sleep);
|
||||
}
|
||||
|
||||
free(config);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static void display_sleep(void) {
|
||||
GDS_DisplayOff(display);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* This is not thread-safe as displayer_task might be in the middle of line drawing
|
||||
* but it won't crash (I think) and making it thread-safe would be complicated for a
|
||||
|
||||
@@ -25,6 +25,8 @@ static const char * TAG = "bt_app_source";
|
||||
static const char * BT_RC_CT_TAG="RCCT";
|
||||
extern int32_t output_bt_data(uint8_t *data, int32_t len);
|
||||
extern void output_bt_tick(void);
|
||||
extern void output_bt_stop(void);
|
||||
extern void output_bt_start(void);
|
||||
extern char* output_state_str(void);
|
||||
extern bool output_stopped(void);
|
||||
extern bool is_recovery_running;
|
||||
@@ -803,6 +805,7 @@ static void bt_app_av_media_proc(uint16_t event, void *param)
|
||||
if (a2d->media_ctrl_stat.cmd == ESP_A2D_MEDIA_CTRL_START &&
|
||||
a2d->media_ctrl_stat.status == ESP_A2D_MEDIA_CTRL_ACK_SUCCESS) {
|
||||
ESP_LOGI(TAG,"a2dp media started successfully.");
|
||||
output_bt_start();
|
||||
set_a2dp_media_state(APP_AV_MEDIA_STATE_STARTED);
|
||||
} else {
|
||||
// not started succesfully, transfer to idle state
|
||||
@@ -831,6 +834,7 @@ static void bt_app_av_media_proc(uint16_t event, void *param)
|
||||
if (a2d->media_ctrl_stat.cmd == ESP_A2D_MEDIA_CTRL_STOP &&
|
||||
a2d->media_ctrl_stat.status == ESP_A2D_MEDIA_CTRL_ACK_SUCCESS) {
|
||||
ESP_LOGI(TAG,"a2dp media stopped successfully...");
|
||||
output_bt_stop();
|
||||
set_a2dp_media_state(APP_AV_MEDIA_STATE_IDLE);
|
||||
} else {
|
||||
ESP_LOGI(TAG,"a2dp media stopping...");
|
||||
|
||||
@@ -38,21 +38,12 @@ struct led_color_t {
|
||||
};
|
||||
|
||||
struct led_strip_t {
|
||||
const enum rgb_led_type_t rgb_led_type;
|
||||
enum rgb_led_type_t rgb_led_type; // should be const, but workaround needed for initialization
|
||||
uint32_t led_strip_length;
|
||||
|
||||
// RMT peripheral settings
|
||||
rmt_channel_t rmt_channel;
|
||||
|
||||
/*
|
||||
* Interrupt table is located in soc.h
|
||||
* As of 11/27/16, reccomended interrupts are:
|
||||
* 9, 12, 13, 17, 18, 19, 20, 21 or 23
|
||||
* Ensure that the same interrupt number isn't used twice
|
||||
* across all libraries
|
||||
*/
|
||||
int rmt_interrupt_num;
|
||||
|
||||
|
||||
gpio_num_t gpio; // Must be less than GPIO_NUM_33
|
||||
|
||||
struct led_color_t *led_strip_working;
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* Driver does support other led device. Maybe look at supporting in future.
|
||||
* The VU refresh rate has been decreaced (100->75) to optimize animation of spin dial. Could make
|
||||
* configurable like text scrolling (or use the same value)
|
||||
* Look at reserving a status led within the effects. (may require nvs setting for center or end position)
|
||||
* Artwork function, but not released as very buggy and not really practical
|
||||
*/
|
||||
|
||||
@@ -22,13 +21,18 @@
|
||||
#include "esp_log.h"
|
||||
|
||||
#include "globdefs.h"
|
||||
#include "monitor.h"
|
||||
#include "led_strip.h"
|
||||
#include "platform_config.h"
|
||||
#include "led_vu.h"
|
||||
|
||||
static const char *TAG = "led_vu";
|
||||
|
||||
#define LED_VU_STACK_SIZE (3*1024)
|
||||
static void (*battery_handler_chain)(float value, int cells);
|
||||
static void battery_svc(float value, int cells);
|
||||
static int battery_status = 0;
|
||||
|
||||
#define LED_VU_STACK_SIZE (3*1024)
|
||||
|
||||
#define LED_VU_PEAK_HOLD 6U
|
||||
|
||||
@@ -36,9 +40,13 @@ static const char *TAG = "led_vu";
|
||||
#define LED_VU_DEFAULT_LENGTH 19
|
||||
#define LED_VU_MAX_LENGTH 255
|
||||
|
||||
#define LED_VU_STATUS_GREEN 75
|
||||
#define LED_VU_STATUS_RED 25
|
||||
|
||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
struct led_strip_t* led_display = NULL;
|
||||
static EXT_RAM_ATTR struct led_strip_t led_strip_config;
|
||||
|
||||
static EXT_RAM_ATTR struct {
|
||||
int gpio;
|
||||
@@ -46,7 +54,7 @@ static EXT_RAM_ATTR struct {
|
||||
int vu_length;
|
||||
int vu_start_l;
|
||||
int vu_start_r;
|
||||
int vu_odd;
|
||||
int vu_status;
|
||||
} strip;
|
||||
|
||||
static int led_addr(int pos ) {
|
||||
@@ -55,6 +63,13 @@ static int led_addr(int pos ) {
|
||||
return pos;
|
||||
}
|
||||
|
||||
static void battery_svc(float value, int cells) {
|
||||
battery_status = battery_level_svc();
|
||||
ESP_LOGI(TAG, "Called for battery service with volt:%f cells:%d status:%d", value, cells, battery_status);
|
||||
|
||||
if (battery_handler_chain) battery_handler_chain(value, cells);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Initialize the led vu strip if configured.
|
||||
*
|
||||
@@ -80,29 +95,41 @@ void led_vu_init()
|
||||
ESP_LOGI(TAG, "led_vu configuration invalid");
|
||||
goto done;
|
||||
}
|
||||
|
||||
battery_handler_chain = battery_handler_svc;
|
||||
battery_handler_svc = battery_svc;
|
||||
battery_status = battery_level_svc();
|
||||
|
||||
if (strip.length > LED_VU_MAX_LENGTH) strip.length = LED_VU_MAX_LENGTH;
|
||||
// initialize vu settings
|
||||
//strip.vu_length = (strip.length % 2) ? strip.length / 2 : (strip.length - 1) / 2;
|
||||
strip.vu_length = (strip.length - 1) / 2;
|
||||
strip.vu_start_l = strip.vu_length;
|
||||
strip.vu_start_r = strip.vu_start_l + 1;
|
||||
strip.vu_odd = strip.length - 1;
|
||||
// initialize vu meter settings
|
||||
if (strip.length < 10) {
|
||||
// single bar for small strips
|
||||
strip.vu_length = strip.length;
|
||||
strip.vu_start_l = 0;
|
||||
strip.vu_start_r = strip.vu_start_l;
|
||||
strip.vu_status = 0;
|
||||
} else {
|
||||
strip.vu_length = (strip.length - 1) / 2;
|
||||
strip.vu_start_l = (strip.length % 2) ? strip.vu_length -1 : strip.vu_length;
|
||||
strip.vu_start_r = strip.vu_length + 1;
|
||||
strip.vu_status = strip.vu_length;
|
||||
}
|
||||
ESP_LOGI(TAG, "vu meter using length:%d left:%d right:%d status:%d", strip.vu_length, strip.vu_start_l, strip.vu_start_r, strip.vu_status);
|
||||
|
||||
// create driver configuration
|
||||
struct led_strip_t led_strip_config = { .rgb_led_type = RGB_LED_TYPE_WS2812 };
|
||||
led_strip_config.rgb_led_type = RGB_LED_TYPE_WS2812;
|
||||
led_strip_config.access_semaphore = xSemaphoreCreateBinary();
|
||||
led_strip_config.led_strip_length = strip.length;
|
||||
led_strip_config.led_strip_working = heap_caps_malloc(strip.length * sizeof(struct led_color_t), MALLOC_CAP_8BIT);
|
||||
led_strip_config.led_strip_showing = heap_caps_malloc(strip.length * sizeof(struct led_color_t), MALLOC_CAP_8BIT);
|
||||
led_strip_config.gpio = strip.gpio;
|
||||
led_strip_config.rmt_channel = rmt_system_base_channel++;
|
||||
led_strip_config.rmt_channel = RMT_NEXT_TX_CHANNEL();
|
||||
|
||||
// initialize driver
|
||||
bool led_init_ok = led_strip_init(&led_strip_config);
|
||||
if (led_init_ok) {
|
||||
led_display = &led_strip_config;
|
||||
ESP_LOGI(TAG, "led_vu using gpio:%d length:%d on channek:%d", strip.gpio, strip.length, led_strip_config.rmt_channel);
|
||||
ESP_LOGI(TAG, "led_vu using gpio:%d length:%d on channel:%d", strip.gpio, strip.length, led_strip_config.rmt_channel);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "led_vu init failed");
|
||||
goto done;
|
||||
@@ -295,7 +322,11 @@ void led_vu_display(int vu_l, int vu_r, int bright, bool comet) {
|
||||
static int decay_r = 0;
|
||||
if (!led_display) return;
|
||||
|
||||
|
||||
// single bar
|
||||
if (strip.vu_start_l == strip.vu_start_r) {
|
||||
vu_r = (vu_l + vu_r) / 2;
|
||||
vu_l = 0;
|
||||
}
|
||||
|
||||
// scale vu samples to length
|
||||
vu_l = vu_l * strip.vu_length / bright;
|
||||
@@ -356,6 +387,14 @@ void led_vu_display(int vu_l, int vu_r, int bright, bool comet) {
|
||||
g = (g < step) ? 0 : g - step;
|
||||
}
|
||||
|
||||
// show battery status
|
||||
if (battery_status > LED_VU_STATUS_GREEN)
|
||||
led_strip_set_pixel_rgb(led_display, strip.vu_status, 0, bright, 0);
|
||||
else if (battery_status > LED_VU_STATUS_RED)
|
||||
led_strip_set_pixel_rgb(led_display, strip.vu_status, bright/2, bright/2, 0);
|
||||
else if (battery_status > 0)
|
||||
led_strip_set_pixel_rgb(led_display, strip.vu_status, bright, 0, 0);
|
||||
|
||||
led_strip_show(led_display);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,14 +13,14 @@ esp_err_t store_nvs_value_len(nvs_type_t type, const char *key, void * data, siz
|
||||
esp_err_t store_nvs_value(nvs_type_t type, const char *key, void * data);
|
||||
esp_err_t get_nvs_value(nvs_type_t type, const char *key, void*value, const uint8_t buf_size);
|
||||
void * get_nvs_value_alloc(nvs_type_t type, const char *key);
|
||||
void * get_nvs_value_alloc_for_partition(const char * partition,const char * namespace,nvs_type_t type, const char *key, size_t * size);
|
||||
esp_err_t erase_nvs_for_partition(const char * partition, const char * namespace,const char *key);
|
||||
esp_err_t store_nvs_value_len_for_partition(const char * partition,const char * namespace,nvs_type_t type, const char *key, const void * data,size_t data_len);
|
||||
void * get_nvs_value_alloc_for_partition(const char * partition,const char * ns,nvs_type_t type, const char *key, size_t * size);
|
||||
esp_err_t erase_nvs_for_partition(const char * partition, const char * ns,const char *key);
|
||||
esp_err_t store_nvs_value_len_for_partition(const char * partition,const char * ns,nvs_type_t type, const char *key, const void * data,size_t data_len);
|
||||
esp_err_t erase_nvs(const char *key);
|
||||
void print_blob(const char *blob, size_t len);
|
||||
const char *type_to_str(nvs_type_t type);
|
||||
nvs_type_t str_to_type(const char *type);
|
||||
esp_err_t erase_nvs_partition(const char * partition, const char * namespace);
|
||||
esp_err_t erase_nvs_partition(const char * partition, const char * ns);
|
||||
void erase_settings_partition();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -43,11 +43,15 @@ const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
|
||||
extern void register_audio_config(void);
|
||||
extern void register_rotary_config(void);
|
||||
extern void register_ledvu_config(void);
|
||||
extern void register_nvs();
|
||||
|
||||
void register_optional_cmd(void) {
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
register_rotary_config();
|
||||
register_ledvu_config();
|
||||
#endif
|
||||
register_audio_config();
|
||||
register_ledvu_config();
|
||||
register_nvs();
|
||||
}
|
||||
|
||||
extern int squeezelite_main(int argc, char **argv);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -73,24 +73,42 @@ static void register_set_services();
|
||||
static void register_tasks();
|
||||
#endif
|
||||
extern BaseType_t network_manager_task;
|
||||
FILE * system_open_memstream(const char * cmdname,char **buf,size_t *buf_size){
|
||||
FILE *f = open_memstream(buf, buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(cmdname,MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
}
|
||||
return f;
|
||||
}
|
||||
void register_system()
|
||||
{
|
||||
register_free();
|
||||
|
||||
register_setdevicename();
|
||||
register_set_services();
|
||||
register_free();
|
||||
register_heap();
|
||||
register_dump_heap();
|
||||
register_setdevicename();
|
||||
register_version();
|
||||
register_restart();
|
||||
register_deep_sleep();
|
||||
register_light_sleep();
|
||||
register_factory_boot();
|
||||
register_restart_ota();
|
||||
#if WITH_TASKS_INFO
|
||||
register_tasks();
|
||||
#endif
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
register_deep_sleep();
|
||||
register_light_sleep();
|
||||
#endif
|
||||
}
|
||||
void simple_restart()
|
||||
{
|
||||
log_send_messaging(MESSAGING_WARNING,"Rebooting.");
|
||||
if(!wait_for_commit()){
|
||||
log_send_messaging(MESSAGING_WARNING,"Unable to commit configuration. ");
|
||||
}
|
||||
vTaskDelay(750/ portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
/* 'version' command */
|
||||
static int get_version(int argc, char **argv)
|
||||
{
|
||||
@@ -128,36 +146,23 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype)
|
||||
{
|
||||
if(is_recovery_running){
|
||||
if(partition_subtype ==ESP_PARTITION_SUBTYPE_APP_FACTORY){
|
||||
log_send_messaging(MESSAGING_WARNING,"RECOVERY application is already active");
|
||||
if(!wait_for_commit()){
|
||||
log_send_messaging(MESSAGING_WARNING,"Unable to commit configuration. ");
|
||||
}
|
||||
|
||||
vTaskDelay(750/ portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
return ESP_OK;
|
||||
// log_send_messaging(MESSAGING_WARNING,"RECOVERY application is already active");
|
||||
simple_restart();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(partition_subtype !=ESP_PARTITION_SUBTYPE_APP_FACTORY){
|
||||
log_send_messaging(MESSAGING_WARNING,"SQUEEZELITE application is already active");
|
||||
if(!wait_for_commit()){
|
||||
log_send_messaging(MESSAGING_WARNING,"Unable to commit configuration. ");
|
||||
}
|
||||
|
||||
vTaskDelay(750/ portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
return ESP_OK;
|
||||
// log_send_messaging(MESSAGING_WARNING,"SQUEEZELITE application is already active");
|
||||
simple_restart();
|
||||
}
|
||||
}
|
||||
esp_err_t err = ESP_OK;
|
||||
bool bFound=false;
|
||||
log_send_messaging(MESSAGING_INFO, "Looking for partition type %u",partition_subtype);
|
||||
// log_send_messaging(MESSAGING_INFO, "Looking for partition type %u",partition_subtype);
|
||||
const esp_partition_t *partition;
|
||||
esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_APP, partition_subtype, NULL);
|
||||
|
||||
if(it == NULL){
|
||||
log_send_messaging(MESSAGING_ERROR,"Reboot failed. Cannot iterate through partitions");
|
||||
log_send_messaging(MESSAGING_ERROR,"Reboot failed. Partitions error");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -166,15 +171,11 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype)
|
||||
ESP_LOGD(TAG, "Releasing partition iterator");
|
||||
esp_partition_iterator_release(it);
|
||||
if(partition != NULL){
|
||||
log_send_messaging(MESSAGING_INFO, "Found application partition %s sub type %u", partition->label,partition_subtype);
|
||||
log_send_messaging(MESSAGING_INFO, "Rebooting to %s", partition->label);
|
||||
err=esp_ota_set_boot_partition(partition);
|
||||
if(err!=ESP_OK){
|
||||
bFound=false;
|
||||
log_send_messaging(MESSAGING_ERROR,"Unable to select partition for reboot: %s",esp_err_to_name(err));
|
||||
}
|
||||
else{
|
||||
bFound=true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -183,13 +184,7 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype)
|
||||
}
|
||||
ESP_LOGD(TAG, "Yielding to other processes");
|
||||
taskYIELD();
|
||||
if(bFound) {
|
||||
if(!wait_for_commit()){
|
||||
log_send_messaging(MESSAGING_WARNING,"Unable to commit configuration changes. ");
|
||||
}
|
||||
vTaskDelay(750/ portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
}
|
||||
simple_restart();
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
@@ -197,46 +192,31 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype)
|
||||
|
||||
static int restart(int argc, char **argv)
|
||||
{
|
||||
log_send_messaging(MESSAGING_WARNING, "\n\nPerforming a simple restart to the currently active partition.");
|
||||
if(!wait_for_commit()){
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING,"Unable to commit configuration. ");
|
||||
}
|
||||
vTaskDelay(750/ portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
simple_restart();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void simple_restart()
|
||||
{
|
||||
log_send_messaging(MESSAGING_WARNING,"System reboot requested.");
|
||||
if(!wait_for_commit()){
|
||||
log_send_messaging(MESSAGING_WARNING,"Unable to commit configuration. ");
|
||||
}
|
||||
|
||||
|
||||
vTaskDelay(750/ portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
esp_err_t guided_restart_ota(){
|
||||
log_send_messaging(MESSAGING_WARNING,"System reboot to Application requested");
|
||||
log_send_messaging(MESSAGING_WARNING,"Booting to Squeezelite");
|
||||
guided_boot(ESP_PARTITION_SUBTYPE_APP_OTA_0);
|
||||
return ESP_FAIL; // return fail. This should never return... we're rebooting!
|
||||
}
|
||||
esp_err_t guided_factory(){
|
||||
log_send_messaging(MESSAGING_WARNING,"System reboot to recovery requested");
|
||||
log_send_messaging(MESSAGING_WARNING,"Booting to recovery");
|
||||
guided_boot(ESP_PARTITION_SUBTYPE_APP_FACTORY);
|
||||
return ESP_FAIL; // return fail. This should never return... we're rebooting!
|
||||
}
|
||||
static int restart_factory(int argc, char **argv)
|
||||
{
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING, "Executing guided boot into recovery");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING, "Booting to Recovery");
|
||||
guided_boot(ESP_PARTITION_SUBTYPE_APP_FACTORY);
|
||||
return 0; // return fail. This should never return... we're rebooting!
|
||||
}
|
||||
static int restart_ota(int argc, char **argv)
|
||||
{
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING, "Executing guided boot into ota app 0");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING, "Booting to Squeezelite");
|
||||
guided_boot(ESP_PARTITION_SUBTYPE_APP_OTA_0);
|
||||
return 0; // return fail. This should never return... we're rebooting!
|
||||
}
|
||||
@@ -248,7 +228,9 @@ static void register_restart()
|
||||
.hint = NULL,
|
||||
.func = &restart,
|
||||
};
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
cmd_to_json(&cmd);
|
||||
#endif
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
static void register_restart_ota()
|
||||
@@ -259,7 +241,9 @@ static void register_restart_ota()
|
||||
.hint = NULL,
|
||||
.func = &restart_ota,
|
||||
};
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
cmd_to_json(&cmd);
|
||||
#endif
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
|
||||
@@ -271,7 +255,9 @@ static void register_factory_boot()
|
||||
.hint = NULL,
|
||||
.func = &restart_factory,
|
||||
};
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
cmd_to_json(&cmd);
|
||||
#endif
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
/** 'free' command prints available heap memory */
|
||||
@@ -287,11 +273,14 @@ static void register_free()
|
||||
{
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "free",
|
||||
.help = "Get the current size of free heap memory",
|
||||
.help = "Get free heap memory",
|
||||
.hint = NULL,
|
||||
.func = &free_mem,
|
||||
};
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
cmd_to_json(&cmd);
|
||||
#endif
|
||||
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
static int dump_heap(int argc, char **argv)
|
||||
@@ -303,16 +292,16 @@ static int dump_heap(int argc, char **argv)
|
||||
/* 'heap' command prints minumum heap size */
|
||||
static int heap_size(int argc, char **argv)
|
||||
{
|
||||
ESP_LOGI(TAG,"Heap internal:%zu (min:%zu) (largest block:%zu)\nexternal:%zu (min:%zu) (largest block:%zd)\ndma :%zu (min:%zu) (largest block:%zd)",
|
||||
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_free_size(MALLOC_CAP_DMA),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_DMA),
|
||||
heap_caps_get_largest_free_block(MALLOC_CAP_DMA));
|
||||
// ESP_LOGI(TAG,"Heap internal:%zu (min:%zu) (largest block:%zu)\nexternal:%zu (min:%zu) (largest block:%zd)\ndma :%zu (min:%zu) (largest block:%zd)",
|
||||
// heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
|
||||
// heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
|
||||
// heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL),
|
||||
// heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
|
||||
// heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM),
|
||||
// heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM),
|
||||
// heap_caps_get_free_size(MALLOC_CAP_DMA),
|
||||
// heap_caps_get_minimum_free_size(MALLOC_CAP_DMA),
|
||||
// heap_caps_get_largest_free_block(MALLOC_CAP_DMA));
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO,"Heap internal:%zu (min:%zu) (largest block:%zu)\nexternal:%zu (min:%zu) (largest block:%zd)\ndma :%zu (min:%zu) (largest block:%zd)",
|
||||
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
|
||||
@@ -457,9 +446,8 @@ static int setdevicename(int argc, char **argv)
|
||||
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
FILE *f = system_open_memstream(argv[0],&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 1;
|
||||
}
|
||||
nerrors+=setnamevar("a2dp_dev_name", f, name);
|
||||
@@ -488,11 +476,13 @@ static void register_heap()
|
||||
{
|
||||
const esp_console_cmd_t heap_cmd = {
|
||||
.command = "heap",
|
||||
.help = "Get minimum size of free heap memory found during execution",
|
||||
.help = "Get minimum size of free heap memory",
|
||||
.hint = NULL,
|
||||
.func = &heap_size,
|
||||
};
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
cmd_to_json(&heap_cmd);
|
||||
#endif
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&heap_cmd) );
|
||||
|
||||
}
|
||||
@@ -521,6 +511,7 @@ static void register_setdevicename()
|
||||
.func = &setdevicename,
|
||||
.argtable = &name_args
|
||||
};
|
||||
|
||||
cmd_to_json_with_cb(&set_name,&setdevicename_cb);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&set_name));
|
||||
}
|
||||
@@ -618,9 +609,7 @@ static void register_deep_sleep()
|
||||
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "deep_sleep",
|
||||
.help = "Enter deep sleep mode. "
|
||||
"Two wakeup modes are supported: timer and GPIO. "
|
||||
"If no wakeup option is specified, will sleep indefinitely.",
|
||||
.help = "Enter deep sleep mode. ",
|
||||
.hint = NULL,
|
||||
.func = &deep_sleep,
|
||||
.argtable = &deep_sleep_args
|
||||
@@ -649,9 +638,8 @@ static int do_set_services(int argc, char **argv)
|
||||
}
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
FILE *f = system_open_memstream(argv[0],&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -674,7 +662,7 @@ static int do_set_services(int argc, char **argv)
|
||||
|
||||
if(err!=ESP_OK){
|
||||
nerrors++;
|
||||
fprintf(f,"Error setting telnet service to %s. %s\n",set_services_args.telnet->sval[0], esp_err_to_name(err));
|
||||
fprintf(f,"Error setting telnet to %s. %s\n",set_services_args.telnet->sval[0], esp_err_to_name(err));
|
||||
}
|
||||
else {
|
||||
fprintf(f,"Telnet service changed to %s\n",set_services_args.telnet->sval[0]);
|
||||
@@ -706,7 +694,6 @@ cJSON * set_services_cb(){
|
||||
#if WITH_TASKS_INFO
|
||||
console_set_bool_parameter(values,"stats",set_services_args.stats);
|
||||
#endif
|
||||
|
||||
if ((p = config_alloc_get(NVS_TYPE_STR, "telnet_enable")) != NULL) {
|
||||
if(strcasestr("YX",p)!=NULL){
|
||||
cJSON_AddStringToObject(values,set_services_args.telnet->hdr.longopts,"Telnet Only");
|
||||
@@ -717,7 +704,6 @@ cJSON * set_services_cb(){
|
||||
else {
|
||||
cJSON_AddStringToObject(values,set_services_args.telnet->hdr.longopts,"Disabled");
|
||||
}
|
||||
|
||||
FREE_AND_NULL(p);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ void register_system();
|
||||
esp_err_t guided_factory();
|
||||
esp_err_t guided_restart_ota();
|
||||
void simple_restart();
|
||||
FILE * system_open_memstream(const char * cmdname,char **buf,size_t *buf_size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -204,8 +204,10 @@ void register_wifi_join()
|
||||
|
||||
void register_wifi()
|
||||
{
|
||||
#ifdef WIFI_CMDLINE
|
||||
register_wifi_join();
|
||||
if(bypass_network_manager){
|
||||
initialise_wifi();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -626,15 +626,19 @@ static bool handle_rtsp(raop_ctx_t *ctx, int sock)
|
||||
struct metadata_s metadata;
|
||||
dmap_settings settings = {
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, on_dmap_string, NULL,
|
||||
NULL
|
||||
};
|
||||
NULL
|
||||
};
|
||||
|
||||
settings.ctx = &metadata;
|
||||
memset(&metadata, 0, sizeof(struct metadata_s));
|
||||
settings.ctx = &metadata;
|
||||
if (!dmap_parse(&settings, body, len)) {
|
||||
uint32_t timestamp = 0;
|
||||
if ((p = kd_lookup(headers, "RTP-Info")) != NULL) sscanf(p, "%*[^=]=%d", ×tamp);
|
||||
LOG_INFO("[%p]: received metadata (ts: %d)\n\tartist: %s\n\talbum: %s\n\ttitle: %s",
|
||||
ctx, metadata.artist ? metadata.artist : "", metadata.album ? metadata.album : "",
|
||||
metadata.title ? metadata.title : "");
|
||||
ctx, timestamp, metadata.artist ? metadata.artist : "", metadata.album ? metadata.album : "",
|
||||
metadata.title ? metadata.title : "");
|
||||
success = ctx->cmd_cb(RAOP_METADATA, metadata.artist, metadata.album, metadata.title, timestamp);
|
||||
free_metadata(&metadata);
|
||||
}
|
||||
} else if (body && ((p = kd_lookup(headers, "Content-Type")) != NULL) && strcasestr(p, "image/jpeg")) {
|
||||
uint32_t timestamp = 0;
|
||||
|
||||
@@ -113,6 +113,7 @@ static bool cmd_handler(raop_event_t event, ...) {
|
||||
case RAOP_SETUP:
|
||||
actrls_set(controls, false, NULL, actrls_ir_action);
|
||||
displayer_control(DISPLAYER_ACTIVATE, "AIRPLAY", true);
|
||||
displayer_artwork(NULL);
|
||||
break;
|
||||
case RAOP_PLAY:
|
||||
displayer_control(DISPLAYER_TIMER_RUN);
|
||||
@@ -132,7 +133,6 @@ static bool cmd_handler(raop_event_t event, ...) {
|
||||
case RAOP_METADATA: {
|
||||
char *artist = va_arg(args, char*), *album = va_arg(args, char*), *title = va_arg(args, char*);
|
||||
displayer_metadata(artist, album, title);
|
||||
displayer_artwork(NULL);
|
||||
break;
|
||||
}
|
||||
case RAOP_ARTWORK: {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "driver/i2s.h"
|
||||
#include "driver/spi_master.h"
|
||||
#include "gpio_exp.h"
|
||||
|
||||
#include "cJSON.h"
|
||||
extern const char *i2c_name_type;
|
||||
extern const char *spi_name_type;
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "buttons.h"
|
||||
#include "platform_config.h"
|
||||
#include "accessors.h"
|
||||
#include "services.h"
|
||||
#include "audio_controls.h"
|
||||
|
||||
typedef esp_err_t (actrls_config_map_handler) (const cJSON * member, actrls_config_t *cur_config,uint32_t offset);
|
||||
@@ -61,7 +62,7 @@ static const char * actrls_action_s[ ] = { EP(ACTRLS_POWER),EP(ACTRLS_VOLUP),EP(
|
||||
EP(ACTRLS_PAUSE),EP(ACTRLS_STOP),EP(ACTRLS_REW),EP(ACTRLS_FWD),EP(ACTRLS_PREV),EP(ACTRLS_NEXT),
|
||||
EP(BCTRLS_UP),EP(BCTRLS_DOWN),EP(BCTRLS_LEFT),EP(BCTRLS_RIGHT),
|
||||
EP(BCTRLS_PS0),EP(BCTRLS_PS1),EP(BCTRLS_PS2),EP(BCTRLS_PS3),EP(BCTRLS_PS4),EP(BCTRLS_PS5),EP(BCTRLS_PS6),EP(BCTRLS_PS7),EP(BCTRLS_PS8),EP(BCTRLS_PS9),
|
||||
EP(KNOB_LEFT),EP(KNOB_RIGHT),EP(KNOB_PUSH),
|
||||
EP(KNOB_LEFT),EP(KNOB_RIGHT),EP(KNOB_PUSH), EP(ACTRLS_SLEEP),
|
||||
""} ;
|
||||
|
||||
static const char * TAG = "audio controls";
|
||||
@@ -170,13 +171,6 @@ static void control_handler(void *client, button_event_e event, button_press_e p
|
||||
actrls_config_t *key = (actrls_config_t*) client;
|
||||
actrls_action_detail_t action_detail;
|
||||
|
||||
// in raw mode, we just do normal action press *and* release, there is no longpress nor shift
|
||||
if (current_raw_controls) {
|
||||
ESP_LOGD(TAG, "calling action %u in raw mode", key->normal[0].action);
|
||||
if (current_controls[key->normal[0].action]) (*current_controls[key->normal[0].action])(event == BUTTON_PRESSED);
|
||||
return;
|
||||
}
|
||||
|
||||
switch(press) {
|
||||
case BUTTON_NORMAL:
|
||||
if (long_press) action_detail = key->longpress[event == BUTTON_PRESSED ? 0 : 1];
|
||||
@@ -195,7 +189,15 @@ static void control_handler(void *client, button_event_e event, button_press_e p
|
||||
|
||||
// stop here if control hook served the request
|
||||
if (current_hook && (*current_hook)(key->gpio, action_detail.action, event, press, long_press)) return;
|
||||
|
||||
|
||||
// in raw mode, we just do normal action press *and* release, there is no longpress nor shift
|
||||
if (current_raw_controls && action_detail.action != ACTRLS_SLEEP) {
|
||||
actrls_action_e action = key->normal[0].action != ACTRLS_NONE ? key->normal[0].action : key->normal[1].action;
|
||||
ESP_LOGD(TAG, "calling action %u in raw mode", action);
|
||||
if (action != ACTRLS_NONE && current_controls[action]) current_controls[action](event == BUTTON_PRESSED);
|
||||
return;
|
||||
}
|
||||
|
||||
// otherwise process using configuration
|
||||
if (action_detail.action == ACTRLS_REMAP) {
|
||||
// remap requested
|
||||
@@ -216,7 +218,10 @@ static void control_handler(void *client, button_event_e event, button_press_e p
|
||||
} else {
|
||||
ESP_LOGE(TAG,"Invalid profile name %s. Cannot remap buttons",action_detail.name);
|
||||
}
|
||||
} else if (action_detail.action != ACTRLS_NONE) {
|
||||
} else if (action_detail.action == ACTRLS_SLEEP) {
|
||||
ESP_LOGI(TAG, "special sleep button pressed");
|
||||
services_sleep_activate(SLEEP_ONKEY);
|
||||
} else if (action_detail.action != ACTRLS_NONE) {
|
||||
ESP_LOGD(TAG, "calling action %u", action_detail.action);
|
||||
if (current_controls[action_detail.action]) (*current_controls[action_detail.action])(event == BUTTON_PRESSED);
|
||||
}
|
||||
|
||||
@@ -11,11 +11,12 @@
|
||||
#include "buttons.h"
|
||||
|
||||
// BEWARE: this is the index of the array of action below (change actrls_action_s as well!)
|
||||
typedef enum { ACTRLS_NONE = -1, ACTRLS_POWER,ACTRLS_VOLUP, ACTRLS_VOLDOWN, ACTRLS_TOGGLE, ACTRLS_PLAY,
|
||||
typedef enum { ACTRLS_NONE = -1, ACTRLS_POWER, ACTRLS_VOLUP, ACTRLS_VOLDOWN, ACTRLS_TOGGLE, ACTRLS_PLAY,
|
||||
ACTRLS_PAUSE, ACTRLS_STOP, ACTRLS_REW, ACTRLS_FWD, ACTRLS_PREV, ACTRLS_NEXT,
|
||||
BCTRLS_UP, BCTRLS_DOWN, BCTRLS_LEFT, BCTRLS_RIGHT,
|
||||
BCTRLS_PS0,BCTRLS_PS1,BCTRLS_PS2,BCTRLS_PS3,BCTRLS_PS4,BCTRLS_PS5,BCTRLS_PS6,BCTRLS_PS7,BCTRLS_PS8,BCTRLS_PS9,
|
||||
KNOB_LEFT, KNOB_RIGHT, KNOB_PUSH,
|
||||
ACTRLS_SLEEP,
|
||||
ACTRLS_REMAP, ACTRLS_MAX
|
||||
} actrls_action_e;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ static struct {
|
||||
.cells = 2,
|
||||
};
|
||||
|
||||
void (*battery_handler_svc)(float value);
|
||||
void (*battery_handler_svc)(float value, int cells);
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
@@ -66,7 +66,7 @@ static void battery_callback(TimerHandle_t xTimer) {
|
||||
if (++battery.count == 30) {
|
||||
battery.avg = battery.sum / battery.count;
|
||||
battery.sum = battery.count = 0;
|
||||
if (battery_handler_svc) (battery_handler_svc)(battery.avg);
|
||||
if (battery_handler_svc) (battery_handler_svc)(battery.avg, battery.cells);
|
||||
ESP_LOGI(TAG, "Voltage %.2fV", battery.avg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,14 @@
|
||||
#include "driver/rmt.h"
|
||||
#include "gpio_exp.h"
|
||||
#include "buttons.h"
|
||||
#include "services.h"
|
||||
#include "rotary_encoder.h"
|
||||
#include "globdefs.h"
|
||||
|
||||
static const char * TAG = "buttons";
|
||||
|
||||
static EXT_RAM_ATTR int n_buttons;
|
||||
static EXT_RAM_ATTR uint32_t buttons_idle_since;
|
||||
|
||||
#define BUTTON_STACK_SIZE 4096
|
||||
#define MAX_BUTTONS 32
|
||||
@@ -156,18 +158,29 @@ static void buttons_handler(struct button_s *button, int level) {
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Get inactivity callback
|
||||
*/
|
||||
static uint32_t buttons_idle_callback(void) {
|
||||
return pdTICKS_TO_MS(xTaskGetTickCount()) - buttons_idle_since;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Tasks that calls the appropriate functions when buttons are pressed
|
||||
*/
|
||||
static void buttons_task(void* arg) {
|
||||
ESP_LOGI(TAG, "starting button tasks");
|
||||
ESP_LOGI(TAG, "starting button tasks");
|
||||
|
||||
buttons_idle_since = pdTICKS_TO_MS(xTaskGetTickCount());
|
||||
services_sleep_setsleeper(buttons_idle_callback);
|
||||
|
||||
while (1) {
|
||||
QueueSetMemberHandle_t xActivatedMember;
|
||||
bool active = true;
|
||||
|
||||
// wait on button, rotary and infrared queues
|
||||
if ((xActivatedMember = xQueueSelectFromSet( common_queue_set, portMAX_DELAY )) == NULL) continue;
|
||||
|
||||
|
||||
if (xActivatedMember == button_queue) {
|
||||
struct button_s button;
|
||||
button_event_e event;
|
||||
@@ -221,8 +234,11 @@ static void buttons_task(void* arg) {
|
||||
ROTARY_RIGHT : ROTARY_LEFT, false);
|
||||
} else {
|
||||
// this is IR
|
||||
infrared_receive(infrared.rb, infrared.handler);
|
||||
active = infrared_receive(infrared.rb, infrared.handler);
|
||||
}
|
||||
|
||||
// mark the last activity
|
||||
if (active) buttons_idle_since = pdTICKS_TO_MS(xTaskGetTickCount());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,11 +13,15 @@
|
||||
#define I2C_SYSTEM_PORT 1
|
||||
#define SPI_SYSTEM_HOST SPI2_HOST
|
||||
|
||||
#define RMT_NEXT_TX_CHANNEL() rmt_system_base_tx_channel++;
|
||||
#define RMT_NEXT_RX_CHANNEL() rmt_system_base_rx_channel--;
|
||||
|
||||
extern int i2c_system_port;
|
||||
extern int i2c_system_speed;
|
||||
extern int spi_system_host;
|
||||
extern int spi_system_dc_gpio;
|
||||
extern int rmt_system_base_channel;
|
||||
extern int rmt_system_base_tx_channel;
|
||||
extern int rmt_system_base_rx_channel;
|
||||
typedef struct {
|
||||
int timer, base_channel, max;
|
||||
} pwm_system_t;
|
||||
|
||||
@@ -22,6 +22,8 @@ static const char* TAG = "IR";
|
||||
#define IR_TOOLS_FLAGS_PROTO_EXT (1 << 0) /*!< Enable Extended IR protocol */
|
||||
#define IR_TOOLS_FLAGS_INVERSE (1 << 1) /*!< Inverse the IR signal, i.e. take high level as low, and vice versa */
|
||||
|
||||
static int8_t ir_gpio = -1;
|
||||
|
||||
/**
|
||||
* @brief IR device type
|
||||
*
|
||||
@@ -446,14 +448,14 @@ err:
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void infrared_receive(RingbufHandle_t rb, infrared_handler handler) {
|
||||
bool infrared_receive(RingbufHandle_t rb, infrared_handler handler) {
|
||||
size_t rx_size = 0;
|
||||
rmt_item32_t* item = (rmt_item32_t*) xRingbufferReceive(rb, &rx_size, 10 / portTICK_RATE_MS);
|
||||
bool decoded = false;
|
||||
|
||||
if (item) {
|
||||
uint32_t addr, cmd;
|
||||
bool repeat = false;
|
||||
bool decoded = false;
|
||||
|
||||
rx_size /= 4; // one RMT = 4 Bytes
|
||||
|
||||
@@ -474,14 +476,22 @@ void infrared_receive(RingbufHandle_t rb, infrared_handler handler) {
|
||||
// after parsing the data, return spaces to ringbuffer.
|
||||
vRingbufferReturnItem(rb, (void*) item);
|
||||
}
|
||||
|
||||
return decoded;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
int8_t infrared_gpio(void) {
|
||||
return ir_gpio;
|
||||
};
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void infrared_init(RingbufHandle_t *rb, int gpio, infrared_mode_t mode) {
|
||||
int rmt_channel = rmt_system_base_channel++;
|
||||
int rmt_channel = RMT_NEXT_RX_CHANNEL();
|
||||
rmt_config_t rmt_rx_config = RMT_DEFAULT_CONFIG_RX(gpio, rmt_channel);
|
||||
rmt_config(&rmt_rx_config);
|
||||
rmt_driver_install(rmt_rx_config.channel, 1000, 0);
|
||||
@@ -489,6 +499,7 @@ void infrared_init(RingbufHandle_t *rb, int gpio, infrared_mode_t mode) {
|
||||
ir_parser_config.flags |= IR_TOOLS_FLAGS_PROTO_EXT; // Using extended IR protocols (both NEC and RC5 have extended version)
|
||||
|
||||
ir_parser = (mode == IR_NEC) ? ir_parser_rmt_new_nec(&ir_parser_config) : ir_parser_rmt_new_rc5(&ir_parser_config);
|
||||
ir_gpio = gpio;
|
||||
|
||||
// get RMT RX ringbuffer
|
||||
rmt_get_ringbuf_handle(rmt_channel, rb);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
typedef enum {IR_NEC, IR_RC5} infrared_mode_t;
|
||||
typedef void (*infrared_handler)(uint16_t addr, uint16_t cmd);
|
||||
|
||||
void infrared_receive(RingbufHandle_t rb, infrared_handler handler);
|
||||
bool infrared_receive(RingbufHandle_t rb, infrared_handler handler);
|
||||
void infrared_init(RingbufHandle_t *rb, int gpio, infrared_mode_t mode);
|
||||
int8_t infrared_gpio(void);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "led.h"
|
||||
#include "globdefs.h"
|
||||
#include "accessors.h"
|
||||
#include "services.h"
|
||||
|
||||
#define MAX_LED 8
|
||||
#define BLOCKTIME 10 // up to portMAX_DELAY
|
||||
@@ -240,7 +241,7 @@ bool led_config(int idx, gpio_num_t gpio, int color, int bright, led_type_t type
|
||||
for (const struct rmt_led_param_s *p = rmt_led_param; !leds[idx].rmt && p->type >= 0; p++) if (p->type == type) leds[idx].rmt = p;
|
||||
if (!leds[idx].rmt) return false;
|
||||
|
||||
if (led_rmt_channel < 0) led_rmt_channel = rmt_system_base_channel++;
|
||||
if (led_rmt_channel < 0) led_rmt_channel = RMT_NEXT_TX_CHANNEL();
|
||||
leds[idx].channel = led_rmt_channel;
|
||||
leds[idx].bright = bright > 0 ? bright : 100;
|
||||
|
||||
@@ -276,6 +277,14 @@ bool led_config(int idx, gpio_num_t gpio, int color, int bright, led_type_t type
|
||||
return true;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static void led_suspend(void) {
|
||||
led_off(LED_GREEN);
|
||||
led_off(LED_RED);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
@@ -283,7 +292,8 @@ void set_led_gpio(int gpio, char *value) {
|
||||
struct led_config_s *config;
|
||||
|
||||
if (strcasestr(value, "green")) config = &green;
|
||||
else config = &red;
|
||||
else if (strcasestr(value, "red"))config = &red;
|
||||
else return;
|
||||
|
||||
config->gpio = gpio;
|
||||
char *p = value;
|
||||
@@ -325,6 +335,9 @@ void led_svc_init(void) {
|
||||
|
||||
led_config(LED_GREEN, green.gpio, green.color, green.bright, green.type);
|
||||
led_config(LED_RED, red.gpio, red.color, red.bright, red.type);
|
||||
|
||||
// make sure we switch off all leds (useful for gpio expanders)
|
||||
services_sleep_setsuspend(led_suspend);
|
||||
|
||||
ESP_LOGI(TAG,"Configuring LEDs green:%d (on:%d rmt:%d %d%% ), red:%d (on:%d rmt:%d %d%% )",
|
||||
green.gpio, green.color, green.type, green.bright,
|
||||
|
||||
@@ -22,7 +22,7 @@ extern bool jack_inserted_svc(void);
|
||||
extern void (*spkfault_handler_svc)(bool inserted);
|
||||
extern bool spkfault_svc(void);
|
||||
|
||||
extern void (*battery_handler_svc)(float value);
|
||||
extern void (*battery_handler_svc)(float value, int cells);
|
||||
extern float battery_value_svc(void);
|
||||
extern uint16_t battery_level_svc(void);
|
||||
|
||||
|
||||
@@ -7,7 +7,11 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/timers.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_sleep.h"
|
||||
#include "driver/rtc_io.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/ledc.h"
|
||||
#include "driver/i2c.h"
|
||||
@@ -20,6 +24,8 @@
|
||||
#include "globdefs.h"
|
||||
#include "accessors.h"
|
||||
#include "messaging.h"
|
||||
#include "buttons.h"
|
||||
#include "services.h"
|
||||
|
||||
extern void battery_svc_init(void);
|
||||
extern void monitor_svc_init(void);
|
||||
@@ -29,24 +35,38 @@ int i2c_system_port = I2C_SYSTEM_PORT;
|
||||
int i2c_system_speed = 400000;
|
||||
int spi_system_host = SPI_SYSTEM_HOST;
|
||||
int spi_system_dc_gpio = -1;
|
||||
int rmt_system_base_channel = RMT_CHANNEL_0;
|
||||
pwm_system_t pwm_system = {
|
||||
int rmt_system_base_tx_channel = RMT_CHANNEL_0;
|
||||
int rmt_system_base_rx_channel = RMT_CHANNEL_MAX-1;
|
||||
|
||||
pwm_system_t pwm_system = {
|
||||
.timer = LEDC_TIMER_0,
|
||||
.base_channel = LEDC_CHANNEL_0,
|
||||
.max = (1 << LEDC_TIMER_13_BIT),
|
||||
};
|
||||
};
|
||||
|
||||
static EXT_RAM_ATTR struct {
|
||||
uint64_t wake_gpio, wake_level;
|
||||
uint64_t rtc_gpio, rtc_level;
|
||||
uint32_t delay, spurious;
|
||||
float battery_level;
|
||||
int battery_count;
|
||||
void (*idle_chain)(uint32_t now);
|
||||
void (*battery_chain)(float level, int cells);
|
||||
void (*suspend[10])(void);
|
||||
uint32_t (*sleeper[10])(void);
|
||||
} sleep_context;
|
||||
|
||||
static const char *TAG = "services";
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*
|
||||
*/
|
||||
void set_chip_power_gpio(int gpio, char *value) {
|
||||
bool parsed = true;
|
||||
|
||||
// we only parse on-chip GPIOs
|
||||
if (gpio >= GPIO_NUM_MAX) return;
|
||||
|
||||
|
||||
if (!strcasecmp(value, "vcc") ) {
|
||||
gpio_pad_select_gpio(gpio);
|
||||
gpio_set_direction(gpio, GPIO_MODE_OUTPUT);
|
||||
@@ -56,16 +76,19 @@ void set_chip_power_gpio(int gpio, char *value) {
|
||||
gpio_set_direction(gpio, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level(gpio, 0);
|
||||
} else parsed = false;
|
||||
|
||||
if (parsed) ESP_LOGI(TAG, "set GPIO %u to %s", gpio, value);
|
||||
}
|
||||
|
||||
if (parsed) ESP_LOGI(TAG, "set GPIO %u to %s", gpio, value);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void set_exp_power_gpio(int gpio, char *value) {
|
||||
bool parsed = true;
|
||||
|
||||
// we only parse on-chip GPIOs
|
||||
if (gpio < GPIO_NUM_MAX) return;
|
||||
|
||||
|
||||
if (!strcasecmp(value, "vcc") ) {
|
||||
gpio_exp_set_direction(gpio, GPIO_MODE_OUTPUT, NULL);
|
||||
gpio_exp_set_level(gpio, 1, true, NULL);
|
||||
@@ -73,18 +96,264 @@ void set_exp_power_gpio(int gpio, char *value) {
|
||||
gpio_exp_set_direction(gpio, GPIO_MODE_OUTPUT, NULL);
|
||||
gpio_exp_set_level(gpio, 0, true, NULL);
|
||||
} else parsed = false;
|
||||
|
||||
|
||||
if (parsed) ESP_LOGI(TAG, "set expanded GPIO %u to %s", gpio, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*
|
||||
*/
|
||||
static void sleep_gpio_handler(void *id, button_event_e event, button_press_e mode, bool long_press) {
|
||||
if (event == BUTTON_PRESSED) services_sleep_activate(SLEEP_ONGPIO);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static void sleep_timer(uint32_t now) {
|
||||
static EXT_RAM_ATTR uint32_t last, first;
|
||||
|
||||
// first chain the calls to pseudo_idle function
|
||||
if (sleep_context.idle_chain) sleep_context.idle_chain(now);
|
||||
|
||||
// we need boot time for spurious timeout calculation
|
||||
if (!first) first = now;
|
||||
|
||||
// only query callbacks every 30s if we have at least one sleeper
|
||||
if (!*sleep_context.sleeper || now < last + 30*1000) return;
|
||||
last = now;
|
||||
|
||||
// time to evaluate if we had spurious wake-up
|
||||
if (sleep_context.spurious && now > sleep_context.spurious + first) {
|
||||
bool spurious = true;
|
||||
|
||||
// see if at least one sleeper has been awake since we started
|
||||
for (uint32_t (**sleeper)(void) = sleep_context.sleeper; *sleeper && spurious; sleeper++) {
|
||||
spurious &= (*sleeper)() >= now - first;
|
||||
}
|
||||
|
||||
// no activity since we woke-up, this was a spurious one
|
||||
if (spurious) {
|
||||
ESP_LOGI(TAG, "spurious wake of %d sec, going back to sleep", (now - first) / 1000);
|
||||
services_sleep_activate(SLEEP_ONTIMER);
|
||||
}
|
||||
|
||||
// resume normal work but we might have no "regular" inactivity delay
|
||||
sleep_context.spurious = 0;
|
||||
if (!sleep_context.delay) *sleep_context.sleeper = NULL;
|
||||
ESP_LOGI(TAG, "wake-up was not spurious after %d sec", (now - first) / 1000);
|
||||
}
|
||||
|
||||
// we might be here because we are waiting for spurious
|
||||
if (sleep_context.delay) {
|
||||
// call all sleepers to know how long for how long they have been inactive
|
||||
for (uint32_t (**sleeper)(void) = sleep_context.sleeper; sleep_context.delay && *sleeper; sleeper++) {
|
||||
if ((*sleeper)() < sleep_context.delay) return;
|
||||
}
|
||||
|
||||
// if we are here, we are ready to sleep;
|
||||
services_sleep_activate(SLEEP_ONTIMER);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static void sleep_battery(float level, int cells) {
|
||||
// chain if any
|
||||
if (sleep_context.battery_chain) sleep_context.battery_chain(level, cells);
|
||||
|
||||
// then assess if we have to stop because of low batt
|
||||
if (level < sleep_context.battery_level) {
|
||||
if (sleep_context.battery_count++ == 2) services_sleep_activate(SLEEP_ONBATTERY);
|
||||
} else {
|
||||
sleep_context.battery_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void services_sleep_init(void) {
|
||||
char *config = config_alloc_get(NVS_TYPE_STR, "sleep_config");
|
||||
char *p;
|
||||
|
||||
// get the wake criteria
|
||||
if ((p = strcasestr(config, "wake"))) {
|
||||
char list[32] = "", item[8];
|
||||
sscanf(p, "%*[^=]=%31[^,]", list);
|
||||
p = list - 1;
|
||||
while (p++ && sscanf(p, "%7[^|]", item)) {
|
||||
int level = 0, gpio = atoi(item);
|
||||
if (!rtc_gpio_is_valid_gpio(gpio)) {
|
||||
ESP_LOGE(TAG, "invalid wake GPIO %d (not in RTC domain)", gpio);
|
||||
} else {
|
||||
sleep_context.wake_gpio |= 1LL << gpio;
|
||||
}
|
||||
if (sscanf(item, "%*[^:]:%d", &level)) sleep_context.wake_level |= level << gpio;
|
||||
p = strchr(p, '|');
|
||||
}
|
||||
|
||||
// when moving to esp-idf more recent than 4.4.x, multiple gpio wake-up with level specific can be done
|
||||
if (sleep_context.wake_gpio) {
|
||||
ESP_LOGI(TAG, "Sleep wake-up gpio bitmap 0x%llx (active 0x%llx)", sleep_context.wake_gpio, sleep_context.wake_level);
|
||||
}
|
||||
}
|
||||
|
||||
// do we want battery safety
|
||||
PARSE_PARAM_FLOAT(config, "batt", '=', sleep_context.battery_level);
|
||||
if (sleep_context.battery_level != 0.0) {
|
||||
sleep_context.battery_chain = battery_handler_svc;
|
||||
battery_handler_svc = sleep_battery;
|
||||
ESP_LOGI(TAG, "Sleep on battery level of %.2f", sleep_context.battery_level);
|
||||
}
|
||||
|
||||
|
||||
// get the rtc-pull criteria
|
||||
if ((p = strcasestr(config, "rtc"))) {
|
||||
char list[32] = "", item[8];
|
||||
sscanf(p, "%*[^=]=%31[^,]", list);
|
||||
p = list - 1;
|
||||
while (p++ && sscanf(p, "%7[^|]", item)) {
|
||||
int level = 0, gpio = atoi(item);
|
||||
if (!rtc_gpio_is_valid_gpio(gpio)) {
|
||||
ESP_LOGE(TAG, "invalid rtc GPIO %d", gpio);
|
||||
} else {
|
||||
sleep_context.rtc_gpio |= 1LL << gpio;
|
||||
}
|
||||
if (sscanf(item, "%*[^:]:%d", &level)) sleep_context.rtc_level |= level << gpio;
|
||||
p = strchr(p, '|');
|
||||
}
|
||||
|
||||
// when moving to esp-idf more recent than 4.4.x, multiple gpio wake-up with level specific can be done
|
||||
if (sleep_context.rtc_gpio) {
|
||||
ESP_LOGI(TAG, "RTC forced gpio bitmap 0x%llx (active 0x%llx)", sleep_context.rtc_gpio, sleep_context.rtc_level);
|
||||
}
|
||||
}
|
||||
|
||||
// get the GPIOs that activate sleep (we could check that we have a valid wake)
|
||||
if ((p = strcasestr(config, "sleep"))) {
|
||||
int gpio, level = 0;
|
||||
char sleep[8] = "";
|
||||
sscanf(p, "%*[^=]=%7[^,]", sleep);
|
||||
gpio = atoi(sleep);
|
||||
if ((p = strchr(sleep, ':')) != NULL) level = atoi(p + 1);
|
||||
ESP_LOGI(TAG, "Sleep activation gpio %d (active %d)", gpio, level);
|
||||
button_create(NULL, gpio, level ? BUTTON_HIGH : BUTTON_LOW, true, 0, sleep_gpio_handler, 0, -1);
|
||||
}
|
||||
|
||||
// do we want delay sleep
|
||||
PARSE_PARAM(config, "delay", '=', sleep_context.delay);
|
||||
sleep_context.delay *= 60*1000;
|
||||
|
||||
// now check why we woke-up
|
||||
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
|
||||
if (cause == ESP_SLEEP_WAKEUP_EXT0 || cause == ESP_SLEEP_WAKEUP_EXT1) {
|
||||
ESP_LOGI(TAG, "waking-up from deep sleep with cause %d", cause);
|
||||
|
||||
// find the type of wake-up
|
||||
uint64_t wake_gpio;
|
||||
if (cause == ESP_SLEEP_WAKEUP_EXT0) wake_gpio = sleep_context.wake_gpio;
|
||||
else wake_gpio = esp_sleep_get_ext1_wakeup_status();
|
||||
|
||||
// we might be woken up by infrared in which case we want a short sleep
|
||||
if (infrared_gpio() >= 0 && ((1LL << infrared_gpio()) & wake_gpio)) {
|
||||
sleep_context.spurious = 1;
|
||||
PARSE_PARAM(config, "spurious", '=', sleep_context.spurious);
|
||||
sleep_context.spurious *= 60*1000;
|
||||
ESP_LOGI(TAG, "spurious wake-up detection during %d sec", sleep_context.spurious / 1000);
|
||||
}
|
||||
}
|
||||
|
||||
// if we have inactivity timer (user-set or because of IR wake) then active counters
|
||||
if (sleep_context.delay || sleep_context.spurious) {
|
||||
sleep_context.idle_chain = pseudo_idle_svc;
|
||||
pseudo_idle_svc = sleep_timer;
|
||||
if (sleep_context.delay) ESP_LOGI(TAG, "inactivity timer of %d minute(s)", sleep_context.delay / (60*1000));
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void services_sleep_activate(sleep_cause_e cause) {
|
||||
// call all sleep hooks that might want to do something
|
||||
for (void (**suspend)(void) = sleep_context.suspend; *suspend; suspend++) (*suspend)();
|
||||
|
||||
// isolate all possible GPIOs, except the wake-up and RTC-maintaines ones
|
||||
esp_sleep_config_gpio_isolate();
|
||||
|
||||
// keep RTC domain up if we need to maintain pull-up/down of some GPIO from RTC
|
||||
if (sleep_context.rtc_gpio) esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||
|
||||
for (int i = 0; i < GPIO_NUM_MAX; i++) {
|
||||
// must be a RTC GPIO
|
||||
if (!rtc_gpio_is_valid_gpio(i)) continue;
|
||||
|
||||
// do we need to maintain a pull-up or down of that GPIO
|
||||
if ((1LL << i) & sleep_context.rtc_gpio) {
|
||||
if ((sleep_context.rtc_level >> i) & 0x01) rtc_gpio_pullup_en(i);
|
||||
else rtc_gpio_pulldown_en(i);
|
||||
// or is this not wake-up GPIO, just isolate it
|
||||
} else if (!((1LL << i) & sleep_context.wake_gpio)) {
|
||||
rtc_gpio_isolate(i);
|
||||
}
|
||||
}
|
||||
|
||||
// is there just one GPIO
|
||||
if (sleep_context.wake_gpio & (sleep_context.wake_gpio - 1)) {
|
||||
ESP_LOGI(TAG, "going to sleep cause %d, wake-up on multiple GPIO, any '1' wakes up 0x%llx", cause, sleep_context.wake_gpio);
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S3) && ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
|
||||
if (!sleep_context.wake_level) esp_sleep_enable_ext1_wakeup(sleep_context.wake_gpio, ESP_EXT1_WAKEUP_ANY_LOW);
|
||||
else
|
||||
#endif
|
||||
esp_sleep_enable_ext1_wakeup(sleep_context.wake_gpio, ESP_EXT1_WAKEUP_ANY_HIGH);
|
||||
} else if (sleep_context.wake_gpio) {
|
||||
int gpio = __builtin_ctzll(sleep_context.wake_gpio);
|
||||
int level = (sleep_context.wake_level >> gpio) & 0x01;
|
||||
ESP_LOGI(TAG, "going to sleep cause %d, wake-up on GPIO %d level %d", cause, gpio, level);
|
||||
esp_sleep_enable_ext0_wakeup(gpio, level);
|
||||
} else {
|
||||
ESP_LOGW(TAG, "going to sleep cause %d, no wake-up option", cause);
|
||||
}
|
||||
|
||||
// we need to use a timer in case the same button is used for sleep and wake-up and it's "pressed" vs "released" selected
|
||||
if (cause == SLEEP_ONKEY) xTimerStart(xTimerCreate("sleepTimer", pdMS_TO_TICKS(1000), pdFALSE, NULL, (void (*)(void*)) esp_deep_sleep_start), 0);
|
||||
else esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static void register_method(void **store, size_t size, void *method) {
|
||||
for (int i = 0; i < size; i++, *store++) if (!*store) {
|
||||
*store = method;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void services_sleep_setsuspend(void (*hook)(void)) {
|
||||
register_method((void**) sleep_context.suspend, sizeof(sleep_context.suspend)/sizeof(*sleep_context.suspend), (void*) hook);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void services_sleep_setsleeper(uint32_t (*sleeper)(void)) {
|
||||
register_method((void**) sleep_context.sleeper, sizeof(sleep_context.sleeper)/sizeof(*sleep_context.sleeper), (void*) sleeper);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void services_init(void) {
|
||||
messaging_service_init();
|
||||
gpio_install_isr_service(0);
|
||||
|
||||
|
||||
#ifdef CONFIG_I2C_LOCKED
|
||||
if (i2c_system_port == 0) {
|
||||
i2c_system_port = 1;
|
||||
@@ -95,7 +364,7 @@ void services_init(void) {
|
||||
// set potential power GPIO on chip first in case expanders are power using these
|
||||
parse_set_GPIO(set_chip_power_gpio);
|
||||
|
||||
// shared I2C bus
|
||||
// shared I2C bus
|
||||
const i2c_config_t * i2c_config = config_i2c_get(&i2c_system_port);
|
||||
ESP_LOGI(TAG,"Configuring I2C sda:%d scl:%d port:%u speed:%u", i2c_config->sda_io_num, i2c_config->scl_io_num, i2c_system_port, i2c_config->master.clk_speed);
|
||||
|
||||
@@ -105,44 +374,44 @@ void services_init(void) {
|
||||
} else {
|
||||
i2c_system_port = -1;
|
||||
ESP_LOGW(TAG, "no I2C configured");
|
||||
}
|
||||
}
|
||||
|
||||
const spi_bus_config_t * spi_config = config_spi_get((spi_host_device_t*) &spi_system_host);
|
||||
ESP_LOGI(TAG,"Configuring SPI mosi:%d miso:%d clk:%d host:%u dc:%d", spi_config->mosi_io_num, spi_config->miso_io_num, spi_config->sclk_io_num, spi_system_host, spi_system_dc_gpio);
|
||||
|
||||
|
||||
if (spi_config->mosi_io_num != -1 && spi_config->sclk_io_num != -1) {
|
||||
spi_bus_initialize( spi_system_host, spi_config, 1 );
|
||||
spi_bus_initialize( spi_system_host, spi_config, SPI_DMA_CH_AUTO );
|
||||
if (spi_system_dc_gpio != -1) {
|
||||
gpio_reset_pin(spi_system_dc_gpio);
|
||||
gpio_set_direction( spi_system_dc_gpio, GPIO_MODE_OUTPUT );
|
||||
gpio_set_level( spi_system_dc_gpio, 0 );
|
||||
} else {
|
||||
ESP_LOGW(TAG, "No DC GPIO set, SPI display will not work");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
spi_system_host = -1;
|
||||
ESP_LOGW(TAG, "no SPI configured");
|
||||
}
|
||||
}
|
||||
|
||||
// create GPIO expanders
|
||||
const gpio_exp_config_t* gpio_exp_config;
|
||||
for (int count = 0; (gpio_exp_config = config_gpio_exp_get(count)); count++) gpio_exp_create(gpio_exp_config);
|
||||
|
||||
// now set potential power GPIO on expander
|
||||
// now set potential power GPIO on expander
|
||||
parse_set_GPIO(set_exp_power_gpio);
|
||||
|
||||
// system-wide PWM timer configuration
|
||||
ledc_timer_config_t pwm_timer = {
|
||||
.duty_resolution = LEDC_TIMER_13_BIT,
|
||||
.freq_hz = 5000,
|
||||
.duty_resolution = LEDC_TIMER_13_BIT,
|
||||
.freq_hz = 5000,
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32S3
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
#else
|
||||
.speed_mode = LEDC_HIGH_SPEED_MODE,
|
||||
#endif
|
||||
.speed_mode = LEDC_HIGH_SPEED_MODE,
|
||||
#endif
|
||||
.timer_num = pwm_system.timer,
|
||||
};
|
||||
|
||||
|
||||
ledc_timer_config(&pwm_timer);
|
||||
|
||||
led_svc_init();
|
||||
|
||||
17
components/services/services.h
Normal file
17
components/services/services.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Squeezelite for esp32
|
||||
*
|
||||
* (c) Philippe G. 2019, philippe_44@outlook.com
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef enum { SLEEP_ONTIMER, SLEEP_ONKEY, SLEEP_ONGPIO, SLEEP_ONIR, SLEEP_ONBATTERY } sleep_cause_e;
|
||||
void services_sleep_activate(sleep_cause_e cause);
|
||||
void services_sleep_setsuspend(void (*hook)(void));
|
||||
void services_sleep_setsleeper(uint32_t (*sleeper)(void));
|
||||
void services_sleep_init(void);
|
||||
@@ -30,10 +30,16 @@
|
||||
#include "cspot_private.h"
|
||||
#include "cspot_sink.h"
|
||||
#include "platform_config.h"
|
||||
#include "nvs_utilities.h"
|
||||
#include "tools.h"
|
||||
|
||||
static class cspotPlayer *player;
|
||||
|
||||
static const struct {
|
||||
const char *ns;
|
||||
const char *credentials;
|
||||
} spotify_ns = { .ns = "spotify", .credentials = "credentials" };
|
||||
|
||||
/****************************************************************************************
|
||||
* Player's main class & task
|
||||
*/
|
||||
@@ -42,7 +48,12 @@ class cspotPlayer : public bell::Task {
|
||||
private:
|
||||
std::string name;
|
||||
bell::WrappedSemaphore clientConnected;
|
||||
std::atomic<bool> isPaused, isConnected;
|
||||
std::atomic<bool> isPaused;
|
||||
enum states { ABORT, LINKED, DISCO };
|
||||
std::atomic<states> state;
|
||||
std::string credentials;
|
||||
bool zeroConf;
|
||||
std::atomic<bool> flushed = false, notify = true;
|
||||
|
||||
int startOffset, volume = 0, bitrate = 160;
|
||||
httpd_handle_t serverHandle;
|
||||
@@ -50,6 +61,7 @@ private:
|
||||
cspot_cmd_cb_t cmdHandler;
|
||||
cspot_data_cb_t dataHandler;
|
||||
std::string lastTrackId;
|
||||
cspot::TrackInfo trackInfo;
|
||||
|
||||
std::shared_ptr<cspot::LoginBlob> blob;
|
||||
std::unique_ptr<cspot::SpircHandler> spirc;
|
||||
@@ -57,6 +69,7 @@ private:
|
||||
void eventHandler(std::unique_ptr<cspot::SpircHandler::Event> event);
|
||||
void trackHandler(void);
|
||||
size_t pcmWrite(uint8_t *pcm, size_t bytes, std::string_view trackId);
|
||||
void enableZeroConf(void);
|
||||
|
||||
void runTask();
|
||||
|
||||
@@ -79,8 +92,25 @@ cspotPlayer::cspotPlayer(const char* name, httpd_handle_t server, int port, cspo
|
||||
if ((item = cJSON_GetObjectItem(config, "volume")) != NULL) volume = item->valueint;
|
||||
if ((item = cJSON_GetObjectItem(config, "bitrate")) != NULL) bitrate = item->valueint;
|
||||
if ((item = cJSON_GetObjectItem(config, "deviceName") ) != NULL) this->name = item->valuestring;
|
||||
else this->name = name;
|
||||
cJSON_Delete(config);
|
||||
else this->name = name;
|
||||
|
||||
if ((item = cJSON_GetObjectItem(config, "zeroConf")) != NULL) {
|
||||
zeroConf = item->valueint;
|
||||
cJSON_Delete(config);
|
||||
} else {
|
||||
zeroConf = true;
|
||||
cJSON_AddNumberToObject(config, "zeroConf", 1);
|
||||
config_set_cjson_str_and_free("cspot_config", config);
|
||||
}
|
||||
|
||||
// get optional credentials from own NVS
|
||||
if (!zeroConf) {
|
||||
char *credentials = (char*) get_nvs_value_alloc_for_partition(NVS_DEFAULT_PART_NAME, spotify_ns.ns, NVS_TYPE_STR, spotify_ns.credentials, NULL);
|
||||
if (credentials) {
|
||||
this->credentials = credentials;
|
||||
free(credentials);
|
||||
}
|
||||
}
|
||||
|
||||
if (bitrate != 96 && bitrate != 160 && bitrate != 320) bitrate = 160;
|
||||
}
|
||||
@@ -92,8 +122,7 @@ size_t cspotPlayer::pcmWrite(uint8_t *pcm, size_t bytes, std::string_view trackI
|
||||
trackHandler();
|
||||
}
|
||||
|
||||
dataHandler(pcm, bytes);
|
||||
return bytes;
|
||||
return dataHandler(pcm, bytes);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
@@ -179,11 +208,13 @@ void cspotPlayer::eventHandler(std::unique_ptr<cspot::SpircHandler::Event> event
|
||||
trackStatus = TRACK_INIT;
|
||||
// memorize position for when track's beginning will be detected
|
||||
startOffset = std::get<int>(event->data);
|
||||
notify = !flushed;
|
||||
flushed = false;
|
||||
// Spotify servers do not send volume at connection
|
||||
spirc->setRemoteVolume(volume);
|
||||
|
||||
cmdHandler(CSPOT_START, 44100);
|
||||
CSPOT_LOG(info, "(re)start playing");
|
||||
CSPOT_LOG(info, "(re)start playing at %d", startOffset);
|
||||
break;
|
||||
}
|
||||
case cspot::SpircHandler::EventType::PLAY_PAUSE: {
|
||||
@@ -192,23 +223,20 @@ void cspotPlayer::eventHandler(std::unique_ptr<cspot::SpircHandler::Event> event
|
||||
break;
|
||||
}
|
||||
case cspot::SpircHandler::EventType::TRACK_INFO: {
|
||||
auto trackInfo = std::get<cspot::TrackInfo>(event->data);
|
||||
cmdHandler(CSPOT_TRACK_INFO, trackInfo.duration, startOffset, trackInfo.artist.c_str(),
|
||||
trackInfo.album.c_str(), trackInfo.name.c_str(), trackInfo.imageUrl.c_str());
|
||||
spirc->updatePositionMs(startOffset);
|
||||
startOffset = 0;
|
||||
trackInfo = std::get<cspot::TrackInfo>(event->data);
|
||||
break;
|
||||
}
|
||||
case cspot::SpircHandler::EventType::FLUSH:
|
||||
flushed = true;
|
||||
__attribute__ ((fallthrough));
|
||||
case cspot::SpircHandler::EventType::NEXT:
|
||||
case cspot::SpircHandler::EventType::PREV:
|
||||
case cspot::SpircHandler::EventType::FLUSH: {
|
||||
// FLUSH is sent when there is no next, just clean everything
|
||||
case cspot::SpircHandler::EventType::PREV: {
|
||||
cmdHandler(CSPOT_FLUSH);
|
||||
break;
|
||||
}
|
||||
case cspot::SpircHandler::EventType::DISC:
|
||||
cmdHandler(CSPOT_DISC);
|
||||
isConnected = false;
|
||||
state = DISCO;
|
||||
break;
|
||||
case cspot::SpircHandler::EventType::SEEK: {
|
||||
cmdHandler(CSPOT_SEEK, std::get<int>(event->data));
|
||||
@@ -266,7 +294,7 @@ void cspotPlayer::command(cspot_event_t event) {
|
||||
* generate any cspot::event */
|
||||
case CSPOT_DISC:
|
||||
cmdHandler(CSPOT_DISC);
|
||||
isConnected = false;
|
||||
state = ABORT;
|
||||
break;
|
||||
// spirc->setRemoteVolume does not generate a cspot::event so call cmdHandler
|
||||
case CSPOT_VOLUME_UP:
|
||||
@@ -286,34 +314,48 @@ void cspotPlayer::command(cspot_event_t event) {
|
||||
}
|
||||
}
|
||||
|
||||
void cspotPlayer::runTask() {
|
||||
void cspotPlayer::enableZeroConf(void) {
|
||||
httpd_uri_t request = {
|
||||
.uri = "/spotify_info",
|
||||
.method = HTTP_GET,
|
||||
.handler = ::handleGET,
|
||||
.user_ctx = NULL,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
// register GET and POST handler for built-in server
|
||||
httpd_register_uri_handler(serverHandle, &request);
|
||||
request.method = HTTP_POST;
|
||||
request.handler = ::handlePOST;
|
||||
httpd_register_uri_handler(serverHandle, &request);
|
||||
|
||||
// construct blob for that player
|
||||
blob = std::make_unique<cspot::LoginBlob>(name);
|
||||
|
||||
CSPOT_LOG(info, "ZeroConf mode (port %d)", serverPort);
|
||||
|
||||
// Register mdns service, for spotify to find us
|
||||
bell::MDNSService::registerService( blob->getDeviceName(), "_spotify-connect", "_tcp", "", serverPort,
|
||||
{ {"VERSION", "1.0"}, {"CPath", "/spotify_info"}, {"Stack", "SP"} });
|
||||
|
||||
{ {"VERSION", "1.0"}, {"CPath", "/spotify_info"}, {"Stack", "SP"} });
|
||||
}
|
||||
|
||||
void cspotPlayer::runTask() {
|
||||
bool useZeroConf = zeroConf;
|
||||
|
||||
// construct blob for that player
|
||||
blob = std::make_unique<cspot::LoginBlob>(name);
|
||||
|
||||
CSPOT_LOG(info, "CSpot instance service name %s (id %s)", blob->getDeviceName().c_str(), blob->getDeviceId().c_str());
|
||||
|
||||
if (!zeroConf && !credentials.empty()) {
|
||||
blob->loadJson(credentials);
|
||||
CSPOT_LOG(info, "Reusable credentials mode");
|
||||
} else {
|
||||
// whether we want it or not we must use ZeroConf
|
||||
useZeroConf = true;
|
||||
enableZeroConf();
|
||||
}
|
||||
|
||||
// gone with the wind...
|
||||
while (1) {
|
||||
clientConnected.wait();
|
||||
|
||||
CSPOT_LOG(info, "Spotify client connected for %s", name.c_str());
|
||||
if (useZeroConf) clientConnected.wait();
|
||||
CSPOT_LOG(info, "Spotify client launched for %s", name.c_str());
|
||||
|
||||
auto ctx = cspot::Context::createFromBlob(blob);
|
||||
|
||||
@@ -322,12 +364,26 @@ void cspotPlayer::runTask() {
|
||||
else ctx->config.audioFormat = AudioFormat_OGG_VORBIS_160;
|
||||
|
||||
ctx->session->connectWithRandomAp();
|
||||
auto token = ctx->session->authenticate(blob);
|
||||
ctx->config.authData = ctx->session->authenticate(blob);
|
||||
|
||||
// Auth successful
|
||||
if (token.size() > 0) {
|
||||
if (ctx->config.authData.size() > 0) {
|
||||
// we might have been forced to use zeroConf, so store credentials and reset zeroConf usage
|
||||
if (!zeroConf) {
|
||||
useZeroConf = false;
|
||||
// can't call store_nvs... from a task running on EXTRAM stack
|
||||
TimerHandle_t timer = xTimerCreate( "credentials", 1, pdFALSE, strdup(ctx->getCredentialsJson().c_str()),
|
||||
[](TimerHandle_t xTimer) {
|
||||
auto credentials = (char*) pvTimerGetTimerID(xTimer);
|
||||
store_nvs_value_len_for_partition(NVS_DEFAULT_PART_NAME, spotify_ns.ns, NVS_TYPE_STR, spotify_ns.credentials, credentials, 0);
|
||||
free(credentials);
|
||||
xTimerDelete(xTimer, portMAX_DELAY);
|
||||
} );
|
||||
xTimerStart(timer, portMAX_DELAY);
|
||||
}
|
||||
|
||||
spirc = std::make_unique<cspot::SpircHandler>(ctx);
|
||||
isConnected = true;
|
||||
state = LINKED;
|
||||
|
||||
// set call back to calculate a hash on trackId
|
||||
spirc->getTrackPlayer()->setDataCallback(
|
||||
@@ -348,7 +404,7 @@ void cspotPlayer::runTask() {
|
||||
cmdHandler(CSPOT_VOLUME, volume);
|
||||
|
||||
// exit when player has stopped (received a DISC)
|
||||
while (isConnected) {
|
||||
while (state == LINKED) {
|
||||
ctx->session->handlePacket();
|
||||
|
||||
// low-accuracy polling events
|
||||
@@ -357,8 +413,13 @@ void cspotPlayer::runTask() {
|
||||
uint32_t started;
|
||||
cmdHandler(CSPOT_QUERY_STARTED, &started);
|
||||
if (started) {
|
||||
CSPOT_LOG(info, "next track's audio has reached DAC");
|
||||
spirc->notifyAudioReachedPlayback();
|
||||
CSPOT_LOG(info, "next track's audio has reached DAC (offset %d)", startOffset);
|
||||
if (notify) spirc->notifyAudioReachedPlayback();
|
||||
else notify = true;
|
||||
cmdHandler(CSPOT_TRACK_INFO, trackInfo.duration, startOffset, trackInfo.artist.c_str(),
|
||||
trackInfo.album.c_str(), trackInfo.name.c_str(), trackInfo.imageUrl.c_str());
|
||||
spirc->updatePositionMs(startOffset);
|
||||
startOffset = 0;
|
||||
trackStatus = TRACK_STREAM;
|
||||
}
|
||||
} else if (trackStatus == TRACK_END) {
|
||||
@@ -369,26 +430,35 @@ void cspotPlayer::runTask() {
|
||||
CSPOT_LOG(info, "last track finished");
|
||||
trackStatus = TRACK_INIT;
|
||||
cmdHandler(CSPOT_STOP);
|
||||
spirc->setPause(true);
|
||||
spirc->notifyAudioEnded();
|
||||
}
|
||||
}
|
||||
|
||||
// on disconnect, stay in the core loop unless we are in ZeroConf mode
|
||||
if (state == DISCO) {
|
||||
// update volume then
|
||||
cJSON *config = config_alloc_get_cjson("cspot_config");
|
||||
cJSON_DeleteItemFromObject(config, "volume");
|
||||
cJSON_AddNumberToObject(config, "volume", volume);
|
||||
config_set_cjson_str_and_free("cspot_config", config);
|
||||
|
||||
// in ZeroConf mod, stay connected (in this loop)
|
||||
if (!zeroConf) state = LINKED;
|
||||
}
|
||||
}
|
||||
|
||||
spirc->disconnect();
|
||||
spirc.reset();
|
||||
|
||||
CSPOT_LOG(info, "disconnecting player %s", name.c_str());
|
||||
} else {
|
||||
CSPOT_LOG(error, "failed authentication, forcing ZeroConf");
|
||||
if (!useZeroConf) enableZeroConf();
|
||||
useZeroConf = true;
|
||||
}
|
||||
|
||||
|
||||
// we want to release memory ASAP and for sure
|
||||
ctx.reset();
|
||||
token.clear();
|
||||
|
||||
// update volume when we disconnect
|
||||
cJSON *config = config_alloc_get_cjson("cspot_config");
|
||||
cJSON_DeleteItemFromObject(config, "volume");
|
||||
cJSON_AddNumberToObject(config, "volume", volume);
|
||||
config_set_cjson_str_and_free("cspot_config", config);
|
||||
ctx.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -397,6 +467,7 @@ void cspotPlayer::runTask() {
|
||||
*/
|
||||
struct cspot_s* cspot_create(const char *name, httpd_handle_t server, int port, cspot_cmd_cb_t cmd_cb, cspot_data_cb_t data_cb) {
|
||||
bell::setDefaultLogger();
|
||||
bell::enableTimestampLogging(true);
|
||||
player = new cspotPlayer(name, server, port, cmd_cb, data_cb);
|
||||
player->startTask();
|
||||
return (cspot_s*) player;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
file(GLOB AACDEC_SOURCES "src/*.c")
|
||||
file(GLOB AACDEC_HEADERS "src/*.h" "oscl/*.h" "include/*.h")
|
||||
|
||||
add_library(opencore-aacdec SHARED ${AACDEC_SOURCES})
|
||||
add_library(opencore-aacdec STATIC ${AACDEC_SOURCES})
|
||||
if(NOT MSVC)
|
||||
target_compile_options(opencore-aacdec PRIVATE -Wno-array-parameter)
|
||||
endif()
|
||||
add_definitions(-DAAC_PLUS -DHQ_SBR -DPARAMETRICSTEREO -DC_EQUIVALENT)
|
||||
target_compile_options(opencore-aacdec PRIVATE -Wno-array-parameter)
|
||||
target_include_directories(opencore-aacdec PUBLIC "src/" "oscl/" "include/")
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "AACDecoder.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h> // for free, malloc
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "e_tmp4audioobjecttype.h"
|
||||
#include "pvmp4audiodecoder_api.h"
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class DecodersInstance {
|
||||
|
||||
void ensureAAC() {
|
||||
// if (aacDecoder == NULL) {
|
||||
// aacDecoder = AACInitDecoder();
|
||||
// aacDecoder = AACInitDecoder();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
|
||||
using namespace bell;
|
||||
|
||||
MP3Container::MP3Container(std::istream& istr, const std::byte* headingBytes) : bell::AudioContainer(istr) {
|
||||
MP3Container::MP3Container(std::istream& istr, const std::byte* headingBytes)
|
||||
: bell::AudioContainer(istr) {
|
||||
if (headingBytes != nullptr) {
|
||||
memcpy(buffer.data(), headingBytes, 7);
|
||||
bytesInBuffer = 7;
|
||||
@@ -38,7 +39,6 @@ std::byte* MP3Container::readSample(uint32_t& len) {
|
||||
bytesInBuffer -= toConsume;
|
||||
}
|
||||
|
||||
|
||||
if (!this->fillBuffer()) {
|
||||
len = 0;
|
||||
return nullptr;
|
||||
|
||||
@@ -292,7 +292,7 @@ void reader::extract_all_files(std::string dest_directory) {
|
||||
if (fileType == '0' && !fileName.starts_with("._")) {
|
||||
#else
|
||||
if (fileType == '0' && fileName.find("._") != 0) {
|
||||
#endif
|
||||
#endif
|
||||
std::string path = dest_directory + "/" + fileName;
|
||||
|
||||
size_t pos = 0;
|
||||
|
||||
@@ -2,76 +2,77 @@
|
||||
#include "MGStreamAdapter.h"
|
||||
|
||||
mg_buf::mg_buf(struct mg_connection* _conn) : conn(_conn) {
|
||||
setp(buffer, buffer + BUF_SIZE - 1); // -1 to leave space for overflow '\0'
|
||||
setp(buffer, buffer + BUF_SIZE - 1); // -1 to leave space for overflow '\0'
|
||||
}
|
||||
|
||||
mg_buf::int_type mg_buf::overflow(int_type c) {
|
||||
if (c != EOF) {
|
||||
*pptr() = c;
|
||||
pbump(1);
|
||||
}
|
||||
if (c != EOF) {
|
||||
*pptr() = c;
|
||||
pbump(1);
|
||||
}
|
||||
|
||||
if (flush_buffer() == EOF) {
|
||||
return EOF;
|
||||
}
|
||||
if (flush_buffer() == EOF) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
return c;
|
||||
return c;
|
||||
}
|
||||
|
||||
int mg_buf::flush_buffer() {
|
||||
int len = int(pptr() - pbase());
|
||||
if (mg_write(conn, buffer, len) != len) {
|
||||
return EOF;
|
||||
}
|
||||
pbump(-len); // reset put pointer accordingly
|
||||
return len;
|
||||
int len = int(pptr() - pbase());
|
||||
if (mg_write(conn, buffer, len) != len) {
|
||||
return EOF;
|
||||
}
|
||||
pbump(-len); // reset put pointer accordingly
|
||||
return len;
|
||||
}
|
||||
|
||||
int mg_buf::sync() {
|
||||
if (flush_buffer() == EOF) {
|
||||
return -1; // return -1 on error
|
||||
}
|
||||
return 0;
|
||||
if (flush_buffer() == EOF) {
|
||||
return -1; // return -1 on error
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
MGStreamAdapter::MGStreamAdapter(struct mg_connection* _conn) : std::ostream(&buf), buf(_conn) {
|
||||
rdbuf(&buf); // set the custom streambuf
|
||||
MGStreamAdapter::MGStreamAdapter(struct mg_connection* _conn)
|
||||
: std::ostream(&buf), buf(_conn) {
|
||||
rdbuf(&buf); // set the custom streambuf
|
||||
}
|
||||
|
||||
|
||||
mg_read_buf::mg_read_buf(struct mg_connection* _conn) : conn(_conn) {
|
||||
setg(buffer + BUF_SIZE, // beginning of putback area
|
||||
buffer + BUF_SIZE, // read position
|
||||
buffer + BUF_SIZE); // end position
|
||||
setg(buffer + BUF_SIZE, // beginning of putback area
|
||||
buffer + BUF_SIZE, // read position
|
||||
buffer + BUF_SIZE); // end position
|
||||
}
|
||||
|
||||
mg_read_buf::int_type mg_read_buf::underflow() {
|
||||
if (gptr() < egptr()) { // buffer not exhausted
|
||||
return traits_type::to_int_type(*gptr());
|
||||
}
|
||||
|
||||
char* base = buffer;
|
||||
char* start = base;
|
||||
|
||||
if (eback() == base) { // true when this isn't the first fill
|
||||
// Make arrangements for putback characters
|
||||
std::memmove(base, egptr() - 2, 2);
|
||||
start += 2;
|
||||
}
|
||||
|
||||
// Read new characters
|
||||
int n = mg_read(conn, start, buffer + BUF_SIZE - start);
|
||||
if (n == 0) {
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
// Set buffer pointers
|
||||
setg(base, start, start + n);
|
||||
|
||||
// Return next character
|
||||
if (gptr() < egptr()) { // buffer not exhausted
|
||||
return traits_type::to_int_type(*gptr());
|
||||
}
|
||||
|
||||
char* base = buffer;
|
||||
char* start = base;
|
||||
|
||||
if (eback() == base) { // true when this isn't the first fill
|
||||
// Make arrangements for putback characters
|
||||
std::memmove(base, egptr() - 2, 2);
|
||||
start += 2;
|
||||
}
|
||||
|
||||
// Read new characters
|
||||
int n = mg_read(conn, start, buffer + BUF_SIZE - start);
|
||||
if (n == 0) {
|
||||
return traits_type::eof();
|
||||
}
|
||||
|
||||
// Set buffer pointers
|
||||
setg(base, start, start + n);
|
||||
|
||||
// Return next character
|
||||
return traits_type::to_int_type(*gptr());
|
||||
}
|
||||
|
||||
MGInputStreamAdapter::MGInputStreamAdapter(struct mg_connection* _conn) : std::istream(&buf), buf(_conn) {
|
||||
rdbuf(&buf); // set the custom streambuf
|
||||
MGInputStreamAdapter::MGInputStreamAdapter(struct mg_connection* _conn)
|
||||
: std::istream(&buf), buf(_conn) {
|
||||
rdbuf(&buf); // set the custom streambuf
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "X509Bundle.h"
|
||||
|
||||
#include <mbedtls/md.h> // for mbedtls_md, mbedtls_md_get_size
|
||||
#include <mbedtls/pk.h> // for mbedtls_pk_can_do, mbedtls_pk_pa...
|
||||
#include <mbedtls/ssl.h> // for mbedtls_ssl_conf_ca_chain, mbedt...
|
||||
#include <mbedtls/x509.h> // for mbedtls_x509_buf, MBEDTLS_ERR_X5...
|
||||
#include <stdlib.h> // for free, calloc
|
||||
#include <string.h> // for memcmp, memcpy
|
||||
#include <stdexcept> // for runtime_error
|
||||
#include <mbedtls/md.h> // for mbedtls_md, mbedtls_md_get_size
|
||||
#include <mbedtls/pk.h> // for mbedtls_pk_can_do, mbedtls_pk_pa...
|
||||
#include <mbedtls/ssl.h> // for mbedtls_ssl_conf_ca_chain, mbedt...
|
||||
#include <mbedtls/x509.h> // for mbedtls_x509_buf, MBEDTLS_ERR_X5...
|
||||
#include <stdlib.h> // for free, calloc
|
||||
#include <string.h> // for memcmp, memcpy
|
||||
#include <stdexcept> // for runtime_error
|
||||
|
||||
#include "BellLogger.h" // for AbstractLogger, BELL_LOG
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <cstring>
|
||||
#include "civetweb.h"
|
||||
|
||||
const size_t BUF_SIZE = 1024;
|
||||
@@ -36,25 +36,24 @@ class MGStreamAdapter : public std::ostream {
|
||||
|
||||
// Custom streambuf
|
||||
class mg_read_buf : public std::streambuf {
|
||||
private:
|
||||
struct mg_connection* conn;
|
||||
char buffer[BUF_SIZE];
|
||||
private:
|
||||
struct mg_connection* conn;
|
||||
char buffer[BUF_SIZE];
|
||||
|
||||
public:
|
||||
mg_read_buf(struct mg_connection* _conn);
|
||||
|
||||
protected:
|
||||
virtual int_type underflow();
|
||||
public:
|
||||
mg_read_buf(struct mg_connection* _conn);
|
||||
|
||||
protected:
|
||||
virtual int_type underflow();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Adapts istream to mg_read
|
||||
*/
|
||||
class MGInputStreamAdapter : public std::istream {
|
||||
private:
|
||||
mg_read_buf buf;
|
||||
private:
|
||||
mg_read_buf buf;
|
||||
|
||||
public:
|
||||
MGInputStreamAdapter(struct mg_connection* _conn);
|
||||
public:
|
||||
MGInputStreamAdapter(struct mg_connection* _conn);
|
||||
};
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ void bell::enableSubmoduleLogging() {
|
||||
bell::bellGlobalLogger->enableSubmodule = true;
|
||||
}
|
||||
|
||||
void bell::enableTimestampLogging() {
|
||||
void bell::enableTimestampLogging(bool local) {
|
||||
bell::bellGlobalLogger->enableTimestamp = true;
|
||||
bell::bellGlobalLogger->shortTime = local;
|
||||
}
|
||||
|
||||
@@ -141,14 +141,14 @@ std::vector<uint8_t> CryptoMbedTLS::pbkdf2HmacSha1(
|
||||
mbedtls_pkcs5_pbkdf2_hmac(&sha1Context, password.data(), password.size(),
|
||||
salt.data(), salt.size(), iterations, digestSize,
|
||||
digest.data());
|
||||
|
||||
|
||||
// Free sha context
|
||||
mbedtls_md_free(&sha1Context);
|
||||
#else
|
||||
mbedtls_pkcs5_pbkdf2_hmac_ext(MBEDTLS_MD_SHA1, password.data(), password.size(),
|
||||
salt.data(), salt.size(), iterations, digestSize,
|
||||
digest.data());
|
||||
#endif
|
||||
mbedtls_pkcs5_pbkdf2_hmac_ext(MBEDTLS_MD_SHA1, password.data(),
|
||||
password.size(), salt.data(), salt.size(),
|
||||
iterations, digestSize, digest.data());
|
||||
#endif
|
||||
|
||||
return digest;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ class AbstractLogger {
|
||||
public:
|
||||
bool enableSubmodule = false;
|
||||
bool enableTimestamp = false;
|
||||
bool shortTime = false;
|
||||
|
||||
virtual void debug(std::string filename, int line, std::string submodule,
|
||||
const char* format, ...) = 0;
|
||||
@@ -94,10 +95,17 @@ class BellLogger : public bell::AbstractLogger {
|
||||
now.time_since_epoch()) %
|
||||
1000;
|
||||
|
||||
auto gmt_time = gmtime(&now_time);
|
||||
printf(colorReset);
|
||||
std::cout << std::put_time(gmt_time, "[%Y-%m-%d %H:%M:%S") << '.'
|
||||
<< std::setfill('0') << std::setw(3) << nowMs.count() << "] ";
|
||||
struct tm* gmt_time;
|
||||
if (shortTime) {
|
||||
gmt_time = localtime(&now_time);
|
||||
std::cout << std::put_time(gmt_time, "[%H:%M:%S") << '.'
|
||||
<< std::setfill('0') << std::setw(3) << nowMs.count() << "] ";
|
||||
} else {
|
||||
gmt_time = gmtime(&now_time);
|
||||
std::cout << std::put_time(gmt_time, "[%Y-%m-%d %H:%M:%S") << '.'
|
||||
<< std::setfill('0') << std::setw(3) << nowMs.count() << "] ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +137,7 @@ class BellLogger : public bell::AbstractLogger {
|
||||
|
||||
void setDefaultLogger();
|
||||
void enableSubmoduleLogging();
|
||||
void enableTimestampLogging();
|
||||
void enableTimestampLogging(bool local = false);
|
||||
} // namespace bell
|
||||
|
||||
#define BELL_LOG(type, ...) \
|
||||
|
||||
@@ -31,8 +31,8 @@ class CryptoMbedTLS {
|
||||
CryptoMbedTLS();
|
||||
~CryptoMbedTLS();
|
||||
// Base64
|
||||
std::vector<uint8_t> base64Decode(const std::string& data);
|
||||
std::string base64Encode(const std::vector<uint8_t>& data);
|
||||
static std::vector<uint8_t> base64Decode(const std::string& data);
|
||||
static std::string base64Encode(const std::vector<uint8_t>& data);
|
||||
|
||||
// Sha1
|
||||
void sha1Init();
|
||||
|
||||
@@ -3,10 +3,19 @@
|
||||
#include <stdint.h>
|
||||
#include <memory>
|
||||
|
||||
#include "Crypto.h"
|
||||
#include "LoginBlob.h"
|
||||
#include "MercurySession.h"
|
||||
#include "TimeProvider.h"
|
||||
#include "protobuf/authentication.pb.h" // for AuthenticationType_AUTHE...
|
||||
#include "protobuf/metadata.pb.h"
|
||||
#ifdef BELL_ONLY_CJSON
|
||||
#include "cJSON.h"
|
||||
#else
|
||||
#include "nlohmann/detail/json_pointer.hpp" // for json_pointer<>::string_t
|
||||
#include "nlohmann/json.hpp" // for basic_json<>::object_t, basic_json
|
||||
#include "nlohmann/json_fwd.hpp" // for json
|
||||
#endif
|
||||
|
||||
namespace cspot {
|
||||
struct Context {
|
||||
@@ -26,6 +35,32 @@ struct Context {
|
||||
|
||||
std::shared_ptr<TimeProvider> timeProvider;
|
||||
std::shared_ptr<cspot::MercurySession> session;
|
||||
std::string getCredentialsJson() {
|
||||
#ifdef BELL_ONLY_CJSON
|
||||
cJSON* json_obj = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(json_obj, "authData",
|
||||
Crypto::base64Encode(config.authData).c_str());
|
||||
cJSON_AddNumberToObject(
|
||||
json_obj, "authType",
|
||||
AuthenticationType_AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS);
|
||||
cJSON_AddStringToObject(json_obj, "username", config.username.c_str());
|
||||
|
||||
char* str = cJSON_PrintUnformatted(json_obj);
|
||||
cJSON_Delete(json_obj);
|
||||
std::string json_objStr(str);
|
||||
free(str);
|
||||
|
||||
return json_objStr;
|
||||
#else
|
||||
nlohmann::json obj;
|
||||
obj["authData"] = Crypto::base64Encode(config.authData);
|
||||
obj["authType"] =
|
||||
AuthenticationType_AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS;
|
||||
obj["username"] = config.username;
|
||||
|
||||
return obj.dump();
|
||||
#endif
|
||||
}
|
||||
|
||||
static std::shared_ptr<Context> createFromBlob(
|
||||
std::shared_ptr<LoginBlob> blob) {
|
||||
|
||||
@@ -88,8 +88,8 @@ class MercurySession : public bell::Task, public cspot::Session {
|
||||
void unregisterAudioKey(uint32_t sequenceId);
|
||||
|
||||
uint32_t requestAudioKey(const std::vector<uint8_t>& trackId,
|
||||
const std::vector<uint8_t>& fileId,
|
||||
AudioKeyCallback audioCallback);
|
||||
const std::vector<uint8_t>& fileId,
|
||||
AudioKeyCallback audioCallback);
|
||||
|
||||
std::string getCountryCode();
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <variant> // for variant
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "CDNAudioFile.h" // for CDNTrackStream, CDNTrackStream::Track...
|
||||
#include "CDNAudioFile.h" // for CDNTrackStream, CDNTrackStream::Track...
|
||||
#include "TrackQueue.h"
|
||||
#include "protobuf/spirc.pb.h" // for MessageType
|
||||
|
||||
@@ -48,11 +48,12 @@ class SpircHandler {
|
||||
|
||||
void setPause(bool pause);
|
||||
|
||||
void previousSong();
|
||||
bool previousSong();
|
||||
|
||||
void nextSong();
|
||||
bool nextSong();
|
||||
|
||||
void notifyAudioReachedPlayback();
|
||||
void notifyAudioEnded();
|
||||
void updatePositionMs(uint32_t position);
|
||||
void setRemoteVolume(int volume);
|
||||
void loadTrackFromURI(const std::string& uri);
|
||||
@@ -74,7 +75,7 @@ class SpircHandler {
|
||||
void sendEvent(EventType type);
|
||||
void sendEvent(EventType type, EventData data);
|
||||
|
||||
void skipSong(TrackQueue::SkipDirection dir);
|
||||
bool skipSong(TrackQueue::SkipDirection dir);
|
||||
void handleFrame(std::vector<uint8_t>& data);
|
||||
void notify();
|
||||
};
|
||||
|
||||
@@ -32,8 +32,10 @@ struct TrackReference;
|
||||
class TrackPlayer : bell::Task {
|
||||
public:
|
||||
// Callback types
|
||||
typedef std::function<void(std::shared_ptr<QueuedTrack>)> TrackLoadedCallback;
|
||||
typedef std::function<size_t(uint8_t*, size_t, std::string_view)> DataCallback;
|
||||
typedef std::function<void(std::shared_ptr<QueuedTrack>, bool)>
|
||||
TrackLoadedCallback;
|
||||
typedef std::function<size_t(uint8_t*, size_t, std::string_view)>
|
||||
DataCallback;
|
||||
typedef std::function<void()> EOFCallback;
|
||||
typedef std::function<bool()> isAiringCallback;
|
||||
|
||||
@@ -48,7 +50,7 @@ class TrackPlayer : bell::Task {
|
||||
|
||||
// CDNTrackStream::TrackInfo getCurrentTrackInfo();
|
||||
void seekMs(size_t ms);
|
||||
void resetState();
|
||||
void resetState(bool paused = false);
|
||||
|
||||
// Vorbis codec callbacks
|
||||
size_t _vorbisRead(void* ptr, size_t size, size_t nmemb);
|
||||
@@ -88,6 +90,7 @@ class TrackPlayer : bell::Task {
|
||||
std::atomic<bool> pendingReset = false;
|
||||
std::atomic<bool> inFuture = false;
|
||||
std::atomic<size_t> pendingSeekPositionMs = 0;
|
||||
std::atomic<bool> startPaused = false;
|
||||
|
||||
std::mutex runningMutex;
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include <stddef.h> // for size_t
|
||||
#include <atomic>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
|
||||
#include "BellTask.h"
|
||||
#include "PlaybackState.h"
|
||||
@@ -94,7 +94,6 @@ class TrackQueue : public bell::Task {
|
||||
std::shared_ptr<bell::WrappedSemaphore> playableSemaphore;
|
||||
std::atomic<bool> notifyPending = false;
|
||||
|
||||
|
||||
void runTask() override;
|
||||
void stopTask();
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <pb_encode.h>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include "NanoPBHelper.h"
|
||||
#include "pb_decode.h"
|
||||
#include "protobuf/spirc.pb.h"
|
||||
|
||||
@@ -2,4 +2,9 @@ LoginCredentials.username max_size:30, fixed_length:false
|
||||
LoginCredentials.auth_data max_size:512, fixed_length:false
|
||||
SystemInfo.system_information_string max_size:16, fixed_length:false
|
||||
SystemInfo.device_id max_size:50, fixed_length:false
|
||||
ClientResponseEncrypted.version_string max_size:32, fixed_length:false
|
||||
ClientResponseEncrypted.version_string max_size:32, fixed_length:false
|
||||
APWelcome.canonical_username max_size:30, fixed_length:false
|
||||
APWelcome.reusable_auth_credentials max_size:512, fixed_length:false
|
||||
APWelcome.lfs_secret max_size:128, fixed_length:false
|
||||
AccountInfoFacebook.access_token max_size:128, fixed_length:false
|
||||
AccountInfoFacebook.machine_id max_size:50, fixed_length:false
|
||||
|
||||
@@ -37,6 +37,11 @@ enum Os {
|
||||
OS_BCO = 0x16;
|
||||
}
|
||||
|
||||
enum AccountType {
|
||||
Spotify = 0x0;
|
||||
Facebook = 0x1;
|
||||
}
|
||||
|
||||
enum AuthenticationType {
|
||||
AUTHENTICATION_USER_PASS = 0x0;
|
||||
AUTHENTICATION_STORED_SPOTIFY_CREDENTIALS = 0x1;
|
||||
@@ -62,4 +67,28 @@ message ClientResponseEncrypted {
|
||||
required LoginCredentials login_credentials = 0xa;
|
||||
required SystemInfo system_info = 0x32;
|
||||
optional string version_string = 0x46;
|
||||
}
|
||||
|
||||
message APWelcome {
|
||||
required string canonical_username = 0xa;
|
||||
required AccountType account_type_logged_in = 0x14;
|
||||
required AccountType credentials_type_logged_in = 0x19;
|
||||
required AuthenticationType reusable_auth_credentials_type = 0x1e;
|
||||
required bytes reusable_auth_credentials = 0x28;
|
||||
optional bytes lfs_secret = 0x32;
|
||||
optional AccountInfo account_info = 0x3c;
|
||||
optional AccountInfoFacebook fb = 0x46;
|
||||
}
|
||||
|
||||
message AccountInfo {
|
||||
optional AccountInfoSpotify spotify = 0x1;
|
||||
optional AccountInfoFacebook facebook = 0x2;
|
||||
}
|
||||
|
||||
message AccountInfoSpotify {
|
||||
}
|
||||
|
||||
message AccountInfoFacebook {
|
||||
optional string access_token = 0x1;
|
||||
optional string machine_id = 0x2;
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <string_view> // for string_view
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "HTTPClient.h" // for HTTPClient, HTTPClient::Response
|
||||
#include "HTTPClient.h" // for HTTPClient, HTTPClient::Response
|
||||
#ifdef BELL_ONLY_CJSON
|
||||
#include "cJSON.h"
|
||||
#else
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
#include "AccessKeyFetcher.h" // for AccessKeyFetcher
|
||||
#include "BellLogger.h" // for AbstractLogger
|
||||
#include "Crypto.h"
|
||||
#include "Logger.h" // for CSPOT_LOG
|
||||
#include "Packet.h" // for cspot
|
||||
#include "SocketStream.h" // for SocketStream
|
||||
#include "Utils.h" // for bigNumAdd, bytesToHexString, string...
|
||||
#include "WrappedSemaphore.h" // for WrappedSemaphore
|
||||
#include "Logger.h" // for CSPOT_LOG
|
||||
#include "Packet.h" // for cspot
|
||||
#include "SocketStream.h" // for SocketStream
|
||||
#include "Utils.h" // for bigNumAdd, bytesToHexString, string...
|
||||
#include "WrappedSemaphore.h" // for WrappedSemaphore
|
||||
#ifdef BELL_ONLY_CJSON
|
||||
#include "cJSON.h"
|
||||
#else
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
#include <stdio.h> // for sprintf
|
||||
#include <initializer_list> // for initializer_list
|
||||
|
||||
#include "BellLogger.h" // for AbstractLogger
|
||||
#include "ConstantParameters.h" // for brandName, cspot, protoc...
|
||||
#include "Logger.h" // for CSPOT_LOG
|
||||
#include "protobuf/authentication.pb.h" // for AuthenticationType_AUTHE...
|
||||
#include "BellLogger.h" // for AbstractLogger
|
||||
#include "ConstantParameters.h" // for brandName, cspot, protoc...
|
||||
#include "Logger.h" // for CSPOT_LOG
|
||||
#include "protobuf/authentication.pb.h" // for AuthenticationType_AUTHE...
|
||||
#ifdef BELL_ONLY_CJSON
|
||||
#include "cJSON.h"
|
||||
#else
|
||||
@@ -144,6 +144,7 @@ void LoginBlob::loadJson(const std::string& json) {
|
||||
this->username = cJSON_GetObjectItem(root, "username")->valuestring;
|
||||
std::string authDataObject =
|
||||
cJSON_GetObjectItem(root, "authData")->valuestring;
|
||||
this->authData = crypto->base64Decode(authDataObject);
|
||||
cJSON_Delete(root);
|
||||
#else
|
||||
auto root = nlohmann::json::parse(json);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <type_traits> // for remove_extent_t, __underlying_type_impl<>:...
|
||||
#include <utility> // for pair
|
||||
#ifndef _WIN32
|
||||
#include <arpa/inet.h> // for htons, ntohs, htonl, ntohl
|
||||
#include <arpa/inet.h> // for htons, ntohs, htonl, ntohl
|
||||
#endif
|
||||
#include "BellLogger.h" // for AbstractLogger
|
||||
#include "BellTask.h" // for Task
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
#include "PlainConnection.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <netdb.h> // for addrinfo, freeaddrinfo, getaddrinfo
|
||||
#include <netinet/in.h> // for IPPROTO_IP, IPPROTO_TCP
|
||||
#include <sys/errno.h> // for EAGAIN, EINTR, ETIMEDOUT, errno
|
||||
#include <sys/socket.h> // for setsockopt, connect, recv, send, shutdown
|
||||
#include <sys/time.h> // for timeval
|
||||
#include <cstring> // for memset
|
||||
#include <stdexcept> // for runtime_error
|
||||
#include <netinet/tcp.h> // for TCP_NODELAY
|
||||
#include <netdb.h> // for addrinfo, freeaddrinfo, getaddrinfo
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h> // for IPPROTO_IP, IPPROTO_TCP
|
||||
#include <netinet/tcp.h> // for TCP_NODELAY
|
||||
#include <sys/errno.h> // for EAGAIN, EINTR, ETIMEDOUT, errno
|
||||
#include <sys/socket.h> // for setsockopt, connect, recv, send, shutdown
|
||||
#include <sys/time.h> // for timeval
|
||||
#include <cstring> // for memset
|
||||
#include <stdexcept> // for runtime_error
|
||||
#else
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
#include "BellLogger.h" // for AbstractLogger
|
||||
#include "Logger.h" // for CSPOT_LOG
|
||||
#include "Packet.h" // for cspot
|
||||
#include "Utils.h" // for extract, pack
|
||||
#include "BellLogger.h" // for AbstractLogger
|
||||
#include "Logger.h" // for CSPOT_LOG
|
||||
#include "Packet.h" // for cspot
|
||||
#include "Utils.h" // for extract, pack
|
||||
|
||||
using namespace cspot;
|
||||
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
#include "PlainConnection.h" // for PlainConnection, timeoutCallback
|
||||
#include "ShannonConnection.h" // for ShannonConnection
|
||||
|
||||
#include "NanoPBHelper.h" // for pbPutString, pbEncode, pbDecode
|
||||
#include "pb_decode.h"
|
||||
#include "protobuf/authentication.pb.h"
|
||||
|
||||
using random_bytes_engine =
|
||||
std::independent_bits_engine<std::default_random_engine, CHAR_BIT, uint8_t>;
|
||||
|
||||
@@ -79,9 +83,12 @@ std::vector<uint8_t> Session::authenticate(std::shared_ptr<LoginBlob> blob) {
|
||||
auto packet = this->shanConn->recvPacket();
|
||||
switch (packet.command) {
|
||||
case AUTH_SUCCESSFUL_COMMAND: {
|
||||
APWelcome welcome;
|
||||
CSPOT_LOG(debug, "Authorization successful");
|
||||
return std::vector<uint8_t>(
|
||||
{0x1}); // TODO: return actual reusable credentaials to be stored somewhere
|
||||
pbDecode(welcome, APWelcome_fields, packet.data);
|
||||
return std::vector<uint8_t>(welcome.reusable_auth_credentials.bytes,
|
||||
welcome.reusable_auth_credentials.bytes +
|
||||
welcome.reusable_auth_credentials.size);
|
||||
break;
|
||||
}
|
||||
case AUTH_DECLINED_COMMAND: {
|
||||
|
||||
@@ -31,15 +31,17 @@ SpircHandler::SpircHandler(std::shared_ptr<cspot::Context> ctx) {
|
||||
}
|
||||
};
|
||||
|
||||
auto trackLoadedCallback = [this](std::shared_ptr<QueuedTrack> track) {
|
||||
playbackState->setPlaybackState(PlaybackState::State::Playing);
|
||||
auto trackLoadedCallback = [this](std::shared_ptr<QueuedTrack> track,
|
||||
bool paused = false) {
|
||||
playbackState->setPlaybackState(paused ? PlaybackState::State::Paused
|
||||
: PlaybackState::State::Playing);
|
||||
playbackState->updatePositionMs(track->requestedPosition);
|
||||
|
||||
this->notify();
|
||||
|
||||
// Send playback start event, unpause
|
||||
sendEvent(EventType::PLAYBACK_START, (int) track->requestedPosition);
|
||||
sendEvent(EventType::PLAY_PAUSE, false);
|
||||
// Send playback start event, pause/unpause per request
|
||||
sendEvent(EventType::PLAYBACK_START, (int)track->requestedPosition);
|
||||
sendEvent(EventType::PLAY_PAUSE, paused);
|
||||
};
|
||||
|
||||
this->ctx = ctx;
|
||||
@@ -77,6 +79,12 @@ void SpircHandler::subscribeToMercury() {
|
||||
|
||||
void SpircHandler::loadTrackFromURI(const std::string& uri) {}
|
||||
|
||||
void SpircHandler::notifyAudioEnded() {
|
||||
playbackState->updatePositionMs(0);
|
||||
notify();
|
||||
trackPlayer->resetState(true);
|
||||
}
|
||||
|
||||
void SpircHandler::notifyAudioReachedPlayback() {
|
||||
int offset = 0;
|
||||
|
||||
@@ -111,7 +119,7 @@ void SpircHandler::updatePositionMs(uint32_t position) {
|
||||
|
||||
void SpircHandler::disconnect() {
|
||||
this->trackQueue->stopTask();
|
||||
this->trackPlayer->resetState();
|
||||
this->trackPlayer->stop();
|
||||
this->ctx->session->disconnect();
|
||||
}
|
||||
|
||||
@@ -142,7 +150,6 @@ void SpircHandler::handleFrame(std::vector<uint8_t>& data) {
|
||||
notify();
|
||||
|
||||
sendEvent(EventType::SEEK, (int)playbackState->remoteFrame.position);
|
||||
//sendEvent(EventType::FLUSH);
|
||||
break;
|
||||
}
|
||||
case MessageType_kMessageTypeVolume:
|
||||
@@ -157,12 +164,14 @@ void SpircHandler::handleFrame(std::vector<uint8_t>& data) {
|
||||
setPause(false);
|
||||
break;
|
||||
case MessageType_kMessageTypeNext:
|
||||
nextSong();
|
||||
sendEvent(EventType::NEXT);
|
||||
if (nextSong()) {
|
||||
sendEvent(EventType::NEXT);
|
||||
}
|
||||
break;
|
||||
case MessageType_kMessageTypePrev:
|
||||
previousSong();
|
||||
sendEvent(EventType::PREV);
|
||||
if (previousSong()) {
|
||||
sendEvent(EventType::PREV);
|
||||
}
|
||||
break;
|
||||
case MessageType_kMessageTypeLoad: {
|
||||
this->trackPlayer->start();
|
||||
@@ -195,12 +204,17 @@ void SpircHandler::handleFrame(std::vector<uint8_t>& data) {
|
||||
CSPOT_LOG(debug, "Got replace frame");
|
||||
playbackState->syncWithRemote();
|
||||
|
||||
trackQueue->updateTracks(playbackState->remoteFrame.state.position_ms,
|
||||
false);
|
||||
// 1st track is the current one, but update the position
|
||||
trackQueue->updateTracks(
|
||||
playbackState->remoteFrame.state.position_ms +
|
||||
ctx->timeProvider->getSyncedTimestamp() -
|
||||
playbackState->innerFrame.state.position_measured_at,
|
||||
false);
|
||||
|
||||
this->notify();
|
||||
|
||||
trackPlayer->resetState();
|
||||
sendEvent(EventType::FLUSH);
|
||||
trackPlayer->resetState();
|
||||
break;
|
||||
}
|
||||
case MessageType_kMessageTypeShuffle: {
|
||||
@@ -227,34 +241,22 @@ void SpircHandler::notify() {
|
||||
this->sendCmd(MessageType_kMessageTypeNotify);
|
||||
}
|
||||
|
||||
void SpircHandler::skipSong(TrackQueue::SkipDirection dir) {
|
||||
if (trackQueue->skipTrack(dir)) {
|
||||
playbackState->setPlaybackState(PlaybackState::State::Playing);
|
||||
notify();
|
||||
bool SpircHandler::skipSong(TrackQueue::SkipDirection dir) {
|
||||
bool skipped = trackQueue->skipTrack(dir);
|
||||
|
||||
// Reset track state
|
||||
trackPlayer->resetState();
|
||||
// Reset track state
|
||||
trackPlayer->resetState(!skipped);
|
||||
|
||||
sendEvent(EventType::PLAY_PAUSE, false);
|
||||
} else {
|
||||
playbackState->setPlaybackState(PlaybackState::State::Paused);
|
||||
playbackState->updatePositionMs(0);
|
||||
notify();
|
||||
|
||||
sendEvent(EventType::PLAY_PAUSE, true);
|
||||
}
|
||||
|
||||
notify();
|
||||
|
||||
sendEvent(EventType::FLUSH);
|
||||
// send NEXT or PREV event only when successful
|
||||
return skipped;
|
||||
}
|
||||
|
||||
void SpircHandler::nextSong() {
|
||||
skipSong(TrackQueue::SkipDirection::NEXT);
|
||||
bool SpircHandler::nextSong() {
|
||||
return skipSong(TrackQueue::SkipDirection::NEXT);
|
||||
}
|
||||
|
||||
void SpircHandler::previousSong() {
|
||||
skipSong(TrackQueue::SkipDirection::PREV);
|
||||
bool SpircHandler::previousSong() {
|
||||
return skipSong(TrackQueue::SkipDirection::PREV);
|
||||
}
|
||||
|
||||
std::shared_ptr<TrackPlayer> SpircHandler::getTrackPlayer() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "TimeProvider.h"
|
||||
|
||||
#include "BellLogger.h" // for AbstractLogger
|
||||
#include "Logger.h" // for CSPOT_LOG
|
||||
#include "Utils.h" // for extract, getCurrentTimestamp
|
||||
#include "BellLogger.h" // for AbstractLogger
|
||||
#include "Logger.h" // for CSPOT_LOG
|
||||
#include "Utils.h" // for extract, getCurrentTimestamp
|
||||
#ifndef _WIN32
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
@@ -13,8 +13,10 @@
|
||||
#include "WrappedSemaphore.h" // for WrappedSemaphore
|
||||
|
||||
#ifdef BELL_VORBIS_FLOAT
|
||||
#define VORBIS_SEEK(file, position) (ov_time_seek(file, (double)position / 1000))
|
||||
#define VORBIS_READ(file, buffer, bufferSize, section) (ov_read(file, buffer, bufferSize, 0, 2, 1, section))
|
||||
#define VORBIS_SEEK(file, position) \
|
||||
(ov_time_seek(file, (double)position / 1000))
|
||||
#define VORBIS_READ(file, buffer, bufferSize, section) \
|
||||
(ov_read(file, buffer, bufferSize, 0, 2, 1, section))
|
||||
#else
|
||||
#define VORBIS_SEEK(file, position) (ov_time_seek(file, position))
|
||||
#define VORBIS_READ(file, buffer, bufferSize, section) \
|
||||
@@ -68,6 +70,7 @@ TrackPlayer::TrackPlayer(std::shared_ptr<cspot::Context> ctx,
|
||||
|
||||
TrackPlayer::~TrackPlayer() {
|
||||
isRunning = false;
|
||||
resetState();
|
||||
std::scoped_lock lock(runningMutex);
|
||||
}
|
||||
|
||||
@@ -84,10 +87,11 @@ void TrackPlayer::stop() {
|
||||
std::scoped_lock lock(runningMutex);
|
||||
}
|
||||
|
||||
void TrackPlayer::resetState() {
|
||||
void TrackPlayer::resetState(bool paused) {
|
||||
// Mark for reset
|
||||
this->pendingReset = true;
|
||||
this->currentSongPlaying = false;
|
||||
this->startPaused = paused;
|
||||
|
||||
std::scoped_lock lock(dataOutMutex);
|
||||
|
||||
@@ -116,7 +120,7 @@ void TrackPlayer::runTask() {
|
||||
while (isRunning) {
|
||||
// Ensure we even have any tracks to play
|
||||
if (!this->trackQueue->hasTracks() ||
|
||||
(endOfQueueReached && trackQueue->isFinished())) {
|
||||
(!pendingReset && endOfQueueReached && trackQueue->isFinished())) {
|
||||
this->trackQueue->playableSemaphore->twait(300);
|
||||
continue;
|
||||
}
|
||||
@@ -181,7 +185,8 @@ void TrackPlayer::runTask() {
|
||||
}
|
||||
|
||||
if (trackOffset == 0 && pendingSeekPositionMs == 0) {
|
||||
this->trackLoaded(track);
|
||||
this->trackLoaded(track, startPaused);
|
||||
startPaused = false;
|
||||
}
|
||||
|
||||
int32_t r =
|
||||
@@ -233,8 +238,8 @@ void TrackPlayer::runTask() {
|
||||
if (!currentSongPlaying || pendingReset)
|
||||
break;
|
||||
|
||||
written =
|
||||
dataCallback(pcmBuffer.data() + (ret - toWrite), toWrite, track->identifier);
|
||||
written = dataCallback(pcmBuffer.data() + (ret - toWrite),
|
||||
toWrite, track->identifier);
|
||||
}
|
||||
if (written == 0) {
|
||||
BELL_SLEEP_MS(50);
|
||||
|
||||
@@ -504,11 +504,18 @@ void TrackQueue::processTrack(std::shared_ptr<QueuedTrack> track) {
|
||||
|
||||
bool TrackQueue::queueNextTrack(int offset, uint32_t positionMs) {
|
||||
const int requestedRefIndex = offset + currentTracksIndex;
|
||||
|
||||
if (requestedRefIndex < 0 || requestedRefIndex >= currentTracks.size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (offset < 0) {
|
||||
// in case we re-queue current track, make sure position is updated (0)
|
||||
if (offset == 0 && preloadedTracks.size() &&
|
||||
preloadedTracks[0]->ref == currentTracks[currentTracksIndex]) {
|
||||
preloadedTracks.pop_front();
|
||||
}
|
||||
|
||||
if (offset <= 0) {
|
||||
preloadedTracks.push_front(std::make_shared<QueuedTrack>(
|
||||
currentTracks[requestedRefIndex], ctx, positionMs));
|
||||
} else {
|
||||
@@ -520,13 +527,30 @@ bool TrackQueue::queueNextTrack(int offset, uint32_t positionMs) {
|
||||
}
|
||||
|
||||
bool TrackQueue::skipTrack(SkipDirection dir, bool expectNotify) {
|
||||
bool canSkipNext = currentTracks.size() > currentTracksIndex + 1;
|
||||
bool canSkipPrev = currentTracksIndex > 0;
|
||||
bool skipped = true;
|
||||
std::scoped_lock lock(tracksMutex);
|
||||
|
||||
if ((dir == SkipDirection::NEXT && canSkipNext) ||
|
||||
(dir == SkipDirection::PREV && canSkipPrev)) {
|
||||
std::scoped_lock lock(tracksMutex);
|
||||
if (dir == SkipDirection::NEXT) {
|
||||
if (dir == SkipDirection::PREV) {
|
||||
uint64_t position =
|
||||
!playbackState->innerFrame.state.has_position_ms
|
||||
? 0
|
||||
: playbackState->innerFrame.state.position_ms +
|
||||
ctx->timeProvider->getSyncedTimestamp() -
|
||||
playbackState->innerFrame.state.position_measured_at;
|
||||
|
||||
if (currentTracksIndex > 0 && position < 3000) {
|
||||
queueNextTrack(-1);
|
||||
|
||||
if (preloadedTracks.size() > MAX_TRACKS_PRELOAD) {
|
||||
preloadedTracks.pop_back();
|
||||
}
|
||||
|
||||
currentTracksIndex--;
|
||||
} else {
|
||||
queueNextTrack(0);
|
||||
}
|
||||
} else {
|
||||
if (currentTracks.size() > currentTracksIndex + 1) {
|
||||
preloadedTracks.pop_front();
|
||||
|
||||
if (!queueNextTrack(preloadedTracks.size() + 1)) {
|
||||
@@ -535,15 +559,11 @@ bool TrackQueue::skipTrack(SkipDirection dir, bool expectNotify) {
|
||||
|
||||
currentTracksIndex++;
|
||||
} else {
|
||||
queueNextTrack(-1);
|
||||
|
||||
if (preloadedTracks.size() > MAX_TRACKS_PRELOAD) {
|
||||
preloadedTracks.pop_back();
|
||||
}
|
||||
|
||||
currentTracksIndex--;
|
||||
skipped = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (skipped) {
|
||||
// Update frame data
|
||||
playbackState->innerFrame.state.playing_track_index = currentTracksIndex;
|
||||
|
||||
@@ -551,11 +571,9 @@ bool TrackQueue::skipTrack(SkipDirection dir, bool expectNotify) {
|
||||
// Reset position to zero
|
||||
notifyPending = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return skipped;
|
||||
}
|
||||
|
||||
bool TrackQueue::hasTracks() {
|
||||
|
||||
@@ -24,11 +24,7 @@ void TrackReference::decodeURI() {
|
||||
gid = bigNumAdd(gid, d);
|
||||
}
|
||||
|
||||
#if __cplusplus >= 202002L
|
||||
if (uri.starts_with("episode")) {
|
||||
#else
|
||||
if (uri.find("episode") == 0) {
|
||||
#endif
|
||||
if (uri.find("episode:") != std::string::npos) {
|
||||
type = Type::EPISODE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "Utils.h"
|
||||
|
||||
#include <stdlib.h> // for strtol
|
||||
#include <stdlib.h> // for strtol
|
||||
#include <chrono>
|
||||
#include <iomanip> // for operator<<, setfill, setw
|
||||
#include <iostream> // for basic_ostream, hex
|
||||
#include <sstream> // for stringstream
|
||||
#include <string> // for string
|
||||
#include <type_traits> // for enable_if<>::type
|
||||
#include <chrono>
|
||||
#ifndef _WIN32
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
@@ -136,10 +136,8 @@ static bool cmd_handler(cspot_event_t event, ...) {
|
||||
displayer_timer(DISPLAYER_ELAPSED, va_arg(args, int), -1);
|
||||
break;
|
||||
case CSPOT_TRACK_INFO: {
|
||||
uint32_t duration = va_arg(args, int);
|
||||
uint32_t offset = va_arg(args, int);
|
||||
char *artist = va_arg(args, char*), *album = va_arg(args, char*), *title = va_arg(args, char*);
|
||||
char *artwork = va_arg(args, char*);
|
||||
uint32_t duration = va_arg(args, int), offset = va_arg(args, int);
|
||||
char *artist = va_arg(args, char*), *album = va_arg(args, char*), *title = va_arg(args, char*), *artwork = va_arg(args, char*);
|
||||
if (artwork && displayer_can_artwork()) {
|
||||
ESP_LOGI(TAG, "requesting artwork %s", artwork);
|
||||
http_download(artwork, 128*1024, got_artwork, NULL);
|
||||
|
||||
@@ -25,7 +25,7 @@ typedef enum { CSPOT_START, CSPOT_DISC, CSPOT_FLUSH, CSPOT_STOP, CSPOT_PLAY, CS
|
||||
|
||||
typedef bool (*cspot_cmd_cb_t)(cspot_event_t event, ...);
|
||||
typedef bool (*cspot_cmd_vcb_t)(cspot_event_t event, va_list args);
|
||||
typedef void (*cspot_data_cb_t)(const uint8_t *data, size_t len);
|
||||
typedef uint32_t (*cspot_data_cb_t)(const uint8_t *data, size_t len);
|
||||
|
||||
/**
|
||||
* @brief init sink mode (need to be provided)
|
||||
|
||||
@@ -70,7 +70,7 @@ static void sendBUTN(int code, bool pressed) {
|
||||
pkt_header.jiffies = htonl(gettime_ms());
|
||||
pkt_header.button = htonl(code + (pressed ? DOWN_OFS : UP_OFS));
|
||||
|
||||
LOG_INFO("sending BUTN code %04x %s", code, pressed ? "down" : "up");
|
||||
LOG_DEBUG("sending BUTN code %04x %s", code, pressed ? "down" : "up");
|
||||
|
||||
LOCK_P;
|
||||
send_packet((uint8_t *) &pkt_header, sizeof(pkt_header));
|
||||
|
||||
@@ -65,15 +65,16 @@ extern log_level loglevel;
|
||||
/****************************************************************************************
|
||||
* Common sink data handler
|
||||
*/
|
||||
static void sink_data_handler(const uint8_t *data, uint32_t len)
|
||||
static uint32_t sink_data_handler(const uint8_t *data, uint32_t len, int retries)
|
||||
{
|
||||
size_t bytes, space;
|
||||
int wait = 10;
|
||||
uint32_t written = 0;
|
||||
int wait = retries + 1;
|
||||
|
||||
// would be better to lock output, but really, it does not matter
|
||||
if (!output.external) {
|
||||
LOG_SDEBUG("Cannot use external sink while LMS is controlling player");
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
LOCK_O;
|
||||
@@ -98,27 +99,38 @@ static void sink_data_handler(const uint8_t *data, uint32_t len)
|
||||
|
||||
len -= bytes;
|
||||
data += bytes;
|
||||
written += bytes;
|
||||
|
||||
// allow i2s to empty the buffer if needed
|
||||
if (len && !space) {
|
||||
if (output.state == OUTPUT_RUNNING) wait--;
|
||||
if (!retries) break;
|
||||
wait--;
|
||||
UNLOCK_O; usleep(50000); LOCK_O;
|
||||
}
|
||||
}
|
||||
|
||||
if (!wait) {
|
||||
// re-align the buffer according to what we throw away
|
||||
// re-align the buffer according to what we threw away
|
||||
_buf_inc_writep(outputbuf, outputbuf->size - (BYTES_PER_FRAME - (len % BYTES_PER_FRAME)));
|
||||
LOG_WARN("Waited too long, dropping frames %d", len);
|
||||
}
|
||||
|
||||
UNLOCK_O;
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* BT sink data handler
|
||||
*/
|
||||
#if CONFIG_BT_SINK
|
||||
static void bt_sink_data_handler(const uint8_t *data, uint32_t len) {
|
||||
sink_data_handler(data, len, 10);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* BT sink command handler
|
||||
*/
|
||||
#if CONFIG_BT_SINK
|
||||
static bool bt_sink_cmd_handler(bt_sink_cmd_t cmd, va_list args)
|
||||
{
|
||||
// don't LOCK_O as there is always a chance that LMS takes control later anyway
|
||||
@@ -195,7 +207,7 @@ static void raop_sink_data_handler(const uint8_t *data, uint32_t len, u32_t play
|
||||
raop_sync.playtime = playtime;
|
||||
raop_sync.len = len;
|
||||
|
||||
sink_data_handler(data, len);
|
||||
sink_data_handler(data, len, 10);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
@@ -332,9 +344,17 @@ static bool raop_sink_cmd_handler(raop_event_t event, va_list args)
|
||||
#endif
|
||||
|
||||
/****************************************************************************************
|
||||
* cspot sink command handler
|
||||
* cspot sink data handler
|
||||
*/
|
||||
#if CONFIG_CSPOT_SINK
|
||||
static uint32_t cspot_sink_data_handler(const uint8_t *data, uint32_t len) {
|
||||
return sink_data_handler(data, len, 0);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* cspot sink command handler
|
||||
*/
|
||||
|
||||
static bool cspot_cmd_handler(cspot_event_t cmd, va_list args)
|
||||
{
|
||||
// don't LOCK_O as there is always a chance that LMS takes control later anyway
|
||||
@@ -433,7 +453,7 @@ void register_external(void) {
|
||||
enable_bt_sink = !strcmp(p,"1") || !strcasecmp(p,"y");
|
||||
free(p);
|
||||
if (!strcasestr(output.device, "BT") && enable_bt_sink) {
|
||||
bt_sink_init(bt_sink_cmd_handler, sink_data_handler);
|
||||
bt_sink_init(bt_sink_cmd_handler, bt_sink_data_handler);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -454,7 +474,7 @@ void register_external(void) {
|
||||
enable_cspot = strcmp(p,"1") == 0 || strcasecmp(p,"y") == 0;
|
||||
free(p);
|
||||
if (enable_cspot){
|
||||
cspot_sink_init(cspot_cmd_handler, sink_data_handler);
|
||||
cspot_sink_init(cspot_cmd_handler, cspot_sink_data_handler);
|
||||
LOG_INFO("Initializing CSpot sink");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,41 @@
|
||||
#include "esp_system.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_log.h"
|
||||
#include "monitor.h"
|
||||
#include "platform_config.h"
|
||||
#include "messaging.h"
|
||||
#include "gpio_exp.h"
|
||||
#include "accessors.h"
|
||||
|
||||
#ifndef CONFIG_POWER_GPIO_LEVEL
|
||||
#define CONFIG_POWER_GPIO_LEVEL 1
|
||||
#endif
|
||||
|
||||
static const char TAG[] = "embedded";
|
||||
|
||||
static struct {
|
||||
int gpio, active;
|
||||
} power_control = { CONFIG_POWER_GPIO, CONFIG_POWER_GPIO_LEVEL };
|
||||
|
||||
extern void sb_controls_init(void);
|
||||
extern bool sb_displayer_init(void);
|
||||
|
||||
u8_t custom_player_id = 12;
|
||||
|
||||
mutex_type slimp_mutex;
|
||||
static jmp_buf jumpbuf;
|
||||
|
||||
#ifndef POWER_LOCKED
|
||||
static void set_power_gpio(int gpio, char *value) {
|
||||
if (strcasestr(value, "power")) {
|
||||
char *p = strchr(value, ':');
|
||||
if (p) power_control.active = atoi(p + 1);
|
||||
power_control.gpio = gpio;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void get_mac(u8_t mac[]) {
|
||||
esp_read_mac(mac, ESP_MAC_WIFI_STA);
|
||||
}
|
||||
@@ -56,16 +84,22 @@ uint32_t _gettime_ms_(void) {
|
||||
return (uint32_t) (esp_timer_get_time() / 1000);
|
||||
}
|
||||
|
||||
extern void sb_controls_init(void);
|
||||
extern bool sb_displayer_init(void);
|
||||
|
||||
u8_t custom_player_id = 12;
|
||||
|
||||
int embedded_init(void) {
|
||||
mutex_create(slimp_mutex);
|
||||
sb_controls_init();
|
||||
custom_player_id = sb_displayer_init() ? 100 : 101;
|
||||
|
||||
#ifndef POWER_LOCKED
|
||||
parse_set_GPIO(set_power_gpio);
|
||||
#endif
|
||||
|
||||
if (power_control.gpio != -1) {
|
||||
gpio_pad_select_gpio_x(power_control.gpio);
|
||||
gpio_set_direction_x(power_control.gpio, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level_x(power_control.gpio, !power_control.active);
|
||||
ESP_LOGI(TAG, "setting power GPIO %d (active:%d)", power_control.gpio, power_control.active);
|
||||
}
|
||||
|
||||
return setjmp(jumpbuf);
|
||||
}
|
||||
|
||||
@@ -73,6 +107,13 @@ void embedded_exit(int code) {
|
||||
longjmp(jumpbuf, code + 1);
|
||||
}
|
||||
|
||||
void powering(bool on) {
|
||||
if (power_control.gpio != -1) {
|
||||
ESP_LOGI(TAG, "powering player %s", on ? "ON" : "OFF");
|
||||
gpio_set_level_x(power_control.gpio, on ? power_control.active : !power_control.active);
|
||||
}
|
||||
}
|
||||
|
||||
u16_t get_RSSI(void) {
|
||||
wifi_ap_record_t wifidata;
|
||||
esp_wifi_sta_get_ap_info(&wifidata);
|
||||
|
||||
@@ -71,6 +71,7 @@ int embedded_init(void);
|
||||
void register_external(void);
|
||||
void deregister_external(void);
|
||||
void decode_restore(int external);
|
||||
void powering(bool on);
|
||||
// used when other client wants to use slimproto socket to send messages
|
||||
extern mutex_type slimp_mutex;
|
||||
#define LOCK_P mutex_lock(slimp_mutex)
|
||||
|
||||
36
components/squeezelite/external/dac_external.c
vendored
36
components/squeezelite/external/dac_external.c
vendored
@@ -14,6 +14,7 @@
|
||||
#include <driver/i2s.h>
|
||||
#include "driver/i2c.h"
|
||||
#include "esp_log.h"
|
||||
#include "gpio_exp.h"
|
||||
#include "cJSON.h"
|
||||
#include "platform_config.h"
|
||||
#include "adac.h"
|
||||
@@ -123,9 +124,28 @@ bool i2c_json_execute(char *set) {
|
||||
if (!json_set) return true;
|
||||
|
||||
cJSON_ArrayForEach(item, json_set) {
|
||||
cJSON *reg = cJSON_GetObjectItemCaseSensitive(item, "reg");
|
||||
cJSON *action;
|
||||
|
||||
// is this a delay
|
||||
if ((action = cJSON_GetObjectItemCaseSensitive(item, "delay")) != NULL) {
|
||||
vTaskDelay(pdMS_TO_TICKS(action->valueint));
|
||||
ESP_LOGI(TAG, "DAC waiting %d ms", action->valueint);
|
||||
continue;
|
||||
}
|
||||
|
||||
// is this a gpio toggle
|
||||
if ((action = cJSON_GetObjectItemCaseSensitive(item, "gpio")) != NULL) {
|
||||
cJSON *level = cJSON_GetObjectItemCaseSensitive(item, "level");
|
||||
ESP_LOGI(TAG, "set GPIO %d at %d", action->valueint, level->valueint);
|
||||
gpio_set_direction_x(action->valueint, GPIO_MODE_OUTPUT);
|
||||
gpio_set_level_x(action->valueint, level->valueint);
|
||||
continue;
|
||||
}
|
||||
|
||||
action= cJSON_GetObjectItemCaseSensitive(item, "reg");
|
||||
cJSON *val = cJSON_GetObjectItemCaseSensitive(item, "val");
|
||||
|
||||
// this is gpio register setting or crap
|
||||
if (cJSON_IsArray(val)) {
|
||||
cJSON *value;
|
||||
uint8_t *data = malloc(cJSON_GetArraySize(val));
|
||||
@@ -137,23 +157,23 @@ bool i2c_json_execute(char *set) {
|
||||
data[count++] = value->valueint;
|
||||
}
|
||||
|
||||
adac_write(i2c_addr, reg->valueint, data, count);
|
||||
adac_write(i2c_addr, action->valueint, data, count);
|
||||
free(data);
|
||||
} else {
|
||||
cJSON *mode = cJSON_GetObjectItemCaseSensitive(item, "mode");
|
||||
|
||||
if (!reg || !val) continue;
|
||||
if (!action || !val) continue;
|
||||
|
||||
if (!mode) {
|
||||
adac_write_byte(i2c_addr, reg->valueint, val->valueint);
|
||||
adac_write_byte(i2c_addr, action->valueint, val->valueint);
|
||||
} else if (!strcasecmp(mode->valuestring, "or")) {
|
||||
uint8_t data = adac_read_byte(i2c_addr,reg->valueint);
|
||||
uint8_t data = adac_read_byte(i2c_addr, action->valueint);
|
||||
data |= (uint8_t) val->valueint;
|
||||
adac_write_byte(i2c_addr, reg->valueint, data);
|
||||
adac_write_byte(i2c_addr, action->valueint, data);
|
||||
} else if (!strcasecmp(mode->valuestring, "and")) {
|
||||
uint8_t data = adac_read_byte(i2c_addr, reg->valueint);
|
||||
uint8_t data = adac_read_byte(i2c_addr, action->valueint);
|
||||
data &= (uint8_t) val->valueint;
|
||||
adac_write_byte(i2c_addr, reg->valueint, data);
|
||||
adac_write_byte(i2c_addr, action->valueint, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ static int read_opus_header(void) {
|
||||
switch (u->status) {
|
||||
case OGG_SYNC:
|
||||
u->status = OGG_ID_HEADER;
|
||||
OG(&gu, stream_init, &u->state, OG(&gu, page_serialno, &u->page));
|
||||
OG(&gu, stream_reset_serialno, &u->state, OG(&gu, page_serialno, &u->page));
|
||||
fetch = false;
|
||||
break;
|
||||
case OGG_ID_HEADER:
|
||||
@@ -359,10 +359,10 @@ static void opus_open(u8_t size, u8_t rate, u8_t chan, u8_t endianness) {
|
||||
|
||||
u->status = OGG_SYNC;
|
||||
u->overframes = 0;
|
||||
|
||||
OG(&gu, sync_clear, &u->sync);
|
||||
OG(&gu, stream_clear, &u->state);
|
||||
OG(&gu, stream_init, &u->state, -1);
|
||||
|
||||
OG(&go, stream_clear, &u->state);
|
||||
OG(&go, sync_clear, &u->sync);
|
||||
OG(&go, stream_init, &u->state, -1);
|
||||
}
|
||||
|
||||
static void opus_close(void) {
|
||||
@@ -372,8 +372,8 @@ static void opus_close(void) {
|
||||
free(u->overbuf);
|
||||
u->overbuf = NULL;
|
||||
|
||||
OG(&gu, stream_clear, &u->state);
|
||||
OG(&gu, sync_clear, &u->sync);
|
||||
OG(&go, stream_clear, &u->state);
|
||||
OG(&go, sync_clear, &u->sync);
|
||||
}
|
||||
|
||||
static bool load_opus(void) {
|
||||
@@ -394,7 +394,7 @@ static bool load_opus(void) {
|
||||
}
|
||||
|
||||
g_handle->ogg_stream_clear = dlsym(g_handle->handle, "ogg_stream_clear");
|
||||
g_handle->.ogg_stream_reset = dlsym(g_handle->handle, "ogg_stream_reset");
|
||||
g_handle->ogg_stream_reset = dlsym(g_handle->handle, "ogg_stream_reset");
|
||||
g_handle->ogg_stream_eos = dlsym(g_handle->handle, "ogg_stream_eos");
|
||||
g_handle->ogg_stream_reset_serialno = dlsym(g_handle->handle, "ogg_stream_reset_serialno");
|
||||
g_handle->ogg_sync_clear = dlsym(g_handle->handle, "ogg_sync_clear");
|
||||
|
||||
@@ -9,12 +9,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include "driver/gpio.h"
|
||||
#include "squeezelite.h"
|
||||
#include "equalizer.h"
|
||||
#include "perf_trace.h"
|
||||
#include "platform_config.h"
|
||||
#include <assert.h>
|
||||
#include "services.h"
|
||||
#include "led.h"
|
||||
|
||||
extern struct outputstate output;
|
||||
extern struct buffer *outputbuf;
|
||||
@@ -39,6 +41,7 @@ static bool running = false;
|
||||
static uint8_t *btout;
|
||||
static frames_t oframes;
|
||||
static bool stats;
|
||||
static uint32_t bt_idle_since;
|
||||
|
||||
static int _write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR, u8_t flags,
|
||||
s32_t cross_gain_in, s32_t cross_gain_out, ISAMPLE_T **cross_ptr);
|
||||
@@ -60,10 +63,28 @@ static int _write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t g
|
||||
RESET_MIN_MAX_DURATION(lock_out_time)
|
||||
|
||||
DECLARE_ALL_MIN_MAX;
|
||||
|
||||
/****************************************************************************************
|
||||
* Get inactivity callback
|
||||
*/
|
||||
static uint32_t bt_idle_callback(void) {
|
||||
return output.state <= OUTPUT_STOPPED ? pdTICKS_TO_MS(xTaskGetTickCount()) - bt_idle_since : 0;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Init BT sink
|
||||
*/
|
||||
void output_init_bt(log_level level, char *device, unsigned output_buf_size, char *params, unsigned rates[], unsigned rate_delay, unsigned idle) {
|
||||
loglevel = level;
|
||||
running = true;
|
||||
|
||||
// idle counter
|
||||
bt_idle_since = pdTICKS_TO_MS(xTaskGetTickCount());
|
||||
services_sleep_setsleeper(bt_idle_callback);
|
||||
|
||||
// even BT has a right to use led :-)
|
||||
led_blink(LED_GREEN, 200, 1000);
|
||||
|
||||
running = true;
|
||||
output.write_cb = &_write_frames;
|
||||
hal_bluetooth_init(device);
|
||||
char *p = config_alloc_get_default(NVS_TYPE_STR, "stats", "n", 0);
|
||||
@@ -72,6 +93,9 @@ void output_init_bt(log_level level, char *device, unsigned output_buf_size, cha
|
||||
equalizer_set_samplerate(output.current_sample_rate);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Close BT sink
|
||||
*/
|
||||
void output_close_bt(void) {
|
||||
LOCK;
|
||||
running = false;
|
||||
@@ -80,6 +104,9 @@ void output_close_bt(void) {
|
||||
equalizer_close();
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Data framing callback
|
||||
*/
|
||||
static int _write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t gainR, u8_t flags,
|
||||
s32_t cross_gain_in, s32_t cross_gain_out, ISAMPLE_T **cross_ptr) {
|
||||
|
||||
@@ -120,6 +147,9 @@ static int _write_frames(frames_t out_frames, bool silence, s32_t gainL, s32_t g
|
||||
return (int)out_frames;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Data callback for BT stack
|
||||
*/
|
||||
int32_t output_bt_data(uint8_t *data, int32_t len) {
|
||||
int32_t iframes = len / BYTES_PER_FRAME, start_timer = 0;
|
||||
|
||||
@@ -153,6 +183,9 @@ int32_t output_bt_data(uint8_t *data, int32_t len) {
|
||||
return oframes * BYTES_PER_FRAME;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Tick for BT
|
||||
*/
|
||||
void output_bt_tick(void) {
|
||||
static time_t lastTime=0;
|
||||
|
||||
@@ -186,3 +219,18 @@ void output_bt_tick(void) {
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* BT playback stop
|
||||
*/
|
||||
void output_bt_stop(void) {
|
||||
led_blink(LED_GREEN, 200, 1000);
|
||||
bt_idle_since = pdTICKS_TO_MS(xTaskGetTickCount());
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* BT playback start
|
||||
*/
|
||||
void output_bt_start(void) {
|
||||
led_on(LED_GREEN);
|
||||
bt_idle_since = pdTICKS_TO_MS(xTaskGetTickCount());
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ sure that using rate_delay would fix that
|
||||
#include "adac.h"
|
||||
#include "time.h"
|
||||
#include "led.h"
|
||||
#include "services.h"
|
||||
#include "monitor.h"
|
||||
#include "platform_config.h"
|
||||
#include "gpio_exp.h"
|
||||
@@ -102,6 +103,8 @@ const struct adac_s *adac = &dac_external;
|
||||
|
||||
static log_level loglevel;
|
||||
|
||||
static uint32_t i2s_idle_since;
|
||||
static void (*pseudo_idle_chain)(uint32_t);
|
||||
static bool (*slimp_handler_chain)(u8_t *data, int len);
|
||||
static bool jack_mutes_amp;
|
||||
static bool running, isI2SStarted, ended;
|
||||
@@ -111,7 +114,6 @@ static frames_t oframes;
|
||||
static struct {
|
||||
bool enabled;
|
||||
u8_t *buf;
|
||||
size_t count;
|
||||
} spdif;
|
||||
static size_t dma_buf_frames;
|
||||
static TaskHandle_t output_i2s_task;
|
||||
@@ -126,7 +128,8 @@ static int _i2s_write_frames(frames_t out_frames, bool silence, s32_t gainL, s32
|
||||
s32_t cross_gain_in, s32_t cross_gain_out, ISAMPLE_T **cross_ptr);
|
||||
static void output_thread_i2s(void *arg);
|
||||
static void i2s_stats(uint32_t now);
|
||||
static void spdif_convert(ISAMPLE_T *src, size_t frames, u32_t *dst, size_t *count);
|
||||
|
||||
static void spdif_convert(ISAMPLE_T *src, size_t frames, u32_t *dst);
|
||||
static void (*jack_handler_chain)(bool inserted);
|
||||
|
||||
#define I2C_PORT 0
|
||||
@@ -198,6 +201,13 @@ static void set_amp_gpio(int gpio, char *value) {
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************************
|
||||
* Get inactivity callback
|
||||
*/
|
||||
static uint32_t i2s_idle_callback(void) {
|
||||
return output.state <= OUTPUT_STOPPED ? pdTICKS_TO_MS(xTaskGetTickCount()) - i2s_idle_since : 0;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Set pin from config string
|
||||
*/
|
||||
@@ -411,7 +421,19 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch
|
||||
else adac->speaker(true);
|
||||
|
||||
adac->headset(jack_inserted_svc());
|
||||
|
||||
// do we want stats
|
||||
p = config_alloc_get_default(NVS_TYPE_STR, "stats", "n", 0);
|
||||
if (p && (*p == '1' || *p == 'Y' || *p == 'y')) {
|
||||
pseudo_idle_chain = pseudo_idle_svc;
|
||||
pseudo_idle_svc = i2s_stats;
|
||||
}
|
||||
free(p);
|
||||
|
||||
// register a callback for inactivity
|
||||
i2s_idle_since = pdTICKS_TO_MS(xTaskGetTickCount());
|
||||
services_sleep_setsleeper(i2s_idle_callback);
|
||||
|
||||
// create task as a FreeRTOS task but uses stack in internal RAM
|
||||
{
|
||||
static DRAM_ATTR StaticTask_t xTaskBuffer __attribute__ ((aligned (4)));
|
||||
@@ -419,17 +441,8 @@ void output_init_i2s(log_level level, char *device, unsigned output_buf_size, ch
|
||||
output_i2s_task = xTaskCreateStaticPinnedToCore( (TaskFunction_t) output_thread_i2s, "output_i2s", OUTPUT_THREAD_STACK_SIZE,
|
||||
NULL, CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT + 1, xStack, &xTaskBuffer, 0 );
|
||||
}
|
||||
|
||||
// do we want stats
|
||||
p = config_alloc_get_default(NVS_TYPE_STR, "stats", "n", 0);
|
||||
if (p && (*p == '1' || *p == 'Y' || *p == 'y')) {
|
||||
pseudo_idle_chain = pseudo_idle_svc;
|
||||
pseudo_idle_svc = i2s_stats;
|
||||
}
|
||||
free(p);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************
|
||||
* Terminate DAC output
|
||||
*/
|
||||
@@ -493,7 +506,7 @@ static void output_thread_i2s(void *arg) {
|
||||
uint32_t fullness = gettime_ms();
|
||||
bool synced;
|
||||
output_state state = OUTPUT_OFF - 1;
|
||||
|
||||
|
||||
while (running) {
|
||||
|
||||
TIME_MEASUREMENT_START(timer_start);
|
||||
@@ -508,6 +521,7 @@ static void output_thread_i2s(void *arg) {
|
||||
if (amp_control.gpio != -1) gpio_set_level_x(amp_control.gpio, !amp_control.active);
|
||||
LOG_INFO("switching off amp GPIO %d", amp_control.gpio);
|
||||
} else if (output.state == OUTPUT_STOPPED) {
|
||||
i2s_idle_since = pdTICKS_TO_MS(xTaskGetTickCount());
|
||||
adac->speaker(false);
|
||||
led_blink(LED_GREEN, 200, 1000);
|
||||
} else if (output.state == OUTPUT_RUNNING) {
|
||||
@@ -526,7 +540,6 @@ static void output_thread_i2s(void *arg) {
|
||||
isI2SStarted = false;
|
||||
i2s_stop(CONFIG_I2S_NUM);
|
||||
adac->power(ADAC_STANDBY);
|
||||
spdif.count = 0;
|
||||
}
|
||||
usleep(100000);
|
||||
continue;
|
||||
@@ -573,6 +586,7 @@ static void output_thread_i2s(void *arg) {
|
||||
i2s_zero_dma_buffer(CONFIG_I2S_NUM);
|
||||
i2s_start(CONFIG_I2S_NUM);
|
||||
adac->power(ADAC_ON);
|
||||
if (spdif.enabled) spdif_convert(NULL, 0, NULL);
|
||||
}
|
||||
|
||||
// this does not work well as set_sample_rates resets the fifos (and it's too early)
|
||||
@@ -602,7 +616,7 @@ static void output_thread_i2s(void *arg) {
|
||||
// need IRAM for speed but can't allocate a FRAME_BLOCK * 16, so process by smaller chunks
|
||||
while (count < oframes) {
|
||||
size_t chunk = min(SPDIF_BLOCK, oframes - count);
|
||||
spdif_convert((ISAMPLE_T*) obuf + count * 2, chunk, (u32_t*) spdif.buf, &spdif.count);
|
||||
spdif_convert((ISAMPLE_T*) obuf + count * 2, chunk, (u32_t*) spdif.buf);
|
||||
i2s_write(CONFIG_I2S_NUM, spdif.buf, chunk * 16, &obytes, portMAX_DELAY);
|
||||
bytes += obytes / (16 / BYTES_PER_FRAME);
|
||||
count += chunk;
|
||||
@@ -632,7 +646,7 @@ static void output_thread_i2s(void *arg) {
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Stats output thread
|
||||
* stats output callback
|
||||
*/
|
||||
static void i2s_stats(uint32_t now) {
|
||||
static uint32_t last;
|
||||
@@ -643,7 +657,7 @@ static void i2s_stats(uint32_t now) {
|
||||
// then see if we need to act
|
||||
if (output.state <= OUTPUT_STOPPED || now < last + STATS_PERIOD_MS) return;
|
||||
last = now;
|
||||
|
||||
|
||||
LOG_INFO( "Output State: %d, current sample rate: %d, bytes per frame: %d", output.state, output.current_sample_rate, BYTES_PER_FRAME);
|
||||
LOG_INFO( LINE_MIN_MAX_FORMAT_HEAD1);
|
||||
LOG_INFO( LINE_MIN_MAX_FORMAT_HEAD2);
|
||||
@@ -667,47 +681,45 @@ static void i2s_stats(uint32_t now) {
|
||||
/****************************************************************************************
|
||||
* SPDIF support
|
||||
*/
|
||||
|
||||
#define PREAMBLE_B (0xE8) //11101000
|
||||
#define PREAMBLE_M (0xE2) //11100010
|
||||
#define PREAMBLE_W (0xE4) //11100100
|
||||
|
||||
#define VUCP ((0xCC) << 24)
|
||||
#define VUCP_MUTE ((0xD4) << 24) // To mute PCM, set VUCP = invalid.
|
||||
static const u8_t VUCP24[2] = { 0xCC, 0x32 };
|
||||
|
||||
static const u16_t spdif_bmclookup[256] = { //biphase mark encoded values (least significant bit first)
|
||||
0xcccc, 0x4ccc, 0x2ccc, 0xaccc, 0x34cc, 0xb4cc, 0xd4cc, 0x54cc,
|
||||
0x32cc, 0xb2cc, 0xd2cc, 0x52cc, 0xcacc, 0x4acc, 0x2acc, 0xaacc,
|
||||
0x334c, 0xb34c, 0xd34c, 0x534c, 0xcb4c, 0x4b4c, 0x2b4c, 0xab4c,
|
||||
0xcd4c, 0x4d4c, 0x2d4c, 0xad4c, 0x354c, 0xb54c, 0xd54c, 0x554c,
|
||||
0x332c, 0xb32c, 0xd32c, 0x532c, 0xcb2c, 0x4b2c, 0x2b2c, 0xab2c,
|
||||
0xcd2c, 0x4d2c, 0x2d2c, 0xad2c, 0x352c, 0xb52c, 0xd52c, 0x552c,
|
||||
0xccac, 0x4cac, 0x2cac, 0xacac, 0x34ac, 0xb4ac, 0xd4ac, 0x54ac,
|
||||
0x32ac, 0xb2ac, 0xd2ac, 0x52ac, 0xcaac, 0x4aac, 0x2aac, 0xaaac,
|
||||
0x3334, 0xb334, 0xd334, 0x5334, 0xcb34, 0x4b34, 0x2b34, 0xab34,
|
||||
0xcd34, 0x4d34, 0x2d34, 0xad34, 0x3534, 0xb534, 0xd534, 0x5534,
|
||||
0xccb4, 0x4cb4, 0x2cb4, 0xacb4, 0x34b4, 0xb4b4, 0xd4b4, 0x54b4,
|
||||
0x32b4, 0xb2b4, 0xd2b4, 0x52b4, 0xcab4, 0x4ab4, 0x2ab4, 0xaab4,
|
||||
0xccd4, 0x4cd4, 0x2cd4, 0xacd4, 0x34d4, 0xb4d4, 0xd4d4, 0x54d4,
|
||||
0x32d4, 0xb2d4, 0xd2d4, 0x52d4, 0xcad4, 0x4ad4, 0x2ad4, 0xaad4,
|
||||
0x3354, 0xb354, 0xd354, 0x5354, 0xcb54, 0x4b54, 0x2b54, 0xab54,
|
||||
0xcd54, 0x4d54, 0x2d54, 0xad54, 0x3554, 0xb554, 0xd554, 0x5554,
|
||||
0x3332, 0xb332, 0xd332, 0x5332, 0xcb32, 0x4b32, 0x2b32, 0xab32,
|
||||
0xcd32, 0x4d32, 0x2d32, 0xad32, 0x3532, 0xb532, 0xd532, 0x5532,
|
||||
0xccb2, 0x4cb2, 0x2cb2, 0xacb2, 0x34b2, 0xb4b2, 0xd4b2, 0x54b2,
|
||||
0x32b2, 0xb2b2, 0xd2b2, 0x52b2, 0xcab2, 0x4ab2, 0x2ab2, 0xaab2,
|
||||
0xccd2, 0x4cd2, 0x2cd2, 0xacd2, 0x34d2, 0xb4d2, 0xd4d2, 0x54d2,
|
||||
0x32d2, 0xb2d2, 0xd2d2, 0x52d2, 0xcad2, 0x4ad2, 0x2ad2, 0xaad2,
|
||||
0x3352, 0xb352, 0xd352, 0x5352, 0xcb52, 0x4b52, 0x2b52, 0xab52,
|
||||
0xcd52, 0x4d52, 0x2d52, 0xad52, 0x3552, 0xb552, 0xd552, 0x5552,
|
||||
0xccca, 0x4cca, 0x2cca, 0xacca, 0x34ca, 0xb4ca, 0xd4ca, 0x54ca,
|
||||
0x32ca, 0xb2ca, 0xd2ca, 0x52ca, 0xcaca, 0x4aca, 0x2aca, 0xaaca,
|
||||
0x334a, 0xb34a, 0xd34a, 0x534a, 0xcb4a, 0x4b4a, 0x2b4a, 0xab4a,
|
||||
0xcd4a, 0x4d4a, 0x2d4a, 0xad4a, 0x354a, 0xb54a, 0xd54a, 0x554a,
|
||||
0x332a, 0xb32a, 0xd32a, 0x532a, 0xcb2a, 0x4b2a, 0x2b2a, 0xab2a,
|
||||
0xcd2a, 0x4d2a, 0x2d2a, 0xad2a, 0x352a, 0xb52a, 0xd52a, 0x552a,
|
||||
0xccaa, 0x4caa, 0x2caa, 0xacaa, 0x34aa, 0xb4aa, 0xd4aa, 0x54aa,
|
||||
0x32aa, 0xb2aa, 0xd2aa, 0x52aa, 0xcaaa, 0x4aaa, 0x2aaa, 0xaaaa
|
||||
static const u16_t spdif_bmclookup[256] = {
|
||||
0xcccc, 0xb333, 0xd333, 0xaccc, 0xcb33, 0xb4cc, 0xd4cc, 0xab33,
|
||||
0xcd33, 0xb2cc, 0xd2cc, 0xad33, 0xcacc, 0xb533, 0xd533, 0xaacc,
|
||||
0xccb3, 0xb34c, 0xd34c, 0xacb3, 0xcb4c, 0xb4b3, 0xd4b3, 0xab4c,
|
||||
0xcd4c, 0xb2b3, 0xd2b3, 0xad4c, 0xcab3, 0xb54c, 0xd54c, 0xaab3,
|
||||
0xccd3, 0xb32c, 0xd32c, 0xacd3, 0xcb2c, 0xb4d3, 0xd4d3, 0xab2c,
|
||||
0xcd2c, 0xb2d3, 0xd2d3, 0xad2c, 0xcad3, 0xb52c, 0xd52c, 0xaad3,
|
||||
0xccac, 0xb353, 0xd353, 0xacac, 0xcb53, 0xb4ac, 0xd4ac, 0xab53,
|
||||
0xcd53, 0xb2ac, 0xd2ac, 0xad53, 0xcaac, 0xb553, 0xd553, 0xaaac,
|
||||
0xcccb, 0xb334, 0xd334, 0xaccb, 0xcb34, 0xb4cb, 0xd4cb, 0xab34,
|
||||
0xcd34, 0xb2cb, 0xd2cb, 0xad34, 0xcacb, 0xb534, 0xd534, 0xaacb,
|
||||
0xccb4, 0xb34b, 0xd34b, 0xacb4, 0xcb4b, 0xb4b4, 0xd4b4, 0xab4b,
|
||||
0xcd4b, 0xb2b4, 0xd2b4, 0xad4b, 0xcab4, 0xb54b, 0xd54b, 0xaab4,
|
||||
0xccd4, 0xb32b, 0xd32b, 0xacd4, 0xcb2b, 0xb4d4, 0xd4d4, 0xab2b,
|
||||
0xcd2b, 0xb2d4, 0xd2d4, 0xad2b, 0xcad4, 0xb52b, 0xd52b, 0xaad4,
|
||||
0xccab, 0xb354, 0xd354, 0xacab, 0xcb54, 0xb4ab, 0xd4ab, 0xab54,
|
||||
0xcd54, 0xb2ab, 0xd2ab, 0xad54, 0xcaab, 0xb554, 0xd554, 0xaaab,
|
||||
0xcccd, 0xb332, 0xd332, 0xaccd, 0xcb32, 0xb4cd, 0xd4cd, 0xab32,
|
||||
0xcd32, 0xb2cd, 0xd2cd, 0xad32, 0xcacd, 0xb532, 0xd532, 0xaacd,
|
||||
0xccb2, 0xb34d, 0xd34d, 0xacb2, 0xcb4d, 0xb4b2, 0xd4b2, 0xab4d,
|
||||
0xcd4d, 0xb2b2, 0xd2b2, 0xad4d, 0xcab2, 0xb54d, 0xd54d, 0xaab2,
|
||||
0xccd2, 0xb32d, 0xd32d, 0xacd2, 0xcb2d, 0xb4d2, 0xd4d2, 0xab2d,
|
||||
0xcd2d, 0xb2d2, 0xd2d2, 0xad2d, 0xcad2, 0xb52d, 0xd52d, 0xaad2,
|
||||
0xccad, 0xb352, 0xd352, 0xacad, 0xcb52, 0xb4ad, 0xd4ad, 0xab52,
|
||||
0xcd52, 0xb2ad, 0xd2ad, 0xad52, 0xcaad, 0xb552, 0xd552, 0xaaad,
|
||||
0xccca, 0xb335, 0xd335, 0xacca, 0xcb35, 0xb4ca, 0xd4ca, 0xab35,
|
||||
0xcd35, 0xb2ca, 0xd2ca, 0xad35, 0xcaca, 0xb535, 0xd535, 0xaaca,
|
||||
0xccb5, 0xb34a, 0xd34a, 0xacb5, 0xcb4a, 0xb4b5, 0xd4b5, 0xab4a,
|
||||
0xcd4a, 0xb2b5, 0xd2b5, 0xad4a, 0xcab5, 0xb54a, 0xd54a, 0xaab5,
|
||||
0xccd5, 0xb32a, 0xd32a, 0xacd5, 0xcb2a, 0xb4d5, 0xd4d5, 0xab2a,
|
||||
0xcd2a, 0xb2d5, 0xd2d5, 0xad2a, 0xcad5, 0xb52a, 0xd52a, 0xaad5,
|
||||
0xccaa, 0xb355, 0xd355, 0xacaa, 0xcb55, 0xb4aa, 0xd4aa, 0xab55,
|
||||
0xcd55, 0xb2aa, 0xd2aa, 0xad55, 0xcaaa, 0xb555, 0xd555, 0xaaaa
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -723,65 +735,69 @@ static const u16_t spdif_bmclookup[256] = { //biphase mark encoded values (least
|
||||
The I2S interface must output first the B/M/W preamble which means that second
|
||||
32 bits words must be first and so must be marked right channel.
|
||||
*/
|
||||
static void IRAM_ATTR spdif_convert(ISAMPLE_T *src, size_t frames, u32_t *dst, size_t *count) {
|
||||
register u16_t hi, lo, aux;
|
||||
size_t cnt = *count;
|
||||
|
||||
static void IRAM_ATTR spdif_convert(ISAMPLE_T *src, size_t frames, u32_t *dst) {
|
||||
static u8_t vu, count;
|
||||
register u16_t hi, lo;
|
||||
#if BYTES_PER_FRAME == 8
|
||||
register u16_t aux;
|
||||
#endif
|
||||
|
||||
// we assume frame == 0 as well...
|
||||
if (!src) {
|
||||
count = 0;
|
||||
vu = VUCP24[0];
|
||||
}
|
||||
|
||||
while (frames--) {
|
||||
// start with left channel
|
||||
#if BYTES_PER_FRAME == 4
|
||||
hi = spdif_bmclookup[(u8_t)(*src >> 8)];
|
||||
lo = spdif_bmclookup[(u8_t) *src++];
|
||||
|
||||
// invert if last preceeding bit is 1
|
||||
lo ^= ~((s16_t)hi) >> 16;
|
||||
// first 16 bits
|
||||
aux = 0xb333 ^ (((u32_t)((s16_t)lo)) >> 17);
|
||||
#else
|
||||
hi = spdif_bmclookup[(u8_t)(*src >> 24)];
|
||||
lo = spdif_bmclookup[(u8_t)(*src >> 16)];
|
||||
|
||||
// invert if last preceeding bit is 1
|
||||
lo ^= ~((s16_t)hi) >> 16;
|
||||
// first 16 bits
|
||||
// we use 20 bits samples as we need to force parity
|
||||
aux = spdif_bmclookup[(u8_t)(*src++ >> 12)];
|
||||
aux = (u8_t) (aux ^ (~((s16_t)lo) >> 16));
|
||||
aux |= (0xb3 ^ (((u16_t)((s8_t)aux)) >> 9)) << 8;
|
||||
#endif
|
||||
|
||||
// set special preamble every 192 iteration
|
||||
if (++cnt > 191) {
|
||||
*dst++ = VUCP | (PREAMBLE_B << 16 ) | aux; //special preamble for one of 192 frames
|
||||
cnt = 0;
|
||||
hi = spdif_bmclookup[(u8_t)(*src >> 8)];
|
||||
lo = spdif_bmclookup[(u8_t)*src++];
|
||||
if (lo & 1) hi = ~hi;
|
||||
|
||||
if (!count--) {
|
||||
*dst++ = (vu << 24) | (PREAMBLE_B << 16) | 0xCCCC;
|
||||
count = 191;
|
||||
} else {
|
||||
*dst++ = VUCP | (PREAMBLE_M << 16) | aux;
|
||||
}
|
||||
// now write sample's 16 low bits
|
||||
*dst++ = ((u32_t)lo << 16) | hi;
|
||||
*dst++ = (vu << 24) | (PREAMBLE_M << 16) | 0xCCCC;
|
||||
}
|
||||
#else
|
||||
hi = spdif_bmclookup[(u8_t)(*src >> 24)];
|
||||
lo = spdif_bmclookup[(u8_t)(*src >> 16)];
|
||||
aux = spdif_bmclookup[(u8_t)(*src++ >> 8)];
|
||||
if (aux & 1) lo = ~lo;
|
||||
if (lo & 1) hi = ~hi;
|
||||
|
||||
|
||||
if (!count--) {
|
||||
*dst++ = (vu << 24) | (PREAMBLE_B << 16) | aux;
|
||||
count = 191;
|
||||
} else {
|
||||
*dst++ = (vu << 24) | (PREAMBLE_M << 16) | aux;
|
||||
}
|
||||
#endif
|
||||
|
||||
vu = VUCP24[hi & 1];
|
||||
*dst++ = ((u32_t)lo << 16) | hi;
|
||||
|
||||
// then do right channel, no need to check PREAMBLE_B
|
||||
#if BYTES_PER_FRAME == 4
|
||||
hi = spdif_bmclookup[(u8_t)(*src >> 8)];
|
||||
lo = spdif_bmclookup[(u8_t) *src++];
|
||||
lo ^= ~((s16_t)hi) >> 16;
|
||||
aux = 0xb333 ^ (((u32_t)((s16_t)lo)) >> 17);
|
||||
hi = spdif_bmclookup[(u8_t)(*src >> 8)];
|
||||
lo = spdif_bmclookup[(u8_t)*src++];
|
||||
if (lo & 1) hi = ~hi;
|
||||
|
||||
*dst++ = (vu << 24) | (PREAMBLE_W << 16) | 0xCCCC;
|
||||
#else
|
||||
hi = spdif_bmclookup[(u8_t)(*src >> 24)];
|
||||
lo = spdif_bmclookup[(u8_t)(*src >> 16)];
|
||||
lo ^= ~((s16_t)hi) >> 16;
|
||||
aux = spdif_bmclookup[(u8_t)(*src++ >> 12)];
|
||||
aux = (u8_t) (aux ^ (~((s16_t)lo) >> 16));
|
||||
aux |= (0xb3 ^ (((u16_t)((s8_t)aux)) >> 9)) << 8;
|
||||
#endif
|
||||
*dst++ = VUCP | (PREAMBLE_W << 16) | aux;
|
||||
*dst++ = ((u32_t)lo << 16) | hi;
|
||||
hi = spdif_bmclookup[(u8_t)(*src >> 24)];
|
||||
lo = spdif_bmclookup[(u8_t)(*src >> 16)];
|
||||
aux = spdif_bmclookup[(u8_t)(*src++ >> 8)];
|
||||
if (aux & 1) lo = ~lo;
|
||||
if (lo & 1) hi = ~hi;
|
||||
|
||||
*dst++ = (vu << 24) | (PREAMBLE_W << 16) | aux;
|
||||
#endif
|
||||
|
||||
vu = VUCP24[hi & 1];
|
||||
*dst++ = ((u32_t)lo << 16) | hi;
|
||||
}
|
||||
|
||||
*count = cnt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -441,6 +441,10 @@ static void process_aude(u8_t *pkt, int len) {
|
||||
struct aude_packet *aude = (struct aude_packet *)pkt;
|
||||
|
||||
LOG_DEBUG("enable spdif: %d dac: %d", aude->enable_spdif, aude->enable_dac);
|
||||
|
||||
#if EMBEDDED
|
||||
powering(aude->enable_spdif),
|
||||
#endif
|
||||
|
||||
LOCK_O;
|
||||
if (!aude->enable_spdif && output.state != OUTPUT_OFF) {
|
||||
|
||||
@@ -72,6 +72,13 @@ static struct vorbis {
|
||||
// vorbis symbols to be dynamically loaded - from either vorbisfile or vorbisidec (tremor) version of library
|
||||
vorbis_info *(* ov_info)(OggVorbis_File *vf, int link);
|
||||
int (* ov_clear)(OggVorbis_File *vf);
|
||||
void (* ov_info_init)(vorbis_info* vi);
|
||||
void (* ov_info_clear)(vorbis_info* vi);
|
||||
void (* ov_comment_init)(vorbis_comment* vc);
|
||||
void (* ov_comment_clear(vorbis_comment *vc);
|
||||
int (* ov_block_init)(vorbis_dsp_state* v, vorbis_block* vb);
|
||||
int (* ov_block_clear)(vorbis_block* vb);
|
||||
void (* ov_vorbis_dsp_clear)(vorbis_dsp_state* v);
|
||||
long (* ov_read)(OggVorbis_File *vf, char *buffer, int length, int bigendianp, int word, int sgned, int *bitstream);
|
||||
long (* ov_read_tremor)(OggVorbis_File *vf, char *buffer, int length, int *bitstream);
|
||||
int (* ov_open_callbacks)(void *datasource, OggVorbis_File *vf, const char *initial, long ibytes, ov_callbacks callbacks);
|
||||
@@ -396,33 +403,32 @@ static decode_state vorbis_decode(void) {
|
||||
}
|
||||
|
||||
static void vorbis_open(u8_t size, u8_t rate, u8_t chan, u8_t endianness) {
|
||||
LOG_INFO("OPENING CODEC");
|
||||
if (v->opened) {
|
||||
OV(&go, block_clear, &v->block);
|
||||
OV(&go, info_clear, &v->info);
|
||||
OV(&go, dsp_clear, &v->decoder);
|
||||
OV(&gv, block_clear, &v->block);
|
||||
OV(&gv, dsp_clear, &v->decoder);
|
||||
OV(&gv, info_clear, &v->info);
|
||||
}
|
||||
|
||||
v->opened = false;
|
||||
v->status = OGG_SYNC;
|
||||
v->overflow = 0;
|
||||
|
||||
OG(&gu, sync_clear, &v->sync);
|
||||
OG(&gu, stream_clear, &v->state);
|
||||
OG(&gu, stream_init, &v->state, -1);
|
||||
|
||||
OG(&go, stream_clear, &v->state);
|
||||
OG(&go, sync_clear, &v->sync);
|
||||
OG(&go, stream_init, &v->state, -1);
|
||||
}
|
||||
|
||||
static void vorbis_close() {
|
||||
return;
|
||||
LOG_INFO("CLOSING CODEC");
|
||||
if (v->opened) {
|
||||
OV(&go, block_clear, &v->block);
|
||||
OV(&go, info_clear, &v->info);
|
||||
OV(&go, dsp_clear, &v->decoder);
|
||||
OV(&gv, block_clear, &v->block);
|
||||
OV(&gv, dsp_clear, &v->decoder);
|
||||
// info must be last otherwise there is memory leak (where is it said... nowhere)
|
||||
OV(&gv, info_clear, &v->info);
|
||||
// we don' t have comments to free
|
||||
}
|
||||
|
||||
v->opened = false;
|
||||
|
||||
|
||||
OG(&go, stream_clear, &v->state);
|
||||
OG(&go, sync_clear, &v->sync);
|
||||
}
|
||||
@@ -469,6 +475,11 @@ static bool load_vorbis() {
|
||||
v_handle.ov_read = dlsym(handle, "ov_read");
|
||||
v_handle.ov_info = dlsym(handle, "ov_info");
|
||||
v_handle.ov_clear = dlsym(handle, "ov_clear");
|
||||
v.handle.ov_info_clear = dlsym(gv.handle, "vorbis_info_clear");
|
||||
v.handle.ov_comment_init = dlsym(gv.handle, "vorbis_comment_init");
|
||||
v.handle.ov_comment_clear = dlsym(gv.handle, "vorbis_comment_clear");
|
||||
v.handle.ov_block_init = dlsym(gv.handle, "vorbis_block_init");
|
||||
v.handle.ov_block_clear = dlsym(gv.handle, "vorbis_block_clear");
|
||||
v_handle.ov_open_callbacks = dlsym(handle, "ov_open_callbacks");
|
||||
|
||||
if ((err = dlerror()) != NULL) {
|
||||
|
||||
@@ -48,8 +48,8 @@ void ws2812_write_leds(struct led_state new_state);
|
||||
|
||||
static const char TAG[] = "muse";
|
||||
|
||||
static void (*battery_handler_chain)(float value);
|
||||
static void battery_svc(float value);
|
||||
static void (*battery_handler_chain)(float value, int cells);
|
||||
static void battery_svc(float value, int cells);
|
||||
static bool init(void);
|
||||
static void set_battery_led(float value);
|
||||
|
||||
@@ -81,11 +81,11 @@ static void set_battery_led(float value) {
|
||||
ws2812_write_leds(new_state);
|
||||
}
|
||||
|
||||
static void battery_svc(float value) {
|
||||
static void battery_svc(float value, int cells) {
|
||||
set_battery_led(value);
|
||||
ESP_LOGI(TAG, "Called for battery service with %f", value);
|
||||
|
||||
if (battery_handler_chain) battery_handler_chain(value);
|
||||
if (battery_handler_chain) battery_handler_chain(value, cells);
|
||||
}
|
||||
|
||||
// This is the buffer which the hw peripheral will access while pulsing the output pin
|
||||
@@ -95,7 +95,7 @@ void setup_rmt_data_buffer(struct led_state new_state);
|
||||
|
||||
void ws2812_control_init(void)
|
||||
{
|
||||
rmt_channel = rmt_system_base_channel++;
|
||||
rmt_channel = RMT_NEXT_TX_CHANNEL();
|
||||
rmt_config_t config;
|
||||
config.rmt_mode = RMT_MODE_TX;
|
||||
config.channel = rmt_channel;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* (c) Philippe G. 20201, philippe_44@outlook.com
|
||||
* see other copyrights below
|
||||
*
|
||||
@@ -20,6 +20,10 @@
|
||||
#include "esp_log.h"
|
||||
#include "tools.h"
|
||||
|
||||
#if CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS < 2
|
||||
#error CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS must be at least 2
|
||||
#endif
|
||||
|
||||
const static char TAG[] = "tools";
|
||||
|
||||
/****************************************************************************************
|
||||
@@ -104,11 +108,11 @@ static uint8_t UNICODEtoCP1252(uint16_t chr) {
|
||||
void utf8_decode(char *src) {
|
||||
uint32_t codep = 0, state = UTF8_ACCEPT;
|
||||
char *dst = src;
|
||||
|
||||
|
||||
while (src && *src) {
|
||||
if (!decode(&state, &codep, *src++)) *dst++ = UNICODEtoCP1252(codep);
|
||||
}
|
||||
|
||||
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
@@ -178,12 +182,61 @@ char * strdup_psram(const char * source){
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* URL download
|
||||
* Task manager
|
||||
*/
|
||||
|
||||
#define TASK_TLS_INDEX 1
|
||||
|
||||
typedef struct {
|
||||
StaticTask_t *xTaskBuffer;
|
||||
StackType_t *xStack;
|
||||
} task_context_t;
|
||||
|
||||
static void task_cleanup(int index, task_context_t *context) {
|
||||
free(context->xTaskBuffer);
|
||||
free(context->xStack);
|
||||
free(context);
|
||||
}
|
||||
|
||||
BaseType_t xTaskCreateEXTRAM( TaskFunction_t pvTaskCode,
|
||||
const char * const pcName,
|
||||
configSTACK_DEPTH_TYPE usStackDepth,
|
||||
void *pvParameters,
|
||||
UBaseType_t uxPriority,
|
||||
TaskHandle_t *pxCreatedTask) {
|
||||
// create the worker task as a static
|
||||
task_context_t *context = calloc(1, sizeof(task_context_t));
|
||||
context->xTaskBuffer = (StaticTask_t*) heap_caps_malloc(sizeof(StaticTask_t), (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT));
|
||||
context->xStack = heap_caps_malloc(usStackDepth,(MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT));
|
||||
TaskHandle_t handle = xTaskCreateStatic(pvTaskCode, pcName, usStackDepth, pvParameters, uxPriority, context->xStack, context->xTaskBuffer);
|
||||
|
||||
// store context in TCB or free everything in case of failure
|
||||
if (!handle) {
|
||||
free(context->xTaskBuffer);
|
||||
free(context->xStack);
|
||||
free(context);
|
||||
} else {
|
||||
vTaskSetThreadLocalStoragePointerAndDelCallback( handle, TASK_TLS_INDEX, context, (TlsDeleteCallbackFunction_t) task_cleanup);
|
||||
}
|
||||
|
||||
if (pxCreatedTask) *pxCreatedTask = handle;
|
||||
return handle != NULL ? pdPASS : pdFAIL;
|
||||
}
|
||||
|
||||
void vTaskDeleteEXTRAM(TaskHandle_t xTask) {
|
||||
/* At this point we leverage FreeRTOS extension to have callbacks on task deletion.
|
||||
* If not, we need to have here our own deletion implementation that include delayed
|
||||
* free for when this is called with NULL (self-deletion)
|
||||
*/
|
||||
vTaskDelete(xTask);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* URL download
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
void *user_context;
|
||||
http_download_cb_t callback;
|
||||
http_download_cb_t callback;
|
||||
size_t max, bytes;
|
||||
bool abort;
|
||||
uint8_t *data;
|
||||
@@ -192,22 +245,22 @@ typedef struct {
|
||||
|
||||
static void http_downloader(void *arg);
|
||||
static esp_err_t http_event_handler(esp_http_client_event_t *evt);
|
||||
|
||||
|
||||
void http_download(char *url, size_t max, http_download_cb_t callback, void *context) {
|
||||
http_context_t *http_context = (http_context_t*) heap_caps_calloc(sizeof(http_context_t), 1, MALLOC_CAP_SPIRAM);
|
||||
|
||||
|
||||
esp_http_client_config_t config = {
|
||||
.url = url,
|
||||
.event_handler = http_event_handler,
|
||||
.user_data = http_context,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
http_context->callback = callback;
|
||||
http_context->user_context = context;
|
||||
http_context->max = max;
|
||||
http_context->client = esp_http_client_init(&config);
|
||||
|
||||
xTaskCreate(http_downloader, "downloader", 4*1024, http_context, ESP_TASK_PRIO_MIN + 1, NULL);
|
||||
|
||||
xTaskCreateEXTRAM(http_downloader, "downloader", 8*1024, http_context, ESP_TASK_PRIO_MIN + 1, NULL);
|
||||
}
|
||||
|
||||
static void http_downloader(void *arg) {
|
||||
@@ -215,14 +268,14 @@ static void http_downloader(void *arg) {
|
||||
|
||||
esp_http_client_perform(http_context->client);
|
||||
esp_http_client_cleanup(http_context->client);
|
||||
|
||||
|
||||
free(http_context);
|
||||
vTaskDelete(NULL);
|
||||
vTaskDeleteEXTRAM(NULL);
|
||||
}
|
||||
|
||||
static esp_err_t http_event_handler(esp_http_client_event_t *evt) {
|
||||
http_context_t *http_context = (http_context_t*) evt->user_data;
|
||||
|
||||
|
||||
if (http_context->abort) return ESP_FAIL;
|
||||
|
||||
switch(evt->event_id) {
|
||||
@@ -234,42 +287,42 @@ static esp_err_t http_event_handler(esp_http_client_event_t *evt) {
|
||||
if (!strcasecmp(evt->header_key, "Content-Length")) {
|
||||
size_t len = atoi(evt->header_value);
|
||||
if (!len || len > http_context->max) {
|
||||
ESP_LOGI(TAG, "content-length null or too large %zu / %zu", len, http_context->max);
|
||||
ESP_LOGI(TAG, "content-length null or too large %zu / %zu", len, http_context->max);
|
||||
http_context->abort = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case HTTP_EVENT_ON_DATA: {
|
||||
size_t len = esp_http_client_get_content_length(evt->client);
|
||||
if (!http_context->data) {
|
||||
if ((http_context->data = (uint8_t*) malloc(len)) == NULL) {
|
||||
http_context->abort = true;
|
||||
ESP_LOGE(TAG, "gailed to allocate memory for output buffer %zu", len);
|
||||
ESP_LOGE(TAG, "failed to allocate memory for output buffer %zu", len);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
memcpy(http_context->data + http_context->bytes, evt->data, evt->data_len);
|
||||
http_context->bytes += evt->data_len;
|
||||
break;
|
||||
}
|
||||
}
|
||||
case HTTP_EVENT_ON_FINISH:
|
||||
http_context->callback(http_context->data, http_context->bytes, http_context->user_context);
|
||||
http_context->callback(http_context->data, http_context->bytes, http_context->user_context);
|
||||
break;
|
||||
case HTTP_EVENT_DISCONNECTED: {
|
||||
int mbedtls_err = 0;
|
||||
esp_err_t err = esp_tls_get_and_clear_last_error(evt->data, &mbedtls_err, NULL);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "HTTP download disconnect %d", err);
|
||||
ESP_LOGE(TAG, "HTTP download disconnect %d", err);
|
||||
if (http_context->data) free(http_context->data);
|
||||
http_context->callback(NULL, 0, http_context->user_context);
|
||||
http_context->callback(NULL, 0, http_context->user_context);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -56,6 +56,18 @@ const char* str_or_null(const char * str);
|
||||
typedef void (*http_download_cb_t)(uint8_t* data, size_t len, void *context);
|
||||
void http_download(char *url, size_t max, http_download_cb_t callback, void *context);
|
||||
|
||||
/* Use these to dynamically create tasks whose stack is on EXTRAM. Be aware that it
|
||||
* requires configNUM_THREAD_LOCAL_STORAGE_POINTERS to bet set to 2 at least (index 0
|
||||
* is used by pthread and this uses index 1, obviously
|
||||
*/
|
||||
BaseType_t xTaskCreateEXTRAM( TaskFunction_t pvTaskCode,
|
||||
const char * const pcName,
|
||||
configSTACK_DEPTH_TYPE usStackDepth,
|
||||
void *pvParameters,
|
||||
UBaseType_t uxPriority,
|
||||
TaskHandle_t *pxCreatedTask);
|
||||
void vTaskDeleteEXTRAM(TaskHandle_t xTask);
|
||||
|
||||
extern const char unknown_string_placeholder[];
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
6
components/wifi-manager/webapp/dist/css/index.1ab179394339385e0a02.css
vendored
Normal file
6
components/wifi-manager/webapp/dist/css/index.1ab179394339385e0a02.css
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
components/wifi-manager/webapp/dist/css/index.1ab179394339385e0a02.css.gz
vendored
Normal file
BIN
components/wifi-manager/webapp/dist/css/index.1ab179394339385e0a02.css.gz
vendored
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
BIN
components/wifi-manager/webapp/dist/index.html.gz
vendored
BIN
components/wifi-manager/webapp/dist/index.html.gz
vendored
Binary file not shown.
File diff suppressed because one or more lines are too long
Binary file not shown.
File diff suppressed because one or more lines are too long
2
components/wifi-manager/webapp/dist/js/index.e0b953.bundle.js
vendored
Normal file
2
components/wifi-manager/webapp/dist/js/index.e0b953.bundle.js
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
components/wifi-manager/webapp/dist/js/index.e0b953.bundle.js.gz
vendored
Normal file
BIN
components/wifi-manager/webapp/dist/js/index.e0b953.bundle.js.gz
vendored
Normal file
Binary file not shown.
1
components/wifi-manager/webapp/dist/js/index.e0b953.bundle.js.map
vendored
Normal file
1
components/wifi-manager/webapp/dist/js/index.e0b953.bundle.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user