void Player::update_jump_land() { if(sprite.switched_actions()) { set_run(); return; } }
TEST print_check_runs_and_pass(unsigned int id) { if (print_flag) { printf("running test %u\n", id); } if (check_run(id)) { fprintf(stderr, "Error: Shuffling made test run multiple times!\n"); assert(0); } else { set_run(id); } PASS(); }
/* * Clears count bits starting at a given block. */ int omfs_clear_range(struct super_block *sb, u64 block, int count) { struct omfs_sb_info *sbi = OMFS_SB(sb); int bits_per_entry = 8 * sb->s_blocksize; u64 tmp; unsigned int map, bit; int ret; tmp = block; bit = do_div(tmp, bits_per_entry); map = tmp; if (map >= sbi->s_imap_size) return 0; mutex_lock(&sbi->s_bitmap_lock); ret = set_run(sb, map, bits_per_entry, bit, count, 0); mutex_unlock(&sbi->s_bitmap_lock); return ret; }
/* * Tries to allocate a set of blocks. The request size depends on the * type: for inodes, we must allocate sbi->s_mirrors blocks, and for file * blocks, we try to allocate sbi->s_clustersize, but can always get away * with just one block. */ int omfs_allocate_range(struct super_block *sb, int min_request, int max_request, u64 *return_block, int *return_size) { struct omfs_sb_info *sbi = OMFS_SB(sb); int bits_per_entry = 8 * sb->s_blocksize; int ret = 0; int i, run, bit; mutex_lock(&sbi->s_bitmap_lock); for (i = 0; i < sbi->s_imap_size; i++) { bit = 0; while (bit < bits_per_entry) { bit = find_next_zero_bit(sbi->s_imap[i], bits_per_entry, bit); if (bit == bits_per_entry) break; run = count_run(&sbi->s_imap[i], bits_per_entry, sbi->s_imap_size-i, bit, max_request); if (run >= min_request) goto found; bit += run; } } ret = -ENOSPC; goto out; found: *return_block = i * bits_per_entry + bit; *return_size = run; ret = set_run(sb, i, bits_per_entry, bit, run, 1); out: mutex_unlock(&sbi->s_bitmap_lock); return ret; }
void Player::update_walk() { if (controller.get_axis_state(X_AXIS) == 0) { leave_walk(); set_stand(); return; } if(get_direction() == WEST && controller.get_axis_state(X_AXIS) > 0 || get_direction() == EAST && controller.get_axis_state(X_AXIS) < 0) { leave_walk(); set_turnaround(); return; } if(controller.get_button_state(RUN_BUTTON)) { leave_walk(); set_run(); return; } }
int main(void) { // UDP Creation struct sockaddr_in si_me, si_other; int s, slen = sizeof(si_other) , recv_len; char buf[BUFLEN]; char motor1_2, motor1_1,motor2_2, motor2_1,motor3_2, motor3_1,motor4_2, motor4_1,motor5_2, motor5_1,motor6_2, motor6_1; char motor1[3], motor2[3], motor3[3], motor4[3], motor5[3], motor6[3]; //create a UDP socket if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { die("socket"); } // zero out the structure memset((char *) &si_me, 0, sizeof(si_me)); si_me.sin_family = AF_INET; si_me.sin_port = htons(PORT); si_me.sin_addr.s_addr = htonl(INADDR_ANY); //bind socket to port if( bind(s , (struct sockaddr*)&si_me, sizeof(si_me) ) == -1) { die("bind"); } //Set up pwms char freq[5]; int i, motor_num; set_pwms(); //Ask the user what the frequency should be printf("What should the frequency be? "); fflush(stdout); scanf("%s", freq); //Set all frequencies to the user input for(i='1';i<'7';i++){ set_freq(i,freq); } //Activate the run file in each pwm folder for(i='1';i<'7';i++){ set_run(i,"1"); } //Set the duty percent to 50 for all pwms for(i='1';i<'7';i++){ set_duty(i,"50"); } while(1){ //try to receive some data if ((recv_len = recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *) &si_other, &slen)) == -1) { die("recvfrom()"); } // Figure out the number of motors from first three bytes of the array received from UDP packet motor_num = buf[3]; int motors[motor_num]; // Create an array that has the duty percent for each motor in the elements for(i=0; i<motor_num; i++){ motors[i] = buf[i+4]; if(motors[i] > 100) motors[i] = motors[i] - 256; //Conversion for numbers that should be negative } fflush(stdout); //Change the percentages from -100-100 to 0-100 because that's the percentages the BeagleBone can do for(i=0; i<6; i++){ motors[i] = (motors[i] + 100)/2; } // The next bunch of if else statements convert the integer duty percent number into strings that the // Beaglebone can understand. Each statement will go through the first and second digit of the integer // and then change them to ASCII code and put them into an array. if(motors[0] == 100){ motor1[0] = '1'; motor1[1] = '0'; motor1[2] = '0'; motor1[3] = '\0'; } else { motor1_2 = motors[0]%10 + 0x30; motor1_1 = (motors[0]/10)%10 + 0x30; motor1[0] = '0'; motor1[1] = motor1_1; motor1[2] = motor1_2; motor1[3] = '\0'; } if(motors[1] == 100){ motor2[0] = '1'; motor2[1] = '0'; motor2[2] = '0'; motor2[3] = '\0'; } else { motor2_2 = motors[1]%10 + 0x30; motor2_1 = (motors[1]/10)%10 + 0x30; motor2[0] = '0'; motor2[1] = motor2_1; motor2[2] = motor2_2; motor2[3] = '\0'; } if(motors[2] == 100){ motor3[0] = '1'; motor3[1] = '0'; motor3[2] = '0'; motor3[3] = '\0'; } else { motor3_2 = motors[2]%10 + 0x30; motor3_1 = (motors[2]/10)%10 + 0x30; motor3[0] = '0'; motor3[1] = motor3_1; motor3[2] = motor3_2; motor3[3] = '\0'; } if(motors[3] == 100){ motor4[0] = '1'; motor4[1] = '0'; motor4[2] = '0'; motor4[3] = '\0'; } else { motor4_2 = motors[3]%10 + 0x30; motor4_1 = (motors[3]/10)%10 + 0x30; motor4[0] = '0'; motor4[1] = motor4_1; motor4[2] = motor4_2; motor4[3] = '\0'; } if(motors[4] == 100){ motor5[0] = '1'; motor5[1] = '0'; motor5[2] = '0'; motor5[3] = '\0'; } else { motor5_2 = motors[4]%10 + 0x30; motor5_1 = (motors[4]/10)%10 + 0x30; motor5[0] = '0'; motor5[1] = motor5_1; motor5[2] = motor5_2; motor5[3] = '\0'; } if(motors[5] == 100){ motor6[0] = '1'; motor6[1] = '0'; motor6[2] = '0'; motor6[3] = '\0'; } else { motor6_2 = motors[5]%10 + 0x30; motor6_1 = (motors[5]/10)%10 + 0x30; motor6[0] = '0'; motor6[1] = motor6_1; motor6[2] = motor6_2; motor6[3] = '\0'; } // Print all the duty percents that were calculated printf("First Motor: %s\n", motor1); printf("Second Motor: %s\n", motor2); printf("Third Motor: %s\n", motor3); printf("Fourth Motor: %s\n", motor4); printf("Fifth Motor: %s\n", motor5); printf("Sixth Motor: %s\n\n", motor6); // Set the duty percent of each motor set_duty('1', motor1); set_duty('2', motor2); set_duty('3', motor3); set_duty('4', motor4); set_duty('5', motor5); set_duty('6', motor6); } close(s); return 0; }