コード例 #1
0
ファイル: scope.cpp プロジェクト: Angolier/sonic-pi
ScopePanel::ScopePanel( const QString& name, double* sample_x, double* sample_y, int num_samples, QWidget* parent ) : QWidget(parent), name(name), plot(QwtText(name),this)
{
#if QWT_VERSION >= 0x60100
  plot_curve.setPaintAttribute( QwtPlotCurve::PaintAttribute::FilterPoints );
#endif

  plot_curve.setRawSamples( sample_x, sample_y, num_samples );
  setXRange( 0, num_samples, false );
  setYRange( -1, 1, true );
  setPen(QPen(QColor("deeppink"), 2));

  plot_curve.attach(&plot);

  QSizePolicy sp(QSizePolicy::MinimumExpanding,QSizePolicy::Expanding);
  plot.setSizePolicy(sp);

  QVBoxLayout* layout = new QVBoxLayout();
  layout->addWidget(&plot);
  layout->setContentsMargins(0,0,0,0);
  layout->setSpacing(0);
  setLayout(layout);
}
コード例 #2
0
void handSensing(){

	queueHandler_init();
    charger_init(&charger);
    queueHanlder_drawTextAtCenter("Calibration...");

    //calibration
    calibrate(&charger);
    setXRange(charger.range_x);
    setYRange(charger.range_y);
    setZRange(charger.range_z);

    charger.x_state = NOT_READY;
    charger.y_state = NOT_READY;
    charger.z_state = NOT_READY;

	queueHanlder_drawTextAtCenter("System Ready...");

    while(1){

    	//recalibration interrupt
    	if(charger.y_state == READY){
    		charger.x_state = NOT_READY;
			charger.y_state = NOT_READY;
			charger.z_state = NOT_READY;
    		charger.calibration_state = BASELINE;
    		calibrate(&charger);
			setXRange(charger.range_x);
			setYRange(charger.range_y);
			setZRange(charger.range_z);

			charger.x_state = NOT_READY;
			charger.y_state = NOT_READY;
			charger.z_state = NOT_READY;
			continue;
    	}

    	//gettimeofday(&time_start, NULL);

    	if(ERROR == charger_run(&charger)){
    		charger.newDataFlag = 0;
    		continue;
    	}

		diff_x = charger.xTime - charger.baseline_x;
		diff_y = charger.yTime - charger.baseline_y;
		diff_z = charger.zTime - charger.baseline_z;

		//recalibration detection
		if(diff_x < -50 || diff_y < -50 || diff_z < -50){
			negative_count++;
			if(negative_count == NEGATIVE_MAX){
				negative_count = 0;
				calibrate_baseline(&charger);
				continue;
			}
		}else{
			negative_count = 0;
		}

		//valid point
		if((diff_x > RADIUS && diff_x <= charger.range_x )
				&& (diff_y > RADIUS && diff_y <= charger.range_y)){
			point1.x_pos = diff_x;
			point1.y_pos = diff_y;
			point1.z_pos = diff_z;
			queueHandler_pushPoint(&point1);
			queueHandler_draw();
			//gettimeofday(&time_stop, NULL);
			//printf("\r\ntime diff: %d\r\n", (int)time_stop.tv_usec - (int)time_start.tv_usec);
			printf("In range");

		}else{
			printf("Out range.");
		}

		printf("Time: %f %f %f, Diff: %f %f %f, Range: %d %d %d\r\n",
			charger.xTime, charger.yTime, charger.zTime,
			diff_x, diff_y, diff_z,
			charger.range_x, charger.range_y, charger.range_z);

        charger.newDataFlag = 0;
    }
}