embedded.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Squeezelite for esp32
  3. *
  4. * (c) Sebastien 2019
  5. * Philippe G. 2019, philippe_44@outlook.com
  6. *
  7. * This software is released under the MIT License.
  8. * https://opensource.org/licenses/MIT
  9. *
  10. */
  11. #include "squeezelite.h"
  12. #include "pthread.h"
  13. #include "esp_pthread.h"
  14. #include "esp_system.h"
  15. #include "esp_timer.h"
  16. #include "esp_wifi.h"
  17. #include "monitor.h"
  18. mutex_type slimp_mutex;
  19. void get_mac(u8_t mac[]) {
  20. esp_read_mac(mac, ESP_MAC_WIFI_STA);
  21. }
  22. _sig_func_ptr signal(int sig, _sig_func_ptr func) {
  23. return NULL;
  24. }
  25. void *audio_calloc(size_t nmemb, size_t size) {
  26. return calloc(nmemb, size);
  27. }
  28. int pthread_create_name(pthread_t *thread, _CONST pthread_attr_t *attr,
  29. void *(*start_routine)( void * ), void *arg, char *name) {
  30. esp_pthread_cfg_t cfg = esp_pthread_get_default_config();
  31. cfg.thread_name = name;
  32. cfg.inherit_cfg = true;
  33. esp_pthread_set_cfg(&cfg);
  34. return pthread_create(thread, attr, start_routine, arg);
  35. }
  36. uint32_t _gettime_ms_(void) {
  37. return (uint32_t) (esp_timer_get_time() / 1000);
  38. }
  39. extern void sb_controls_init(void);
  40. extern bool sb_display_init(void);
  41. u8_t custom_player_id = 12;
  42. void embedded_init(void) {
  43. mutex_create(slimp_mutex);
  44. sb_controls_init();
  45. if (sb_display_init()) custom_player_id = 100;
  46. }
  47. u16_t get_RSSI(void) {
  48. wifi_ap_record_t wifidata;
  49. esp_wifi_sta_get_ap_info(&wifidata);
  50. // we'll assume dBm, -30 to -100
  51. if (wifidata.primary != 0) return 100 + wifidata.rssi + 30;
  52. else return 0xffff;
  53. }
  54. u16_t get_plugged(void) {
  55. return jack_inserted_svc() ? PLUG_HEADPHONE : 0;
  56. }
  57. u8_t get_battery(void) {
  58. return (battery_level_svc() * 16) / 100;
  59. }