void Download(char *commandline, blobStatus *status) { u32 startAddress = 0; int bufLen; int *numRead = 0; if(MyStrNCmp(commandline, "kernel", 6) == 0) { /* download kernel */ startAddress = KERNEL_RAM_BASE; bufLen = status->blockSize - KERNEL_BLOCK_OFFSET; numRead = &status->kernelSize; status->kernelType = fromDownload; } else if(MyStrNCmp(commandline, "ramdisk", 7) == 0) { /* download ramdisk */ startAddress = RAMDISK_RAM_BASE; bufLen = status->blockSize - RAMDISK_BLOCK_OFFSET; numRead = &status->ramdiskSize; status->ramdiskType = fromDownload; } else { SerialOutputString("*** Don't know how to download \""); SerialOutputString(commandline); SerialOutputString("\"\r"); return; } SerialOutputString("Switching to "); PrintSerialSpeed(status->downloadSpeed); SerialOutputString(" baud\r"); SerialOutputString("You have 60 seconds to switch your terminal emulator to the same speed and\r"); SerialOutputString("start downloading. After that " PACKAGE " will switch back to 9600 baud.\r"); SerialInit(status->downloadSpeed); *numRead = UUDecode((char *)startAddress, bufLen); SerialOutputString("\r(Please switch your terminal emulator back to 9600 baud)\r"); if(*numRead < 0) { /* something went wrong */ SerialOutputString("*** Uudecode receive failed\r"); /* reload the correct memory */ Reload(commandline, status); SerialInit(baud9k6); return; } SerialOutputString("Received "); SerialOutputDec(*numRead); SerialOutputString(" (0x"); SerialOutputHex(*numRead); SerialOutputString(") bytes.\r"); SerialInit(baud9k6); }
/** * Initializes the UARTS. * @return The return value of SerialInit(). */ int UARTInit(void){ char* env_ptr; int uart_selection = 0; unsigned int uarts[1] = { PHYSICAL_UART0 }; return SerialInit(uarts, 1); }
void main() { uchar len,i; uchar xdata Tvalue[6],Hvalue[6]; SerialInit(); LCDInit(); while(1) { RH(); SerialPutString(buff); sprintf(Tvalue,"%2.2f",temperature); sprintf(Hvalue,"%2.2f%%",humidity); LCDWriteCom(0x01);//ÇåÆÁ LCDWriteCom(0x80); len=strlen(info1); //дÊý¾Ýµ½LCD1602 for(i=0;i<len;i++) LCDWriteData(info1[i]); len=strlen(Tvalue); for(i=0;i<len;i++) LCDWriteData(Tvalue[i]); LCDWriteData((uchar)223); LCDWriteData('C'); LCDWriteCom(0x80+0x43); len=strlen(info2); for(i=0;i<len;i++) LCDWriteData(info2[i]); len=strlen(Hvalue); for(i=0;i<len;i++) LCDWriteData(Hvalue[i]); // Delay(10000); } }
void SerialReInit(HANDLE * hCom, int PortNum, int BaudRate, int dataBit, int parity, int cts, int rts, int dsr, int dtr) { close(*hCom); *hCom = SerialInit(PortNum, BaudRate, dataBit, parity, cts, rts, dsr, dtr); }
int main(int argc, char **argv) { int nRet = 0,i; char buf[SIZE]; if(argc<2)perror("Null Commend"); if( SerialInit() == -1 ) { perror("SerialInit Error!\n"); return -1; } bzero(buf, SIZE); for(i=0;i<strlen(argv[1]);i++) { buf[i]=argv[1][i]; } buf[i++]='\r'; buf[i++]='\n'; buf[i++]=0; printf(buf); write(nFd,buf,i-1); bzero(buf, SIZE); nRet = read(nFd, buf, SIZE); if(0 < nRet) { buf[nRet] = 0; printf("Recv Data: %s\n", buf); } if(-1 == nRet) { perror("Read Data Error!\n"); } close(nFd); return 0; }
void main() { //delay(10000); SerialInit(); //串口初始化,用以向调试终端发送数据 while(1) { SerialPutString("yahoo!!!"); //发送一个测试字符串 } /* MMC_Init(); //SD卡初始化 delay(10000); MMC_get_volume_info(); //获得SD卡相关信息,输出到终端 FAT32_Init(&Init_Arg); //FAT32文件系统初始化,装入参数 Printf("BPB_Sector_No" ,Init_Arg.BPB_Sector_No); Printf("Total_Size" ,Init_Arg.Total_Size ); Printf("FirstDirClust" ,Init_Arg.FirstDirClust); Printf("FirstDataSector",Init_Arg.FirstDataSector); Printf("BytesPerSector" ,Init_Arg.BytesPerSector); Printf("FATsectors" ,Init_Arg.FATsectors); Printf("SectorsPerClust",Init_Arg.SectorsPerClust); Printf("FirstFATSector" ,Init_Arg.FirstFATSector); Printf("FirstDirSector" ,Init_Arg.FirstDirSector); //以上几个语句用以输出参数值到终端 Printf("FAT32_OpenFile" ,(FAT32_OpenFile("\\TEST.TXT"))->FileSize); //打开根目录下的TEST.TXT文件,并输出文件大小 FAT32_ReadFile(&FileInfo); //读取文件数据,输出到终端 */ // while(1); }
//**************************************************************************** // // This is the main loop that runs the application. // //**************************************************************************** int main(void) { // // Set the clocking to run from the PLL at 50MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set the system tick to fire 100 times per second. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Pass the USB library our device information, initialize the USB // controller and connect the device to the bus. // g_psCompDevices[0].pvInstance = USBDHIDMouseCompositeInit(0, (tUSBDHIDMouseDevice *)&g_sMouseDevice); g_psCompDevices[1].pvInstance = USBDCDCCompositeInit(0, (tUSBDCDCDevice *)&g_sCDCDevice); // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass the device information to the USB library and place the device // on the bus. // USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_DATA_SIZE, g_pucDescriptorData); // // Initialize the mouse and serial devices. // MouseInit(); SerialInit(); // // Drop into the main loop. // while(1) { // // Allow the main mouse routine to run. // MouseMain(); // // Allow the main serial routine to run. // SerialMain(); } }
void Serial_Begin(unsigned int baudrate) { //init buffers and attach events SerialInit(); //configure registers USART_Begin(baudrate); }
void Serial_BeginConfigured(unsigned int baudrate, uint8_t conf) { //init buffers and attach events SerialInit(); //configure registers USART_BeginConfigured(baudrate, conf); }
void main() { union { unsigned int32 hours; unsigned int8 minutes; unsigned int8 seconds;} upTime; TICK_TYPE CurrentTick,PreviousUDPTick,PreviousSATick; resetStatus = (RCON & 0b00111111) | !(STKPTR & 0b11000000); // Get the Reset Status RCON = RCON | 0b00111111; //Reset RCON Reset flags... (Reset Register) STKPTR = STKPTR & 0b00111111; // Clear Stack Overflow/Underflow flags PortInit(); OutputInit(); restart_wdt(); romEZHRInit(); //set up default ezhr settings eeROMinit(); //set up default eprom settings IPAddressInit(); //set up MAC and default IP addresses delay_ms(500); ADCInit(); //set up ADC ports iniADCParams(); SerialInit(); //set up serial ports TickInit(); //set up tick timer enable_interrupts(INT_RDA); enable_interrupts(GLOBAL); StackInit(); WritePHYReg(ERXFCON,EthernetRXfilterSetting); // Allow only uni & multi SetLEDConfig(E_LED_CONFIG); // swap LED's output_high(E_SW_PWR_DN); // Power Ethernet Switch output_high(E_SW_RST); output_low(RS485_TXEN); output_high(RS485_RXDIS); output_high(RS232_F_OFF); output_high(RS232_F_ON); CurrentTick = PreviousUDPTick = get_ticks(); UDPSampleRate = eeReadUDPRate() * TICKS_PER_MILLISECOND; portControlInit(); while(TRUE) { CurrentTick = get_ticks(); restart_wdt(); StackTask(); restart_wdt(); MyTCPTask();//handles TCP connections restart_wdt(); setIO();// checks voltage status and sets ports accordingly //! if(CurrentTick-PreviousUDPTick >= UDPSampleRate) //! { //! currentRoutine=UDPTASK; //! BOOL UDPDone = MyUDPTask(); //! if(UDPDone) //! { //! PreviousUDPTick=CurrentTick; //! } //! } StackApplications(); } }
void OutboundThread(void) { WINDOW *local ; /* INITIALIZATION: Paint the local window. Create a */ /* mailbox object to receive keystroke codes from the */ /* keyboard ISR. Initialize the keyboard hardware. */ /* Point interrupt vector 33 at the keyboard ISR. */ /* Unmask the IRQ line in the 8259 PIC. */ local = WindowCreate("Local", 0, 10, 0, 79) ; KeyboardInit() ; /* SerialInit have a guard inside to prevent multiple initializations */ SerialInit() ; for (;;) { BYTE8 err, scan_code ; char ascii ; /* Suspend this thread (let it "sleep") until a */ /* keyboard interrupt posts something to our */ /* mailbox. But first position the cursor */ /* at the next character position as a prompt. */ WindowSelect(local) ; scan_code = ((unsigned) OSQPend(kybd_queue, 0, &err)) & 0xFF ; if (scan_code & 0x80) continue ; /* Key up */ /* The keyboard ISR just woke us up. scan_code */ /* is the keystroke that occurred. First check */ /* to see if it simply changes state, like caps */ /* lock, shift, ctrl, or alt. Then convert the */ /* scancode to ascii using the current state. */ if (SetsKybdState(scan_code)) continue ; ascii = ScanCode2Ascii(scan_code) & 0xFF ; if (!isprint(ascii) && !iscntrl(ascii)) continue ; /* Display the character in the local window. */ WindowPutChar(local, ascii) ; SendPacket(1, &ascii, 1) ; if (ascii == '\r') { static char linefeed = '\n' ; WindowPutChar(local, linefeed) ; SendPacket(1, &linefeed, 1) ; } } }
int main( void ) { SerialInit(MYUBRR); while(1) { _delay_ms(10000); SendString("LAB"); } }
void ResetTerminal(void) { int i; SerialInit(baud9k6); SerialOutputString(" c"); for(i = 0; i < 100; i++) SerialOutputByte('\r'); SerialOutputString("c"); }
int main(void) { ClockInit(); SerialInit(); TimerInit(); //ADMUX = POWER_IN;//A7 power DIDR0 |= _BV(0);//1 ADCSRA = _BV(ADEN) | _BV(ADPS0) | _BV(ADPS1) | _BV(ADPS2);// | _BV(ADIE) | _BV(ADATE) _BV(ADSC) | ADCSRB = _BV(ADLAR); loop(); }
void MasterInitialize()//called on startup, will call the port setup etc. as well as find the appropriate setting for the pot { cli();//disable interrupts ADCInit(); PortInit();//these init values (clock and port) are taken directly from our old code ClockInit(); SerialInit(); sei();//enable interrupts return; }
void main() { //uchar i; //EX1=1; //IT1=1; LCDInit(); SerialInit(); len=strlen(value); for(i=0; i<len; i++) LCDWriteData(value[i]); //sendsms(); //DialVoiceCall(); // while(1) { ConnectGPRS(0.3,0.4,0.8); //delay(3000); //LCDWriteCom(0x01);//清屏 /* LCDWriteCom(0x80); if(pulse==1) { TL0=0; while(pulse); TR0=1; while(!pulse); TR0=0; count=TL0; P1=count; duration=(unsigned long)count; lowpulseoccupancy = lowpulseoccupancy+duration; ratio = lowpulseoccupancy/(sampletime_ms*10.0); // Integer percentage 0=>100 concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve //Serial.print("yeelink:"); //Serial.println(concentration); //ConnectGPRS(concentration,(float)DHT11.temperature,(float)DHT11.humidity); memset(value,0x00,20); sprintf(value,"%s%f","yeelink:",concentration); len=strlen(value); for(i=0;i<len;i++) LCDWriteData(value[i]); lowpulseoccupancy = 0; // delay(3000); } */ } }
int serial_init (void) { const char * serial_port = "/dev/ttyUSB0"; out = (char *) malloc(sizeof(char)*8); SerialInit(serial_port, 9600, &serial_fd); fd = fdopen(serial_fd, "rw"); if (serial_fd > 0) { pthread_mutex_t serial_mutex = PTHREAD_MUTEX_INITIALIZER; servo.xPos = MIN_X_PWM+(MAX_X_PWM-MIN_X_PWM)/2; servo.yPos = MIN_Y_PWM+(MAX_Y_PWM-MIN_Y_PWM)/2; sprintf(out, "#%04d%04d$", MIN_X_PWM+(MAX_X_PWM-MIN_X_PWM)/2, MIN_Y_PWM+(MAX_Y_PWM-MIN_Y_PWM)/2); write(serial_fd,out,10); tcflush(serial_fd, TCIFLUSH); return 0; } else { fprintf (stderr,"failed to open serial port!\n"); return -1; } }
void __cdecl ldr_logo() { kboot_info *bi; unsigned char ch; UINT32 e; HeapInit(); ConsoleInit(); TxtSetFlags(BGCOLOR_BLACK|FGCOLOR_GREEN); TxtClearScreen(); SerialInit(); PicInit(); DescriptorsInit(); InterruptsInit(); ExceptionsInit(); DbgInit(); _enable(); IrqInit(); TssInit(); Vm86Init(); TimerInit(); KbdInit(); //DbgStepEnable(); StorageProbe(); e = VolReadFile("A:\\OSLDR.EXE", (VPTR)0x300000); DbgPrintf("%s\n", DbgStatusStr(e)); if(VideoInit()) { DbgPrintf("\nError Initializing Video Subsystem"); } while(1) { ch=KbdGetKey(); _Putch(ch); if(ch==33) KbdCpuReset(); } while(1); }
/***************************************************************************** * * This is the main loop that runs the application. * *****************************************************************************/ int main(void) { tRectangle sRect; MMUConfigAndEnable(); /* Enable USB module clock */ USB0ModuleClkConfig(); /* configures arm interrupt controller to generate raster interrupt */ USBInterruptEnable(); /* LCD Back light setup */ LCDBackLightEnable(); /* UPD Pin setup */ UPDNPinControl(); /* Delay timer setup */ DelayTimerSetup(); /* Configures raster to display image */ SetUpLCD(); /* Configures raster to display image and Copy palette info into buffer */ LCDInit(); GrOffScreen24BPPInit(&g_s35_800x480x24Display, g_pucBuffer, LCD_WIDTH, LCD_HEIGHT); /* Initialize a drawing context. */ GrContextInit(&g_sContext, &g_s35_800x480x24Display); /* enable End of frame interrupt */ RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS); /* enable raster */ RasterEnable(SOC_LCDC_0_REGS); /* Fill the top 24 rows of the screen with blue to create the banner. */ sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = (MAX_ROW_NUM - 1); GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); /* Put a white box around the banner. */ GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); /* Put the application name in the middle of the banner. */ GrContextFontSet(&g_sContext, &g_sFontCm20); GrStringDrawCentered(&g_sContext, "usb-dev-composite", -1, GrContextDpyWidthGet(&g_sContext) / 2, 10, 0); /* Show the various static text elements on the color STN display. */ GrContextFontSet(&g_sContext, TEXT_FONT); GrContextForegroundSet(&g_sContext, ClrViolet); GrStringDraw(&g_sContext, "CDC Serial 1 :-", -1, CDC1_STR_X_POSITION, CDC1_STR_Y_POSITION, false); GrStringDraw(&g_sContext, "CDC Serial 2 :-", -1, CDC2_STR_X_POSITION, CDC1_STR_Y_POSITION, false); GrContextForegroundSet(&g_sContext, ClrWhite); GrStringDraw(&g_sContext, "Tx bytes:", -1, CDC1_STR_X_POSITION, (CDC1_STR_Y_POSITION + CDC_STR_Y_DIFF), false); GrStringDraw(&g_sContext, "Tx buffer:", -1, CDC1_STR_X_POSITION, (CDC1_STR_Y_POSITION + (CDC_STR_Y_DIFF * 2)), false); GrStringDraw(&g_sContext, "Rx bytes:", -1, CDC1_STR_X_POSITION, (CDC1_STR_Y_POSITION + (CDC_STR_Y_DIFF * 4)), false); GrStringDraw(&g_sContext, "Rx buffer:", -1, CDC1_STR_X_POSITION, (CDC1_STR_Y_POSITION + (CDC_STR_Y_DIFF * 5)), false); DrawBufferMeter(&g_sContext, CDC1_BUF_METER_X_POS, CDC1_BUF_METER_Y_POS); DrawBufferMeter(&g_sContext, CDC1_BUF_METER_X_POS, (CDC1_BUF_METER_Y_POS + CDC_BUF_METER_Y_DIFF)); GrStringDraw(&g_sContext, "Tx bytes:", -1, CDC2_STR_X_POSITION, (CDC2_STR_Y_POSITION + CDC_STR_Y_DIFF), false); GrStringDraw(&g_sContext, "Tx buffer:", -1, CDC2_STR_X_POSITION, (CDC2_STR_Y_POSITION + (CDC_STR_Y_DIFF * 2)), false); GrStringDraw(&g_sContext, "Rx bytes:", -1, CDC2_STR_X_POSITION, (CDC2_STR_Y_POSITION + (CDC_STR_Y_DIFF * 4)), false); GrStringDraw(&g_sContext, "Rx buffer:", -1, CDC2_STR_X_POSITION, (CDC2_STR_Y_POSITION + (CDC_STR_Y_DIFF * 5)), false); DrawBufferMeter(&g_sContext, CDC2_BUF_METER_X_POS, CDC2_BUF_METER_Y_POS); DrawBufferMeter(&g_sContext, CDC2_BUF_METER_X_POS, (CDC2_BUF_METER_Y_POS + CDC_BUF_METER_Y_DIFF)); DisplayStatus(&g_sContext, " Waiting for host... "); /* Pass the USB library our device information, initialize the USB controller and connect the device to the bus. */ g_psCompDevices[0].pvInstance = USBDCDCCompositeInit(0, (tUSBDCDCDevice *)&g_sCDCDevice1); g_psCompDevices[1].pvInstance = USBDCDCCompositeInit(0, (tUSBDCDCDevice *)&g_sCDCDevice2); /* Pass the device information to the USB library and place the device on the bus. */ USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_DATA_SIZE, g_pucDescriptorData); /* Initialize the serial devices. */ SerialInit(); /* Drop into the main loop. */ while(1) { /* Allow the main serial routine to run. */ SerialMain(); } }
//**************************************************************************** // // This is the main loop that runs the application. // //**************************************************************************** int main(void) { // // Set the clocking to run from the PLL at 50MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set the system tick to fire 100 times per second. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&sDMAControlTable[0]); ROM_uDMAEnable(); // // Initialize the idle timeout and reset all flags. // g_ulIdleTimeout = 0; g_ulFlags = 0; g_eMSCState = MSC_DEV_DISCONNECTED; // // Pass the USB library our device information, initialize the USB // controller and connect the device to the bus. // g_psCompDevices[0].pvInstance = USBDMSCInit(0, (tUSBDMSCDevice *)&g_sMSCDevice); g_psCompDevices[1].pvInstance = USBDCDCCompositeInit(0, (tUSBDCDCDevice *)&g_sCDCDevice); // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass the device information to the USB library and place the device // on the bus. // USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_DATA_SIZE, g_pucDescriptorData); SerialInit(); disk_initialize(0); // // Drop into the main loop. // while(1) { // // Allow the main serial routine to run. // SerialMain(); switch(g_eMSCState) { case MSC_DEV_READ: { // // Update the screen if necessary. // if(g_ulFlags & FLAG_UPDATE_STATUS) { g_ulFlags &= ~FLAG_UPDATE_STATUS; } // // If there is no activity then return to the idle state. // if(g_ulIdleTimeout == 0) { g_eMSCState = MSC_DEV_IDLE; } break; } case MSC_DEV_WRITE: { // // Update the screen if necessary. // if(g_ulFlags & FLAG_UPDATE_STATUS) { g_ulFlags &= ~FLAG_UPDATE_STATUS; } // // If there is no activity then return to the idle state. // if(g_ulIdleTimeout == 0) { g_eMSCState = MSC_DEV_IDLE; } break; } case MSC_DEV_DISCONNECTED: { // // Update the screen if necessary. // if(g_ulFlags & FLAG_UPDATE_STATUS) { g_ulFlags &= ~FLAG_UPDATE_STATUS; } break; } case MSC_DEV_IDLE: { break; } default: { break; } } } }
void initArduino() { //armArduinoHandle = SerialInit(armArduinoPort, 9600, 8, 0, 0, 0, 0, 0); bagArduinoHandle = SerialInit(bagArduinoPort, 9600, 8, 0, 0, 0, 0, 0); }
int _tmain(int argc, _TCHAR* argv[]) { int hmin=175, hmax=185, smin=65, smax=108, vmin=136, vmax=253; cv::VideoCapture cap; DCB dcb; DWORD byteswritten; char a[]="abcdefg"; HANDLE hPort; SerialInit(&hPort,&dcb); WriteFile( hPort, a, sizeof(a), &byteswritten, NULL); std::cout<<byteswritten; CloseHandle(hPort); exit(1); std::cout << "initial webcam..."; cap.open(0); if(!cap.isOpened()) { std::printf("err init webcam!"); std::getchar(); return 0; } std::cout << "OK\n"; cv::namedWindow("Raw",cv::WINDOW_AUTOSIZE); cv::namedWindow("Histrogram",cv::WINDOW_AUTOSIZE); cv::namedWindow("Filtered",cv::WINDOW_AUTOSIZE); cv::namedWindow("Setting",cv::WINDOW_AUTOSIZE); cv::setMouseCallback("Raw",onMouse,0); cv::createTrackbar("Hmin","Setting",&hmin,255,0); cv::createTrackbar("Hmax","Setting",&hmax,255,0); cv::createTrackbar("Smin","Setting",&smin,255,0); cv::createTrackbar("Smax","Setting",&smax,255,0); cv::createTrackbar("Vmin","Setting",&vmin,255,0); cv::createTrackbar("Vmax","Setting",&vmax,255,0); int keycode=-1; while(keycode!=27) { cv::Mat frame,hsv,hist,histshow; cv::Mat hue,sat,val; histshow=cv::Mat::zeros(CAM_X,CAM_Y,CV_8UC3); hue=cv::Mat::zeros(CAM_X,CAM_Y,CV_8UC1); sat=cv::Mat::zeros(CAM_X,CAM_Y,CV_8UC1); val=cv::Mat::zeros(CAM_X,CAM_Y,CV_8UC1); cv::Mat threshold=cv::Mat::zeros(CAM_X,CAM_Y,CV_8UC1); double tt=(double)cv::getTickCount(); cap >> frame; if(frame.empty()) { std::cout<<"err!!!"; cv::waitKey(0); break; } cv::cvtColor(frame,hsv,CV_BGR2HSV); //split channels cv::Mat out[]={hue,sat,val}; int channelmapping[]={0,0,1,1,2,2}; cv::mixChannels(&hsv,3,out,3,channelmapping,3); //end split channels /* frame.adjustROI( select_rect.y, select_rect.x+select_rect.height, select_rect.x, select_rect.x+select_rect.width); */ float histranges[] = {0,180}; const float* phistranges = histranges; int ch[]={0}; int histdim=64; cv::Mat mask; cv::Mat roi(hue,select_rect); cv::Mat maskroi(mask,select_rect); cv::calcHist(&roi,1,0,maskroi,hist,1,&histdim,&phistranges,true,false); //threshold cv::inRange(hue,hmin,hmax,hue); cv::inRange(sat,smin,smax,sat); cv::inRange(val,vmin,vmax,val); //end threshold //and cv::bitwise_and(hue,sat,threshold,hue); cv::bitwise_and(threshold,val,threshold,val); //end and //erode&dilate cv::erode(threshold,threshold,cv::getStructuringElement(cv::MORPH_RECT,cv::Size(3,3)),cv::Point(-1,-1),1,0); cv::dilate(threshold,threshold,cv::getStructuringElement(cv::MORPH_RECT,cv::Size(5,5)),cv::Point(-1,-1),10,0); //end erode&dilate //find corner std::vector<cv::Point2f> eig; cv::goodFeaturesToTrack(threshold,eig,50,0.01,10,cv::Mat(),3,false,0.04); cv::cornerSubPix(threshold,eig,cv::Size(10,10),cv::Size(-1,-1),cv::TermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03)); cv::Point obj_origin; cv::Point obj_corner; cv::Rect obj_rect; obj_origin.x=(int)eig[0].x; obj_origin.y=(int)eig[0].y; obj_corner.x=(int)eig[0].x; obj_corner.y=(int)eig[0].y; for(int i=0;i<(int)eig.size();i++) { obj_origin.x=MIN(obj_origin.x,(int)eig[i].x); obj_origin.y=MIN(obj_origin.y,(int)eig[i].y); obj_corner.x=MAX(obj_corner.x,(int)eig[i].x); obj_corner.y=MAX(obj_corner.y,(int)eig[i].y); cv::circle(frame,eig[i],1,cv::Scalar(255,0,0),1,8,0); } obj_rect.x=obj_origin.x; obj_rect.y=obj_origin.y; obj_rect.width=abs(obj_rect.x-obj_corner.x); obj_rect.height=abs(obj_rect.y-obj_corner.y); //end find corner cv::rectangle(frame,obj_rect,cv::Scalar(0,0,255),1,8,0); cv::rectangle(frame,select_rect,cv::Scalar(0,255,0),1,8,0); cv::imshow("Raw",frame); cv::imshow("Filtered",threshold); tt=(double)cv::getTickCount()-tt; tt=tt/cv::getTickFrequency()*1000; std::cout<< "t:" << tt << "ms\n"; keycode=cv::waitKey(1); } std::cout << keycode; cv::destroyWindow("Raw"); cv::destroyWindow("Histrogram"); cv::destroyWindow("Filtered"); cv::destroyWindow("Setting"); cv::waitKey(0); return 0; }
/** * Constructs the AHRS class using serial communication and the default update rate, * and returning processed (rather than raw) data. *<p> * This constructor should be used if communicating via either * TTL UART or USB Serial interface. *<p> * @param serial_port_id SerialPort to use */ AHRS::AHRS(SerialPort::Port serial_port_id) { SerialInit(serial_port_id, SerialDataType::kProcessedData, NAVX_DEFAULT_UPDATE_RATE_HZ); }
/** * Constructs the AHRS class using serial communication, overriding the * default update rate with a custom rate which may be from 4 to 60, * representing the number of updates per second sent by the sensor. *<p> * This constructor should be used if communicating via either * TTL UART or USB Serial interface. *<p> * Note that the serial interfaces can communicate either * processed data, or raw data, but not both simultaneously. * If simultaneous processed and raw data are needed, use * one of the register-based interfaces (SPI or I2C). *<p> * Note that increasing the update rate may increase the * CPU utilization. *<p> * @param serial_port_id SerialPort to use * @param data_type either kProcessedData or kRawData * @param update_rate_hz Custom Update Rate (Hz) */ AHRS::AHRS(SerialPort::Port serial_port_id, AHRS::SerialDataType data_type, uint8_t update_rate_hz) { SerialInit(serial_port_id, data_type, update_rate_hz); }
void initRoboteq() { roboteqHandle = SerialInit(roboteqPort, 115200, 8, 0, 0, 0, 0, 0); SerialPuts(roboteqHandle, "!G 1 0000\r!G 2 0000\r"); }
int main(void) { ClockInit(); SerialInit(); TimerInit(); loop(); }
int main ( void ) { int8_t status; sei(); SerialInit(MYUBRR); InitWatch(); /** * Reuse part of the idle thread's stack for the stack required * during this startup function. */ SP = (int)&idle_thread_stack[(IDLE_STACK_SIZE_BYTES/2) - 1]; /** * Note: to protect OS structures and data during initialisation, * interrupts must remain disabled until the first thread * has been restored. They are reenabled at the very end of * the first thread restore, at which point it is safe for a * reschedule to take place. */ /** * Initialise the OS before creating our threads. * * Note that we cannot enable stack-checking on the idle thread on * this platform because we are already using part of the idle * thread's stack now as our startup stack. Prefilling for stack * checking would overwrite our current stack. * * If you are not reusing the idle thread's stack during startup then * you are free to enable stack-checking here. */ status = atomOSInit(&idle_thread_stack[0], IDLE_STACK_SIZE_BYTES, FALSE); if (status == ATOM_OK) { /* Enable the system tick timer */ avrInitSystemTickTimer(); /* Create the main thread */ status = atomThreadCreate(&main_tcb, MAIN_THREAD_PRIO, main_thread_func, 0, &main_thread_stack[0], MAIN_STACK_SIZE_BYTES, FALSE); if (status == ATOM_OK) { /** * Application threads successfully created. It is * now possible to start the OS. Execution will not return * from atomOSStart(), which will restore the context of * our application thread and start executing it. * * Note that interrupts are still disabled at this point. * They will be enabled as we restore and execute our first * thread in archFirstThreadRestore(). */ atomOSStart(); } } while (1) { atomTimerDelay (2 * SYSTEM_TICKS_PER_SEC); // wait 2 sec } /* There was an error starting the OS if we reach here */ return (0); }
/** * Constructs the AHRS class using serial communication and the default update rate, * and returning processed (rather than raw) data. *<p> * This constructor should be used if communicating via either * TTL UART or USB Serial interface. *<p> * @param serial_port_id SerialPort to use */ AHRS::AHRS(SerialPort::Port serial_port_id) { printf("AHRS Constructor!\n"); SerialInit(serial_port_id, SerialDataType::kProcessedData, NAVX_DEFAULT_UPDATE_RATE_HZ); }
void c_main() { int i; bool autoboot=true; char cmd[128]; long timeout; int argc=0; char *argv[MAX_ARGS]; CMD_TBL *cptr; // initiate status. status.terminalSpeed = SERIAL_SPEED; status.downloadSpeed = SERIAL_DOWNLOAD_SPEED; /* initiate serial and timer */ // serial and timer init. SerialInit(status.terminalSpeed); printf("\n\nFFUART has been initiated"); TimerInit(); //// printf the required GPL string. ////////////////////////////////////// printf("\n\n"); //printf(" "PACKAGE "-" VERSION "\n Copyright 2005 Embedded Group at 211.1010@UESTC\n"); //printf(" Support:211.1010@UESTC\n"); printf("\n"); //MemCpy((char *)KERNEL_DRAM_BASE, (char *)KERNEL_SRAM_BASE, KERNEL_MAX_SIZE); // kernel image reload EthInit(); //sendtest(); ///// wait 10 seconds before starting autoboot. /////////////////////////// printf("Autoboot in progress, press any key to stop "); for (i=0; i<3; i++){ timeout = GetTime()+1; // 1ÃÊ°£ Delay printf("."); while (GetTime()<timeout){ if ((FFLSR & 0x00000001)){ // Serial FFRBR; autoboot = false; break; } } if (autoboot==false) break; } /* No key was pressed, so proceed booting the kernel. */ if (autoboot) { printf("Autoboot started.\n"); for (cptr=cmdTbl; cptr->cmd; cptr++){ if (!StrCmp(cptr->cmd, "boot")) break; } DoBootKernel(cptr, 1, 0); } /* Key was pressed, so proceed command mode. */ printf("\nAutoboot aborted\n"); printf("Type \"help\" to get a list of commands\n"); // the command loop. endless, of course. for(;;) { DisplayPrompt("bootloader>"); // wait an hour to get a command. GetCommand(cmd, 128, 3600); if (!cmd || !cmd[0]) continue; argc = GetArgs(cmd, argv); for (cptr=cmdTbl; cptr->cmd; cptr++){ if (!StrCmp(argv[0], cptr->cmd)){ (cptr->run)(cptr, argc, argv); break; } } if (!StrCmp(argv[0], "help") || !StrCmp(argv[0], "?")){ DoPrintfHelp(argc, argv); } else if (!(cptr->cmd)){ printf("\tUnknown command : %s\n", argv[0]); } } } // CMain.
/** * Constructs the AHRS class using serial communication, overriding the * default update rate with a custom rate which may be from 4 to 60, * representing the number of updates per second sent by the sensor. *<p> * This constructor should be used if communicating via either * TTL UART or USB Serial interface. *<p> * Note that the serial interfaces can communicate either * processed data, or raw data, but not both simultaneously. * If simultaneous processed and raw data are needed, use * one of the register-based interfaces (SPI or I2C). *<p> * Note that increasing the update rate may increase the * CPU utilization. *<p> * @param serial_port_id SerialPort to use * @param data_type either kProcessedData or kRawData * @param update_rate_hz Custom Update Rate (Hz) */ AHRS::AHRS(SerialPort::Port serial_port_id, AHRS::SerialDataType data_type, uint8_t update_rate_hz) { printf("AHRS Constructor!\n"); SerialInit(serial_port_id, data_type, update_rate_hz); }