/** * @brief performs a basic error check and after everything has passed, passes the information onto server via sendall * after the execution of this function, we will have set a key along with its values inside the database * @param table name of the table we want to set to * @param key name of the key we want to set * @param record is the struct holding the configuration parameters of everything inside the configuration file * @param conn a pointer to the connection status of the server * @return return 0 for success, -1 for failure */ int storage_set(const char *table, const char *key, struct storage_record *record, void *conn) { // if we have not Connected, do not execute. Also raise the error if (didConnect != 1){ errno = ERR_CONNECTION_FAIL; return -1; } if (didAuthenticate != 1){ errno = ERR_NOT_AUTHENTICATED; return -1; } if (table == NULL || key == NULL || conn == NULL ){ errno = ERR_INVALID_PARAM; return -1; } // parse the values to see if its correct if (tablecheck(table) == 1 || keycheck(key) == 1 ){ errno = ERR_INVALID_PARAM; return -1; } // Connection is really just a socket file descriptor. int sock = (int)conn; // Send some data. char buf[MAX_CMD_LEN]; memset(buf, 0, sizeof buf); if(record != NULL){ snprintf(buf, sizeof buf, "SET %s %s %s\n", table, key, record->value); } else if(record == NULL){ snprintf(buf,sizeof buf, "SET %s %s null\n", table, key); } if (sendall(sock, buf, strlen(buf)) == 0 && recvline(sock, buf, sizeof buf) == 0) { if (strcmp("table_fail", buf)== 0){ errno = ERR_TABLE_NOT_FOUND; return -1; } else if (strcmp("key_fail", buf)== 0){ errno = ERR_KEY_NOT_FOUND; return -1; } else if (strcmp("unknown", buf)== 0){ errno = ERR_UNKNOWN; return -1; } else if (strcmp("invalid_param", buf)== 0){ errno = ERR_INVALID_PARAM; return -1; } else { return 0; } } return -1; }
void main() { init (); LCD1602_init(); LCD_init(); while(1) { keyscan (); keycheck (); f_choose(); } }
int main(int argc, char *argv[]) { int ch; pthread_t wc_thread; unsigned long interval=INTERVAL_MS*1000; fd = pc104_open(); get_wheels_state(fd, wheels); /* いっかいget_stateしておく */ for(ch = 0; ch < WHEELS_NUM; ch++) { wheels[ch].control_mode = VELOCITY_CONTROL; wheels[ch].pwm = 0; wheels[ch].encoder = 0; wheels[ch].angle_error_integration = 0.0; wheels[ch].velocity_error_integration = 0.0; wheels[ch].angle = 0.0; wheels[ch].velocity = 0.0; } set_wheels_gains(wheels); running_flag = TRUE; if (pthread_create( &wc_thread, NULL, wheels_control, NULL)) { perror("pthread_create"); exit(1); } while(1) { get_wheels_state(fd, wheels); read_bumper(fd); print_bumper(); bumper_action(); if(keycheck()) break; usleep(interval); } running_flag = FALSE; pthread_join( wc_thread, NULL ); wheels_power_off(fd); pc104_close(fd); return 0; }
void gameloop() { while(1) { fps(); count++; monstermove(); monstermake(); bulletmove(); attackcheck(); keycheck(); draw(); Console_Flip(); gamewait(); if(endcheck() == 1) { Print("clear!\n", 10, 5); Print("game end...", 10, 6); _getch(); Console_Close(); exit(0); } } }
// The main Allegro loop, all input handling, animation and drawing is done here _Bool main_loop(void) { // Flag for drawing _Bool needredraw = true; // Declare primitive data types float old_time = 0.0, current_time = 0, dt = 0; while(!data->exit) { if(needredraw && al_event_queue_is_empty(data->queue) && al_event_queue_is_empty(data->queue2)) { // Clear, draw, flip al_clear_to_color(data->background_color); render(); if(get_fps_status()) al_draw_textf(data->font, data->text_color, 0, res_height-30, 0, "fps: %.2f", 1/dt); al_flip_display(); needredraw = false; } // Block until an event enters the queue al_wait_for_event(data->queue, &(data->event)); while(!al_event_queue_is_empty(data->queue2)) { al_get_next_event(data->queue2, &(data->event2)); switch(data->event2.type) { case ALLEGRO_EVENT_DISPLAY_CLOSE: { // If x button is pressed on window data->exit = true; data->gamestarted = false; } break; case ALLEGRO_EVENT_DISPLAY_RESIZE: { al_acknowledge_resize(data->event2.display.source); scale(res_width, res_height); } break; case ALLEGRO_EVENT_MOUSE_AXES: { // Stores the mouse's new position and change in position mouseaxes(&(data->event2.mouse)); } case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN: { // Stores the mouse button pressed mousedown(&(data->event2.mouse)); } break; case ALLEGRO_EVENT_MOUSE_BUTTON_UP: { // Stores the mouse button released mouseup(&(data->event2.mouse)); } break; case ALLEGRO_EVENT_KEY_DOWN: { // Stores keydown keycode into keycode array for processing keydown(&(data->event2.keyboard)); } break; case ALLEGRO_EVENT_KEY_UP: { // Stores keycode into keycode array for processing keyup(&(data->event2.keyboard)); } break; default: break; } } switch (data->event.type) { case ALLEGRO_EVENT_TIMER: { // Determine the change in time between frames, in seconds current_time = al_current_time(); dt = current_time-old_time; // If the computer lags for some reason, don't penalize the player // Cap dt at 0.5 seconds if(dt > 0.25) { dt = 0.25; } // Handle Mouse and Keyboard events and Button Events buttoncheck(&buttonhandler, data); keycheck(&keyhandler, data); mousecheck(&mousehandler, data); keyupdate(); mouseupdate(); // Check if data->quit has been set before updating and drawing if(data->exit) break; // Update the game, always update(); // Skip drawing frames if computer lags if(current_time - data->event.timer.timestamp <= 1.0/al_get_display_refresh_rate(data->display)) { needredraw = true; } // Make the time at this frame the old time, for the next frame old_time = current_time; } break; default: break; } } return true; }
/*struct txtfld { int x; int y; int r; char *feild_name; }; struct txtfld t1;*/ void draw_txtbox(int leftx,int lefty,int rightx,char *fname) { int pos=0,insflg=0,tempflg=0; int i=-1,row,j=0,temp,col,maxsize; char c[1]; ch[0]=(char*)calloc(sizeof(char),20); row=lefty+7; col=leftx+5; maxsize=(rightx-leftx)/8 - 2; settextstyle(0,0,1); setcolor(15); // outtextxy(leftx,lefty-10,fname); showbox(leftx,lefty,rightx,fname); do { i=i+1; cursor(ch[j],col,row,pos); ch[j][i]=temp=bioskey(0); // printf("%c",ch[j][i]); ch[j][i+1]='\0'; if(temp == HOME||temp == END||temp ==LEFT||temp ==RIGHT||temp ==DEL||temp ==INSERT) { specialkey(ch[j],col,row,temp,&pos,&i,&insflg); continue; } if(ch[j][i]=='\x1B' || ch[j][i]=='\x0D') //escape { ch[j][i]='\0'; // hidebox(leftx,lefty,rightx); // hidebox(leftx,lefty,rightx,fname); break; } if(ch[j][i]!='\t' && ch[j][i]!='\x1B' && ch[j][i]!='\b') { if(i==maxsize) { ch[j][i]='\0'; i=i-1; continue; } keycheck(ch[j],&i,5,&tempflg); if(tempflg==1) { tempflg=0; continue; } } if(ch[j][i]=='.') //.(full stop) { ch[j][i]='.'; } setcolor(15); outtextxy((strlen(ch[j])-1)*8+col,row+2,"_"); setcolor(0); if(ch[j][i]=='\b') //backspace { backspace(ch[j],&i,pos,row,col); continue; } if(insflg%2==1) { insert(ch[j],&i,pos,row,col); continue; } // if(ch[j][i]!='\b') // { if(pos>0) { setfillstyle(1,15); bar(strlen(ch[j])*8+col-pos*8-8,row,strlen(ch[j])*8+col-pos*8-1,row+7); ch[j][i-pos]=ch[j][i]; ch[j][i]='\x0'; sprintf(c,"%c",ch[j][i-pos]); setcolor(0); outtextxy(strlen(ch[j])*8+col-pos*8,row,c); pos=pos-1; i=i-1; } else { sprintf(c,"%c",ch[j][i]); setcolor(0); outtextxy(strlen(ch[j])*8+col-8-pos*8,row,c); } // } }while(ch[j][i]!='\x1B' || ch[j][i]!='\x0D'); }