int plp_init(const char *driver, const char *_title, int _is_complex) { int i; if (2*NOF_INPUT_ITF > 1) { modinfo("Multiple signals are currently displayed in the same plot\n"); } plsdev(driver); plinit(); pladv(0); title = _title; is_complex = _is_complex; for (i=0;i<2*NOF_INPUT_ITF;i++) { legends[i] = (const char*) ""; } for (i=0;i<INPUT_MAX_SAMPLES;i++) { t[i] = i; } setup_legend(); xlabel = xlabel_def; ylabel = ylabel_def; plscol0a( 14, 0, 0, 0, 1); reset_axis(); return 0; }
void jogging_state_machine(struct jog_state_input* data){ static JOG_STATE state = INIT; static JOG_STATE next_state = INIT; static unsigned int delay = 0; float x = 0; float y = 0; float z = 0; /* sprintf(debug_str, "joy: %d , %d \t", data->x, data->y); printString(debug_str); sprintf(debug_str, "but: %d, %d\n", data->button_a, data->button_b); printString(debug_str);*/ switch(state){ case INIT: if(!data->button_a && !data->button_b){ next_state = JOG_XY; printString("Jogging XY\n"); delay = delay_debounce; state = WAIT; } break; case JOG_XY: if(data->x == 0){ x = -1; jog(X, x); } else if(data->x == 255){ x = 1; jog(X, x); } if(data->y == 0){ y = -1; jog(Y, y); } else if(data->y == 255){ y = 1; jog(Y, y); } if(!data->button_a){ next_state = JOG_Z; printString("Jogging Z\n"); delay = delay_debounce; state = WAIT; } else { next_state = JOG_XY; delay = delay_debounce; state = WAIT; } break; case JOG_Z: if(data->y == 0){ jog(Z, -1); } else if(data->y == 255){ jog(Z, 1); } if(!data->button_b){ next_state = JOG_XY; printString("Jogging XY\n"); delay = delay_debounce; state = WAIT; } else if(!data->button_a){ next_state = ZERO_X; printString("Reset zero X?\n"); delay = delay_debounce; state = WAIT; } else { next_state = JOG_Z; delay = delay_debounce; state = WAIT; } break; case ZERO_X: if(!data->button_a){ reset_axis(X); } if(!data->button_a || !data->button_b){ next_state = ZERO_Y; printString("Reset zero Y?\n"); delay = delay_debounce; state = WAIT; } break; case ZERO_Y: if(!data->button_a){ reset_axis(Y); } if(!data->button_a || !data->button_b){ next_state = ZERO_Z; printString("Reset zero Z?\n"); delay = delay_debounce; state = WAIT; } break; case ZERO_Z: if(!data->button_a){ reset_axis(Z); } if(!data->button_a || !data->button_b){ next_state = INIT; printString("Jogging back to init\n"); delay = delay_debounce; state = WAIT; } case WAIT: if (delay == 0) state = next_state; else delay--; break; } }
/** * @ingroup plp_sink * * Initializes the plplot driver if mode is SCOPE or PSD. If the mode is PSD, it * also initializes computes the fftw3 plan for the selected dft_size. * * \param is_complex 0: The input data for all interfaces is real; * 1: The input data for all interfaces is complex. This parameter is mandatory. * \param mode 0: Do nothing; 1: Print to stdout the received samples; 2: SCOPE mode, plots the * received signal using plplot; 3: PSD mode, plots the power spectral density of the received signal. * Default is 0 (silent) * \param fft_size Size of the DFT to compute the PSD. Default is 128. */ int initialize() { int i; int mode; int tslen; int data_type; last_rcv_samples=0; memset(plans,0,sizeof(dft_plan_t)*NOF_PRECOMPUTED_DFT); memset(extra_plans,0,sizeof(dft_plan_t)*MAX_EXTRA_PLANS); setup_legends(); if (param_get_int_name("data_type", &data_type)) { data_type = 0; } switch(data_type) { case 0: is_complex = 0; break; case 1: is_complex = 1; break; case 2: moderror("Only data_type 0 or 1 is supported\n"); return -1; } if (param_get_int_name("print_not_received",&print_not_received)!=1) { print_not_received = 0; } modinfo_msg("print_not_received=%d\n",print_not_received); mode_id = param_id("mode"); if (mode_id == NULL) { modinfo("Mode is not configured, using default mode 'silent'\n"); } else { if (param_get_int(mode_id,&mode) != 1) { moderror("Error getting parameter mode\n"); return -1; } if (mode == MODE_SCOPE || mode == MODE_PSD) { modinfo("Initiating plplot...\n"); if (plp_init(PL_DRIVER,"",is_complex)) { return -1; } plp_initiated = 1; reset_axis(); modinfo("-- Warning --: plplot crashes at stop. Restart ALOE after stopping the waveform.\n"); } } if (mode == MODE_PSD) { fft_size=0; param_get_int_name("fft_size",&fft_size); if (is_complex) { if (dft_plan_multi_c2r(precomputed_dft_len, FORWARD, NOF_PRECOMPUTED_DFT, plans)) { moderror("Precomputing plans\n"); return -1; } } else { if (dft_plan_multi_r2r(precomputed_dft_len, FORWARD, NOF_PRECOMPUTED_DFT, plans)) { moderror("Precomputing plans\n"); return -1; } } for (i=0;i<NOF_PRECOMPUTED_DFT;i++) { plans[i].options = DFT_PSD | DFT_OUT_DB | DFT_NORMALIZE; } fft_initiated = 1; } #ifdef _COMPILE_ALOE tslen = oesr_tslot_length(ctx); if (tslen > EXEC_MIN_INTERVAL_MS*1000) { interval_ts = 1; } else { interval_ts = (EXEC_MIN_INTERVAL_MS*1000)/tslen; modinfo_msg("Timeslot is %d usec, refresh interval set to %d tslots\n",tslen,interval_ts); } last_tstamp = 0; #endif return 0; }