예제 #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;
    }
}
예제 #3
0
KstObject::UpdateType KstHistogram::update(int update_counter) {
  bool force = dirty();
  setDirty(false);

  if (KstObject::checkUpdateCounter(update_counter) && !force) {
    return lastUpdateResult();
  }

  if (update_counter <= 0) {
    assert(update_counter == 0);
    force = true;
  }

  bool xUpdated = KstObject::UPDATE == _inputVectors[RAWVECTOR]->update(update_counter);
  if (!xUpdated && !force) {
    return setLastUpdateResult(KstObject::NO_CHANGE);
  }

  int i_bin, i_pt, ns;
  double y = 0.0;
  double MaxY = 0.0;
  // do auto-binning if necessary
  if (_realTimeAutoBin) {
    int temp_NBins;
    double temp_xMin, temp_xMax;
    KstHistogram::AutoBin(_inputVectors[RAWVECTOR], &temp_NBins, &temp_xMax, &temp_xMin);
    internalSetNBins(temp_NBins);
    setXRange(temp_xMin, temp_xMax);
  }

  _NS = 3 * _NBins + 1;
  _W = (_MaxX - _MinX)/double(_NBins);

  memset(_Bins, 0, _NBins*sizeof(*_Bins));

  ns = _inputVectors[RAWVECTOR]->length();
  for (i_pt = 0; i_pt < ns ; i_pt++) {
    y = _inputVectors[RAWVECTOR]->interpolate(i_pt, ns);
    i_bin = (int)floor((y-_MinX)/_W);
    if (i_bin >= 0 && i_bin < _NBins) {
      _Bins[i_bin]++;
    } else {
      // the top boundry of the top bin is included in the top bin.
      // for all other bins, the top boundry is included in the next bin
      if (y == _MaxX) {
        _Bins[_NBins-1]++;
      }
    }
  }

  for (i_bin=0; i_bin<_NBins; i_bin++) {
    y = _Bins[i_bin];
    if (y > MaxY) {
      MaxY = y;
    }
  }

  switch (_NormMode) {
    case KST_HS_NUMBER:
      _Normalization = 1.0;
      (*_hVector)->setLabel(i18n("Number in bin"));
      break;
    case KST_HS_PERCENT:
      if (ns > 0) {
        _Normalization = 100.0/(double)ns;
      } else {
        _Normalization = 1.0;
      }
      (*_hVector)->setLabel(i18n("Percent in bin"));
      break;
    case KST_HS_FRACTION:
      if (ns > 0) {
        _Normalization = 1.0/(double)ns;
      } else {
        _Normalization = 1.0;
      }
      (*_hVector)->setLabel(i18n("Fraction in bin"));
      break;
    case KST_HS_MAX_ONE:
      if (MaxY > 0) {
        _Normalization = 1.0/MaxY;
      } else {
        _Normalization = 1.0;
      }
      (*_hVector)->setLabel("");
      break;
    default:
      _Normalization = 1.0;
      break;
  }

  (*_bVector)->setLabel(_inputVectors[RAWVECTOR]->tagName());

  double *bins = (*_bVector)->value();
  double *hist = (*_hVector)->value();

  for ( i_bin = 0; i_bin<_NBins; i_bin++ ) {
    bins[i_bin] = ( double( i_bin ) + 0.5 )*_W + _MinX;
    hist[i_bin] = _Bins[i_bin]*_Normalization;
  }
  
  (*_bVector)->setDirty();
  (*_bVector)->update(update_counter);
  (*_hVector)->setDirty();
  (*_hVector)->update(update_counter);

  return setLastUpdateResult(UPDATE);
}