From: Nils Date: Mon, 11 Oct 2021 22:10:15 +0000 (+0200) Subject: Some changes X-Git-Url: https://gitweb.forssennils.se/?a=commitdiff_plain;h=a64b79a726008a6e1ae5518ed8f524e42545c126;p=Audiolib.git Some changes --- diff --git a/.gitignore b/.gitignore index c795b05..d963f57 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -build \ No newline at end of file +build +.vscode/* diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 72cf943..85b1042 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -21,8 +21,8 @@ "${workspaceFolder}" ], "limitSymbolsToIncludedHeaders": false - }, - "compileCommands": "${workspaceFolder}/build/compile_commands.json" + } + //"compileCommands": "${workspaceFolder}/build/compile_commands.json" } ], "version": 4 diff --git a/.vscode/settings.json b/.vscode/settings.json index f974680..7ccfcbd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,6 +13,7 @@ "files.associations": { "chrono": "cpp", "random": "cpp", - "limits": "cpp" + "limits": "cpp", + "bt_font.c": "cpp" } } diff --git a/main/BT_font.c b/main/BT_font.c new file mode 100644 index 0000000..b72aa82 --- /dev/null +++ b/main/BT_font.c @@ -0,0 +1,73 @@ +#include "u8g2.h" + + +/* + Fontname: BT_FONT + Copyright: Created with Fony 1.4.0.2 + Glyphs: 224/256 + BBX Build Mode: 0 +*/ +const uint8_t BT_FONT[1976] U8G2_FONT_SECTION("BT_FONT") = + "\340\0\3\3\4\5\3\5\5\10\20\0\0\17\0\17\0\1\206\3^\7\233 \5\0\10\61!\10\362\16" + "\61>\4\11\42\10\65\314\61$,\2#\5\0\10\61$\5\0\10\61%\5\0\10\61&\22\366\12q" + "(\207\20O!\12\223D\251\24\261L\2'\6\62\316\61\14(\13\364\12\261$\26\221\376\264$)\14" + "\364\16\61DK\372\27\213\10\0*\5\0\10\61+\5\0\10\61,\11C\16q$\24\11\0-\7$" + "\134\61\16\1.\6\42\16\61\10/\17\366\12\61\265\11\325\204jB\65\241\42\0\60\20\366\12\261d\244" + "\134D\374$\11e\242\211\0\61\12\365\12q&l\372\237\10\62\21\366\12\61H\305\241\332LQ\66\23" + "\312\204\207\2\63\21\366\12\61H\65\242\332\204D\34j\223TH\0\64\22\367\12\261h$\211H\242$" + "\21I\16G\251\276\0\65\20\366\12\61\36\65VLD\22\251\42)M\0\66\21\366\12\261(\25\231P" + "c\345\20\342t\210P\0\67\21\366\12\61\16E\65\241\232PM(\233\11\205\0\70\21\366\12q(\207" + "\20'\11\345\20\342\351\20\241\0\71\22\366\12q(\207\20\247C\244\250\66\223MH\63\0:\7b." + "\61\210\4;\13\203\34q\324\1\22\212\4\0<\17\366\12\61\265\11\325\204jB\65\241\42\0=\17\366" + "\12\61\265\11\325\204jB\65\241\42\0>\17\366\12\61\265\11\325\204jB\65\241\42\0\77\23\366\12q" + "(\207\20I\250&\224\315\204r$\241\10\0@\17\366\12\61\265\11\325\204jB\65\241\42\0A\17\366" + "\12\261d$\312\341D:\34D|\22B\22\366\12qd\244\212\376B\252HJL\207\10\5\0C\20" + "\366\12\261F\207\10m\250\337(\222\322\4\0D\17\366\12qF\25-%\376R\221\224F\0E\16\366" + "\12q\16F\35+\25\241FK\1F\15\366\12q\16F\35+\25\241\36\1G\21\366\12\261F\207\10" + "m\250\227\22\251\42)M\0H\14\366\12\61D\374t\70\210\370$I\12\364\14\61(\42\375_\10J" + "\15\366\12\361\206\372G\22\351\20\241\0K\21\366\12\61d#\26-$\322l\215D\222\350$L\12\366" + "\12\61\204\372\77Z\12M\15\366\12\61\202#\322\341E\37\365\30N\21\366\12\61\202\263\31\211I\242S" + "D\304\266\61\0O\15\366\12\261d\24\21\377\223\204&\2P\20\366\12\61H\25I\211\345\20!\11\365" + "\21\0Q\17\366\12\261d\224C\210\177\221XJ\21\1R\23\366\12\61H\25I\211\345\20!\315H$" + "\211N$\1S\22\366\12q(\7\11QH#\16\205$\322\341B\1T\13\366\12\61\16%\241\376O" + "\0U\14\366\12\61D\374\237\16\27\12\0V\16\366\12\61D\374\323!Bb\23\212\0W\22\370\10\61" + "\204|\221P$\24\311\341i\42\322/\0X\20\366\12\61D\234$$\232P\215D\21q\22Y\15\366" + "\12\61D|:DhB}\2Z\21\366\12\61\16E\65\241\60\250&\224\11\205\207\2[\17\366\12\61" + "\265\11\325\204jB\65\241\42\0\134\17\366\12\61\265\11\325\204jB\65\241\42\0]\17\366\12\61\265\11" + "\325\204jB\65\241\42\0^\17\366\12\61\265\11\325\204jB\65\241\42\0_\17\366\12\61\265\11\325\204" + "jB\65\241\42\0`\17\366\12\61\265\11\325\204jB\65\241\42\0a\20\207\12q*\26\221D$\21" + "ID\222\213\1b\16\366\12\61\204\372X\71\204\70\35,\0c\14\206\12q(\207\330P\355B\1d" + "\14\366\12\61\365\313\301\304\351\20)e\14\206\12q\16\266\311!\62\263\24f\17\366\12q(\207\333P" + "\261R\21\352\21\0g\21\266\12q(\207\20\351\20)\316H\207\10\5\0h\15\366\12\61\204\372X\71" + "DJ<\11i\11\302\16\61\210\207\203\0j\17\366\12\61\325\221\204z$\221\16\21\12\0k\20\366\12" + "\61\204\272\34L\263\65\22I\242\223\0l\7\362\16\61~\20m\14\206\12\61D\244\303!\242\217\1n" + "\14\206\12\61\204\225C\244\304I\0o\14\206\12q(\207\20\247C\204\2p\17\266\12\61H\25I\211" + "\345\20!\11\25\1q\16\266\12\261(\207\10\211T\221\224\210\32r\15\206\12\61D\224C\204\64\23*" + "\2s\13\206\12q\16F\306\203\5\0t\20\267\10q\244\212\64\242T-\62\221\230(\0u\11\206\12" + "\61D|:\34v\14\206\12\61D\234\16\21\232P\4w\15\206\12\61\202*Z\16\226P\26\0x\16" + "\206\12\61D\207\10M(\243\34B\2y\20\266\12\61\202#\322!R\232\215\326fB\0z\13\206\12" + "\61\16\265\321\266C\1{\17\366\12\61\265\11\325\204jB\65\241\42\0|\17\366\12\61\265\11\325\204j" + "B\65\241\42\0}\17\366\12\61\265\11\325\204jB\65\241\42\0~\17\366\12\61\265\11\325\204jB\65" + "\241\42\0\177\32\10\11\61B\62\311l\42\23\351\42\234\212\305C\211L\244e\242\62\12\311\0\200\21\270" + "(\61\342\200i\315t\71\34\42\246\332\64\16\201\10\250\70\61\376\77\14\202\11\246:\61D\374'\1\203" + "\5\0\10\61\204\5\0\10\61\205\5\0\10\61\206\5\0\10\61\207\5\0\10\61\210\5\0\10\61\211\5\0" + "\10\61\212\5\0\10\61\213\5\0\10\61\214\5\0\10\61\215\5\0\10\61\216\5\0\10\61\217\5\0\10\61" + "\220\5\0\10\61\221\5\0\10\61\222\5\0\10\61\223\5\0\10\61\224\5\0\10\61\225\5\0\10\61\226\5" + "\0\10\61\227\5\0\10\61\230\5\0\10\61\231\5\0\10\61\232\5\0\10\61\233\5\0\10\61\234\5\0\10" + "\61\235\5\0\10\61\236\5\0\10\61\237\5\0\10\61\240\5\0\10\61\241\5\0\10\61\242\5\0\10\61\243" + "\5\0\10\61\244\5\0\10\61\245\5\0\10\61\246\5\0\10\61\247\5\0\10\61\250\5\0\10\61\251\5\0" + "\10\61\252\5\0\10\61\253\5\0\10\61\254\5\0\10\61\255\5\0\10\61\256\5\0\10\61\257\5\0\10\61" + "\260\5\0\10\61\261\5\0\10\61\262\5\0\10\61\263\5\0\10\61\264\5\0\10\61\265\5\0\10\61\266\5" + "\0\10\61\267\5\0\10\61\270\5\0\10\61\271\5\0\10\61\272\5\0\10\61\273\5\0\10\61\274\5\0\10" + "\61\275\5\0\10\61\276\5\0\10\61\277\5\0\10\61\300\5\0\10\61\301\5\0\10\61\302\5\0\10\61\303" + "\5\0\10\61\304\5\0\10\61\305\5\0\10\61\306\5\0\10\61\307\5\0\10\61\310\5\0\10\61\311\5\0" + "\10\61\312\5\0\10\61\313\5\0\10\61\314\5\0\10\61\315\5\0\10\61\316\5\0\10\61\317\5\0\10\61" + "\320\5\0\10\61\321\5\0\10\61\322\5\0\10\61\323\5\0\10\61\324\5\0\10\61\325\5\0\10\61\326\5" + "\0\10\61\327\5\0\10\61\330\5\0\10\61\331\5\0\10\61\332\5\0\10\61\333\5\0\10\61\334\5\0\10" + "\61\335\5\0\10\61\336\5\0\10\61\337\5\0\10\61\340\5\0\10\61\341\5\0\10\61\342\5\0\10\61\343" + "\5\0\10\61\344\5\0\10\61\345\5\0\10\61\346\5\0\10\61\347\5\0\10\61\350\5\0\10\61\351\5\0" + "\10\61\352\5\0\10\61\353\5\0\10\61\354\5\0\10\61\355\5\0\10\61\356\5\0\10\61\357\5\0\10\61" + "\360\5\0\10\61\361\5\0\10\61\362\5\0\10\61\363\5\0\10\61\364\5\0\10\61\365\5\0\10\61\366\5" + "\0\10\61\367\5\0\10\61\370\5\0\10\61\371\5\0\10\61\372\5\0\10\61\373\5\0\10\61\374\5\0\10" + "\61\375\5\0\10\61\376\5\0\10\61\377\5\0\10\61\0\0\0\4\377\377\0"; + diff --git a/main/BT_font.fon b/main/BT_font.fon new file mode 100644 index 0000000..1f994ea Binary files /dev/null and b/main/BT_font.fon differ diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 54f9ce8..a0b3c9e 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,2 +1,2 @@ -idf_component_register(SRCS "Peripherals.cpp" "Audiolib.cpp" "main.cpp" "u8g2_esp32_hal.cpp" +idf_component_register(SRCS "BT_font.c" "Peripherals.cpp" "Audiolib.cpp" "main.cpp" "u8g2_esp32_hal.cpp" INCLUDE_DIRS ".") \ No newline at end of file diff --git a/main/main.cpp b/main/main.cpp index 867b257..305d1a6 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -6,6 +6,30 @@ #include "u8g2.h" #include "u8g2_esp32_hal.h" #include "cstring" +#include "BT_font.c" + +enum StatusBM { + BT = 1, + PLAY = 2, + STOP = 4, + PAUSE = 8 +}; + +u8g2_t u8g2; +u8g2_esp32_hal_t u8g2_esp32_hal; + +char* titleText = (char*) ""; +char* artistText = (char*) ""; + +int displayStatus = 0; +int SCREENHEIGHT; +int SCREENWIDTH; + +void update_display(al_event_cb_t, al_event_cb_param_t*); +void draw(); + + +Audiolib Audiosource = Audiolib("HESA FREDRIK", &update_display); //void updateFilter(const uint8_t, float*, float*, CombinedChannelFilter*); Potentiometer* pot1 = new Potentiometer(ADC_UNIT_2, ADC_CHANNEL_5, 70, 1010); //65/66 -> 572/573 -> 1019 @@ -19,71 +43,13 @@ CombinedChannelFilter* highpass_filter = new CombinedChannelFilter(new Filter(LO CombinedChannelFilter* lowpass_filter = new CombinedChannelFilter(new Filter(HIGHPASS, 60, 44100, 0.75, 0), new Filter(HIGHPASS, 60, 44100, 0.75, 0)); CombinedChannelFilter* peak_filter = new CombinedChannelFilter(new Filter(PEAK, 700, 44100, 0.8, 0), new Filter(PEAK, 700, 44100, 0.8, 0)); -u8g2_t u8g2; -u8g2_uint_t displayHeight = u8g2_GetDisplayHeight(&u8g2); -u8g2_uint_t displayWidth = u8g2_GetDisplayWidth(&u8g2); - -u8g2_esp32_hal_t u8g2_esp32_hal; - -struct timeval tv_now; - -/* - Fontname: Untitledthisfon - Copyright: Created with Fony 1.4.0.2 - Glyphs: 224/256 - BBX Build Mode: 0 -*/ -const uint8_t BT_font[939] U8G2_FONT_SECTION("BT_font") = - "\340\0\3\3\4\4\1\1\5\10\17\0\0\17\0\0\0\0\204\1\20\3\216 \4\0c!\4\0c\42" - "\4\0c#\4\0c$\4\0c%\4\0c&\4\0c'\4\0c(\4\0c)\4\0c*" - "\4\0c+\4\0c,\4\0c-\4\0c.\4\0c/\4\0c\60\4\0c\61\4\0c\62" - "\4\0c\63\4\0c\64\4\0c\65\4\0c\66\4\0c\67\4\0c\70\4\0c\71\4\0c:" - "\4\0c;\4\0c<\4\0c=\4\0c>\4\0c\77\4\0c@\4\0cA\20\370\343\211" - "\245D\66\221\236,\207!\343X\34B\4\0cC\4\0cD\4\0cE\4\0cF\4\0cG" - "\4\0cH\4\0cI\4\0cJ\4\0cK\4\0cL\4\0cM\4\0cN\4\0cO" - "\4\0cP\4\0cQ\4\0cR\4\0cS\4\0cT\4\0cU\4\0cV\4\0cW" - "\4\0cX\4\0cY\4\0cZ\4\0c[\4\0c\134\4\0c]\4\0c^\4\0c_" - "\4\0c`\4\0ca\4\0cb\4\0cc\4\0cd\4\0ce\4\0cf\4\0cg" - "\4\0ch\4\0ci\4\0cj\4\0ck\4\0cl\4\0cm\4\0cn\4\0co" - "\4\0cp\4\0cq\4\0cr\4\0cs\4\0ct\4\0cu\4\0cv\4\0cw" - "\4\0cx\4\0cy\4\0cz\4\0c{\4\0c|\4\0c}\4\0c~\4\0c\177" - "\4\0c\200\4\0c\201\4\0c\202\4\0c\203\4\0c\204\4\0c\205\4\0c\206\4\0c\207" - "\4\0c\210\4\0c\211\4\0c\212\4\0c\213\4\0c\214\4\0c\215\4\0c\216\4\0c\217" - "\4\0c\220\4\0c\221\4\0c\222\4\0c\223\4\0c\224\4\0c\225\4\0c\226\4\0c\227" - "\4\0c\230\4\0c\231\4\0c\232\4\0c\233\4\0c\234\4\0c\235\4\0c\236\4\0c\237" - "\4\0c\240\4\0c\241\4\0c\242\4\0c\243\4\0c\244\4\0c\245\4\0c\246\4\0c\247" - "\4\0c\250\4\0c\251\4\0c\252\4\0c\253\4\0c\254\4\0c\255\4\0c\256\4\0c\257" - "\4\0c\260\4\0c\261\4\0c\262\4\0c\263\4\0c\264\4\0c\265\4\0c\266\4\0c\267" - "\4\0c\270\4\0c\271\4\0c\272\4\0c\273\4\0c\274\4\0c\275\4\0c\276\4\0c\277" - "\4\0c\300\4\0c\301\4\0c\302\4\0c\303\4\0c\304\4\0c\305\4\0c\306\4\0c\307" - "\4\0c\310\4\0c\311\4\0c\312\4\0c\313\4\0c\314\4\0c\315\4\0c\316\4\0c\317" - "\4\0c\320\4\0c\321\4\0c\322\4\0c\323\4\0c\324\4\0c\325\4\0c\326\4\0c\327" - "\4\0c\330\4\0c\331\4\0c\332\4\0c\333\4\0c\334\4\0c\335\4\0c\336\4\0c\337" - "\4\0c\340\4\0c\341\4\0c\342\4\0c\343\4\0c\344\4\0c\345\4\0c\346\4\0c\347" - "\4\0c\350\4\0c\351\4\0c\352\4\0c\353\4\0c\354\4\0c\355\4\0c\356\4\0c\357" - "\4\0c\360\4\0c\361\4\0c\362\4\0c\363\4\0c\364\4\0c\365\4\0c\366\4\0c\367" - "\4\0c\370\4\0c\371\4\0c\372\4\0c\373\4\0c\374\4\0c\375\4\0c\376\4\0c\377" - "\4\0c\0\0\0\4\377\377\0"; - -static char* text = (char*) "Disconnected!"; -static int textWidth; -static bool connected = false; -static int SCREENHEIGHT; -static int SCREENWIDTH; -void update_display(al_event_cb_t, al_event_cb_param_t*); -void draw(); - -Audiolib Audiosource = Audiolib("Titta vad jag heter", &update_display); - extern "C" { void app_main(void){ - u8g2_esp32_hal.sda = GPIO_NUM_32; u8g2_esp32_hal.scl = GPIO_NUM_33; u8g2_esp32_hal_init(u8g2_esp32_hal); - u8g2_Setup_ssd1306_i2c_128x32_univision_f( &u8g2, U8G2_R0, @@ -93,11 +59,10 @@ extern "C" { u8x8_SetI2CAddress(&u8g2.u8x8, 0x3C); u8g2_InitDisplay(&u8g2); u8g2_SetPowerSave(&u8g2, 0); - u8g2_SetFont(&u8g2, BT_font); + u8g2_SetFont(&u8g2, BT_FONT); SCREENWIDTH = u8g2_GetDisplayWidth(&u8g2); SCREENHEIGHT = u8g2_GetDisplayHeight(&u8g2); - textWidth = u8g2_GetStrWidth(&u8g2, text); Audiosource.set_I2S(26, 27, 25); @@ -110,77 +75,71 @@ extern "C" { while (true) { draw(); + printf("%d\n", pot1->get_raw()); + vTaskDelay(pdMS_TO_TICKS(10)); } } } - void draw() { - u8g2_DrawStr(&u8g2, 0, SCREENHEIGHT, "AAAAAAAAAA"); + if (displayStatus & BT) { + u8g2_DrawGlyph(&u8g2, 0, SCREENHEIGHT/2, 127); + } + if (displayStatus & STOP) { + u8g2_DrawGlyph(&u8g2, 12, SCREENHEIGHT/2, 129); + } + else if (displayStatus & PAUSE) { + u8g2_DrawGlyph(&u8g2, 12, SCREENHEIGHT/2, 130); + } + else if (displayStatus & PLAY) { + u8g2_DrawGlyph(&u8g2, 12, SCREENHEIGHT/2, 128); + } + if ((displayStatus & PLAY) || (displayStatus & STOP) || (displayStatus & PAUSE)) { + u8g2_DrawStr(&u8g2, 23, SCREENHEIGHT/2, artistText); + u8g2_DrawStr(&u8g2, 0, SCREENHEIGHT, titleText); + } + else { + u8g2_DrawStr(&u8g2, 0, SCREENHEIGHT/2, "Disconnected!"); + u8g2_DrawStr(&u8g2, 0, SCREENHEIGHT, "Connect Device!"); + } u8g2_SendBuffer(&u8g2); - vTaskDelay(pdMS_TO_TICKS(10)); + u8g2_ClearBuffer(&u8g2); } void update_display(al_event_cb_t event, al_event_cb_param_t* param) { switch (event) { case AL_CONNECTED: - text = (char*) "Connected!"; + displayStatus = BT | STOP; printf("AL, Connected\n"); - connected = true; break; case AL_DISCONNECTED: - text = (char*) "Disconnected!"; + displayStatus = 0; printf("AL, Disconnected\n"); break; case AL_PLAYING: - text = (char*) "PLAY"; + displayStatus = BT | PLAY; printf("AL, Playing\n"); break; case AL_PAUSED: - text = (char*) "PAUSE"; + displayStatus = BT | PAUSE; printf("AL, Paused\n"); break; case AL_STOPPED: + displayStatus = BT | STOP; printf("AL, Stopped\n"); break; case AL_META_UPDATE: - int titleLen = strlen(param->metadata.title); - int artistLen = strlen(param->metadata.artist); - - text = (char*) malloc(titleLen + artistLen + 3 + 1); //Maybe runaway pointer every time this is done? - memcpy(text, param->metadata.title, titleLen); - memcpy(text + titleLen, (char*)" - ", 3); - memcpy(text + titleLen + 3, param->metadata.artist, artistLen); - *(text + titleLen + 3 + artistLen) = *"\0"; - - printf("%s\n", text); - + titleText = param->metadata.title; + artistText = param->metadata.artist; + if ((*artistText == '\0') || (*titleText == '\0')) { + displayStatus = BT | STOP; + } printf("AL, Meta_Update\n"); break; - } - textWidth = u8g2_GetStrWidth(&u8g2, text); - draw(); -} - - -/* -int substr(char* string, int startPixel, int totPixels) { - - int len = strlen(strin); - int newlen = (int) len/2; - - char* newstr = (char*) malloc(newlen + 1); - memcpy(newstr, &str[start], newlen); - newstr[newlen] = *"\0"; - - - if (pixels > u8g2_GetUTF8Width((int) len/2) - for (int i = 0; i < strlen(string)) - -}*/ \ No newline at end of file +} \ No newline at end of file