int main(void) { lb_init(&lb); event_init(); motor_init(); uart_init(); // init USART enc_init(); i2c_init(); adc_init(); kalman_init(); sei(); // enable interrupts // Wait a second at startup _delay_ms(1000); // send initial string printf_P(PSTR("Hello world!\n")); imu_init(); for (;/*ever*/;) { // ADCSRA |= (1<<ADSC); // Set start conversion bit and wait for conversion to finish // while(ADCSRA&(1<<ADSC)); // OCR1AL = ADCH; // Set ADC reading to timer 0 compare if(event_pending()) { event_action(); } else // No pending operation, do low priority tasks { // dequeue receive buffer if any bytes waiting while (uart_avail()) { char c = uart_getc(); if (lb_append(&lb, c) == LB_BUFFER_FULL) { lb_init(&lb); // Clear line printf_P(PSTR("\nMax line length exceeded\n")); } // Process command if line buffer is ready ... if (lb_line_ready(&lb)) { strcpy(cmd_string,lb_gets(&lb)); do_cmd(cmd_string); lb_init(&lb); } } } // Process command if line buffer is terminated by a line feed or carriage return } return 0; }
/************************************************************************ * * * Expression text callback routine. * (STATIC) * * */ void Win_math::text_proc(Panel_item item, Event *event) { short action = event_action(event); short chr = xview_to_ascii(action); fprintf(stderr,"char=0x%x\n", chr); /*fprintf(stderr,"posn=%d\n", (int)xv_get(item, PANEL_TEXT_CURSOR));*/ xv_set(item, PANEL_TEXT_SELECT_LINE, NULL); #ifndef LINUX textsw_set_selection(wm->expression_box, 1, 4, 1); #endif xv_set(wm->expression_box, TEXTSW_INSERTION_POINT, 4, NULL); }
/* * Event callback function for `status_pu'. */ Notify_value status_pu_status_pu_event_callback(Xv_window win, Event *event, Notify_arg arg, Notify_event_type type) { status_pu_status_pu_objects *ip = (status_pu_status_pu_objects *) xv_get(win, XV_KEY_DATA, INSTANCE); fprintf(stderr, "cidd_gui: status_pu_status_pu_event_callback: event %d\n", event_id(event)); /* gxv_start_connections DO NOT EDIT THIS SECTION */ if (event_action(event) == WIN_RESIZE) { status_resize_proc(win, event, arg, type); } /* gxv_end_connections */ return notify_next_event_func(win, (Notify_event) event, arg, type); }
static void Zlab_event_proc(Xv_Window window, Event *event) { int itrc; itrc= (int)xv_get(window, XV_KEY_DATA, TRACK_INDEX)+lowZTrkIndex; if (itrc>LastTrack || traces[itrc]->wave==NULL) return; /* ignore */ switch(event_action(event)) { case ACTION_MENU: case MS_RIGHT: { if(event_is_up(event)) { open_info_win(); DisplayTraceInfo(itrc); } break; } default: break; } }
/*doworking*/ void select_my_fd(char *device_id) { int ret = 0; int event_fd = -1 ; int fifo_fd = -1; int maxfd = 0; int rd = 0; char cmd_str[1024] = {0}; fd_set rfds; struct input_event ev[64]; memset(&ev[0], 0, 64*sizeof(struct input_event)); CONTEXT ctx; memset(&ctx, 0, sizeof(CONTEXT)); ctx.mode = MODE_ACTIVE; ctx.state = STATE_UNLOGIN; ctx.pdata = NULL; struct timeval tv; memset(&tv, 0, sizeof(struct timeval)); event_fd = open("/dev/input/event0", O_RDONLY); if (event_fd < 0) { perror("open event0 file"); } while(1) { if (fifo_fd < 0) { fifo_fd = open("/var/run/comm.fifo", O_RDONLY | O_NONBLOCK); } FD_ZERO(&rfds); if (event_fd > 0) { FD_SET(event_fd, &rfds); } if (fifo_fd > 0) { FD_SET(fifo_fd, &rfds); } maxfd = MAX(fifo_fd, event_fd); //printf("doworking maxfd: %d\n", maxfd); ret = select(maxfd + 1, &rfds, NULL, NULL, NULL); if (ret < 0) { perror("select error"); break; } else if (FD_ISSET(event_fd, &rfds)) { printf("get event\n"); rd = read(event_fd, ev, sizeof(struct input_event) *64); if (rd < (int )sizeof(struct input_event)) { perror("reading input_event"); continue; } event_action(&ctx, ev, rd / sizeof(struct input_event)); } else if (FD_ISSET(fifo_fd, &rfds)) { printf("get cmd!\n"); memset(cmd_str, 0, 1024); rd = read(fifo_fd, cmd_str, 1024); if (rd < 0) { perror("read command fifo"); //continue; } printf("get cmd:%s from fifo\n", cmd_str); struct json_object * pjson_obj_cmd = NULL; pjson_obj_cmd = json_tokener_parse(cmd_str); parse_cmdstr(pjson_obj_cmd); json_object_put(pjson_obj_cmd); close(fifo_fd); fifo_fd = -1; } } printf("doworking end!\n"); }
/************************************************************************ * * * Mouse event Graphics-tool: Zoom. * * This function will be called if there is an event related to Zoom. * * */ Routine_type Zoom_routine::process(Event *e) { static float left; // Starting positions of zoom cursors static float right; static float top; static float bottom; static int prevx; static int prevy; static short firstx; // first x mouse cursor value static short firsty; // first y mouse cursor value static Imginfo *z_imginfo; // Hold the selected image information static Gframe *z_gframe; // Hold the selected frame info Gframe *gframe; // loop for selected frame int nth; // loop counter Imginfo *iptr; // image information pointer short x = event_x(e); short y = event_y(e); int nfrms; switch (event_action(e)) { case LOC_DRAG: // Execute only if there is a selected zoomed lines. if (Zoomf::zline == 0){ return(ROUTINE_FRAME_SELECT); } // Move the zoom-lines to which the cursor points z_imginfo->move_zlines(x - firstx, y - firsty, left, right, top, bottom, Zoomf::color, Zoomf::zline); if (Zoomf::bind){ // Move zoom-lines for all selected frames nfrms = 0; for (nth=1, gframe=Frame_select::get_selected_frame(nth); gframe; nth++, gframe=Frame_select::get_selected_frame(nth)) { if ((iptr = gframe->imginfo) && (iptr != z_imginfo) && nfrms < Zoomf::max_tracks) { iptr->replace_zlines(z_imginfo->zlinex1, z_imginfo->zlinex2, z_imginfo->zliney1, z_imginfo->zliney2, Zoomf::color); nfrms++; } } /* for */ } /* if (Zoomf::bind) */ prevx = x; prevy = y; return(ROUTINE_DONE); case ACTION_SELECT: if (event_is_down(e)) { // Move zoom-lines. Note that we search for all frames for (nth=1, gframe=Frame_select::get_selected_frame(nth); gframe; nth++, gframe=Frame_select::get_selected_frame(nth)) { // A frame should contains an image and the cursor should be // within image boundary if ((iptr = gframe->imginfo) && com_point_in_rect(x, y, iptr->pixstx - Zoomf::aperture, iptr->pixsty - Zoomf::aperture, iptr->pixstx + iptr->pixwd + Zoomf::aperture, iptr->pixsty + iptr->pixht + Zoomf::aperture)) { // If no selected zoom-line, it means that it moves all // zoom lines if (!(Zoomf::zline=gframe->imginfo->select_zoom_lines(x, y, Zoomf::aperture, Zoomf::zline))) { Zoomf::zline |= ZLINE_ALL; } prevx = firstx = x; prevy = firsty = y; z_gframe = gframe; z_imginfo = gframe->imginfo; left = z_imginfo->zlinex1; right = z_imginfo->zlinex2; top = z_imginfo->zliney1; bottom = z_imginfo->zliney2; return(ROUTINE_DONE); } /* if com_point_in_rect(...) */ } /* for */ // Nothing to zoom return(ROUTINE_FRAME_SELECT); } else { // event_is_up(e) // Execute only if there is a selected zoomed line. if (Zoomf::zline == 0){ return(ROUTINE_FRAME_SELECT); } // Move the zoom-lines to which the cursor points z_imginfo->move_zlines(x - firstx, y - firsty, left, right, top, bottom, Zoomf::color, Zoomf::zline); /*z_imginfo->move_zlines(x, y, prevx, prevy, Zoomf::color, Zoomf::zline);*/ if (Zoomf::bind){ // Move zoom-lines for all selected frames for (nth=1, gframe=Frame_select::get_selected_frame(nth); gframe; nth++, gframe=Frame_select::get_selected_frame(nth)) { if ((iptr = gframe->imginfo) && (iptr != z_imginfo)) { iptr->replace_zlines(z_imginfo->zlinex1, z_imginfo->zlinex2, z_imginfo->zliney1, z_imginfo->zliney2, Zoomf::color); } } /* for */ } /* if (Zoomf::bind) */ Zoomf::zline = 0; return(ROUTINE_DONE); } /* event_is_up */ break; default: break; } /* switch */ return(ROUTINE_DONE); }
static void canvas_event_proc(Xv_Window, Event *event) { int i; register int x, y; // location of mouse pointer on canvas float fx; // Normalized location of mouse on canvas float fy; register int x0, y0; float dis; static int knot = -1; // Which knot mouse controls (-1=>none) static float mctl = 0.5; // Relative Y distance of ctl point from here static float fyother = 0; // Y position of other line end x = (int) event_x(event); y = (int) event_y(event); fx = (float)x / (vsi.canvas_width - 1); fy = (float)(vsi.canvas_height - 1 - y) / (vsi.canvas_height - 1); switch (event_action(event)){ case ACTION_SELECT: case ACTION_ADJUST: if (event_is_down(event)){ /*fprintf(stderr,"%.4f, %.4f, k=%.3f\n", fx, fy, knot2logparm(fx, fy));/*CMP*/ /* Find out which knot we want to change */ /* See if mouse pointer <= 2 * G_APERTURE pixels from a knot. */ int tst = 4 * G_APERTURE * G_APERTURE; knot = -1; for (i=0; i<vsi.nknots[vsi.myknots]; i++){ x0 = (int)(vsi.knotlists[vsi.myknots][i].x * (vsi.canvas_width - 1) + 0.5); y0 = (int)(vsi.canvas_height * (1-vsi.knotlists[vsi.myknots][i].y) + 0.5); if ((dis=(x-x0)*(x-x0) + (y-y0)*(y-y0)) <= tst){ knot = i; tst = dis; } } if (vsi.myknots == LIN_KNOTS || vsi.myknots == SPL_KNOTS){ if (event_action(event) == ACTION_SELECT){ if (knot < 0){ knot = create_knot(fx, fy); } }else{ // ACTION_ADJUST // Cannot delete end points if (knot > 0 && knot < vsi.nknots[vsi.myknots]-1){ delete_knot(knot); } knot = -1; } }else if (vsi.myknots == CRV_KNOTS){ // Remember relative position of control knot if (knot == 0){ fyother = vsi.knotlists[vsi.myknots][2].y; }else if (knot == 2){ fyother = vsi.knotlists[vsi.myknots][0].y; } if (fabs(fyother - fy) > 5.0 / (1 + vsi.canvas_height)){ mctl = ((vsi.knotlists[vsi.myknots][1].y - fy) / (fyother-fy)); } } }else{ /* (event_is_up) */ set_func_command(); func_update(); report_state(); // Notify client of new settings knot = -1; return; } break; case LOC_DRAG: if (knot == -1){ return; } break; default: return; } // Apply constraints to adjustment of knots if (fy < 0){ // Always stay on canvas fy = 0; }else if (fy > 1){ fy = 1; } if (vsi.myknots == CRV_KNOTS){ // Special contraints for these if (knot == 0 || knot == 2){ // Keep control knot between end points /*fprintf(stderr,"knot=%d, mctl=%f, fyother=%f, fy=%f\n", knot, mctl, fyother, fy);/*CMP*/ vsi.knotlists[vsi.myknots][1].y = fy + mctl * (fyother - fy); }else if (knot == 1){ fy = bound(fy, vsi.knotlists[vsi.myknots][0].y, vsi.knotlists[vsi.myknots][2].y); } } if (knot > 0 && knot < vsi.nknots[vsi.myknots] - 1){ // Knots cannot move past neighbors in x direction if (fx <= vsi.knotlists[vsi.myknots][knot-1].x){ fx = (vsi.knotlists[vsi.myknots][knot-1].x + 1.0 / (vsi.canvas_width - 1)); }else if (fx >= vsi.knotlists[vsi.myknots][knot+1].x){ fx = (vsi.knotlists[vsi.myknots][knot+1].x - 1.0 / (vsi.canvas_width - 1)); } vsi.knotlists[vsi.myknots][knot].x = fx; vsi.knotlists[vsi.myknots][knot].y = fy; }else if (knot == 0){ // First knot stays at left edge vsi.knotlists[vsi.myknots][knot].x = 0; vsi.knotlists[vsi.myknots][knot].y = fy; }else if (knot == vsi.nknots[vsi.myknots] - 1){ // Last knot at right edge vsi.knotlists[vsi.myknots][knot].x = 1; vsi.knotlists[vsi.myknots][knot].y = fy; } func_update(); }
void ResizeScreen(Xv_Window window, Event *event) { int newht, cfght, neww, cfgw; char *s; int tsht= 30; int panel_width = top_panel_width; if (event_action(event)==WIN_REPAINT) { if(Mode_noBorder) { GC gc= DefaultGC(theDisp, DefaultScreen(theDisp)); XFillRectangle(theDisp, xv_get(window,XV_XID), gc, TXTCANV_WIDTH-2,0,5,FrmHeight); } return; } /* only handles RESIZE events for this event_proc */ if (event_action(event)!=WIN_RESIZE) return; newht= (int)xv_get(tracesFrame, XV_HEIGHT); neww= (int)xv_get(tracesFrame, XV_WIDTH); /* ignore synthetic events from window manager */ if (event_xevent(event)->xconfigure.send_event!=TRUE) { int y, i, newtrkht; Track *trk; FrmHeight=newht; FrmWidth=neww; if((newht-panel_width-tsht)/NumTracks<30) tsht= 15; if(Mode_align) { newtrkht= (float)(newht-panel_width-tsht)/NumTracks; tsht= newht-panel_width-newtrkht*NumTracks; }else { newtrkht= (float)(newht-panel_width)/NumTracks; } y=panel_width; xv_set(tracesScvs, XV_X, neww-XVSBARWIDTH, XV_Y, panel_width, NULL); for(i=0; i < NumTracks; i++) { trk= tracks[i]; trk->height=newtrkht; trk->width=neww-TXTCANV_WIDTH-XVSBARWIDTH; if (trk->TxtCanvas) { if(Mode_noBorder) { xv_set(trk->TxtCanvas, XV_X, 0, XV_Y, y, XV_WIDTH, TXTCANV_WIDTH-2, XV_HEIGHT, newtrkht, NULL); }else { xv_set(trk->TxtCanvas, XV_X, 0, XV_Y, y, XV_WIDTH, TXTCANV_WIDTH, XV_HEIGHT, newtrkht, NULL); } } if (trk->canvas) { xv_set(trk->canvas, XV_X, TXTCANV_WIDTH, XV_Y, y, XV_WIDTH, neww-TXTCANV_WIDTH-19, XV_HEIGHT, newtrkht, NULL); } y+=newtrkht; } AdjustSbar(); SetSbarPosition(); for(i=0; i <= LastTrack; i++) { /* can't do this: clipping won't work * traces[i]->axis_needScale= 1; */ RescaleTrace(traces[i], newtrkht, tracks[0]->width); } if (Mode_align) { ResizeTScale(y, neww-19, tsht); } /* don't trust all the canvas being auto-repainted, known to fail user's expectations: here's the forbidden fix, but let the user control it. */ if (Mode_Auto_redraw) RedrawScreen(); } return; }