Update factory example
This commit is contained in:
+140
-124
@@ -96,6 +96,7 @@ lv_group_t *kb_indev_group;
|
|||||||
lv_obj_t *hw_ta;
|
lv_obj_t *hw_ta;
|
||||||
lv_obj_t *radio_ta;
|
lv_obj_t *radio_ta;
|
||||||
lv_obj_t *tv ;
|
lv_obj_t *tv ;
|
||||||
|
SemaphoreHandle_t xSemaphore = NULL;
|
||||||
|
|
||||||
|
|
||||||
void setupLvgl();
|
void setupLvgl();
|
||||||
@@ -294,17 +295,20 @@ bool setupCoder()
|
|||||||
void taskplaySong(void *p)
|
void taskplaySong(void *p)
|
||||||
{
|
{
|
||||||
while (1) {
|
while (1) {
|
||||||
if (SD.exists("/key.mp3")) {
|
if ( xSemaphoreTake( xSemaphore, portMAX_DELAY ) == pdTRUE ) {
|
||||||
const char *path = "key.mp3";
|
if (SD.exists("/key.mp3")) {
|
||||||
audio.setPinout(BOARD_I2S_BCK, BOARD_I2S_WS, BOARD_I2S_DOUT);
|
const char *path = "key.mp3";
|
||||||
audio.setVolume(12);
|
audio.setPinout(BOARD_I2S_BCK, BOARD_I2S_WS, BOARD_I2S_DOUT);
|
||||||
audio.connecttoFS(SD, path);
|
audio.setVolume(12);
|
||||||
Serial.printf("play %s\r\n", path);
|
audio.connecttoFS(SD, path);
|
||||||
while (audio.isRunning()) {
|
Serial.printf("play %s\r\n", path);
|
||||||
audio.loop();
|
while (audio.isRunning()) {
|
||||||
|
audio.loop();
|
||||||
|
}
|
||||||
|
audio.stopSong();
|
||||||
}
|
}
|
||||||
|
xSemaphoreGive( xSemaphore );
|
||||||
}
|
}
|
||||||
audio.stopSong();
|
|
||||||
vTaskSuspend(NULL);
|
vTaskSuspend(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -325,120 +329,123 @@ void loopRadio()
|
|||||||
lv_textarea_set_text(radio_ta, "Radio not online !");
|
lv_textarea_set_text(radio_ta, "Radio not online !");
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
if ( xSemaphoreTake( xSemaphore, portMAX_DELAY ) == pdTRUE ) {
|
||||||
|
digitalWrite(BOARD_SDCARD_CS, HIGH);
|
||||||
|
digitalWrite(RADIO_CS_PIN, HIGH);
|
||||||
|
digitalWrite(BOARD_TFT_CS, HIGH);
|
||||||
|
|
||||||
digitalWrite(BOARD_SDCARD_CS, HIGH);
|
char buf[256];
|
||||||
digitalWrite(RADIO_CS_PIN, HIGH);
|
if (lv_tabview_get_tab_act(tv) != 1) {
|
||||||
digitalWrite(BOARD_TFT_CS, HIGH);
|
xSemaphoreGive( xSemaphore );
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
if (strlen(lv_textarea_get_text(radio_ta)) >= lv_textarea_get_max_length(radio_ta)) {
|
||||||
|
lv_textarea_set_text(radio_ta, "");
|
||||||
|
}
|
||||||
|
|
||||||
char buf[256];
|
if (sender) {
|
||||||
if (lv_tabview_get_tab_act(tv) != 1) {
|
// Send data every 200 ms
|
||||||
return ;
|
if (millis() - runningMillis > 1000) {
|
||||||
}
|
// check if the previous transmission finished
|
||||||
if (strlen(lv_textarea_get_text(radio_ta)) >= lv_textarea_get_max_length(radio_ta)) {
|
if (transmissionFlag) {
|
||||||
lv_textarea_set_text(radio_ta, "");
|
// disable the interrupt service routine while
|
||||||
}
|
// processing the data
|
||||||
|
enableInterrupt = false;
|
||||||
|
// reset flag
|
||||||
|
transmissionFlag = false;
|
||||||
|
|
||||||
if (sender) {
|
if (transmissionState == RADIOLIB_ERR_NONE) {
|
||||||
// Send data every 200 ms
|
// packet was successfully sent
|
||||||
if (millis() - runningMillis > 1000) {
|
Serial.println(F("transmission finished!"));
|
||||||
// check if the previous transmission finished
|
// NOTE: when using interrupt-driven transmit method,
|
||||||
|
// it is not possible to automatically measure
|
||||||
|
// transmission data rate using getDataRate()
|
||||||
|
} else {
|
||||||
|
Serial.print(F("failed, code "));
|
||||||
|
Serial.println(transmissionState);
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(buf, 256, "[ %u ]TX %u finished\n", millis() / 1000, sendCount);
|
||||||
|
lv_textarea_add_text(radio_ta, buf);
|
||||||
|
|
||||||
|
Serial.println(buf);
|
||||||
|
|
||||||
|
// you can also transmit byte array up to 256 bytes long
|
||||||
|
transmissionState = radio.startTransmit(String(sendCount++).c_str());
|
||||||
|
|
||||||
|
// we're ready to send more packets,
|
||||||
|
// enable interrupt service routine
|
||||||
|
enableInterrupt = true;
|
||||||
|
}
|
||||||
|
// snprintf(dispSenderBuff, sizeof(dispSenderBuff), "TX: %u", sendCount);
|
||||||
|
|
||||||
|
runningMillis = millis();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
String recv;
|
||||||
|
|
||||||
|
// check if the flag is set
|
||||||
if (transmissionFlag) {
|
if (transmissionFlag) {
|
||||||
// disable the interrupt service routine while
|
// disable the interrupt service routine while
|
||||||
// processing the data
|
// processing the data
|
||||||
enableInterrupt = false;
|
enableInterrupt = false;
|
||||||
|
|
||||||
// reset flag
|
// reset flag
|
||||||
transmissionFlag = false;
|
transmissionFlag = false;
|
||||||
|
|
||||||
if (transmissionState == RADIOLIB_ERR_NONE) {
|
// you can read received data as an Arduino String
|
||||||
// packet was successfully sent
|
// int state = radio.readData(recv);
|
||||||
Serial.println(F("transmission finished!"));
|
|
||||||
// NOTE: when using interrupt-driven transmit method,
|
// you can also read received data as byte array
|
||||||
// it is not possible to automatically measure
|
/*
|
||||||
// transmission data rate using getDataRate()
|
*/
|
||||||
|
int state = radio.readData(recv);
|
||||||
|
if (state == RADIOLIB_ERR_NONE) {
|
||||||
|
|
||||||
|
|
||||||
|
// packet was successfully received
|
||||||
|
Serial.print(F("[RADIO] Received packet!"));
|
||||||
|
|
||||||
|
// print data of the packet
|
||||||
|
Serial.print(F(" Data:"));
|
||||||
|
Serial.print(recv);
|
||||||
|
|
||||||
|
// print RSSI (Received Signal Strength Indicator)
|
||||||
|
Serial.print(F(" RSSI:"));
|
||||||
|
Serial.print(radio.getRSSI());
|
||||||
|
Serial.print(F(" dBm"));
|
||||||
|
// snprintf(dispRecvicerBuff[1], sizeof(dispRecvicerBuff[1]), "RSSI:%.2f dBm", radio.getRSSI());
|
||||||
|
|
||||||
|
// print SNR (Signal-to-Noise Ratio)
|
||||||
|
Serial.print(F(" SNR:"));
|
||||||
|
Serial.print(radio.getSNR());
|
||||||
|
Serial.println(F(" dB"));
|
||||||
|
|
||||||
|
|
||||||
|
snprintf(buf, 256, "RX:%s RSSI:%.2f SNR:%.2f\n", recv.c_str(), radio.getRSSI(), radio.getSNR());
|
||||||
|
|
||||||
|
lv_textarea_add_text(radio_ta, buf);
|
||||||
|
|
||||||
|
|
||||||
|
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
|
||||||
|
// packet was received, but is malformed
|
||||||
|
Serial.println(F("CRC error!"));
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
// some other error occurred
|
||||||
Serial.print(F("failed, code "));
|
Serial.print(F("failed, code "));
|
||||||
Serial.println(transmissionState);
|
Serial.println(state);
|
||||||
}
|
}
|
||||||
|
// put module back to listen mode
|
||||||
|
radio.startReceive();
|
||||||
|
|
||||||
snprintf(buf, 256, "[ %u ]TX %u finished\n", millis() / 1000, sendCount);
|
// we're ready to receive more packets,
|
||||||
lv_textarea_add_text(radio_ta, buf);
|
|
||||||
|
|
||||||
Serial.println(buf);
|
|
||||||
|
|
||||||
// you can also transmit byte array up to 256 bytes long
|
|
||||||
transmissionState = radio.startTransmit(String(sendCount++).c_str());
|
|
||||||
|
|
||||||
// we're ready to send more packets,
|
|
||||||
// enable interrupt service routine
|
// enable interrupt service routine
|
||||||
enableInterrupt = true;
|
enableInterrupt = true;
|
||||||
}
|
}
|
||||||
// snprintf(dispSenderBuff, sizeof(dispSenderBuff), "TX: %u", sendCount);
|
|
||||||
|
|
||||||
runningMillis = millis();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
String recv;
|
|
||||||
|
|
||||||
// check if the flag is set
|
|
||||||
if (transmissionFlag) {
|
|
||||||
// disable the interrupt service routine while
|
|
||||||
// processing the data
|
|
||||||
enableInterrupt = false;
|
|
||||||
|
|
||||||
// reset flag
|
|
||||||
transmissionFlag = false;
|
|
||||||
|
|
||||||
// you can read received data as an Arduino String
|
|
||||||
// int state = radio.readData(recv);
|
|
||||||
|
|
||||||
// you can also read received data as byte array
|
|
||||||
/*
|
|
||||||
*/
|
|
||||||
int state = radio.readData(recv);
|
|
||||||
if (state == RADIOLIB_ERR_NONE) {
|
|
||||||
|
|
||||||
|
|
||||||
// packet was successfully received
|
|
||||||
Serial.print(F("[RADIO] Received packet!"));
|
|
||||||
|
|
||||||
// print data of the packet
|
|
||||||
Serial.print(F(" Data:"));
|
|
||||||
Serial.print(recv);
|
|
||||||
|
|
||||||
// print RSSI (Received Signal Strength Indicator)
|
|
||||||
Serial.print(F(" RSSI:"));
|
|
||||||
Serial.print(radio.getRSSI());
|
|
||||||
Serial.print(F(" dBm"));
|
|
||||||
// snprintf(dispRecvicerBuff[1], sizeof(dispRecvicerBuff[1]), "RSSI:%.2f dBm", radio.getRSSI());
|
|
||||||
|
|
||||||
// print SNR (Signal-to-Noise Ratio)
|
|
||||||
Serial.print(F(" SNR:"));
|
|
||||||
Serial.print(radio.getSNR());
|
|
||||||
Serial.println(F(" dB"));
|
|
||||||
|
|
||||||
|
|
||||||
snprintf(buf, 256, "RX:%s RSSI:%.2f SNR:%.2f\n", recv.c_str(), radio.getRSSI(), radio.getSNR());
|
|
||||||
|
|
||||||
lv_textarea_add_text(radio_ta, buf);
|
|
||||||
|
|
||||||
|
|
||||||
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
|
|
||||||
// packet was received, but is malformed
|
|
||||||
Serial.println(F("CRC error!"));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// some other error occurred
|
|
||||||
Serial.print(F("failed, code "));
|
|
||||||
Serial.println(state);
|
|
||||||
}
|
|
||||||
// put module back to listen mode
|
|
||||||
radio.startReceive();
|
|
||||||
|
|
||||||
// we're ready to receive more packets,
|
|
||||||
// enable interrupt service routine
|
|
||||||
enableInterrupt = true;
|
|
||||||
}
|
}
|
||||||
|
xSemaphoreGive( xSemaphore );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -617,6 +624,11 @@ void initBoard()
|
|||||||
buttonConfig->setFeature(ButtonConfig::kFeatureClick);
|
buttonConfig->setFeature(ButtonConfig::kFeatureClick);
|
||||||
buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
|
buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
|
||||||
|
|
||||||
|
//Add mutex to allow multitasking access
|
||||||
|
xSemaphore = xSemaphoreCreateBinary();
|
||||||
|
assert(xSemaphore);
|
||||||
|
xSemaphoreGive( xSemaphore );
|
||||||
|
|
||||||
tft.begin();
|
tft.begin();
|
||||||
tft.setRotation( 1 );
|
tft.setRotation( 1 );
|
||||||
tft.fillScreen(TFT_BLACK);
|
tft.fillScreen(TFT_BLACK);
|
||||||
@@ -808,9 +820,6 @@ void initBoard()
|
|||||||
delay(5);
|
delay(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
xTaskCreate(taskplaySong, "play", 1024 * 4, NULL, 10, &playHandle);
|
|
||||||
|
|
||||||
i2s_driver_uninstall(I2S_CH);
|
i2s_driver_uninstall(I2S_CH);
|
||||||
|
|
||||||
pinMode(BOARD_BOOT_PIN, INPUT);
|
pinMode(BOARD_BOOT_PIN, INPUT);
|
||||||
@@ -819,22 +828,26 @@ void initBoard()
|
|||||||
Serial.println("BOOT HAS PRESSED!!!"); delay(500);
|
Serial.println("BOOT HAS PRESSED!!!"); delay(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasRadio) {
|
if ( xSemaphoreTake( xSemaphore, portMAX_DELAY ) == pdTRUE ) {
|
||||||
if (sender) {
|
if (hasRadio) {
|
||||||
transmissionState = radio.startTransmit("0");
|
if (sender) {
|
||||||
sendCount = 0;
|
transmissionState = radio.startTransmit("0");
|
||||||
Serial.println("startTransmit!!!!");
|
sendCount = 0;
|
||||||
} else {
|
Serial.println("startTransmit!!!!");
|
||||||
int state = radio.startReceive();
|
|
||||||
if (state == RADIOLIB_ERR_NONE) {
|
|
||||||
Serial.println(F("success!"));
|
|
||||||
} else {
|
} else {
|
||||||
Serial.print(F("failed, code "));
|
int state = radio.startReceive();
|
||||||
Serial.println(state);
|
if (state == RADIOLIB_ERR_NONE) {
|
||||||
|
Serial.println(F("success!"));
|
||||||
|
} else {
|
||||||
|
Serial.print(F("failed, code "));
|
||||||
|
Serial.println(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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 w = ( area->x2 - area->x1 + 1 );
|
||||||
uint32_t h = ( area->y2 - area->y1 + 1 );
|
uint32_t h = ( area->y2 - area->y1 + 1 );
|
||||||
tft.startWrite();
|
if ( xSemaphoreTake( xSemaphore, portMAX_DELAY ) == pdTRUE ) {
|
||||||
tft.setAddrWindow( area->x1, area->y1, w, h );
|
tft.startWrite();
|
||||||
tft.pushColors( ( uint16_t * )&color_p->full, w * h, false );
|
tft.setAddrWindow( area->x1, area->y1, w, h );
|
||||||
tft.endWrite();
|
tft.pushColors( ( uint16_t * )&color_p->full, w * h, false );
|
||||||
lv_disp_flush_ready( disp );
|
tft.endWrite();
|
||||||
|
lv_disp_flush_ready( disp );
|
||||||
|
xSemaphoreGive( xSemaphore );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user