Update factory example

This commit is contained in:
lewishe
2023-06-14 20:04:02 +08:00
parent df739f3fdc
commit 26f8e18ea6
+21 -5
View File
@@ -96,6 +96,7 @@ lv_group_t *kb_indev_group;
lv_obj_t *hw_ta;
lv_obj_t *radio_ta;
lv_obj_t *tv ;
SemaphoreHandle_t xSemaphore = NULL;
void setupLvgl();
@@ -294,6 +295,7 @@ bool setupCoder()
void taskplaySong(void *p)
{
while (1) {
if ( xSemaphoreTake( xSemaphore, portMAX_DELAY ) == pdTRUE ) {
if (SD.exists("/key.mp3")) {
const char *path = "key.mp3";
audio.setPinout(BOARD_I2S_BCK, BOARD_I2S_WS, BOARD_I2S_DOUT);
@@ -303,8 +305,10 @@ void taskplaySong(void *p)
while (audio.isRunning()) {
audio.loop();
}
}
audio.stopSong();
}
xSemaphoreGive( xSemaphore );
}
vTaskSuspend(NULL);
}
}
@@ -325,13 +329,14 @@ void loopRadio()
lv_textarea_set_text(radio_ta, "Radio not online !");
return ;
}
if ( xSemaphoreTake( xSemaphore, portMAX_DELAY ) == pdTRUE ) {
digitalWrite(BOARD_SDCARD_CS, HIGH);
digitalWrite(RADIO_CS_PIN, HIGH);
digitalWrite(BOARD_TFT_CS, HIGH);
char buf[256];
if (lv_tabview_get_tab_act(tv) != 1) {
xSemaphoreGive( xSemaphore );
return ;
}
if (strlen(lv_textarea_get_text(radio_ta)) >= lv_textarea_get_max_length(radio_ta)) {
@@ -440,6 +445,8 @@ void loopRadio()
enableInterrupt = true;
}
}
xSemaphoreGive( xSemaphore );
}
}
static void event_handler(lv_event_t *e)
@@ -617,6 +624,11 @@ void initBoard()
buttonConfig->setFeature(ButtonConfig::kFeatureClick);
buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
//Add mutex to allow multitasking access
xSemaphore = xSemaphoreCreateBinary();
assert(xSemaphore);
xSemaphoreGive( xSemaphore );
tft.begin();
tft.setRotation( 1 );
tft.fillScreen(TFT_BLACK);
@@ -808,9 +820,6 @@ void initBoard()
delay(5);
}
xTaskCreate(taskplaySong, "play", 1024 * 4, NULL, 10, &playHandle);
i2s_driver_uninstall(I2S_CH);
pinMode(BOARD_BOOT_PIN, INPUT);
@@ -819,6 +828,7 @@ void initBoard()
Serial.println("BOOT HAS PRESSED!!!"); delay(500);
}
if ( xSemaphoreTake( xSemaphore, portMAX_DELAY ) == pdTRUE ) {
if (hasRadio) {
if (sender) {
transmissionState = radio.startTransmit("0");
@@ -834,7 +844,10 @@ void initBoard()
}
}
}
xSemaphoreGive( xSemaphore );
}
xTaskCreate(taskplaySong, "play", 1024 * 4, NULL, 10, &playHandle);
}
@@ -845,11 +858,14 @@ static void disp_flush( lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *
{
uint32_t w = ( area->x2 - area->x1 + 1 );
uint32_t h = ( area->y2 - area->y1 + 1 );
if ( xSemaphoreTake( xSemaphore, portMAX_DELAY ) == pdTRUE ) {
tft.startWrite();
tft.setAddrWindow( area->x1, area->y1, w, h );
tft.pushColors( ( uint16_t * )&color_p->full, w * h, false );
tft.endWrite();
lv_disp_flush_ready( disp );
xSemaphoreGive( xSemaphore );
}
}