Hi,
I want to display an image sent over Bluetooth on my screen which uses the driver st7735. So I have an application which can send images, and I receive data in the function nus_data_handler. With this application, I send array of 20 data (two first and last data are control data to know that an image is sent). The data sent are 4bytes for 1 pixel so RGBα, and 8 bites for red, 8 for green, 8 for blue and 8 for alpha. I display an image with the function nrf_gfx_bmp565_draw, so pixel format is RGB565. When I received data (R, G, and B), I convert these 3 data to one and transform them to RGB565 with this:
RGB16(red, green, blue) (((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3))
I don't care about α for the conversion. After, I have the value of one pixel. I need to save this pixel value, so I created an array image_received of the image size (80x160 = 12800) with all element are 0xFFFF (white) in another file include in main.c. When I have the value of one pixel, I replace the element of image_received by this value. So at the end, I should have in image_received the image received by Bluetooth. When I try to display image_received, it doesn't work: it is the image of the beginning which is displayed, image_received is not updated. Here is my code who receive and display data.
if (p_evt->type == BLE_NUS_EVT_RX_DATA) {
uint32_t err_code;
NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
printf("Received rx of length:%d\r\n", p_evt->params.rx_data.length);
int pixel, red = -1, green = -1, blue = -1;
for (int i = 0; i < p_evt->params.rx_data.length; i++) {
printf("debug received %d at %d\r, i %d\n", p_evt->params.rx_data.p_data[i], p_evt->params.rx_data.length,i);
array_data[i]=p_evt->params.rx_data.p_data[i];
if ((i==2)|(i==6)|(i==10)){
red = array_data[i];
//printf("red %d \n", red);
}
if ((i==3)|(i==7)|(i==11)){
green =array_data[i];
//printf("green %d \n", green);
}
if ((i==4)|(i==8)|(i==12)){ //green ||(i==8)||(i=12)||(i==16))
blue =array_data[i];
// printf("blue %d \n", blue);
pixel = RGB16(red, green, blue); //convert rdb24 to rgb16
// printf("pixel %d \n", pixel);
image_received[cpt_pixel] = pixel;
// printf("valeur image %d \n", image_received[cpt_pixel]);
cpt_pixel ++;
printf("cpt pixel %d \n", cpt_pixel);
}
if ((cpt_pixel == 100)|(cpt_pixel==150)|(cpt_pixel==200)){
screen_clear(BLACK);
nrf_gfx_background_set(p_lcd, (uint16_t const*)image_received);
printf("display !!");
}
}
So I don't know how can I display an image sent over Bluetooth. On the internet, I only find answers to display an image on the application sent by nrf52; but my issue is the other way around. I think it's better to send data received in flash memory, so I can send an array with sd_flash_write, but I still have to stock data in image_received and after reading into the flash and display, but I don't know how to do it.
I use nrf 52832, with PCA10040, s 132, sdk15.3 and Segger embedded.