Increase resolution, decrease send interval

This commit is contained in:
Adam Prochazka
2023-04-08 23:30:23 +02:00
parent 2007a5de10
commit ae0f8749b5
8 changed files with 138 additions and 97 deletions

View File

@ -11,7 +11,7 @@ int Displayer::createWindow() {
window = SDL_CreateWindow("Image Viewer", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1920, 1080, SDL_WINDOW_SHOWN);
if (!window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to create window: %s", SDL_GetError());
SDL_Quit();
//SDL_Quit();
return 1;
}
@ -23,15 +23,29 @@ int Displayer::renderWindow(){
if (!renderer) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to create renderer: %s", SDL_GetError());
SDL_DestroyWindow(window);
SDL_Quit();
//SDL_DestroyWindow(window);
//SDL_Quit();
return 1;
}
return 0;
}
#define PRINT_BUFFER 0
int Displayer::imageFromVector(std::vector<uint8_t>* img){
#if PRINT_BUFFER
std::cout << "______________" << std::endl;
for(int i = 0; i<(int)(img)->size(); i++)
{
std::cout << "0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast<int>((*img)[i]) << " ";
}
std::cout << std::endl;
std::cout << "______________" << std::endl;
#endif
imageRwops = SDL_RWFromMem(img->data(), img->size());
return 0;
}
@ -40,10 +54,10 @@ int Displayer::createImageSurface(){
imageSurface = IMG_Load_RW(imageRwops, 0);
if (!imageSurface) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to load image: %s", IMG_GetError());
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
//SDL_DestroyRenderer(renderer);
//SDL_DestroyWindow(window);
//SDL_Quit();
//return 1;
}
return 0;
@ -130,8 +144,8 @@ int Displayer::windowLoop(){
return 0;
}
int Displayer::vectorToTexture(std::vector<uint8_t>* img){
imageFromVector(img);
createImageSurface();
textureFromSurface();

View File

@ -53,9 +53,9 @@ int Receiver::initSerial(){
return 1;
}
int Receiver::readCdcData(uint8_t (*character)[50]) {
memset(*character, 0x00, 50);
int bytesRead = read(cdcFile, character, 50);
int Receiver::readCdcData(uint8_t (*character)[CDC_FRAME_SIZE]) {
memset(*character, 0x00, CDC_FRAME_SIZE);
int bytesRead = read(cdcFile, character, CDC_FRAME_SIZE);
if (bytesRead == -1) {
std::cerr << "Error in read" << std::endl;
return -1;
@ -65,21 +65,24 @@ int Receiver::readCdcData(uint8_t (*character)[50]) {
return -1;
}
/* PRINT WHAT IS RECEIVED
for(int i = 0; i<50; i++)
{
printHex((*character)[i]);
//std::cout << unsigned(character[i]);
std::cout << " ";
}
std::cout << std::endl << std::endl;
*/
#if 0 // PRINT WHAT IS RECEIVED
for(int i = 0; i<CDC_FRAME_SIZE; i++)
{
printHex((*character)[i]);
//std::cout << unsigned(character[i]);
std::cout << " ";
}
std::cout << std::endl << std::endl;
#endif
return 0;
}
int Receiver::simulateRead(unsigned char (*character)[50]){
memset(*character, 0x00, 50);
int Receiver::simulateRead(unsigned char (*character)[CDC_FRAME_SIZE]){
memset(*character, 0x00, CDC_FRAME_SIZE);
int firstLen = (int)t1.size();
int secondLen = (int)t2.size();
@ -93,7 +96,7 @@ int Receiver::simulateRead(unsigned char (*character)[50]){
vecId = 2;
}
for(int i=0; i<50; i++){
for(int i=0; i<CDC_FRAME_SIZE; i++){
if(vecId == 1){
if(simulateIdx > firstLen){
(*character)[i] = 0x00;
@ -118,7 +121,7 @@ int Receiver::simulateRead(unsigned char (*character)[50]){
}
int Receiver::fillBuffer(){
unsigned char character[50];
unsigned char character[CDC_FRAME_SIZE];
std::vector<uint8_t> tempVec{};
Receiver::readCdcData(&character);
@ -183,6 +186,7 @@ void Receiver::bufferToDisplay(){
currentBufferIndexMutex.lock();
int buffIdx = currentBufferIndex;
currentBufferIndexMutex.unlock();
std::cout << buffIdx << std::endl;
switch(buffIdx){
case 0:
dis->vectorToTexture(&buffer1);
@ -205,15 +209,15 @@ void Receiver::initTextures(){
dis->vectorToTexture(&buffer_initial);
}
int Receiver::findSequence(unsigned char (*str)[50], unsigned char ch1, unsigned char ch2){
int Receiver::findSequence(unsigned char (*str)[CDC_FRAME_SIZE], unsigned char ch1, unsigned char ch2){
if(sequenceEndedFF){
sequenceEndedFF = 0;
if((*str)[0] == ch2){
return 0;
}
}
for(int i=0; i<50; i++){
if((*str)[i] == ch1 && i < 50){
for(int i=0; i<CDC_FRAME_SIZE; i++){
if((*str)[i] == ch1 && i < CDC_FRAME_SIZE){
if((*str)[i+1] == ch2){
return i;
}
@ -225,12 +229,12 @@ int Receiver::findSequence(unsigned char (*str)[50], unsigned char ch1, unsigned
return -1;
}
int Receiver::findStart(unsigned char (*str)[50]){
int Receiver::findStart(unsigned char (*str)[CDC_FRAME_SIZE]){
int res = findSequence(str, 0xFF, 0xD8);
return res;
}
int Receiver::findEnd(unsigned char (*str)[50]){
int Receiver::findEnd(unsigned char (*str)[CDC_FRAME_SIZE]){
int res = findSequence(str, 0xFF, 0xD9);
return res;
}

View File

@ -57,7 +57,7 @@ class Receiver{
Receiver(Displayer *displayerPtr);
void openStream();
int initSerial();
int readCdcData(unsigned char (*character)[50]);
int readCdcData(unsigned char (*character)[CDC_FRAME_SIZE]);
void printHex(unsigned char value);
int fillBuffer();
@ -65,9 +65,9 @@ class Receiver{
void bufferToDisplay();
void initTextures();
int findSequence(unsigned char (*str)[50], unsigned char ch1, unsigned char ch2);
int findStart(unsigned char (*str)[50]);
int findEnd(unsigned char (*str)[50]);
int findSequence(unsigned char (*str)[CDC_FRAME_SIZE], unsigned char ch1, unsigned char ch2);
int findStart(unsigned char (*str)[CDC_FRAME_SIZE]);
int findEnd(unsigned char (*str)[CDC_FRAME_SIZE]);
int simulateRead(unsigned char (*character)[50]);
int simulateRead(unsigned char (*character)[CDC_FRAME_SIZE]);
};

View File

@ -12,7 +12,7 @@ void readLoop(Receiver ** receiverPtr){
(*receiverPtr)->initSerial();
while (true) {
unsigned char character[50];
unsigned char character[CDC_FRAME_SIZE];
(*receiverPtr)->readCdcData(&character);
if((*receiverPtr)->findStart(&character) != -1)
{std::cout << "start" << std::endl;}
@ -21,7 +21,7 @@ void readLoop(Receiver ** receiverPtr){
else{
std::cout << "-";
}
std::this_thread::sleep_for(std::chrono::milliseconds(5));
std::this_thread::sleep_for(std::chrono::milliseconds(3));
}
close(cdcFile);
@ -36,7 +36,7 @@ void receiverLoop(Receiver ** receiverPtr){
while(1){
(*receiverPtr)->fillBuffer();
(*receiverPtr)->bufferToDisplay();
std::this_thread::sleep_for(std::chrono::milliseconds(5));
std::this_thread::sleep_for(std::chrono::milliseconds(3));
}
}

View File

@ -13,4 +13,6 @@
#include <thread>
#include <chrono>
#include <mutex>
#include <fstream>
#include <fstream>
#define CDC_FRAME_SIZE 50