Camera progress

main
aprochazka 2 years ago
parent f05df1ef8e
commit 505b448eeb

@ -135,6 +135,7 @@ target_link_options(${EXECUTABLE} PRIVATE
-Wl,--start-group -Wl,--start-group
-lc -lc
-lm -lm
-lnosys
-lstdc++ -lstdc++
-Wl,--end-group -Wl,--end-group
-Wl,--print-memory-usage) -Wl,--print-memory-usage)

@ -207,11 +207,11 @@ void Cam_Start_Burst_Read(SPI_HandleTypeDef *hspi)
void Cam_Capture(SPI_HandleTypeDef *hspi) void Cam_Capture(SPI_HandleTypeDef *hspi)
{ {
LED_On(); //LED_On();
Cam_Start_Capture(hspi); Cam_Start_Capture(hspi);
Cam_Wait_Capture_Done(hspi); Cam_Wait_Capture_Done(hspi);
LED_Off(); //LED_Off();
} }

@ -68,6 +68,7 @@ static void MX_USB_PCD_Init(void);
/* Private user code ---------------------------------------------------------*/ /* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */ /* USER CODE BEGIN 0 */
/*
static unsigned frame_num = 0; static unsigned frame_num = 0;
static unsigned tx_busy = 0; static unsigned tx_busy = 0;
static unsigned interval_ms = 1000 / FRAME_RATE; static unsigned interval_ms = 1000 / FRAME_RATE;
@ -86,7 +87,7 @@ static struct {
{color_bar_7_jpg_len, color_bar_7_jpg}, {color_bar_7_jpg_len, color_bar_7_jpg},
}; };
*/
/* /*
void cdc_task(void) void cdc_task(void)
{ {
@ -159,6 +160,7 @@ uint8_t sendT[600] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}; };
/*
int currentIdx = 0; int currentIdx = 0;
int currentImg = 0; int currentImg = 0;
@ -203,7 +205,7 @@ int send_CDC_Bulk(){
currentIdx = currentIdx + 10; currentIdx = currentIdx + 10;
return 1; return 1;
} }
*/
/* USER CODE END 0 */ /* USER CODE END 0 */
@ -247,57 +249,80 @@ int main(void)
tud_init(BOARD_DEVICE_RHPORT_NUM); tud_init(BOARD_DEVICE_RHPORT_NUM);
//HAL_Delay(10); HAL_Delay(10);
//SPI_Init(&hspi1); SPI_Init(&hspi1);
// Wait for power stabilization // Wait for power stabilization
//HAL_Delay(1000); //HAL_Delay(1000);
//Cam_Init(&hi2c1, &hspi1); Cam_Init(&hi2c1, &hspi1);
int currentSendingIndex = 0;
Cam_Capture(&hspi1);
uint16_t image_size = Cam_FIFO_length(&hspi1);
//uint8_t *image_data = malloc((image_size + (image_size%10)) * sizeof(uint8_t));
uint8_t image_data[10000];
memset(image_data, 0x00, image_size + (image_size%10));
Cam_Start_Burst_Read(&hspi1);
HAL_SPI_Receive_DMA(&hspi1, image_data, image_size);
while (SPI_Rx_Done_Flag == 0)
{
// Wait for SPI transfer to finish
}
CS_Off();
SPI_Rx_Done_Flag = 0;
/* USER CODE END 2 */ /* USER CODE END 2 */
/* Infinite loop */ /* Infinite loop */
/* USER CODE BEGIN WHILE */ /* USER CODE BEGIN WHILE */
while (1) while (1)
{ {
tud_task();
//tud_cdc_write("1\r", 3);
//tud_cdc_write_flush(); tud_task();
//video_task();
//HAL_Delay(10);
send_CDC_Bulk();
HAL_Delay(5);
if(currentSendingIndex >= 590){
currentSendingIndex = 0;
/* //free(image_data);
Cam_Capture(&hspi1); Cam_Capture(&hspi1);
uint16_t image_size = Cam_FIFO_length(&hspi1); image_size = Cam_FIFO_length(&hspi1);
uint8_t *image_data = malloc(image_size * sizeof(uint8_t)); //image_data = malloc((image_size + (image_size%10)) * sizeof(uint8_t));
memset(image_data, 0x00, image_size); //memset(image_data, 0x00, image_size + (image_size%10));
Cam_Start_Burst_Read(&hspi1); Cam_Start_Burst_Read(&hspi1);
HAL_SPI_Receive_DMA(&hspi1, image_data, image_size); HAL_SPI_Receive_DMA(&hspi1, &(image_data[0]), image_size);
Debug_LED_On(); Debug_LED_On();
while (SPI_Rx_Done_Flag == 0) while (SPI_Rx_Done_Flag == 0)
{ {
// Wait for SPI transfer to finish // Wait for SPI transfer to finish
} }
Debug_LED_Off();
CS_Off(); CS_Off();
SPI_Rx_Done_Flag = 0; SPI_Rx_Done_Flag = 0;
if(image_size < 1){
currentSendingIndex = 10000;
}
}
else {
LED_On();
tud_cdc_write(&sendT[currentSendingIndex], 10);
tud_cdc_write_flush();
currentSendingIndex = currentSendingIndex + 10;
HAL_Delay(5);
}
HAL_UART_Transmit(&huart2, image_data, image_size, HAL_MAX_DELAY);
Debug_LED_Off();
free(image_data);
*/
/* USER CODE END WHILE */ /* USER CODE END WHILE */
/* USER CODE BEGIN 3 */ /* USER CODE BEGIN 3 */

Binary file not shown.

Binary file not shown.

@ -11,7 +11,7 @@ void Receiver::printHex(unsigned char value) {
void Receiver::openStream(){ void Receiver::openStream(){
while(1){ while(1){
// Open the CDC device file for reading // Open the CDC device file for reading
cdcFile = open("/dev/ttyACM2", O_RDWR | O_NOCTTY); cdcFile = open("/dev/ttyACM1", O_RDWR | O_NOCTTY);
if (cdcFile == -1) { if (cdcFile == -1) {
std::cerr << "Failed to open CDC device file" << std::endl; std::cerr << "Failed to open CDC device file" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(std::chrono::milliseconds(500));

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -9,13 +9,22 @@
int cdcFile; int cdcFile;
struct termios tty; struct termios tty;
void readLoop(){
openStream(&cdcFile); void readLoop(Receiver ** receiverPtr){
initSerial(&tty, &cdcFile); (*receiverPtr)->openStream();
(*receiverPtr)->initSerial();
while (true) { while (true) {
readCdcData(&cdcFile); unsigned char character[10];
std::this_thread::sleep_for(std::chrono::milliseconds(5)); (*receiverPtr)->readCdcData(&character);
if((*receiverPtr)->findStart(&character) != -1)
{std::cout << "start" << std::endl;}
else if((*receiverPtr)->findEnd(&character) != -1)
{std::cout << "stop" << std::endl;}
else{
std::cout << "-";
}
std::this_thread::sleep_for(std::chrono::milliseconds(20));
} }
close(cdcFile); close(cdcFile);
@ -36,12 +45,13 @@ void receiverLoop(Receiver ** receiverPtr){
int main() int main()
{ {
Displayer dis; Displayer dis;
Receiver *rec = new Receiver(&dis);
/*
dis.createWindow(); dis.createWindow();
dis.renderWindow(); dis.renderWindow();
Receiver *rec = new Receiver(&dis);
rec->openStream(); rec->openStream();
rec->initSerial(); rec->initSerial();
rec->fillBuffer(); rec->fillBuffer();
@ -52,8 +62,8 @@ int main()
dis.windowLoop(); dis.windowLoop();
t1.join(); t1.join();
*/
readLoop(&rec);
//readLoop();
return 0; return 0;
} }

Binary file not shown.
Loading…
Cancel
Save