int poweroff(void){ int success = 1; // Fail as default int i; for(i=0; i<5; i++){ // Maximum retry: 5 success = send_comm(CAM_POWEROFF, 0x00, 0x00, 0x00, 0x00); if (!success) {break;} } return success; }
// ============================================================================================================ // Resets the camera (For more information see the C329 UM) // Arguments : int res_type (0x00 for reset all, 0x01 for state machine reset) // Return : 0 for success, 1 for fail. // NOTE : [[NOT TESTED]] // ============================================================================================================ int reset(int res_type){ int success = 1; // Fail as default int i; for(i=0; i<5; i++){ // Maximum retries: 5 success = send_comm(CAM_RESET, 0x00, 0x00, 0x00, res_type); if (!success) {break;} } return success; }
void quitme(Display *display, GC gc, GC his_gc, GC refresh_gc, int sockfd, int code) { if(sending) { send_comm(sockfd, 0, -1, -1, -1, -1); close(sockfd); } XFreePixmap(display, back_buffer); XFreeGC(display, gc); XFreeGC(display, his_gc); XFreeGC(display, refresh_gc); XCloseDisplay(display); exit(code); }
void handle_drag(Display* display, GC gc, XButtonEvent* drag_event, unsigned int win_width, unsigned int win_height, int sockfd) { int x, y; x = drag_event->x; y = drag_event->y; if(is_OK(x, y)) { XDrawLine(display, drag_event->window, gc, prevx, prevy, x, y); XDrawLine(display, back_buffer, gc, prevx, prevy, x, y); if(sending) send_comm(sockfd, prevx, prevy, x, y, 0); prevx = x; prevy = y; } XFlush(display); }
void handle_key(Display* display, Window win, GC gc, GC his_gc, GC refresh_gc, Colormap map, XKeyEvent* key_event, int sockfd) { char c = XLookupKeysym(key_event, 0); int w = -1; if(c == 'q') { q_count++; if(q_count >= 3) { quitme(display, gc, his_gc, refresh_gc, sockfd, 0); } } else { q_count = 0; if(c == 'l') { clear_all(display, key_event->window, refresh_gc); if(sending) send_comm(sockfd, 0, 0, 0, 0, 3); } else if('0' <= c && c <= '9') { current_color = c -'0'; set_color(display, gc, cols[c - '0'].pixel, sockfd); set_title(display, win); } else if(c == 'z' || c == 'x' || c == 'c' || c == 'v' || c == 'b' || c == 'n' || c == 'm') { switch(c) { case 'm': w++; case 'n': w++; case 'b': w++; case 'v': w++; case 'c': w++; case 'x': w++; case 'z': w++; break; } if(0 <= w) { current_width = line_widths[w]; set_width(display, gc, line_widths[w], sockfd); set_title(display, win); } } } }
void termios_test_entry(void *p) { int len = 0; int fd = -1; unsigned char *pBuf = RT_NULL; struct termios_test_s *pTerm = (struct termios_test_s *)p; if((fd = open_comm(pTerm->dev)) == -1) { rt_kprintf("Check the device name...\n"); return; } pBuf = (unsigned char *)rt_malloc(BUFFER_SIZE); RT_ASSERT(pBuf != RT_NULL); memset(pBuf, 0x00, BUFFER_SIZE); config_comm(fd, pTerm->baud_rate, Default_parity, 8, 1); flush_comm(fd); rt_kprintf("Block recv 10 bytes.\n"); /* Block recv 10 bytes */ len = recv_comm(fd, pBuf, 10, RT_NULL); rt_kprintf("Recv:%s\n", pBuf); send_comm(fd, pBuf, len); rt_kprintf("Termios test exit.\n"); close_comm(fd); rt_free(pBuf); pBuf = RT_NULL; }
// ============================================================================================================ // This function sends the necessary commands to take a photo in the C329 camera (For more information see C329's UM) // Arguments :The following are DEFAULTS values that WORK well // int resolution (resolution of the photo (0x07 for 640x480 pixels)) // int qual (quality of the photo (0x00 for best)) // int pic_type (type of the photo (0x05 for compression)) // Return :int length (0 is there's no photo or any ACK failed, value (nonzero) if not) // NOTE :[[Length variable type MUST be confirmed - Can be overflown by a big photo]] // ============================================================================================================ unsigned int cam_photo(int resolution, int qual, int pic_type){ unsigned int i; unsigned char recev[8]; unsigned int length = 0; int rinit = 1; int rquality = 1; int rphoto = 1; #if (SCH_CAMERA_VERBOSE>=2) printf("send_comm(INITIAL, 0x00, 0x87, resolution, resolution);\r\n"); #endif rinit = send_comm(CAM_INITIAL, 0x00, 0x87, resolution, resolution); // Send an INITIAL command and store the status flag received if(!rinit){ #if (SCH_CAMERA_VERBOSE>=2) printf("INITIAL was successful\r\n"); #endif __delay_ms(12); // Delay 12 us (Camera requirement) while(PPC_CAM_HOLD_CHECK){;} // Wait for low PPC_CAM_HOLD_CHECK signal rquality = send_comm(CAM_QUALITY, qual, 0x00, 0x00, 0x00); // Send a QUALITY command and store the status flag received if(!rquality){ #if (SCH_CAMERA_VERBOSE>=2) printf("QUALITY was successful\r\n"); #endif __delay_ms(12); // Delay 12 us (Camera requirement) while(PPC_CAM_HOLD_CHECK){;} // Wait for low PPC_CAM_HOLD_CHECK signal //rphoto = send_comm(SNAPSHOT); // This command is not necessary //delay_ms(12); //while(PPC_CAM_HOLD_CHECK){;} rphoto = send_comm(CAM_GETPIC, pic_type, 0x00, 0x00, 0x00); // Send a PHOTO command and store the received status flag if(!rphoto){ #if (SCH_CAMERA_VERBOSE>=2) printf("GETPIC was successful\r\n"); #endif __delay_ms(12); // Delay 12 us (Camera requirement) while(PPC_CAM_HOLD_CHECK){;} // Wait for low PPC_CAM_HOLD_CHECK signal SPI_nSS_1=0; // Select the camera for(i=0; i<8; i++){ recev[i] = SPI_1_transfer(CAM_DUMMY[i]); // Write a DUMMY data to receive a DATA command } SPI_nSS_1=1; // Deselect the camera __delay_ms(12); // Delay 12 us (Camera requierement) //puthex8(recev, 8); if( ( (recev[2]==0xff) && (recev[3]==0x0a) ) ){ // If received comm is DATA length = recev[5] + recev[6]*0x100 + recev[7]*0x10000; // Compute the length of the photo } } } } return length; }
void set_color(Display* display, GC gc, long c, int sockfd) { XSetForeground(display, gc, c); if(sending) send_comm(sockfd, (int)c, -1, -1, -1, 2); }
void set_width(Display* display, GC gc, int w, int sockfd) { XSetLineAttributes(display, gc, w, line_style, cap_style, join_style); if(sending) send_comm(sockfd, w, -1, -1, -1, 1); }