unsigned int send_add_tile(unsigned int i, int x, int y, int w, int h) { send_event(EVENT_ADD_TILE); send_index(i); send_value(x); send_value(y); send_value(w); send_value(h); return add_tile(i, x, y, w, h); }
unsigned int send_add_host(const char *name, int x, int y, int w, int h) { int n = strlen(name) + 1; send_event(EVENT_ADD_HOST); send_value(n); send_value(x); send_value(y); send_value(w); send_value(h); send_array(name, n, 1); return add_host(name, x, y, w, h); }
/** * Handle a value QUERY from server and send back the value */ void RF24SNPNode::handle_query_msg() { RF24NetworkHeader header; measurement_value_t payload; network.read(header, &payload, sizeof(payload)); send_value(payload.sensor); }
void Uniform::reset_bools() { std::map<GLuint,Program_Status>::iterator it=programs_status.begin(); for(;it!=programs_status.end();it++) { if( *((it->second).binded) ) { send_value(it->first); } else { *((it->second).uniform_sended)=false; } } }
int send_create_terrain(const char *filename, int w, int h, int n) { int l = strlen(filename); int i; if ((i = new_terrain())) { /* If the file exists and is successfully loaded... */ if (load_terrain(i, filename, w, h)) { terrain[i].count = 1; terrain[i].w = w; terrain[i].h = h; terrain[i].n = n; terrain[i].m = DEFAULT_SIZE; terrain[i].o = 3396000; terrain[i].bias = DEFAULT_BIAS; terrain[i].magn = DEFAULT_MAGN; /* Pack the header and data. */ send_event(EVENT_CREATE_TERRAIN); send_value(terrain[i].w); send_value(terrain[i].h); send_value(terrain[i].n); send_value(terrain[i].m); send_value(l); send_array(filename, l + 1, 1); /* Encapsulate this object in an entity. */ return send_create_entity(TYPE_TERRAIN, i); } } return -1; }
int main (int argc, char * argv []) { int err = -1; int f = -1; while (1) { if (argc != 3) break; word_t segment = 0; word_t offset = 0; sscanf (argv [2], "%hx:%hx", &segment, &offset); f = open (argv [1], O_RDWR | O_NOCTTY); if (f < 0) { perror ("open tty"); break; } _fi = f; _fo = f; // TTY setup struct termios tios; tcgetattr (f, &tios); //cfmakeraw (&tios); cfsetspeed (&tios, B9600); tcsetattr (f, TCSANOW, &tios); byte_t len; byte_t token [TOKEN_LEN_MAX]; // Check header err = send_value (0); if (err) { perror ("send header"); break; } err = recv_status (); if (err) { perror ("receive status header"); break; } // Set segment and offset err = send_value (segment); if (err) break; err = recv_status (); if (err) { perror ("receive status segment"); break; } err = send_command ('W', '8'); // ES register if (err) break; err = recv_status (); if (err) { perror ("receive status W8"); break; } err = send_value (offset); if (err) break; err = recv_status (); if (err) { perror ("receive status offset"); break; } err = send_command ('W', '5'); // DI register if (err) break; err = recv_status (); if (err) { perror ("receive status W5"); break; } while (1) { word_t val; int n = read (0, &val, 1); if (n != 1) break; err = send_value (val); if (err) { perror ("send value"); break; } err = recv_status (); if (err) { perror ("receive status value"); break; } err = send_command ('X', '1'); // write command if (err) break; err = recv_status (); if (err) { perror ("receive status X1"); break; } } break; } // Cleanup _fi = -1; _fo = -1; if (f) { close (f); f = -1; } return err; }
int main (int argc, char **argv) /* {{{ */ { int i; double last_time; int values_sent = 0; read_options (argc, argv); sigint_action.sa_handler = signal_handler; sigaction (SIGINT, &sigint_action, /* old = */ NULL); sigterm_action.sa_handler = signal_handler; sigaction (SIGTERM, &sigterm_action, /* old = */ NULL); values_heap = c_heap_create (compare_time); if (values_heap == NULL) { fprintf (stderr, "c_heap_create failed.\n"); exit (EXIT_FAILURE); } net = lcc_network_create (); if (net == NULL) { fprintf (stderr, "lcc_network_create failed.\n"); exit (EXIT_FAILURE); } else { lcc_server_t *srv; srv = lcc_server_create (net, conf_destination, conf_service); if (srv == NULL) { fprintf (stderr, "lcc_server_create failed.\n"); exit (EXIT_FAILURE); } lcc_server_set_ttl (srv, 42); #if 0 lcc_server_set_security_level (srv, ENCRYPT, "admin", "password1"); #endif } fprintf (stdout, "Creating %i values ... ", conf_num_values); fflush (stdout); for (i = 0; i < conf_num_values; i++) { lcc_value_list_t *vl; vl = create_value_list (); if (vl == NULL) { fprintf (stderr, "create_value_list failed.\n"); exit (EXIT_FAILURE); } c_heap_insert (values_heap, vl); } fprintf (stdout, "done\n"); last_time = 0; while (loop) { lcc_value_list_t *vl = c_heap_get_root (values_heap); if (vl == NULL) break; if (vl->time != last_time) { printf ("%i values have been sent.\n", values_sent); /* Check if we need to sleep */ double now = dtime (); while (now < vl->time) { /* 1 / 100 second */ struct timespec ts = { 0, 10000000 }; ts.tv_sec = (time_t) now; ts.tv_nsec = (long) ((now - ((double) ts.tv_sec)) * 1e9); nanosleep (&ts, /* remaining = */ NULL); now = dtime (); if (!loop) break; } last_time = vl->time; } send_value (vl); values_sent++; c_heap_insert (values_heap, vl); } fprintf (stdout, "Shutting down.\n"); fflush (stdout); while (42) { lcc_value_list_t *vl = c_heap_get_root (values_heap); if (vl == NULL) break; destroy_value_list (vl); } c_heap_destroy (values_heap); lcc_network_destroy (net); exit (EXIT_SUCCESS); } /* }}} int main */
void remote_thread_entry(void* parameter) { char * ptr; u8 lost=0; rt_tick_t last=rt_tick_get(); while(1) { ptr=pack.buf; get(ptr++); if(pack.buf[0]!=(head&0xFF)) goto wrong; get(ptr++); if(pack.head.head!=head) goto wrong; while(ptr-pack.buf<sizeof(struct tfcr_common)) get(ptr++); if(!TFCR_IS_PACK_TYPE(pack.head.type)) goto wrong; //rt_kprintf("head ok %d\n",sizeof(struct tfcr_common)); switch(pack.head.type) { case TFCR_TYPE_PING: while(ptr-pack.buf<sizeof(struct tfcr_ping)) get(ptr++); if(checksum(pack.buf,sizeof(struct tfcr_ping)-1)!=pack.ping.checksum) goto wrong; send_ack(pack.ping.index); debug("ping %05d\n",pack.ping.index); if(!tfrc_con) rt_kprintf("tfcr connected.\n"); tfrc_con=RT_TRUE; break; case TFCR_TYPE_TASK: while(ptr-pack.buf<sizeof(struct tfcr_task)) get(ptr++); if(checksum(pack.buf,sizeof(struct tfcr_task)-1)!=pack.task.checksum) goto wrong; if(rt_strcasecmp(pack.task.name,"mayday")==0) { excute_task("mayday"); disarm(); send_ack(pack.task.index); break; } if(pack.task.state==1) { fc_task * task=find_task(pack.task.name); if(task==RT_NULL) { send_error(pack.task.index,0xff); rt_kprintf("no task %s!\n",pack.task.name); break; } u8 result= check_safe(task->depend); if(result!=0) { send_error(pack.task.index,result); break; } if(!excute_task(pack.task.name)) { send_error(pack.task.index,0xff); break; } arm(task->depend); send_ack(pack.task.index); } else { excute_task("wait"); send_ack(pack.task.index); rt_kprintf("stop task %s.\n",pack.task.name); } break; case TFCR_TYPE_GET_VALUE: while(ptr-pack.buf<sizeof(struct tfcr_get_value)) get(ptr++); if(checksum(pack.buf,sizeof(struct tfcr_get_value)-1)!=pack.get.checksum) goto wrong; send_value(pack.get.index,pack.get.id); break; } last=rt_tick_get(); lost=0; continue; timeout: if(tfrc_con) { if(lost<3) { rt_kprintf("tfcr time out.\n"); lost++; } else { rt_kprintf("tfcr lost connect.\n"); tfrc_con=RT_FALSE; } } continue; wrong: rt_kprintf("wrong\n"); if(rt_tick_get()-RT_TICK_PER_SECOND/2>last) { rt_tick_t last=rt_tick_get(); goto timeout; } } }
int main(int argc, char **argv) { struct i2c_client cliente; int retval; struct uinput_user_dev uidev; if (argc<3) { printf("Version 7\n"); printf("Format: driver [-res XxY] [-gpio PATH] [-invert_x] [-invert_y] DEVICE FW_FILE\n\n"); printf("-res XxY: specifies that the screen resolution is X width and Y height (default: 800x480)\n"); printf("-gpio PATH: sets the path to the GPIO device that enables and disables the touch chip\n"); printf("-invert_x: inverts the X coordinates\n"); printf("-invert_y: inverts the Y coordinates\n"); printf("-new_scroll: do scroll with a single finger\n"); printf("DEVICE: path to the I2C device where the GSLx680 chip is connected\n"); printf("FW_FILE: path to the firmware file for the GSLx680 chip\n"); return 0; } char *adapter=NULL; char *firmware=NULL; char *option; cliente.invert_x=0; cliente.invert_y=0; cliente.gpio="/sys/devices/virtual/misc/sun4i-gpio/pin/pb3"; cliente.resx=SCREEN_MAX_X; cliente.resy=SCREEN_MAX_Y; #ifdef USE_FB int fb_dev; fb_dev=open("/dev/fb0",O_RDWR); if (fb_dev>0) { struct fb_var_screeninfo vinfo; if (0==ioctl (fb_dev, FBIOGET_VSCREENINFO, &vinfo)) { cliente.resx=vinfo.xres; cliente.resy=vinfo.yres; } close(fb_dev); } #endif int loop=1; while(loop<argc) { option=argv[loop]; loop++; if (option[0]=='-') { if (!strcmp(option,"-invert_x")) { cliente.invert_x=1; continue; } if (!strcmp(option,"-invert_y")) { cliente.invert_y=1; continue; } if (!strcmp(option,"-new_scroll")) { cliente.new_scroll=1; continue; } if (loop==argc) { printf("Error: option %s doesn't have parameters\n",option); return -1; } if (!strcmp(option,"-res")) { if (2!=sscanf(argv[loop],"%dx%d",&cliente.resx,&cliente.resy)) { printf("Error: resolution %s has an incorrect format\n",argv[loop]); return -1; } loop++; continue; } if (!strcmp(option,"-gpio")) { cliente.gpio=strdup(argv[loop]); loop++; continue; } printf("Unknown option %s\n",option); return -1; } if (adapter==NULL) { adapter=strdup(option); continue; } if (firmware==NULL) { firmware=strdup(option); continue; } printf("Too many parameters\n"); return -1; } if (adapter==NULL) { printf("Missing adapter path\n"); return -1; } if (firmware==NULL) { printf("Missing firmware path\n"); return -1; } printf("Connecting to device %s, firmware %s\n",adapter,firmware); cliente.adapter=open(adapter,O_RDWR); if (cliente.adapter<0) { printf("Can't open device %s\n",adapter); return -1; } send_value(0,&cliente); usleep(100000); send_value(1,&cliente); if (ioctl(cliente.adapter, I2C_SLAVE, GSLX680_I2C_ADDR) < 0) { printf("Error selecting device %d\n",GSLX680_I2C_ADDR); return -2; } cliente.ufile=open("/dev/uinput", O_WRONLY | O_NONBLOCK); if (cliente.ufile<0) { cliente.ufile=open("/dev/input/uinput", O_WRONLY | O_NONBLOCK); if (cliente.ufile<0) { printf("Can't connect to UINPUT interface.\n"); return -2; } } retval = ioctl(cliente.ufile, UI_SET_EVBIT, EV_KEY); retval = ioctl(cliente.ufile, UI_SET_KEYBIT, BTN_TOUCH); retval = ioctl(cliente.ufile, UI_SET_EVBIT, EV_ABS); retval = ioctl(cliente.ufile, UI_SET_ABSBIT, ABS_X); retval = ioctl(cliente.ufile, UI_SET_ABSBIT, ABS_Y); memset(&uidev, 0, sizeof(uidev)); snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "gsl1680-uinput"); uidev.id.bustype = BUS_I2C; uidev.id.vendor = 0x1; uidev.id.product = 0x1; uidev.id.version = 1; uidev.absmin[ABS_X] = 0; uidev.absmax[ABS_X] = cliente.resx-1; uidev.absmin[ABS_Y] = 0; uidev.absmax[ABS_Y] = cliente.resy-1; retval = write(cliente.ufile, &uidev, sizeof(uidev)); retval = ioctl(cliente.ufile, UI_DEV_CREATE); retval = ioctl(cliente.ufile, UI_SET_PROPBIT,INPUT_PROP_DIRECT); retval = ioctl(cliente.ufile, UI_SET_PROPBIT,INPUT_PROP_POINTER); cliente.mfile=open("/dev/uinput", O_WRONLY | O_NONBLOCK); if (cliente.mfile<0) { cliente.mfile=open("/dev/input/uinput", O_WRONLY | O_NONBLOCK); if (cliente.mfile<0) { printf("Can't connect to UINPUT interface.\n"); return -2; } } /* When a device uses ABSolute pointing, the X server doesn't allows to also use RELative pointing. * But we need it to allow scrolling and zooming, so we define another device, this time with only * relative pointing. * It also can emit the LEFT CONTROL key to emulate zoom in and zoom out (CTRL+vertical scroll) * Finally, it allows to emit CONTROL+MENU key to interface with TabletWM */ retval = ioctl(cliente.mfile, UI_SET_EVBIT, EV_KEY); retval = ioctl(cliente.mfile, UI_SET_KEYBIT, BTN_LEFT); retval = ioctl(cliente.mfile, UI_SET_KEYBIT, BTN_RIGHT); retval = ioctl(cliente.mfile, UI_SET_KEYBIT, KEY_LEFTCTRL); retval = ioctl(cliente.mfile, UI_SET_KEYBIT, KEY_COMPOSE); retval = ioctl(cliente.mfile, UI_SET_EVBIT, EV_REL); retval = ioctl(cliente.mfile, UI_SET_RELBIT, REL_X); retval = ioctl(cliente.mfile, UI_SET_RELBIT, REL_Y); retval = ioctl(cliente.mfile, UI_SET_RELBIT, REL_WHEEL); retval = ioctl(cliente.mfile, UI_SET_RELBIT, REL_HWHEEL); memset(&uidev, 0, sizeof(uidev)); snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "gsl1680-2-uinput"); uidev.id.bustype = BUS_I2C; uidev.id.vendor = 0x1; uidev.id.product = 0x2; uidev.id.version = 1; retval = write(cliente.mfile, &uidev, sizeof(uidev)); retval = ioctl(cliente.mfile, UI_SET_PROPBIT,INPUT_PROP_POINTER); retval = ioctl(cliente.mfile, UI_DEV_CREATE); init_chip(&cliente,firmware); while(1) { read_coords(&cliente); usleep(20000); // do 50 reads per second } }
static int gslX680_shutdown_high(struct i2c_client *cliente) { send_value(1,cliente); return 0; }
static int gslX680_shutdown_low(struct i2c_client *cliente) { send_value(0,cliente); return 0; }