void SteAccelAdaptor::processSample(int pathId, int fd)
{
    Q_UNUSED(pathId);
    char buf[32];
    int x, y, z;

//    if (pathId != devId) {
//        sensordLogW () << "Wrong pathId" << pathId;
//        return;
//    }

    lseek(fd, 0, SEEK_SET);
    if (read(fd, buf, sizeof(buf)) < 0 ) {
        sensordLogW() << "Read failed";
        stopSensor();
        return;
    }
    QString line(buf);

    x = line.section(":",0,0).toInt();
    y = line.section(":",1,1).toInt();
    z = line.section(":",2,2).toInt();

    AccelerationData *d = buffer->nextSlot();

    d->timestamp_ = Utils::getTimeStamp();

    d->x_ = x * 0.1 * 9.812865328;
    d->y_ = y * 0.1 * 9.812865328;
    d->z_ = z * 0.1 * 9.812865328;
    buffer->commit();
    buffer->wakeUpReaders();
}
bool ProximityAdaptorEvdev::standby()
{
    stopSensor();
    return true;
}
Example #3
0
//--------------------------------------------------------------
void wtmApp::guiEvent(ofxUIEventArgs &e) {
    string widgetName = e.widget->getName();
    // ofLogNotice() << "widget activated: " << widgetName;

    // interpolation type disclosure menu
    ofxUIDropDownList *dropDownlist = (ofxUIDropDownList *) gui->getWidget(kGUIInterpolationDropDownName);
    if (widgetName == kGUIInterpolationDropDownName) {
        moveWidgetsBeneathDropdown(dropDownlist, !dropDownlist->isOpen());
        return;
    }
    if (e.widget->getParent() == dropDownlist) {
        if (widgetName == kGUILinearName) this->interpolatorType = wtmInterpolatorTypeLinear;
        if (widgetName == kGUICatmullName) this->interpolatorType = wtmInterpolatorTypeCatmullRom;
        if (widgetName == kGUICosineName) this->interpolatorType = wtmInterpolatorTypeCosine;
        if (widgetName == kGUICubicName) this->interpolatorType = wtmInterpolatorTypeCubic;
        if (widgetName == kGUIHermiteName) this->interpolatorType = wtmInterpolatorTypeHermite;
        if (widgetName == kGUIWNNName) this->interpolatorType = wtmInterpolatorTypeWNN;
        if (widgetName == kGUILagrangeName) this->interpolatorType = wtmInterpolatorTypeLagrange;
        this->updateInterpolator();
        dropDownlist->setLabelText(widgetName.c_str());
        return;
    }
    
    // serial connection disclosure menu
    dropDownlist = (ofxUIDropDownList *) gui->getWidget(kGUISerialDropDownName);
    if (widgetName == kGUISerialDropDownName) {
        moveWidgetsBeneathDropdown(dropDownlist, !dropDownlist->isOpen());
        return;
    }
    if (e.widget->getParent() == dropDownlist) {
        if (serial.isInitialized()) {
            ofLogNotice() << "serial connection changed";
            if (this->state == wtmAppStateReceivingTouches) {
                stopSensor();
                ofxUILabelButton *startButton = (ofxUILabelButton *) gui->getWidget(kGUIStartName);
            }
            closeSerialConnection();
        }
        return;
    }
    
    // push buttons
    if (e.widget->getKind() == OFX_UI_WIDGET_LABELBUTTON) {
        ofxUILabelButton *button = (ofxUILabelButton *) e.widget;
        if (button->getValue() == 1) { // we only use button-released, not button-pressed and not both
            /* TODO
            if (widgetName == kGUIGridName) {
                bDrawGrid = button->getValue();
                return;
            }*/
            if (widgetName == kGUIStartName) {
                if (wtmAppStateNoSerialConnection == this->state) {
                    vector<string> selected = dropDownlist->getSelectedNames();
                    if (selected.empty()) {
                        ofLogError() << "no serial connection selected";
                    } else {
                        initAndStartSerialConnection(selected[0]);
                        button->setLabelText(kGUIStopName);
                    }
                    return;
                }
                if (wtmAppStateIdle == this->state) {
                    this->startSensor();
                    button->setLabelText(kGUIStopName);
                    return;
                }
                if (wtmAppStateReceivingTouches == this->state) {
                    this->stopSensor();
                    button->setLabelText(kGUIStartName);
                    return;
                }
                return;
            }
            if (widgetName == kGUICalibrateName) {
                if (wtmAppStateReceivingTouches == this->state) {
                    this->stopSensor(); // TODO: serial buffer issue
                    ofSleepMillis(100); // this is a
                    this->stopSensor(); // lousy workaround
                    this->startCalibration();
                    button->setLabelText("CALIBRATING...");
                }
                return;
            }
            if (widgetName == kGUIResetName) {
                if (wtmAppStateReceivingTouches == this->state) {
                    this->resetCalibration();
                }
            }
        }
    }
    
    // toggle buttons
    if (e.widget->getKind() == OFX_UI_WIDGET_LABELTOGGLE) {
        ofxUILabelToggle *toggle = (ofxUILabelToggle *) e.widget;
        if (widgetName == kGUIBlobsName) {
            bTrackBlobs = toggle->getValue();
            return;
        }
    }
    
    // sliders
    if (e.widget->getKind() == OFX_UI_WIDGET_SLIDER_H) {
        ofxUISlider *slider = (ofxUISlider *) e.widget;
        float val = slider->getValue();
        if (widgetName == kGUIHalfwaveAmpName) {
            slider->setValue(round(val));
            sendSliderData(slider);
        } else if (widgetName == kGUIOutputAmpName) {
            slider->setValue(round(val));
            sendSliderData(slider);
        } else if (widgetName == kGUISampleDelayName) {
            slider->setValue(round(val));
            sendSliderData(slider);
        } else if (widgetName == kGUIUpSamplingName) {
            int oldValue = this->interpolatorUpsampleX;
            int newValue = round(val);
            slider->setValue(newValue);
            if (oldValue != newValue) {
                this->interpolatorUpsampleX = newValue;
                this->interpolatorUpsampleY = newValue;
                this->updateInterpolator();
            }
        } else if (widgetName == kGUISignalFrequencyName) {
            slider->setValue(round(val));
            this->updateFrequencyLabel();
            sendSliderData(slider);
        } else if (widgetName == kGUIBlobThresholdName) {
            slider->setValue(round(val));
            this->blobTracker->setThreshold(round(val));
        } else if (widgetName == kGUIBlobVisualizationName) {
            slider->setValue(round(val));
            this->thresholdImageAlpha = round(val);
        } else if (widgetName == kGUIBlobAdaptiveThresholdRangeName) {
            double value = (slider->getValue()/100.0) * this->interpolator->getOutputWidth();
            this->blobTracker->setAdaptiveThresholdRange(((int) value) | 1);
        } else if (widgetName == kGUIBlobGammaName) {
            this->inputGamma = slider->getValue();
        }
    }
}
Example #4
0
ProximityAdaptor::~ProximityAdaptor()
{
    stopSensor();
    delete proximityBuffer_;
}