static inline int vs_compare(VarString *vstr, VarString *vstr1) { /* conditional init */ vs_init(vstr,0); vs_init(vstr1,0); return strcmp(vstr->string, vstr1->string); }
/* Adjust size to the next multiple of the increment after minsize; This can enlarge as well as shrink a VarString. The caller must make sure that the existing data isn't clobbered by shrinking. */ static void vs_adjust_size(VarString *vstr, int minsize) { int newsize; vs_init(vstr,0); /* conditional init */ newsize = (minsize/vstr->increment +1) * (vstr->increment); if (NULL == (vstr->string = (char *)mem_realloc_nocheck(vstr->string, vstr->size, newsize,OTHER_SPACE))) { #ifdef DEBUG_VARSTRING fprintf(stderr, "No room to expand a variable-length string\n"); return; #else vstr->size = 0; vstr->length = 0; xsb_memory_error("memory","No room to expand a variable-length string"); #endif } #ifdef DEBUG_VARSTRING if (newsize > vstr->size) fprintf(stderr, "Expanding a VarString from %d to %d\n", vstr->size, newsize); else if (newsize < vstr->size) fprintf(stderr, "Shrinking a VarString from %d to %d\n", vstr->size, newsize); #endif vstr->size = newsize; }
/* change the increment and also shrink the allocated space to the minimum */ static inline void vs_shrink(VarString *vstr, int increment) { if (vstr->string == NULL) vs_init(vstr,increment); else { /* already initialized */ vstr->increment = increment; /* make sure we don't clobber existing stuff */ vs_adjust_size(vstr, vstr->length+1); } }
static inline void vs_null_terminate(VarString *vstr) { int newlength; vs_init(vstr,0); /* conditional init */ newlength = NEWLENGTH(vstr,0); if (newlength > vstr->size) vs_adjust_size(vstr, newlength); vstr->string[vstr->length] = '\0'; }
static inline int vs_strcmp(VarString *vstr, char *str) { vs_init(vstr,0); /* conditional init */ if (str == NULL) { #ifdef DEBUG_VARSTRING fprintf(stderr, "Comparing string with a NULL pointer\n"); return 0; #else xsb_bug("Comparing string with a NULL pointer"); #endif } return strcmp(vstr->string, str); }
// Initialization and powerdown -- vs_init() does the heavy lifting for begin() uint8_t MidiSynth::begin() { pinMode(MIDI_DREQ, INPUT); pinMode(MIDI_XCS, OUTPUT); pinMode(MIDI_XDCS, OUTPUT); pinMode(MIDI_RESET, OUTPUT); cs_high(); // MIDI_XCS, Init Control Select to deselected dcs_high(); // MIDI_XDCS, Init Data Select to deselected digitalWrite(MIDI_RESET, LOW); // Put VS1053 into hardware reset uint8_t result = vs_init(); if(result) { return result; } return 0; }
/* append block of chars, don't NULL-terminate */ static void vs_appendblk(VarString *vstr, char *blk, int blk_size) { int newlength; vs_init(vstr,0); /* conditional init */ if (blk == NULL) { #ifdef DEBUG_VARSTRING fprintf(stderr, "Appending a NULL string\n"); return; #else xsb_bug("Appending a NULL string"); #endif } newlength = NEWLENGTH(vstr,blk_size); if (newlength > vstr->size) vs_adjust_size(vstr, newlength); strncpy(vstr->string+vstr->length, blk, blk_size); vstr->length=vstr->length + blk_size; }
static void vs_set(VarString *vstr, char *str) { int newlength; vs_init(vstr,0); /* conditional init */ if (str == NULL) { #ifdef DEBUG_VARSTRING fprintf(stderr, "Assigning a NULL pointer to a variable-length string\n"); return; #else xsb_bug("Assigning a NULL pointer to a variable-length string"); #endif } newlength = strlen(str); // vs_adjust_size(vstr, newlength+1); %% dsw changed to avoid too much realloc vs_ensure_size(vstr, newlength+1); strcpy(vstr->string, str); vstr->length=newlength; }
/** * \brief Verse server main function * \param argc The number of options and arguments. * \param argv The array of options and arguments. * \return Function returns 0, when it is ended successfully and non-zero * value, when there some error occurs. This function never reach the end, * because it is server. */ int main(int argc, char *argv[]) { VS_CTX vs_ctx; int opt; char *config_file=NULL; int debug_level_set = 0; void *res; /* Set up initial state */ vs_ctx.state = SERVER_STATE_CONF; /* Default debug prints of verse server */ v_init_print_log(VRS_PRINT_WARNING, stdout); /* When server received some arguments */ if(argc>1) { while( (opt = getopt(argc, argv, "c:hd:")) != -1) { switch(opt) { case 'c': config_file = strdup(optarg); break; case 'd': debug_level_set = vs_set_debug_level(optarg); break; case 'h': vs_print_help(argv[0]); exit(EXIT_SUCCESS); case ':': exit(EXIT_FAILURE); case '?': exit(EXIT_FAILURE); } } } /* Initialize default values first */ vs_init(&vs_ctx); /* Try to load Verse server configuration file */ vs_load_config_file(&vs_ctx, config_file); /* When debug level wasn't specified as option at command line, then use * configuration from file */ if(debug_level_set == 1) { uint8 log_level = v_log_level(); v_init_print_log(log_level, vs_ctx.log_file); } else { v_init_print_log(vs_ctx.print_log_level, vs_ctx.log_file); } /* Add superuser account to the list of users */ vs_add_superuser_account(&vs_ctx); /* Add fake account for other users to the list of users*/ vs_add_other_users_account(&vs_ctx); /* Load user accounts and save them in the linked list of verse server * context */ switch (vs_ctx.auth_type) { case AUTH_METHOD_CSV_FILE: if(vs_load_user_accounts(&vs_ctx) != 1) { v_print_log(VRS_PRINT_ERROR, "vs_load_user_accounts(): failed\n"); vs_destroy_ctx(&vs_ctx); exit(EXIT_FAILURE); } break; case AUTH_METHOD_PAM: /* TODO: read list of supported usernames and their uids somehow */ exit(EXIT_FAILURE); case AUTH_METHOD_LDAP: /* TODO: not implemented yet */ exit(EXIT_FAILURE); default: /* Not supported method */ v_print_log(VRS_PRINT_ERROR, "unsupported auth method: %d\n", vs_ctx.auth_type); vs_destroy_ctx(&vs_ctx); exit(EXIT_FAILURE); } /* Initialize data mutex */ if( pthread_mutex_init(&vs_ctx.data.mutex, NULL) != 0) { v_print_log(VRS_PRINT_ERROR, "pthread_mutex_init(): failed\n"); vs_destroy_ctx(&vs_ctx); exit(EXIT_FAILURE); } /* Create basic node structure of node tree */ if(vs_nodes_init(&vs_ctx) == -1) { v_print_log(VRS_PRINT_ERROR, "vs_nodes_init(): failed\n"); vs_destroy_ctx(&vs_ctx); exit(EXIT_FAILURE); } if(vs_ctx.stream_protocol == TCP) { /* Initialize Verse server context */ if(vs_init_stream_ctx(&vs_ctx) == -1) { v_print_log(VRS_PRINT_ERROR, "vs_init_stream_ctx(): failed\n"); vs_destroy_ctx(&vs_ctx); exit(EXIT_FAILURE); } } else { vs_destroy_ctx(&vs_ctx); exit(EXIT_FAILURE); } if(vs_ctx.flag & SERVER_DEBUG_MODE) { /* Set up signal handlers (only for debug mode, real server should ignore most of signals) */ if(vs_config_signal_handling() == -1 ) { vs_destroy_ctx(&vs_ctx); exit(EXIT_FAILURE); } } else { #if 0 /* Make from verse server real verse application: * - detach from standard file descriptors, terminals, PPID process etc. */ if(vs_init_server(&vs_ctx) == -1) { vs_destroy_ctx(&vs_ctx); exit(EXIT_FAILURE); } #endif } /* Initialize data semaphore */ if( (vs_ctx.data.sem = sem_open(DATA_SEMAPHORE_NAME, O_CREAT, 0644, 1)) == SEM_FAILED) { v_print_log(VRS_PRINT_ERROR, "sem_init(): %s\n", strerror(errno)); vs_destroy_ctx(&vs_ctx); exit(EXIT_FAILURE); } /* Try to create new data thread */ if(pthread_create(&vs_ctx.data_thread, NULL, vs_data_loop, (void*)&vs_ctx) != 0) { v_print_log(VRS_PRINT_ERROR, "pthread_create(): %s\n", strerror(errno)); vs_destroy_ctx(&vs_ctx); exit(EXIT_FAILURE); } /* Try to create cli thread */ if(pthread_create(&vs_ctx.cli_thread, NULL, vs_server_cli, (void*)&vs_ctx) != 0) { v_print_log(VRS_PRINT_ERROR, "pthread_create(): %s\n", strerror(errno)); vs_destroy_ctx(&vs_ctx); exit(EXIT_FAILURE); } /* Set up pointer to local server CTX -> server server could be terminated * with signal now. */ local_vs_ctx = &vs_ctx; vs_ctx.state = SERVER_STATE_READY; if(vs_ctx.stream_protocol == TCP) { if(vs_main_listen_loop(&vs_ctx) == -1) { v_print_log(VRS_PRINT_ERROR, "vs_main_listen_loop(): failed\n"); vs_destroy_ctx(&vs_ctx); exit(EXIT_FAILURE); } } else { v_print_log(VRS_PRINT_ERROR, "unsupported stream protocol: %d\n", vs_ctx.stream_protocol); vs_destroy_ctx(&vs_ctx); exit(EXIT_FAILURE); } /* Free Verse server context */ vs_destroy_ctx(&vs_ctx); /* Join cli thread */ if(pthread_join(vs_ctx.cli_thread, &res) != 0) { v_print_log(VRS_PRINT_ERROR, "pthread_join(): %s\n", strerror(errno)); exit(EXIT_FAILURE); } else { if(res != PTHREAD_CANCELED && res != NULL) free(res); } /* TODO: replace following ifdef */ #ifndef __APPLE__ /* Join data thread */ if(pthread_join(vs_ctx.data_thread, &res) != 0) { v_print_log(VRS_PRINT_ERROR, "pthread_join(): %s\n", strerror(errno)); exit(EXIT_FAILURE); } else { if(res != PTHREAD_CANCELED && res != NULL) free(res); } /* Try to close named semaphore s*/ if(sem_close(vs_ctx.data.sem) == -1) { v_print_log(VRS_PRINT_ERROR, "sem_close(): %s\n", strerror(errno)); } #endif /* Try to unlink named semphore */ if(vs_ctx.data.sem != NULL && sem_unlink(DATA_SEMAPHORE_NAME) == -1) { v_print_log(VRS_PRINT_ERROR, "sem_unlink(): %s\n", strerror(errno)); } return EXIT_SUCCESS; }
int main(void) { // Set clock @ 16Mhz CPU_PRESCALE(0); //Set initial pin states. These are adjusted based on eeprom settings. DDRB=0x00; DDRC=0x00; DDRD=0x00; PORTB=0xFF; PORTC=0xFF; PORTD=0xFF; //dpad and pad restrictions uint8_t u=0, d=0, l=0, r=0, pu=0, pd=0, pl=0, pr=0; //pin assignments and button states uint8_t pos=0, cnt=0; uint8_t ass[40], state[20]; //handle shift and shift lock uint8_t shift=0, shift_last=0, shift_count=0, shift_lock=0; //handle settings uint8_t invert, restrict4; uint8_t setting_delay; uint8_t autofire, auto_toggle=1; uint8_t active=0, delay_power=0; //Flash LEDs #include "../shared/disco.c" //read first 40 eeprom into an array (pins + shifted pins) for(cnt=0;cnt<40;cnt++){ ass[cnt]=read_eeprom_byte(cnt); //set output pins if ((ass[cnt]==28)||(ass[cnt]==29)){ #include "../shared/outputs.c" } if (ass[cnt]==29){delay_power=1;} } //Read other settings (40+ in Eeprom) setting_delay=read_eeprom_byte(41); //wait for specified delay time (allow 2 secs for led flash) if ((delay_power==1)&&(setting_delay>0)){ for(cnt=0;cnt<=setting_delay-3;cnt++){ _delay_ms(1000); } active=1; for(cnt=0;cnt<40;cnt++){ if (ass[cnt]==29){ #include "../shared/showleds.c" } } } // Init USB pad emulation vs_init(true); // Pins polling and gamepad status updates for (;;) { vs_reset_watchdog(); //read KADE pin states into an array #include "../shared/state.c" //set shifted status and detect shift lock (double click) #include "../shared/shift.c" //set default button states //reset direction to centre gamepad_state.direction=8; gamepad_state.l_y_axis=0x80; gamepad_state.l_x_axis=0x80; gamepad_state.square_btn=0x00; gamepad_state.cross_btn=0x00; gamepad_state.circle_btn=0x00; gamepad_state.triangle_btn=0x00; gamepad_state.l1_btn=0x00; gamepad_state.r1_btn=0x00; gamepad_state.l2_btn=0x00; gamepad_state.r2_btn=0x00; gamepad_state.l3_btn=0x00; gamepad_state.r3_btn=0x00; gamepad_state.select_btn=0x00; gamepad_state.start_btn=0x00; gamepad_state.ps_btn=0x00; invert=0; restrict4=0; autofire=0; //pre-loop to deal with any switches/toggles pu=u; pd=d; pl=l; pr=r; u=0; d=0; l=0; r=0; for(cnt=0;cnt<20;cnt++) { if (!(state[cnt])) { //there is input on this pin, also account for shifted input pos = cnt; if (shift==1){pos=pos+20;} if ((ass[cnt]==23)||(ass[pos]==23)){invert=1;} //invert Y axis if ((ass[cnt]==22)||(ass[pos]==22)){restrict4=1;} //restrict dPad 4-way if ((ass[pos]>=24)&&(ass[pos]<=27)){autofire=1;} //autofire mode if ((ass[pos]>=30)&&(ass[pos]<=38)){autofire=1;} //extra autofire mode if (ass[pos]==1){u=1;} if (ass[pos]==2){d=1;} if (ass[pos]==3){l=1;} if (ass[pos]==4){r=1;} } //Show the shift status LED(s) and power up externals with delay if (ass[cnt]==28){ active = shift; #include "../shared/showleds.c" } } //invert Y axis on DPAD (if we want to do this) //if (invert==1){ // if (u==1){d=1; u=0;} // else if (d==1){d=0; u=1;} //} //autofire toggle if(autofire==1){ auto_toggle = auto_toggle * -1; } //Handle dpad and restricted movement if(restrict4==1){ if (u==1){gamepad_state.direction=0;} if (d==1){gamepad_state.direction=4;} if (l==1){gamepad_state.direction=6;} if (r==1){gamepad_state.direction=2;} } else { //left and right directions if (l==1){gamepad_state.direction=6;} //Left if (r==1){gamepad_state.direction=2;} //Right //up, down and diagonal directions if (u==1){ //Up if (l==1){ //left gamepad_state.direction=7; //up-left } else if (r==1){ //right gamepad_state.direction=1; //up-right } else { gamepad_state.direction=0; //up } } if (d==1){ //down if (l==1){ //left gamepad_state.direction=5; //down-left } else if (r==1){ //right gamepad_state.direction=3; //down-right } else { gamepad_state.direction=4; //down } } } //loop through pins checking for inputs from those that are assigned a function for(cnt=0;cnt<20;cnt++) { pos=cnt; if (!(state[cnt])) { //there is input on this pin if (shift==1){pos=pos+20;} //+20 if this is shifted input if (ass[pos]>0) { //there is an assignment to a function //A, B, X, Y if (ass[pos]==5){gamepad_state.square_btn=0xFF;} if (ass[pos]==6){gamepad_state.cross_btn=0xFF;} if (ass[pos]==7){gamepad_state.circle_btn=0xFF;} if (ass[pos]==8){gamepad_state.triangle_btn=0xFF;} //Autofire if (autofire==1){ if(auto_toggle==1){ if (ass[pos]==24){gamepad_state.square_btn=0xFF;} if (ass[pos]==25){gamepad_state.cross_btn=0xFF;} if (ass[pos]==26){gamepad_state.circle_btn=0xFF;} if (ass[pos]==27){gamepad_state.triangle_btn=0xFF;} } _delay_ms(15); } //PS3 Triggers if (ass[pos]==9){gamepad_state.l1_btn=0xFF;} //L1 if (ass[pos]==10){gamepad_state.r1_btn=0xFF;} //R1 if (ass[pos]==11){gamepad_state.l2_btn=0xFF;} //L2 if (ass[pos]==12){gamepad_state.r2_btn=0xFF;} //R2 if (ass[pos]==15){gamepad_state.l3_btn=0xFF;} //L3 if (ass[pos]==16){gamepad_state.r3_btn=0xFF;} //R3 //PS3 Special if (ass[pos]==13){gamepad_state.select_btn=0xFF;} //L3 if (ass[pos]==14){gamepad_state.start_btn=0xFF;} //R3 if (ass[pos]==17){gamepad_state.ps_btn=0xFF;} //PS Button //Analog Stick if (ass[pos]==18+invert){gamepad_state.l_y_axis = 0x00;} //Analog Up if (ass[pos]==19-invert){gamepad_state.l_y_axis = 0xff;} //Analog Down if (ass[pos]==20){gamepad_state.l_x_axis = 0x00;} //Analog Left if (ass[pos]==21){gamepad_state.l_x_axis = 0xff;} //Analog Right //Enter programming mode if (ass[pos]==39){Jump_To_Bootloader();} //Program mode } } } _delay_ms(10); //debounce vs_send_pad_state(); } }
int main(void) { // Set clock @ 16Mhz CPU_PRESCALE(0); //Set initial pin states. DDRB=0x00; DDRC=0x00; DDRD=0x00; PORTB=0xFF; PORTC=0xFF; PORTD=0xFF; //Generic functions used with this firmware (there are others) uint8_t func_dpad_up = 1; uint8_t func_dpad_down = 2; uint8_t func_dpad_left = 3; uint8_t func_dpad_right = 4; uint8_t func_restrict_4way = 22; uint8_t func_invert_y_axis = 23; uint8_t func_autofire_1 = 24; uint8_t func_autofire_2 = 25; uint8_t func_autofire_3 = 26; uint8_t func_autofire_4 = 27; uint8_t func_ext_shift_led = 28; uint8_t func_ext_power_led = 29; uint8_t func_program_mode = 30; //Use default restriction logic (in generic_main_preloop.c) uint8_t default_restrict = 0; //Generic main #include "../shared/generic_main_init.c" // Init USB pad emulation vs_init(true); // Init Trackball if needed if (setting_enable_tb1==1){ PORTD |= (1<<6); initTrackBall(setting_tb1_counts, setting_tb1_samples); } // Pins polling and gamepad status updates for (;;) { vs_reset_watchdog(); //generic stuff at start of main loop #include "../shared/generic_main_preloop.c" //set default button states - reset direction to centre gamepad_state.direction=8; gamepad_state.l_y_axis=0x80; gamepad_state.l_x_axis=0x80; gamepad_state.r_y_axis=0x80; gamepad_state.r_x_axis=0x80; gamepad_state.square_btn=0x00; gamepad_state.cross_btn=0x00; gamepad_state.circle_btn=0x00; gamepad_state.triangle_btn=0x00; gamepad_state.l1_btn=0x00; gamepad_state.r1_btn=0x00; gamepad_state.l2_btn=0x00; gamepad_state.r2_btn=0x00; gamepad_state.l3_btn=0x00; gamepad_state.r3_btn=0x00; gamepad_state.square_axis=0x00; gamepad_state.cross_axis=0x00; gamepad_state.circle_axis=0x00; gamepad_state.triangle_axis=0x00; gamepad_state.l1_axis=0x00; gamepad_state.r1_axis=0x00; gamepad_state.l2_axis=0x00; gamepad_state.r2_axis=0x00; gamepad_state.select_btn=0x00; gamepad_state.start_btn=0x00; gamepad_state.ps_btn=0x00; //Handle dpad and restricted movement //PS3 restriction is easier to manage - ignore mainloop if(restrict4==1){ if (u==1){gamepad_state.direction=0;} if (d==1){gamepad_state.direction=4;} if (l==1){gamepad_state.direction=6;} if (r==1){gamepad_state.direction=2;} } else { //left and right directions if (l==1){gamepad_state.direction=6;} //Left if (r==1){gamepad_state.direction=2;} //Right //up, down and diagonal directions if (u==1){ //Up if (l==1){ //left gamepad_state.direction=7; //up-left } else if (r==1){ //right gamepad_state.direction=1; //up-right } else { gamepad_state.direction=0; //up } } if (d==1){ //down if (l==1){ //left gamepad_state.direction=5; //down-left } else if (r==1){ //right gamepad_state.direction=3; //down-right } else { gamepad_state.direction=4; //down } } } //Trackballs Analog //NOTE: COME BACK AND TIDY THIS LOGIC IF IT WORKS WELL if (setting_enable_tb1==1){ if(setting_tb1_trackball==1){ if (setting_tb1_stick==1){ //Right Analog (1=Right) // //Y Axis (Trackball) if(abs(ps2_y) < 32){ gamepad_state.r_y_axis = 255 - (ps2_y + 128); } else { if (ps2_y > 31){gamepad_state.r_y_axis = 0x00;} if (ps2_y < -31){gamepad_state.r_y_axis = 0xFF;} } //X Axis (Trackball) if(abs(ps2_x) < 32){ gamepad_state.r_x_axis = ps2_x + 128; } else { if (ps2_x > 31){gamepad_state.r_x_axis = 0xFF;} if (ps2_x < -31){gamepad_state.r_x_axis = 0x00;} } } else { //Left Analog (0=Left) // //Y Axis (Trackball) if(abs(ps2_y) < 32){ gamepad_state.l_y_axis = 255 - (ps2_y + 128); } else { if (ps2_y > 31){gamepad_state.l_y_axis = 0x00;} if (ps2_y < -31){gamepad_state.l_y_axis = 0xFF;} } //X Axis (Trackball) if(abs(ps2_x) < 32){ gamepad_state.l_x_axis = ps2_x + 128; } else { if (ps2_x > 31){gamepad_state.l_x_axis = 0xFF;} if (ps2_x < -31){gamepad_state.l_x_axis = 0x00;} } } } else { if (setting_tb1_stick==1){ //Right Analog (1=Right) gamepad_state.r_y_axis = 255 - (ps2_y + 128); gamepad_state.r_x_axis = ps2_x + 128; } else { //Left Analog (0=Left) gamepad_state.l_y_axis = 255 - (ps2_y + 128); gamepad_state.l_x_axis = ps2_x + 128; } } } //loop through pins checking for inputs from those that are assigned a function //for(cnt=0;cnt<20;cnt++) { for(cnt=0;cnt<20;cnt++) { pos=cnt; if (!(state[cnt])) { //there is input on this pin if (shift==1){pos=pos+20;} //+20 if this is shifted input if (ass[pos]>0) { //there is an assignment to a function action = ass[pos]; #include "main_actions.c" } } } //Trackball Buttons if (setting_enable_tb1==1){ for(pos=0;pos<3;pos++) { if (shift==1){ if (pos==0){action = setting_tb1_but1s;} if (pos==1){action = setting_tb1_but2s;} if (pos==2){action = setting_tb1_but3s;} } else { if (pos==0){action = setting_tb1_but1;} if (pos==1){action = setting_tb1_but2;} if (pos==2){action = setting_tb1_but3;} } if (action > 0) { if (((0b00000001 & ps2data[0])&&(pos==0))||((0b00000010 & ps2data[0])&&(pos==1))||((0b00000100 & ps2data[0])&&(pos==2))){ #include "main_actions.c" } } } } _delay_ms(2); //debounce vs_send_pad_state(); } }
/* dsw changed, so it will never shrink the buffer */ static inline void vs_ensure_size(VarString *vstr, int minsize) { vs_init(vstr,0); if (minsize > vstr->size) vs_adjust_size(vstr, minsize+1); }
int rls_mod_init(void) { load_tm_f load_tm; bind_dlg_mod_f bind_dlg; struct timer_ln *i_timer = NULL; DEBUG_LOG("RLS module initialization\n"); /* ??? if other module uses this libraries it might be a problem ??? */ xmlInitParser(); DEBUG_LOG(" ... common libraries\n"); qsa_initialize(); if (time_event_management_init() != 0) { LOG(L_ERR, "rls_mod_init(): Can't initialize time event management!\n"); return -1; } if (subscription_management_init() != 0) { LOG(L_ERR, "rls_mod_init(): Can't initialize time event management!\n"); return -1; } /* import the TM auto-loading function */ if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LOG(L_ERR, "rls_mod_init(): Can't import tm!\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm(&tmb)==-1) { LOG(L_ERR, "rls_mod_init(): load_tm() failed\n"); return -1; } bind_dlg = (bind_dlg_mod_f)find_export("bind_dlg_mod", -1, 0); if (!bind_dlg) { LOG(L_ERR, "Can't import dlg\n"); return -1; } if (bind_dlg(&dlg_func) != 0) { return -1; } if (rls_init() != 0) { return -1; } if (vs_init() != 0) { return -1; } /* xcap_servers = (ptr_vector_t*)mem_alloc(sizeof(ptr_vector_t)); if (!xcap_servers) { LOG(L_ERR, "rls_mod_init(): can't allocate memory for XCAP servers vector\n"); return -1; } ptr_vector_init(xcap_servers, 8); */ /* set authorization type according to requested "auth type name" * and other (type specific) parameters */ if (set_auth_params(&rls_auth_params, auth_type_str) != 0) return -1; use_db = 0; if (db_mode > 0) { int db_url_len = db_url ? strlen(db_url) : 0; if (!db_url_len) { LOG(L_ERR, "rls_mod_init(): no db_url specified but db_mode > 0\n"); db_mode = 0; } } if (db_mode > 0) { if (bind_dbmod(db_url, &rls_dbf) < 0) { LOG(L_ERR, "rls_mod_init(): Can't bind database module via url %s\n", db_url); return -1; } if (!DB_CAPABILITY(rls_dbf, DB_CAP_ALL)) { /* ? */ LOG(L_ERR, "rls_mod_init(): Database module does not implement all functions needed by the module\n"); return -1; } use_db = 1; } /* once-shot timer for reloading data from DB - * needed because it can trigger database operations * in other modules and they mostly intialize their * database connection in child_init functions */ i_timer = timer_alloc(); if (!i_timer) { ERR("can't allocate memory for DB init timer\n"); return -1; } else { timer_init(i_timer, init_timer_cb, i_timer, 0); timer_add(i_timer, S_TO_TICKS(init_timer_delay)); } fill_xcap_params = (fill_xcap_params_func)find_export("fill_xcap_params", 0, -1); return 0; }
int main(void) { // Set Teensy clock @ 16Mhz CPU_PRESCALE(0); DDRB = 0x00; DDRC = 0x00; DDRD = 0x60; // D5,D6 - OUTPUT (LED) PORTB = 0xFF; PORTC = 0xFF; PORTD = 0x9F; // D5,D6 - LOW (LED) bit_set(PORTD,0x20); uint8_t b, c, d; uint8_t shift = 0, shift_last = 0, shift_count = 0, shift_lock = 0; uint8_t up, down, left, right; // Set callback function for USB connect event vs_set_connect_callback(&ledOn); // Set callback function for USB disconnect event vs_set_disconnect_callback(&ledOff); // Init USB pad emulation vs_init(true); //flash them leds #include "..\shared\disco.c" // Pins polling and gamepad status updates for (;;) { vs_reset_watchdog(); b = PINB; c = PINC; d = PIND; //set shifted status and detect shift lock (double click) if(!(d & 0x80)) { shift = 1; if (shift_last == 0) { if (shift_count > 1 && shift_count < 50) { if (shift_lock == 0) {shift_lock = 1;} else {shift_lock = 0;} } shift_count = 0; } } else { shift = 0; } shift_last = shift; if (shift_count <= 50) {shift_count += 1;} //no reason to continue counting if (shift_lock == 1) {shift = 1;} //reset direction to centre gamepad_state.direction = 8; //centre //DPAD (and shifted analog) up = !(c&0x04); down = !(d&0x01); left = !(d&0x02); right = !(d&0x04); if(shift==1) { bit_clear(PORTD,0x20); //Analog if ((up)||(down)) { if (up) {gamepad_state.l_y_axis = 0x00;} //A1-Up if (down) {gamepad_state.l_y_axis = 0xff;} //A2-Down } else {gamepad_state.l_y_axis = 0x80;} if ((left)||(right)) { if (left) {gamepad_state.l_x_axis = 0x00;} //A3-Left if (right) {gamepad_state.l_x_axis = 0xff;} //A4-Right } else {gamepad_state.l_x_axis = 0x80;} } else { bit_set(PORTD,0x20); //Digital //left and right directions if (!(d & 0x02)) { gamepad_state.direction = 6; } //A3-Left if (!(d & 0x04)) { gamepad_state.direction = 2; } //(A4-Right) //up, down and diagonal directions if (!(c & 0x04)) { //A1-up if (!(d & 0x02)) { //A3-left gamepad_state.direction = 7; //(up-left) } else if (!(d & 0x04)) { //A4-right gamepad_state.direction = 1; //(up-right) } else { gamepad_state.direction = 0; //(up) } } if (!(d & 0x01)) { //A2-down if (!(d & 0x02)) { //A3-left gamepad_state.direction = 5; //(down-left) } else if (!(d & 0x04)) { //A4-right gamepad_state.direction = 3; //(down-right) } else { gamepad_state.direction = 4; //(down) } } } //PS3 buttons gamepad_state.square_btn = (!(d & 0x08) == 1); //A5-Square gamepad_state.cross_btn = (!(d & 0x10) == 1); //A6-Cross gamepad_state.circle_btn = (!(b & 0x01) == 1); //A9-Circle gamepad_state.triangle_btn = (!(b & 0x02) == 1); //A10-Triangle //PS3 Triggers gamepad_state.l1_btn = (!(b & 0x04) == 1); //B1-L1 gamepad_state.r1_btn = (!(b & 0x08) == 1); //B2-R1 gamepad_state.l2_btn = (!(b & 0x10) == 1); //B3-L2 gamepad_state.r2_btn = (!(b & 0x20) == 1); //B4-R2 gamepad_state.l3_btn = (!(c & 0x80) == 1); //B7-L3 gamepad_state.r3_btn = (!(c & 0x40) == 1); //B8-R3 //PS3 Special gamepad_state.select_btn = (!(b & 0x40) == 1); //B5-L3 gamepad_state.start_btn = (!(b & 0x80) == 1); //B6-R3 gamepad_state.ps_btn = (!(c & 0x20) == 1); //B9-PS Button _delay_ms(10); //debounce vs_send_pad_state(); } }