rk3399_arm_lvds/testusb/main.cpp

135 lines
3.9 KiB
C++
Raw Permalink Normal View History

2024-03-05 03:46:18 +00:00
#include <iostream>
#include <iomanip>
#include <memory>
#include <thread>
#include <chrono>
#include "filetools.h"
#include "stringex.hpp"
#include <functional>
#include "usbservice.h"
#include "Capturer.h"
#include "motorboard.h"
#include "itransmit.h"
#include "scannerregs.h"
#include "scanner.h"
#include "inotify.h"
#include "memoryex.h"
#include "usbimageprocqueue.h"
#include "imageusbtesthandler.h"
#include "applog.h"
#include "jsonconfig.h"
#include "imageencode.h"
2024-03-05 03:46:18 +00:00
using namespace std;
volatile int done_scan = 0;
int menu()
{
int choice;
cout << " **** Menu **** " << endl
<< endl;
cout << "(1) notify." << endl;
cout << "(2) clear notify. " << endl;
cout << "(3/4) autocorrect " << endl;
cout << "(5) color mode change test " << endl;
cout << "(6) test usb transmit "<< endl;
cout << "(0) Quit. " << endl
2024-03-05 03:46:18 +00:00
<< endl;
cout << ": ";
cin >> choice;
return choice;
}
int main()
{
auto cap = std::shared_ptr<Capturer>(new Capturer());
auto mt = std::shared_ptr<MotorBoard>(new MotorBoard(nullptr));
auto scanner = std::shared_ptr<Scanner>(new Scanner(cap, mt,nullptr));
UsbService us(cap->regs(), mt->regs());
auto notify = us.notify();
std::shared_ptr<UsbImageProcQueue> usbImage(new UsbImageProcQueue(notify));
auto transfer = us.transmiter();
std::shared_ptr<IRegsAccess> regs = std::shared_ptr<IRegsAccess>(new ScannerRegAccess(scanner, usbImage, transfer));
scanner->set_imagehandler(std::shared_ptr<IImageHandler>(new ImageUsbHandler(usbImage)));
us.set_scannerregs(regs);
unsigned int val = 0;
bool exit = false;
int option = 0;
unsigned char data[116] = {0x00};
int count = 0;
// auto mem = std::shared_ptr<VectorMemroy>(new VectorMemroy());
// mem->resize(10);
// memcpy(mem->data(),data,sizeof(data));
for (;;)
{
option = menu();
switch (option)
{
case 0:
exit = true;
break;
case 1:
this_thread::sleep_for(chrono::milliseconds(1));
break;
case 2:
notify->clear();
break;
case 3:
// {
// auto nread= transfer->read_bulk(data,sizeof(data));
// break;
// }
case 4:
scanner->test_autocorrect(option==3);
break;
case 5:
{
HGScanConfig config = {0};
for (size_t i = 0; i < 40; i++)
{
std::string msg=(i % 2 == 0?" mode COLOR ":" mode GRAY ");
std::cout << "Test color mode change index = "<<i<< msg<< std::endl;
//i % 2 == 0 ? config.g200params.color = 1 : config.g200params.color = 0;
config.g200params.color = 0;
config.g200params.dpi = 1;
config.g200params.paper = 2;
scanner->test_cap(config);
this_thread::sleep_for(chrono::milliseconds(1));
}
std::cout << "Please select again! " << std::endl;
break;
}
case 6:
{
std::vector<std::uint8_t> buf;
buf.resize(3762*3200*3);
for(int i =0;i<(3762*3200*3);i++)
buf.push_back(i%256);
while (true)
{
cv::Mat mat(3672,rand()%1000+500,CV_8UC3,buf.data());
usbImage->push(BmpImageEncode().encode(mat),true);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
while(usbImage->size() > 30)
std::this_thread::sleep_for(std::chrono::milliseconds(20));
}
break;
}
2024-03-05 03:46:18 +00:00
default:
std::cout << "Please select again! " << std::endl;
break;
}
/* code */
if (exit)
break;
}
std::cout << "exit munu" << std::endl;
return 0;
}