mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-01-29 22:00:54 +03:00
working buttons (LMS only)
This commit is contained in:
@@ -14,7 +14,8 @@ CFLAGS += -O3 -DLINKALL -DLOOPBACK -DNO_FAAD -DRESAMPLE16 -DEMBEDDED -DTREMOR_ON
|
||||
-I$(COMPONENT_PATH)/../codecs/inc/opus \
|
||||
-I$(COMPONENT_PATH)/../codecs/inc/opusfile \
|
||||
-I$(COMPONENT_PATH)/../driver_bt \
|
||||
-I$(COMPONENT_PATH)/../raop
|
||||
-I$(COMPONENT_PATH)/../raop \
|
||||
-I$(COMPONENT_PATH)/../audio_controls
|
||||
|
||||
# -I$(COMPONENT_PATH)/../codecs/inc/faad2
|
||||
|
||||
|
||||
127
components/squeezelite/controls.c
Normal file
127
components/squeezelite/controls.c
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* (c) Philippe G. 2019, philippe_44@outlook.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "squeezelite.h"
|
||||
#include "audio_controls.h"
|
||||
|
||||
static log_level loglevel = lINFO;
|
||||
|
||||
static in_addr_t server_ip;
|
||||
static u16_t server_hport;
|
||||
static u16_t server_cport;
|
||||
static u8_t mac[6];
|
||||
static void (*chained_notify)(in_addr_t, u16_t, u16_t);
|
||||
|
||||
static void cli_send_cmd(char *cmd);
|
||||
|
||||
static void lms_volume_up(void) {
|
||||
cli_send_cmd("button volup");
|
||||
}
|
||||
|
||||
static void lms_volume_down(void) {
|
||||
cli_send_cmd("button voldown");
|
||||
}
|
||||
|
||||
static void lms_toggle(void) {
|
||||
cli_send_cmd("pause");
|
||||
}
|
||||
|
||||
static void lms_pause(void) {
|
||||
cli_send_cmd("pause 1");
|
||||
}
|
||||
|
||||
static void lms_play(void) {
|
||||
cli_send_cmd("pause 0");
|
||||
}
|
||||
|
||||
static void lms_stop(void) {
|
||||
cli_send_cmd("button stop");
|
||||
}
|
||||
|
||||
static void lms_rew(void) {
|
||||
cli_send_cmd("button rew.repeat");
|
||||
}
|
||||
|
||||
static void lms_fwd(void) {
|
||||
cli_send_cmd("button fwd.repeat");
|
||||
}
|
||||
|
||||
static void lms_prev(void) {
|
||||
cli_send_cmd("button rew");
|
||||
}
|
||||
|
||||
static void lms_next(void) {
|
||||
cli_send_cmd("button fwd");
|
||||
}
|
||||
|
||||
static actrls_t controls = {
|
||||
lms_volume_up, lms_volume_down, // volume up, volume down
|
||||
lms_toggle, lms_play, // toggle, play
|
||||
lms_pause, lms_stop, // pause, stop
|
||||
lms_rew, lms_fwd, // rew, fwd
|
||||
lms_prev, lms_next, // prev, next
|
||||
};
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
static void cli_send_cmd(char *cmd) {
|
||||
char packet[64];
|
||||
struct sockaddr_in addr;
|
||||
socklen_t addrlen = sizeof(addr);
|
||||
int len, sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_addr.s_addr = server_ip;
|
||||
addr.sin_port = htons(server_cport);
|
||||
|
||||
if (connect(sock, (struct sockaddr *) &addr, addrlen) < 0) {
|
||||
LOG_ERROR("unable to connect to server %s:%hu with cli", inet_ntoa(server_ip), server_cport);
|
||||
return;
|
||||
}
|
||||
|
||||
len = sprintf(packet, "%02x:%02x:%02x:%02x:%02x:%02x %s\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], cmd);
|
||||
LOG_DEBUG("sending command %s at %s:%hu", packet, inet_ntoa(server_ip), server_cport);
|
||||
|
||||
if (send(sock, packet, len, 0) < 0) {
|
||||
LOG_WARN("cannot send CLI %s", packet);
|
||||
}
|
||||
|
||||
close(sock);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Notification when server changes
|
||||
*/
|
||||
static void notify(in_addr_t ip, u16_t hport, u16_t cport) {
|
||||
server_ip = ip;
|
||||
server_hport = hport;
|
||||
server_cport = cport;
|
||||
LOG_INFO("notified server %s hport %hu cport %hu", inet_ntoa(ip), hport, cport);
|
||||
if (chained_notify) (*chained_notify)(ip, hport, cport);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
* Initialize controls - shall be called once from output_init_embedded
|
||||
*/
|
||||
void cli_controls_init(void) {
|
||||
get_mac(mac);
|
||||
actrls_set_default(controls);
|
||||
chained_notify = server_notify;
|
||||
server_notify = notify;
|
||||
}
|
||||
@@ -45,5 +45,6 @@ int pthread_create_name(pthread_t *thread, _CONST pthread_attr_t *attr,
|
||||
|
||||
void register_external(void);
|
||||
void deregister_external(void);
|
||||
void (*server_notify)(in_addr_t ip, u16_t hport, u16_t cport);
|
||||
|
||||
#endif // EMBEDDED_H
|
||||
|
||||
@@ -28,18 +28,19 @@ extern struct buffer *outputbuf;
|
||||
#define LOCK mutex_lock(outputbuf->mutex)
|
||||
#define UNLOCK mutex_unlock(outputbuf->mutex)
|
||||
|
||||
// output_bt.c
|
||||
extern void output_init_bt(log_level level, char *device, unsigned output_buf_size, char *params,
|
||||
unsigned rates[], unsigned rate_delay, unsigned idle);
|
||||
extern void output_close_bt(void);
|
||||
|
||||
// output_i2s.c
|
||||
extern void output_init_i2s(log_level level, char *device, unsigned output_buf_size, char *params,
|
||||
unsigned rates[], unsigned rate_delay, unsigned idle);
|
||||
extern bool output_volume_i2s(unsigned left, unsigned right);
|
||||
extern void output_close_i2s(void);
|
||||
|
||||
#ifdef CONFIG_BT_SINK
|
||||
extern void decode_bt_init(void);
|
||||
#endif
|
||||
// controls.c
|
||||
extern void cli_controls_init(void);
|
||||
|
||||
static log_level loglevel;
|
||||
|
||||
@@ -56,6 +57,8 @@ void output_init_embedded(log_level level, char *device, unsigned output_buf_siz
|
||||
output.start_frames = FRAME_BLOCK;
|
||||
output.rate_delay = rate_delay;
|
||||
|
||||
cli_controls_init();
|
||||
|
||||
if (strcasestr(device, "BT ")) {
|
||||
LOG_INFO("init Bluetooth");
|
||||
close_cb = &output_close_bt;
|
||||
|
||||
@@ -583,6 +583,7 @@ static void *output_thread_i2s() {
|
||||
* Stats output thread
|
||||
*/
|
||||
static void *output_thread_i2s_stats() {
|
||||
int memory_count = 0;
|
||||
|
||||
while (running) {
|
||||
#ifdef TAS57xx
|
||||
@@ -617,11 +618,14 @@ static void *output_thread_i2s_stats() {
|
||||
LOG_INFO(" ----------+----------+-----------+-----------+");
|
||||
RESET_ALL_MIN_MAX;
|
||||
}
|
||||
LOG_INFO("Heap internal:%zu (min:%zu) external:%zu (min:%zu)",
|
||||
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
|
||||
if (loglevel == lDEBUG || !memory_count--) {
|
||||
LOG_INFO("Heap internal:%zu (min:%zu) external:%zu (min:%zu)",
|
||||
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
|
||||
memory_count = (60*1000) / STATS_PERIOD_MS;
|
||||
}
|
||||
usleep(STATS_PERIOD_MS *1000);
|
||||
}
|
||||
return NULL;
|
||||
|
||||
@@ -43,6 +43,8 @@ static log_level loglevel;
|
||||
|
||||
static sockfd sock = -1;
|
||||
static in_addr_t slimproto_ip = 0;
|
||||
static u16_t slimproto_hport = 9000;
|
||||
static u16_t slimproto_cport = 9090;
|
||||
|
||||
extern struct buffer *streambuf;
|
||||
extern struct buffer *outputbuf;
|
||||
@@ -768,16 +770,17 @@ void wake_controller(void) {
|
||||
in_addr_t discover_server(char *default_server) {
|
||||
struct sockaddr_in d;
|
||||
struct sockaddr_in s;
|
||||
char *buf;
|
||||
char buf[32], port_d[] = "JSON", clip_d[] = "CLIP";
|
||||
struct pollfd pollinfo;
|
||||
unsigned port;
|
||||
u8_t len;
|
||||
|
||||
int disc_sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
socklen_t enable = 1;
|
||||
setsockopt(disc_sock, SOL_SOCKET, SO_BROADCAST, (const void *)&enable, sizeof(enable));
|
||||
|
||||
buf = "e";
|
||||
len = sprintf(buf,"e%s%c%s", port_d, '\0', clip_d) + 1;
|
||||
|
||||
memset(&d, 0, sizeof(d));
|
||||
d.sin_family = AF_INET;
|
||||
@@ -792,15 +795,26 @@ in_addr_t discover_server(char *default_server) {
|
||||
LOG_INFO("sending discovery");
|
||||
memset(&s, 0, sizeof(s));
|
||||
|
||||
if (sendto(disc_sock, buf, 1, 0, (struct sockaddr *)&d, sizeof(d)) < 0) {
|
||||
if (sendto(disc_sock, buf, len, 0, (struct sockaddr *)&d, sizeof(d)) < 0) {
|
||||
LOG_INFO("error sending disovery");
|
||||
}
|
||||
|
||||
if (poll(&pollinfo, 1, 5000) == 1) {
|
||||
char readbuf[10];
|
||||
char readbuf[32], *p;
|
||||
socklen_t slen = sizeof(s);
|
||||
recvfrom(disc_sock, readbuf, 10, 0, (struct sockaddr *)&s, &slen);
|
||||
memset(readbuf, 0, 32);
|
||||
recvfrom(disc_sock, readbuf, 32 - 1, 0, (struct sockaddr *)&s, &slen);
|
||||
LOG_INFO("got response from: %s:%d", inet_ntoa(s.sin_addr), ntohs(s.sin_port));
|
||||
|
||||
if ((p = strstr(readbuf, port_d)) != NULL) {
|
||||
p += strlen(port_d);
|
||||
slimproto_hport = atoi(p + 1);
|
||||
}
|
||||
|
||||
if ((p = strstr(readbuf, clip_d)) != NULL) {
|
||||
p += strlen(clip_d);
|
||||
slimproto_cport = atoi(p + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (default_server) {
|
||||
@@ -951,6 +965,10 @@ void slimproto(log_level level, char *server, u8_t mac[6], const char *name, con
|
||||
|
||||
sendHELO(reconnect, fixed_cap, var_cap, mac);
|
||||
|
||||
#if EMBEDDED
|
||||
if (server_notify) (*server_notify)(slimproto_ip, slimproto_hport, slimproto_cport);
|
||||
#endif
|
||||
|
||||
slimproto_run();
|
||||
|
||||
if (!reconnect) {
|
||||
|
||||
@@ -282,10 +282,6 @@
|
||||
#include <limits.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if EMBEDDED
|
||||
#include "embedded.h"
|
||||
#endif
|
||||
|
||||
#if LINUX || OSX || FREEBSD || EMBEDDED
|
||||
#include <unistd.h>
|
||||
#include <stdbool.h>
|
||||
@@ -391,6 +387,10 @@ typedef BOOL bool;
|
||||
|
||||
#endif
|
||||
|
||||
#if EMBEDDED
|
||||
#include "embedded.h"
|
||||
#endif
|
||||
|
||||
#if !defined(MSG_NOSIGNAL)
|
||||
#define MSG_NOSIGNAL 0
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user