embedded.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Squeezelite for esp32
  3. *
  4. * (c) Sebastien 2019
  5. * Philippe G. 2019, philippe_44@outlook.com
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #include "squeezelite.h"
  22. #include "pthread.h"
  23. #include "esp_pthread.h"
  24. #include "esp_system.h"
  25. #include "esp_timer.h"
  26. #include "esp_wifi.h"
  27. void get_mac(u8_t mac[]) {
  28. esp_read_mac(mac, ESP_MAC_WIFI_STA);
  29. }
  30. _sig_func_ptr signal(int sig, _sig_func_ptr func) {
  31. return NULL;
  32. }
  33. void *audio_calloc(size_t nmemb, size_t size) {
  34. return calloc(nmemb, size);
  35. }
  36. int pthread_create_name(pthread_t *thread, _CONST pthread_attr_t *attr,
  37. void *(*start_routine)( void * ), void *arg, char *name) {
  38. esp_pthread_cfg_t cfg = esp_pthread_get_default_config();
  39. cfg.thread_name = name;
  40. cfg.inherit_cfg = true;
  41. esp_pthread_set_cfg(&cfg);
  42. return pthread_create(thread, attr, start_routine, arg);
  43. }
  44. uint32_t _gettime_ms_(void) {
  45. return (uint32_t) (esp_timer_get_time() / 1000);
  46. }
  47. extern void sb_controls_init(void);
  48. extern bool sb_display_init(void);
  49. u8_t custom_player_id = 12;
  50. void embedded_init(void) {
  51. sb_controls_init();
  52. if (sb_display_init()) custom_player_id = 100;
  53. }
  54. u16_t get_RSSI(void) {
  55. wifi_ap_record_t wifidata;
  56. esp_wifi_sta_get_ap_info(&wifidata);
  57. // we'll assume dBm, -30 to -100
  58. if (wifidata.primary != 0) return 100 + wifidata.rssi + 30;
  59. else return 0xffff;
  60. }