Skip to content

Commit

Permalink
Moved getBlowIntensity() from ValueInput to Thresholds
Browse files Browse the repository at this point in the history
Which is now also getting the inverted flag
And now Thresholds encapsulates all its logic
And it became much simpler to handle the inverted mode
  • Loading branch information
nununo committed Apr 29, 2017
1 parent dc39860 commit f1ca4f7
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 73 deletions.
16 changes: 10 additions & 6 deletions bin/data/vela.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@
</calibration>
<inputs>
<input type="keyboard" enabled="1"/>
<input type="mouse" enabled="1" inverted="0" calibrated="1"/>
<input type="mouse" enabled="0" inverted="0" calibrated="1">
<low>100</low>
<high>200</high>
<blowOut>300</blowOut>
</input>
<input type="autoFlicker" enabled="0">
<minPeriod>10000</minPeriod>
</input>
<input type="arduino" enabled="0" calibrated="1">
<input type="arduino" enabled="1" calibrated="1">
<devices>
<device name="mac">cu.usbmodem1421</device>
<device name="mac">cu.usbmodem1411</device>
<device name="pi">/dev/ttyUSB0</device>
</devices>
<analogInputs>
Expand All @@ -67,7 +71,7 @@
<blowOut>30</blowOut>
</analogInput>
<analogInput name="top" enabled="0" inverted="1" calibrated="1">
<low>5</low>
<low>-5</low>
<high>15</high>
<blowOut>30</blowOut>
</analogInput>
Expand All @@ -81,13 +85,13 @@
<rotated180>0</rotated180>
<portraitMode>0</portraitMode>
</layer>
<layer type="history" visible="0">
<layer type="history" visible="1">
<offsetX>0</offsetX>
<offsetY>0</offsetY>
<rotated180>0</rotated180>
<portraitMode>0</portraitMode>
</layer>
<layer type="clip" visible="0">
<layer type="clip" visible="1">
<offsetX>0</offsetX>
<offsetY>0</offsetY>
<rotated180>0</rotated180>
Expand Down
3 changes: 1 addition & 2 deletions src/CalibratedValueInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ ofEvent<ThresholdsEventArgs> CalibratedValueInput::thresholdsCalibrated = ofEven
//--------------------------------------------------------------
CalibratedValueInput::CalibratedValueInput(string name,
Thresholds thresholds,
bool inverted,
CalibrationSettings* _settings) : ThresholdsDataInput(name) {

valueInput = new ValueInput(name, thresholds, inverted);
valueInput = new ValueInput(name, thresholds);

settings = _settings;

Expand Down
1 change: 0 additions & 1 deletion src/CalibratedValueInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class CalibratedValueInput : public ThresholdsDataInput {
public:
CalibratedValueInput(string name,
Thresholds thresholds,
bool inverted,
CalibrationSettings* calibrationSettings);
~CalibratedValueInput() {
delete valueInput;
Expand Down
3 changes: 1 addition & 2 deletions src/KeyboardInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ KeyboardInput::KeyboardInput() : DataInput("keyboard") {
ofRegisterKeyEvents(this); // enable our class to listen to keyboard events.

input = new ValueInput(getName(),
Thresholds(1,2,3),
false);
Thresholds(1,2,3,false));
}

//--------------------------------------------------------------
Expand Down
11 changes: 5 additions & 6 deletions src/MouseInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ MouseInput::MouseInput(bool inverted, CalibrationSettings *calibrationSettings)
if (calibrationSettings)
input = new CalibratedValueInput(buildName(inverted, true),
getThresholds(inverted),
inverted,
calibrationSettings);
else
input = new ValueInput(buildName(inverted, false),
getThresholds(inverted),
inverted);
input = new ValueInput(buildName(inverted, false), getThresholds(inverted));
};

//--------------------------------------------------------------
Expand All @@ -31,11 +28,13 @@ Thresholds MouseInput::getThresholds(bool inverted) {
if (!inverted)
thresholds = Thresholds(1*(float)ofGetScreenHeight()/4,
2*(float)ofGetScreenHeight()/4,
3*(float)ofGetScreenHeight()/4);
3*(float)ofGetScreenHeight()/4,
false);
else
thresholds = Thresholds(3*(float)ofGetScreenHeight()/4,
2*(float)ofGetScreenHeight()/4,
1*(float)ofGetScreenHeight()/4);
1*(float)ofGetScreenHeight()/4,
true);

return thresholds;
}
Expand Down
56 changes: 56 additions & 0 deletions src/Thresholds.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// Thresholds.cpp
// vela2017
//
// Created by Nuno on 29/04/2017.
//
//

#include "Thresholds.h"

//--------------------------------------------------------------
Thresholds::Thresholds(float _low, float _high, float _blowOut, bool _inverted) {
inverted = _inverted;
if (!inverted) {
low = _low;
high = _high;
blowOut = _blowOut;
} else {
low = -_low;
high = -_high;
blowOut = -_blowOut;
}
}

//--------------------------------------------------------------
BlowIntensity Thresholds::getBlowIntensity(float value) {

if (!inverted) {
if (value < getLow())
return BlowIntensity::IDLE;

else if (value < getHigh())
return BlowIntensity::LOW;

else if (value < getBlowOut())
return BlowIntensity::HIGH;

else
return BlowIntensity::BLOWOUT;

} else {
if (value > getLow())
return BlowIntensity::IDLE;

else if (value > getHigh())
return BlowIntensity::LOW;

else if (value > getBlowOut())
return BlowIntensity::HIGH;

else
return BlowIntensity::BLOWOUT;

}

}
16 changes: 7 additions & 9 deletions src/Thresholds.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,26 @@
#ifndef Thresholds_h
#define Thresholds_h

#include "BlowIntensity.h"

class Thresholds {

public:
Thresholds() : Thresholds(0,0,0) {}
Thresholds(float _low, float _high, float _blowOut, float _offset=0) {
low = _low;
high = _high;
blowOut = _blowOut;
offset = _offset;
}

Thresholds() : Thresholds(0,0,0,false) {}
Thresholds(float _low, float _high, float _blowOut, bool _inverted);
float getLow() {return low+offset;}
float getHigh() {return high+offset;}
float getBlowOut() {return blowOut+offset;}
float getOffset() {return offset;}
float setOffset(float _offset) {offset=_offset;}
BlowIntensity getBlowIntensity(float value);

private:
float offset=0;
float low;
float high;
float blowOut;
float offset;
bool inverted;
};

#endif /* Thresholds_h */
16 changes: 6 additions & 10 deletions src/ThresholdsDataInputFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,16 @@ DataInput* ThresholdsDataInputFactory::createAux(ofXml *xml, CalibrationSettings
name = xml->getAttribute("name");
if (namePrefix!="")
name = namePrefix + "." + name;

inverted = Util::stringToBool(xml->getAttribute("inverted"));

thresholds = Thresholds(xml->getFloatValue(Util::blowIntensityToString(BlowIntensity::LOW)),
xml->getFloatValue(Util::blowIntensityToString(BlowIntensity::HIGH)),
xml->getFloatValue(Util::blowIntensityToString(BlowIntensity::BLOWOUT)));

inverted = Util::stringToBool(xml->getAttribute("inverted"));
xml->getFloatValue(Util::blowIntensityToString(BlowIntensity::BLOWOUT)),
inverted);

if (calibrationSettings)
return new CalibratedValueInput(name,
thresholds,
inverted,
calibrationSettings);
return new CalibratedValueInput(name, thresholds, calibrationSettings);
else
return new ValueInput(name,
thresholds,
inverted);
return new ValueInput(name, thresholds);
}
31 changes: 0 additions & 31 deletions src/ValueInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,6 @@
// the static event, or any static variable, must be initialized outside of the class definition.
ofEvent<NameFloatEventArgs> ValueInput::newValue = ofEvent<NameFloatEventArgs>();

//--------------------------------------------------------------
BlowIntensity ValueInput::getBlowIntensity() {

if (!inverted) {
if (lastValue < getThresholds()->getLow())
return BlowIntensity::IDLE;

else if (lastValue < getThresholds()->getHigh())
return BlowIntensity::LOW;

else if (lastValue < getThresholds()->getBlowOut())
return BlowIntensity::HIGH;

else
return BlowIntensity::BLOWOUT;

} else {
if (lastValue > getThresholds()->getLow())
return BlowIntensity::IDLE;

else if (lastValue > getThresholds()->getHigh())
return BlowIntensity::LOW;

else if (lastValue > getThresholds()->getBlowOut())
return BlowIntensity::HIGH;

else
return BlowIntensity::BLOWOUT;
}
}

//--------------------------------------------------------------
void ValueInput::setValue(float value) {
lastValue = value;
Expand Down
8 changes: 2 additions & 6 deletions src/ValueInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@

class ValueInput : public ThresholdsDataInput {
public:
ValueInput(string name,
Thresholds _thresholds,
bool _inverted) : ThresholdsDataInput(name) {
ValueInput(string name, Thresholds _thresholds) : ThresholdsDataInput(name) {
thresholds=_thresholds;
inverted=_inverted;
lastValue=0;};

// DataInput
virtual void update() {}
virtual BlowIntensity getBlowIntensity();
virtual BlowIntensity getBlowIntensity() {return thresholds.getBlowIntensity(lastValue);}

// ITrace
virtual string getTrace();
Expand All @@ -41,7 +38,6 @@ class ValueInput : public ThresholdsDataInput {

Thresholds thresholds;
float lastValue;
bool inverted;
};

#endif /* AnalogInputSettings_h */
4 changes: 4 additions & 0 deletions vela2017.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
7D4C8CA71EAD7619009076C4 /* MovieFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7D4C8CA51EAD7619009076C4 /* MovieFactory.cpp */; };
7D58DF111EA286AC00BDFA7F /* MouseInput.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7D58DF0F1EA286AC00BDFA7F /* MouseInput.cpp */; };
7D60A9121E9961F3009FF4F2 /* MultiInput.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7D60A9101E9961F3009FF4F2 /* MultiInput.cpp */; };
7D65E7B81EB4E5F40087018A /* Thresholds.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7D65E7B71EB4E5F40087018A /* Thresholds.cpp */; };
7D7245AE1E7DA83F006E5653 /* Clip.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7D7245AC1E7DA83F006E5653 /* Clip.cpp */; };
7DA246DA1EABB5000077EB85 /* MouseInputFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7DA246D91EABB5000077EB85 /* MouseInputFactory.cpp */; };
7DA246DC1EABBAB70077EB85 /* CalibrationSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7DA246DB1EABBAB70077EB85 /* CalibrationSettings.cpp */; };
Expand Down Expand Up @@ -105,6 +106,7 @@
7D5DA2AF1EAFFC3C00662FB6 /* NameFloatEventArgs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NameFloatEventArgs.h; sourceTree = "<group>"; };
7D60A9101E9961F3009FF4F2 /* MultiInput.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MultiInput.cpp; sourceTree = "<group>"; };
7D60A9111E9961F3009FF4F2 /* MultiInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MultiInput.h; sourceTree = "<group>"; };
7D65E7B71EB4E5F40087018A /* Thresholds.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Thresholds.cpp; sourceTree = "<group>"; };
7D7245AC1E7DA83F006E5653 /* Clip.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Clip.cpp; sourceTree = "<group>"; };
7D7245AD1E7DA83F006E5653 /* Clip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Clip.h; sourceTree = "<group>"; };
7D7245B51E7DCDE7006E5653 /* ClipOutputSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ClipOutputSettings.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -295,6 +297,7 @@
7DE285491EB021D8005C3777 /* ValueHistory.h */,
7DB94A5D1EB146D6008ADD74 /* ThresholdsEventArgs.h */,
7DB94A5E1EB14754008ADD74 /* Thresholds.h */,
7D65E7B71EB4E5F40087018A /* Thresholds.cpp */,
);
name = tools;
sourceTree = "<group>";
Expand Down Expand Up @@ -472,6 +475,7 @@
7DB3F7DB1E8DD1C90025498A /* SystemInfo.cpp in Sources */,
7DAA8B611E776C62005385DD /* Clips.cpp in Sources */,
7DE285411EB00CE1005C3777 /* ValueHistories.cpp in Sources */,
7D65E7B81EB4E5F40087018A /* Thresholds.cpp in Sources */,
7DE285441EB01506005C3777 /* ValueHistoriesLayer.cpp in Sources */,
7D11675C1EAD7D8E00098A21 /* MovieOMXPlayer.cpp in Sources */,
7DABC4181E9AB847006BEB5F /* ValueInput.cpp in Sources */,
Expand Down

0 comments on commit f1ca4f7

Please sign in to comment.