├── .gitignore ├── .gitmodules ├── .travis.yml ├── Arduino ├── ADXL335 │ └── ADXL335.ino ├── ADXL335_LEDs │ └── ADXL335_LEDs.ino ├── Arduino101_Accelerometer │ └── Arduino101_Accelerometer.ino ├── Arduino101_IMU │ └── Arduino101_IMU.ino ├── CapacitiveSensing-MPR121 │ └── CapacitiveSensing-MPR121.ino ├── ColorSensor │ └── ColorSensor.ino ├── ColorSensor_SparkFun_ISL29125 │ └── ColorSensor_SparkFun_ISL29125.ino ├── ElectretMicrophone │ └── ElectretMicrophone.ino ├── Touche │ └── Touche.ino ├── Touche_LEDs │ └── Touche_LEDs.ino └── libraries │ ├── Adafruit_MPR121 │ ├── Adafruit_MPR121.cpp │ ├── Adafruit_MPR121.h │ ├── README.txt │ ├── examples │ │ └── MPR121test │ │ │ └── MPR121test.ino │ ├── keywords.txt │ └── library.properties │ ├── Adafruit_TCS34725 │ ├── Adafruit_TCS34725.cpp │ ├── Adafruit_TCS34725.h │ ├── README.md │ ├── examples │ │ ├── colorview │ │ │ ├── colorview.ino │ │ │ └── processing │ │ │ │ └── colorview │ │ │ │ └── colorview.pde │ │ ├── tcs34725 │ │ │ └── tcs34725.pde │ │ └── tcs34725autorange │ │ │ └── tcs34725autorange.ino │ └── library.properties │ └── SparkFun_ISL29125_Breakout │ ├── .gitattributes │ ├── .gitignore │ ├── LICENSE.md │ ├── README.md │ ├── examples │ ├── ISL29125Basics │ │ └── ISL29125Basics.ino │ ├── ISL29125Interrupts │ │ └── ISL29125Interrupts.ino │ └── ISL29125RGBLED │ │ └── ISL29125RGBLED.ino │ ├── library.properties │ └── src │ ├── SparkFunISL29125.cpp │ └── SparkFunISL29125.h ├── CMakeLists.txt ├── LICENSE.txt ├── Processing └── BallDrop │ └── BallDrop.pde ├── README.md ├── Xcode └── ESP │ ├── .gitignore │ ├── Doxyfile │ ├── ESP.sln │ ├── ESP.vcxproj │ ├── ESP.vcxproj.filters │ ├── ESP.xcodeproj │ ├── project.pbxproj │ └── xcshareddata │ │ └── xcschemes │ │ ├── ESP Debug.xcscheme │ │ └── ESP Release.xcscheme │ ├── ESPlib.vcxproj │ ├── Info.plist │ ├── Makefile │ ├── Project.xcconfig │ ├── addons.make │ ├── bin │ └── data │ │ ├── .gitkeep │ │ ├── ofxbraitsch │ │ ├── fonts │ │ │ └── Verdana.ttf │ │ └── ofxdatgui │ │ │ ├── icon-group-closed.png │ │ │ ├── icon-group-open.png │ │ │ ├── icon-radio-off.png │ │ │ ├── icon-radio-on.png │ │ │ └── picker-rainbow.png │ │ ├── train1.wav │ │ ├── train13.wav │ │ ├── train14.wav │ │ ├── train15.wav │ │ ├── train7.wav │ │ └── verdana.ttf │ ├── config.make │ ├── icon.rc │ ├── libgrt.dylib │ ├── openFrameworks-Info.plist │ └── src │ ├── ESP.h │ ├── Filter.cpp │ ├── Filter.h │ ├── MFCC.cpp │ ├── MFCC.h │ ├── ThresholdDetection.cpp │ ├── ThresholdDetection.h │ ├── calibrator.cpp │ ├── calibrator.h │ ├── cli.cpp │ ├── examples │ ├── user_accelerometer_gestures.cpp │ ├── user_accelerometer_gestures_osc.cpp │ ├── user_accelerometer_gestures_simple.cpp │ ├── user_accelerometer_poses.cpp │ ├── user_accelerometer_walk_detection.cpp │ ├── user_audio_beat_detection.cpp │ ├── user_capacitive_sensing.cpp │ ├── user_color_sensor.cpp │ ├── user_speaker.cpp │ ├── user_speech_detection.cpp │ ├── user_sudden_motion.cpp │ └── user_touche.cpp │ ├── iostream.cpp │ ├── iostream.h │ ├── istream.cpp │ ├── istream.h │ ├── main.cpp │ ├── matplotlibcpp.h │ ├── ofApp.cpp │ ├── ofApp.h │ ├── ofConsoleFileLoggerChannel.cpp │ ├── ofConsoleFileLoggerChannel.h │ ├── ofYesNoDialog.cpp │ ├── ofYesNoDialog.h │ ├── ofxGrtSettings.cpp │ ├── ostream.cpp │ ├── ostream.h │ ├── plotter.cpp │ ├── plotter.h │ ├── stream.h │ ├── training-data-manager-test.cpp │ ├── training-data-manager.cpp │ ├── training-data-manager.h │ ├── training.cpp │ ├── training.h │ ├── tuneable.cpp │ ├── tuneable.h │ ├── user.cpp │ └── user.h ├── cmake ├── DetectArch.cmake ├── FindCairo.cmake ├── FindFontconfig.cmake ├── FindFreeImage.cmake ├── FindGLFW.cmake ├── FindGLib.cmake ├── FindGObject.cmake ├── FindGStreamer.cmake ├── FindGrt.cmake ├── FindOpenFrameworks.cmake ├── FindPoco.cmake └── FindRtAudio.cmake ├── setup.sh └── update-xcode-grt.sh /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore third-party downloads and openFrameworks folder 2 | third-party/*.zip 3 | third-party/*.tar.gz 4 | third-party/openFrameworks 5 | build 6 | 7 | ######################### 8 | # openFrameworks patterns 9 | ######################### 10 | 11 | # build files 12 | openFrameworks.a 13 | openFrameworksDebug.a 14 | openFrameworksUniversal.a 15 | libs/openFrameworksCompiled/lib/*/* 16 | !libs/openFrameworksCompiled/lib/*/.gitkeep 17 | 18 | # apothecary 19 | scripts/apothecary/build 20 | 21 | # rule to avoid non-official addons going into git 22 | # see addons/.gitignore 23 | addons/* 24 | 25 | # rule to avoid non-official apps going into git 26 | # see apps/.gitignore 27 | apps/* 28 | 29 | # also, see examples/.gitignore 30 | 31 | ######################### 32 | # general 33 | ######################### 34 | 35 | [Bb]uild/ 36 | [Oo]bj/ 37 | *.o 38 | examples/**/[Dd]ebug*/ 39 | examples/**/[Rr]elease*/ 40 | examples/**/gcc-debug/ 41 | examples/**/gcc-release/ 42 | tests/**/[Dd]ebug*/ 43 | tests/**/[Rr]elease*/ 44 | tests/**/gcc-debug/ 45 | tests/**/gcc-release/ 46 | *.mode* 47 | *.app/ 48 | *.pyc 49 | .svn/ 50 | *.log 51 | *.cpp.eep 52 | *.cpp.elf 53 | *.cpp.hex 54 | 55 | ######################### 56 | # IDE 57 | ######################### 58 | 59 | # XCode 60 | *.pbxuser 61 | *.perspective 62 | *.perspectivev3 63 | *.mode1v3 64 | *.mode2v3 65 | # XCode 4 66 | xcuserdata 67 | *.xcworkspace 68 | 69 | # Code::Blocks 70 | *.depend 71 | *.layout 72 | 73 | # Visual Studio 74 | *.sdf 75 | *.opensdf 76 | *.suo 77 | *.pdb 78 | *.ilk 79 | *.aps 80 | ipch/ 81 | 82 | # Eclipse 83 | .metadata 84 | local.properties 85 | .externalToolBuilders 86 | 87 | # Android Studio 88 | .idea 89 | .gradle 90 | gradle 91 | gradlew 92 | gradlew.bat 93 | 94 | # QtCreator 95 | *.qbs.user 96 | *.pro.user 97 | *.pri 98 | 99 | 100 | ######################### 101 | # operating system 102 | ######################### 103 | 104 | # Linux 105 | *~ 106 | # KDE 107 | .directory 108 | .AppleDouble 109 | 110 | # OSX 111 | .DS_Store 112 | *.swp 113 | *~.nib 114 | # Thumbnails 115 | ._* 116 | 117 | # Windows 118 | # Windows image file caches 119 | Thumbs.db 120 | # Folder config file 121 | Desktop.ini 122 | 123 | # Android 124 | .csettings 125 | /libs/openFrameworksCompiled/project/android/paths.make 126 | 127 | # Android Studio 128 | *.iml 129 | 130 | ######################### 131 | # miscellaneous 132 | ######################### 133 | 134 | .mailmap 135 | e 136 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "third-party/ofxGrt"] 2 | path = third-party/ofxGrt 3 | url = https://github.com/nebgnahz/ofxGrt.git 4 | [submodule "third-party/grt"] 5 | path = third-party/grt 6 | url = https://github.com/damellis/grt.git 7 | [submodule "third-party/SpaceInvaders"] 8 | path = third-party/SpaceInvaders 9 | url = https://github.com/damellis/Processing_SpaceInv.git 10 | [submodule "third-party/ofxDatGui"] 11 | path = third-party/ofxDatGui 12 | url = https://github.com/nebgnahz/ofxDatGui.git 13 | [submodule "third-party/ofxParagraph"] 14 | path = third-party/ofxParagraph 15 | url = https://github.com/braitsch/ofxParagraph.git 16 | [submodule "third-party/googletest"] 17 | path = third-party/googletest 18 | url = https://github.com/google/googletest.git 19 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | matrix: 4 | include: 5 | - os: linux 6 | dist: trusty 7 | compiler: gcc 8 | env: 9 | - BUILD_TOOL=CMake OS=Linux 10 | sudo: require 11 | - os: osx 12 | osx_image: xcode7.3 13 | compiler: clang 14 | env: 15 | - BUILD_TOOL=Xcode OS=OSX 16 | exclude: 17 | - compiler: clang 18 | 19 | git: 20 | submodules: false 21 | 22 | branches: 23 | only: 24 | - master 25 | 26 | before_script: 27 | # Take care of dependencies. 28 | - sed -i -e 's/git@github.com:/https:\/\/github.com\//' .gitmodules 29 | - sudo apt-get -y install ca-certificates 30 | - ./setup.sh 31 | - > 32 | if [ "$OS" = "OSX" ]; then 33 | xcodebuild -configuration Release -target emptyExample \ 34 | -project "third-party/openFrameworks/scripts/templates/osx/emptyExample.xcodeproj" 35 | else 36 | # Linux/Ubuntu 37 | sudo third-party/openFrameworks/scripts/linux/ubuntu/install_dependencies.sh -y 38 | sed -i '9a\ROOT=`pwd`/third-party/openFrameworks' third-party/openFrameworks/scripts/ci/linux/build.sh 39 | sudo third-party/openFrameworks/scripts/ci/linux/build.sh 40 | sudo apt-get -y install doxygen 41 | sudo apt-get -y install cmake 42 | sudo apt-get -y install libblas-dev 43 | # Build GRT 44 | cd third-party/grt/build 45 | mkdir -p tmp && cd tmp 46 | cmake .. -DBUILD_EXAMPLES=OFF 47 | make 48 | sudo make install 49 | cd ../../../../ 50 | fi 51 | # CMake 52 | - > 53 | if [ "$BUILD_TOOL" = "CMake" ]; then 54 | mkdir build 55 | cd build 56 | cmake .. 57 | fi 58 | script: 59 | - > 60 | if [ "$BUILD_TOOL" = "CMake" ]; then 61 | set -e 62 | # I am in $ROOT/build folder 63 | USER_CPP=../Xcode/ESP/src/user.cpp 64 | EXAMPLES=../Xcode/ESP/src/examples/* 65 | for f in $EXAMPLES 66 | do 67 | name=$(basename "$f") 68 | echo "Compiling example: $f ..." 69 | echo "#include \"user.h\"" > $USER_CPP 70 | echo "#include \"examples/$name\"" >> $USER_CPP 71 | make 72 | done 73 | fi; 74 | - > 75 | if [ "$BUILD_TOOL" = "Xcode" ]; then 76 | xcodebuild -configuration Release -target ESP -project "Xcode/ESP/ESP.xcodeproj" 77 | fi 78 | cache: 79 | directories: 80 | - third-party/openFrameworks/libs 81 | -------------------------------------------------------------------------------- /Arduino/ADXL335/ADXL335.ino: -------------------------------------------------------------------------------- 1 | int zpin = A2; 2 | int ypin = A1; 3 | int xpin = A0; 4 | 5 | // These are only used if you're plugging the ADXL335 (on the 6 | // Adafruit breakout board) directly into the analog input pins 7 | // of your Arduino. See comment below. 8 | int vinpin = A5; 9 | int voutpin = A4; 10 | int gndpin = A3; 11 | 12 | void setup() { 13 | Serial.begin(115200); 14 | 15 | // Uncomment the following lines if you're using an ADXL335 on an 16 | // Adafruit breakout board (https://www.adafruit.com/products/163) 17 | // and want to plug it directly into (and power it from) the analog 18 | // input pins of your Arduino board. 19 | // pinMode(vinpin, OUTPUT); digitalWrite(vinpin, HIGH); 20 | // pinMode(gndpin, OUTPUT); digitalWrite(gndpin, LOW); 21 | // pinMode(voutpin, INPUT); 22 | 23 | pinMode(xpin, INPUT); 24 | pinMode(ypin, INPUT); 25 | pinMode(zpin, INPUT); 26 | } 27 | 28 | void loop() { 29 | Serial.print(analogRead(xpin)); Serial.print("\t"); 30 | Serial.print(analogRead(ypin)); Serial.print("\t"); 31 | Serial.print(analogRead(zpin)); Serial.println(); 32 | delay(10); 33 | } 34 | -------------------------------------------------------------------------------- /Arduino/ADXL335_LEDs/ADXL335_LEDs.ino: -------------------------------------------------------------------------------- 1 | // Arduino example that streams accelerometer data from an ADXL335 2 | // (or other three-axis analog accelerometer) to the ESP system and 3 | // lights different LEDs depending on the predictions made by the 4 | // ESP system. Use with the user_accelerometer_gestures.cpp ESP example. 5 | 6 | // the accelerometer pins 7 | int zpin = A2; 8 | int ypin = A1; 9 | int xpin = A0; 10 | 11 | // the LED pins 12 | int redpin = 9; 13 | int greenpin = 10; 14 | int bluepin = 11; 15 | 16 | // These are only used if you're plugging the ADXL335 (on the 17 | // Adafruit breakout board) directly into the analog input pins 18 | // of your Arduino. See comment below. 19 | int vinpin = A5; 20 | int voutpin = A4; 21 | int gndpin = A3; 22 | 23 | void setup() { 24 | Serial.begin(115200); 25 | 26 | // Lower the serial timeout (from its default value of 1000 ms) 27 | // so that the call to Serial.parseInt() below doesn't pause for 28 | // too long and disrupt the sending of accelerometer data. 29 | Serial.setTimeout(2); 30 | 31 | // Uncomment the following lines if you're using an ADXL335 on an 32 | // Adafruit breakout board (https://www.adafruit.com/products/163) 33 | // and want to plug it directly into (and power it from) the analog 34 | // input pins of your Arduino board. 35 | // pinMode(vinpin, OUTPUT); digitalWrite(vinpin, HIGH); 36 | // pinMode(gndpin, OUTPUT); digitalWrite(gndpin, LOW); 37 | // pinMode(voutpin, INPUT); 38 | 39 | pinMode(xpin, INPUT); 40 | pinMode(ypin, INPUT); 41 | pinMode(zpin, INPUT); 42 | } 43 | 44 | void loop() { 45 | Serial.print(analogRead(xpin)); Serial.print("\t"); 46 | Serial.print(analogRead(ypin)); Serial.print("\t"); 47 | Serial.print(analogRead(zpin)); Serial.println(); 48 | delay(10); 49 | 50 | // Check for a valid prediction. 51 | int val = Serial.parseInt(); 52 | if (val != 0) { 53 | // Turn off all the LEDs. 54 | analogWrite(redpin, 0); 55 | analogWrite(greenpin, 0); 56 | analogWrite(bluepin, 0); 57 | 58 | // Turn on the LED corresponding to the prediction. 59 | if (val == 1) analogWrite(redpin, 255); 60 | if (val == 2) analogWrite(greenpin, 255); 61 | if (val == 3) analogWrite(bluepin, 255); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Arduino/Arduino101_Accelerometer/Arduino101_Accelerometer.ino: -------------------------------------------------------------------------------- 1 | #include "CurieIMU.h" 2 | 3 | int ax, ay, az; 4 | 5 | void setup() { 6 | Serial.begin(115200); 7 | while (!Serial); 8 | 9 | CurieIMU.begin(); 10 | 11 | if (!CurieIMU.testConnection()) { 12 | Serial.println("CurieImu connection failed"); 13 | } 14 | 15 | CurieIMU.setAccelerometerRange(8); 16 | } 17 | 18 | void loop() { 19 | CurieIMU.readAccelerometer(ax, ay, az); 20 | Serial.print(ax); 21 | Serial.print("\t"); 22 | Serial.print(ay); 23 | Serial.print("\t"); 24 | Serial.print(az); 25 | Serial.println(); 26 | delay(10); 27 | } 28 | -------------------------------------------------------------------------------- /Arduino/Arduino101_IMU/Arduino101_IMU.ino: -------------------------------------------------------------------------------- 1 | #include "CurieImu.h" 2 | 3 | int16_t ax, ay, az; 4 | int16_t gx, gy, gz; 5 | 6 | void setup() { 7 | Serial.begin(9600); 8 | while (!Serial); 9 | 10 | CurieImu.initialize(); 11 | 12 | if (!CurieImu.testConnection()) { 13 | Serial.println("CurieImu connection failed"); 14 | } 15 | } 16 | 17 | void loop() { 18 | CurieImu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); 19 | Serial.print(ax); 20 | Serial.print("\t"); 21 | Serial.print(ay); 22 | Serial.print("\t"); 23 | Serial.print(az); 24 | Serial.print("\t"); 25 | Serial.print(gx); 26 | Serial.print("\t"); 27 | Serial.print(gy); 28 | Serial.print("\t"); 29 | Serial.println(gz); 30 | } 31 | -------------------------------------------------------------------------------- /Arduino/CapacitiveSensing-MPR121/CapacitiveSensing-MPR121.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Adafruit_MPR121.h" 3 | 4 | Adafruit_MPR121 cap = Adafruit_MPR121(); 5 | 6 | void setup() { 7 | Serial.begin(9600); 8 | 9 | if (!cap.begin(0x5A)) { 10 | Serial.println("Error: couldn't connect to MPR121."); 11 | while (1); 12 | } 13 | } 14 | 15 | void loop() { 16 | for (int i = 0; i < 12; i++) { 17 | Serial.print(cap.filteredData(i)); Serial.print("\t"); 18 | //Serial.print(cap.baselineData(i)); Serial.print("\t"); 19 | } 20 | Serial.println(); 21 | delay(10); 22 | } 23 | -------------------------------------------------------------------------------- /Arduino/ColorSensor/ColorSensor.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Adafruit_TCS34725.h" 3 | 4 | Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X); 5 | 6 | void setup() { 7 | Serial.begin(9600); 8 | 9 | if (!tcs.begin()) { 10 | Serial.println("No TCS34725 found ... check your connections"); 11 | while (1); // halt! 12 | } 13 | } 14 | 15 | void loop() { 16 | uint16_t clear, red, green, blue; 17 | 18 | tcs.setInterrupt(false); // turn on LED 19 | 20 | delay(60); // takes 50ms to read 21 | 22 | tcs.getRawData(&red, &green, &blue, &clear); 23 | 24 | tcs.setInterrupt(true); // turn off LED 25 | 26 | Serial.print(red); Serial.print("\t"); 27 | Serial.print(green); Serial.print("\t"); 28 | Serial.print(blue); // Serial.print("\t"); 29 | // Serial.print(clear); 30 | Serial.println(); 31 | 32 | // uint32_t sum = clear; 33 | // float r, g, b; 34 | // r = red; r /= sum; 35 | // g = green; g /= sum; 36 | // b = blue; b /= sum; 37 | // r *= 256; g *= 256; b *= 256; 38 | // Serial.print((int)r ); Serial.print("\t"); Serial.print((int)g);Serial.print("\t"); Serial.println((int)b ); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /Arduino/ColorSensor_SparkFun_ISL29125/ColorSensor_SparkFun_ISL29125.ino: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ISL29125_basics.ino 3 | Simple example for using the ISL29125 RGB sensor library. 4 | Jordan McConnell @ SparkFun Electronics 5 | 11 Apr 2014 6 | https://github.com/sparkfun/SparkFun_ISL29125_Breakout_Arduino_Library 7 | 8 | This example declares an SFE_ISL29125 object called RGB_sensor. The 9 | object/sensor is initialized with a basic configuration so that it continuously 10 | samples the light intensity of red, green and blue spectrums. These values are 11 | read from the sensor every 2 seconds and printed to the Serial monitor. 12 | 13 | Developed/Tested with: 14 | Arduino Uno 15 | Arduino IDE 1.0.5 16 | 17 | Requires: 18 | SparkFun_ISL29125_Arduino_Library 19 | 20 | This code is beerware. 21 | Distributed as-is; no warranty is given. 22 | ******************************************************************************/ 23 | 24 | #include 25 | #include "SparkFunISL29125.h" 26 | 27 | // Declare sensor object 28 | SFE_ISL29125 RGB_sensor; 29 | 30 | void setup() 31 | { 32 | // Initialize serial communication 33 | Serial.begin(9600); 34 | 35 | // Initialize the ISL29125 with simple configuration so it starts sampling 36 | if (!RGB_sensor.init()) 37 | { 38 | Serial.println("Sensor Initialization Failed\n\r"); 39 | while (1); 40 | } 41 | } 42 | 43 | // Read sensor values for each color and print them to serial monitor 44 | void loop() 45 | { 46 | // Read sensor values (16 bit integers) 47 | unsigned int red = RGB_sensor.readRed(); 48 | unsigned int green = RGB_sensor.readGreen(); 49 | unsigned int blue = RGB_sensor.readBlue(); 50 | 51 | // Print out readings, change HEX to DEC if you prefer decimal output 52 | Serial.print(red); Serial.print("\t"); 53 | Serial.print(green); Serial.print("\t"); 54 | Serial.print(blue); Serial.print("\t"); 55 | Serial.println(); 56 | } 57 | -------------------------------------------------------------------------------- /Arduino/ElectretMicrophone/ElectretMicrophone.ino: -------------------------------------------------------------------------------- 1 | /**************************************** 2 | * Simple Arduino + Electret Microphone 3 | ****************************************/ 4 | 5 | // Sample window width in uS (200 uS = 5 kHz) 6 | const int sampleWindow = 200; 7 | unsigned int sample; 8 | 9 | void setup() { 10 | Serial.begin(115200); 11 | } 12 | 13 | void loop() { 14 | // Start of sample window 15 | unsigned long startMicros = micros(); 16 | 17 | // Collects data according to sampleWindow 18 | while (micros() - startMicros < sampleWindow) { } 19 | 20 | // sample will be [0, 1023] 21 | sample = analogRead(0); 22 | 23 | // sample / 4 will be [0, 256] 24 | sample = sample >> 2; 25 | 26 | // Writes the byte through serial 27 | byte b = sample; 28 | Serial.write(b); 29 | } 30 | -------------------------------------------------------------------------------- /Arduino/Touche/Touche.ino: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | //**************************************************************************************** 5 | // Illutron take on Disney style capacitive touch sensor using only passives and Arduino 6 | // Dzl 2012 7 | //**************************************************************************************** 8 | 9 | 10 | // 10n 11 | // PIN 9 --[10k]-+-----10mH---+--||-- OBJECT 12 | // | | 13 | // 3.3k | 14 | // | V 1N4148 diode 15 | // GND | 16 | // | 17 | //Analog 0 ---+------+--------+ 18 | // | | 19 | // 100pf 1MOmhm 20 | // | | 21 | // GND GND 22 | 23 | 24 | 25 | #define SET(x,y) (x |=(1< https://www.adafruit.com/products/1982 6 | 7 | These sensors use I2C to communicate, 2+ pins are required to 8 | interface 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. 14 | BSD license, all text above must be included in any redistribution 15 | ****************************************************/ 16 | 17 | #include "Adafruit_MPR121.h" 18 | 19 | Adafruit_MPR121::Adafruit_MPR121() { 20 | } 21 | 22 | boolean Adafruit_MPR121::begin(uint8_t i2caddr) { 23 | Wire.begin(); 24 | 25 | _i2caddr = i2caddr; 26 | 27 | // soft reset 28 | writeRegister(MPR121_SOFTRESET, 0x63); 29 | delay(1); 30 | for (uint8_t i=0; i<0x7F; i++) { 31 | // Serial.print("$"); Serial.print(i, HEX); 32 | // Serial.print(": 0x"); Serial.println(readRegister8(i)); 33 | } 34 | 35 | 36 | writeRegister(MPR121_ECR, 0x0); 37 | 38 | uint8_t c = readRegister8(MPR121_CONFIG2); 39 | 40 | if (c != 0x24) return false; 41 | 42 | 43 | setThreshholds(12, 6); 44 | writeRegister(MPR121_MHDR, 0x01); 45 | writeRegister(MPR121_NHDR, 0x01); 46 | writeRegister(MPR121_NCLR, 0x0E); 47 | writeRegister(MPR121_FDLR, 0x00); 48 | 49 | writeRegister(MPR121_MHDF, 0x01); 50 | writeRegister(MPR121_NHDF, 0x05); 51 | writeRegister(MPR121_NCLF, 0x01); 52 | writeRegister(MPR121_FDLF, 0x00); 53 | 54 | writeRegister(MPR121_NHDT, 0x00); 55 | writeRegister(MPR121_NCLT, 0x00); 56 | writeRegister(MPR121_FDLT, 0x00); 57 | 58 | writeRegister(MPR121_DEBOUNCE, 0); 59 | writeRegister(MPR121_CONFIG1, 0x10); // default, 16uA charge current 60 | writeRegister(MPR121_CONFIG2, 0x20); // 0.5uS encoding, 1ms period 61 | 62 | // writeRegister(MPR121_AUTOCONFIG0, 0x8F); 63 | 64 | // writeRegister(MPR121_UPLIMIT, 150); 65 | // writeRegister(MPR121_TARGETLIMIT, 100); // should be ~400 (100 shifted) 66 | // writeRegister(MPR121_LOWLIMIT, 50); 67 | // enable all electrodes 68 | writeRegister(MPR121_ECR, 0x8F); // start with first 5 bits of baseline tracking 69 | 70 | return true; 71 | } 72 | 73 | void Adafruit_MPR121::setThreshholds(uint8_t touch, uint8_t release) { 74 | 75 | setThresholds(touch, release); 76 | } 77 | 78 | void Adafruit_MPR121::setThresholds(uint8_t touch, uint8_t release) { 79 | for (uint8_t i=0; i<12; i++) { 80 | writeRegister(MPR121_TOUCHTH_0 + 2*i, touch); 81 | writeRegister(MPR121_RELEASETH_0 + 2*i, release); 82 | } 83 | } 84 | 85 | uint16_t Adafruit_MPR121::filteredData(uint8_t t) { 86 | if (t > 12) return 0; 87 | return readRegister16(MPR121_FILTDATA_0L + t*2); 88 | } 89 | 90 | uint16_t Adafruit_MPR121::baselineData(uint8_t t) { 91 | if (t > 12) return 0; 92 | uint16_t bl = readRegister8(MPR121_BASELINE_0 + t); 93 | return (bl << 2); 94 | } 95 | 96 | uint16_t Adafruit_MPR121::touched(void) { 97 | uint16_t t = readRegister16(MPR121_TOUCHSTATUS_L); 98 | return t & 0x0FFF; 99 | } 100 | 101 | /*********************************************************************/ 102 | 103 | 104 | uint8_t Adafruit_MPR121::readRegister8(uint8_t reg) { 105 | Wire.beginTransmission(_i2caddr); 106 | Wire.write(reg); 107 | Wire.endTransmission(false); 108 | while (Wire.requestFrom(_i2caddr, 1) != 1); 109 | return ( Wire.read()); 110 | } 111 | 112 | uint16_t Adafruit_MPR121::readRegister16(uint8_t reg) { 113 | Wire.beginTransmission(_i2caddr); 114 | Wire.write(reg); 115 | Wire.endTransmission(false); 116 | while (Wire.requestFrom(_i2caddr, 2) != 2); 117 | uint16_t v = Wire.read(); 118 | v |= ((uint16_t) Wire.read()) << 8; 119 | return v; 120 | } 121 | 122 | /**************************************************************************/ 123 | /*! 124 | @brief Writes 8-bits to the specified destination register 125 | */ 126 | /**************************************************************************/ 127 | void Adafruit_MPR121::writeRegister(uint8_t reg, uint8_t value) { 128 | Wire.beginTransmission(_i2caddr); 129 | Wire.write((uint8_t)reg); 130 | Wire.write((uint8_t)(value)); 131 | Wire.endTransmission(); 132 | } 133 | -------------------------------------------------------------------------------- /Arduino/libraries/Adafruit_MPR121/Adafruit_MPR121.h: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library for the MPR121 12-Channel Capacitive Sensor 3 | 4 | Designed specifically to work with the MPR121 breakout from Adafruit 5 | ----> https://www.adafruit.com/products/1982 6 | 7 | These sensors use I2C to communicate, 2+ pins are required to 8 | interface 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. 14 | BSD license, all text above must be included in any redistribution 15 | ****************************************************/ 16 | 17 | #ifndef ADAFRUIT_MPR121_H 18 | #define ADAFRUIT_MPR121_H 19 | 20 | #if (ARDUINO >= 100) 21 | #include "Arduino.h" 22 | #else 23 | #include "WProgram.h" 24 | #endif 25 | #include 26 | 27 | // The default I2C address 28 | #define MPR121_I2CADDR_DEFAULT 0x5A 29 | 30 | #define MPR121_TOUCHSTATUS_L 0x00 31 | #define MPR121_TOUCHSTATUS_H 0x01 32 | #define MPR121_FILTDATA_0L 0x04 33 | #define MPR121_FILTDATA_0H 0x05 34 | #define MPR121_BASELINE_0 0x1E 35 | #define MPR121_MHDR 0x2B 36 | #define MPR121_NHDR 0x2C 37 | #define MPR121_NCLR 0x2D 38 | #define MPR121_FDLR 0x2E 39 | #define MPR121_MHDF 0x2F 40 | #define MPR121_NHDF 0x30 41 | #define MPR121_NCLF 0x31 42 | #define MPR121_FDLF 0x32 43 | #define MPR121_NHDT 0x33 44 | #define MPR121_NCLT 0x34 45 | #define MPR121_FDLT 0x35 46 | 47 | #define MPR121_TOUCHTH_0 0x41 48 | #define MPR121_RELEASETH_0 0x42 49 | #define MPR121_DEBOUNCE 0x5B 50 | #define MPR121_CONFIG1 0x5C 51 | #define MPR121_CONFIG2 0x5D 52 | #define MPR121_CHARGECURR_0 0x5F 53 | #define MPR121_CHARGETIME_1 0x6C 54 | #define MPR121_ECR 0x5E 55 | #define MPR121_AUTOCONFIG0 0x7B 56 | #define MPR121_AUTOCONFIG1 0x7C 57 | #define MPR121_UPLIMIT 0x7D 58 | #define MPR121_LOWLIMIT 0x7E 59 | #define MPR121_TARGETLIMIT 0x7F 60 | 61 | #define MPR121_GPIODIR 0x76 62 | #define MPR121_GPIOEN 0x77 63 | #define MPR121_GPIOSET 0x78 64 | #define MPR121_GPIOCLR 0x79 65 | #define MPR121_GPIOTOGGLE 0x7A 66 | 67 | 68 | 69 | #define MPR121_SOFTRESET 0x80 70 | 71 | //.. thru to 0x1C/0x1D 72 | class Adafruit_MPR121 { 73 | public: 74 | // Hardware I2C 75 | Adafruit_MPR121(void); 76 | 77 | boolean begin(uint8_t i2caddr = MPR121_I2CADDR_DEFAULT); 78 | 79 | uint16_t filteredData(uint8_t t); 80 | uint16_t baselineData(uint8_t t); 81 | 82 | uint8_t readRegister8(uint8_t reg); 83 | uint16_t readRegister16(uint8_t reg); 84 | void writeRegister(uint8_t reg, uint8_t value); 85 | uint16_t touched(void); 86 | // Add deprecated attribute so that the compiler shows a warning 87 | __attribute__((deprecated)) void setThreshholds(uint8_t touch, uint8_t release); 88 | void setThresholds(uint8_t touch, uint8_t release); 89 | 90 | private: 91 | int8_t _i2caddr; 92 | }; 93 | 94 | #endif // ADAFRUIT_MPR121_H -------------------------------------------------------------------------------- /Arduino/libraries/Adafruit_MPR121/README.txt: -------------------------------------------------------------------------------- 1 | This is a library for the MPR121 12-channel Capacitive touch sensor 2 | 3 | Designed specifically to work with the MPR121 Breakout in the Adafruit shop 4 | ----> https://www.adafruit.com/products/1982 5 | 6 | These sensors use I2C communicate, at least 2 pins are required 7 | to interface 8 | 9 | Adafruit invests time and resources providing this open source code, 10 | please support Adafruit and open-source hardware by purchasing 11 | products from Adafruit! 12 | 13 | Written by Limor Fried/Ladyada for Adafruit Industries. 14 | BSD license, all text above must be included in any redistribution 15 | 16 | Check out the links above for our tutorials and wiring diagrams 17 | 18 | To download. click the ZIP button, and rename the uncompressed folder Adafruit_MPR121 19 | Check that the Adafruit_MPR121 folder contains Adafruit_MPR121.cpp and Adafruit_MPR121.h 20 | 21 | Place the Adafruit_MPR121 library folder your arduinosketchfolder/libraries/ folder. 22 | You may need to create the libraries subfolder if its your first library. Restart the IDE. 23 | 24 | We also have a great tutorial on Arduino library installation at: 25 | http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use -------------------------------------------------------------------------------- /Arduino/libraries/Adafruit_MPR121/examples/MPR121test/MPR121test.ino: -------------------------------------------------------------------------------- 1 | /********************************************************* 2 | This is a library for the MPR121 12-channel Capacitive touch sensor 3 | 4 | Designed specifically to work with the MPR121 Breakout in the Adafruit shop 5 | ----> https://www.adafruit.com/products/ 6 | 7 | These sensors use I2C communicate, at least 2 pins are required 8 | to interface 9 | 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | Written by Limor Fried/Ladyada for Adafruit Industries. 15 | BSD license, all text above must be included in any redistribution 16 | **********************************************************/ 17 | 18 | #include 19 | #include "Adafruit_MPR121.h" 20 | 21 | // You can have up to 4 on one i2c bus but one is enough for testing! 22 | Adafruit_MPR121 cap = Adafruit_MPR121(); 23 | 24 | // Keeps track of the last pins touched 25 | // so we know when buttons are 'released' 26 | uint16_t lasttouched = 0; 27 | uint16_t currtouched = 0; 28 | 29 | void setup() { 30 | while (!Serial); // needed to keep leonardo/micro from starting too fast! 31 | 32 | Serial.begin(9600); 33 | Serial.println("Adafruit MPR121 Capacitive Touch sensor test"); 34 | 35 | // Default address is 0x5A, if tied to 3.3V its 0x5B 36 | // If tied to SDA its 0x5C and if SCL then 0x5D 37 | if (!cap.begin(0x5A)) { 38 | Serial.println("MPR121 not found, check wiring?"); 39 | while (1); 40 | } 41 | Serial.println("MPR121 found!"); 42 | } 43 | 44 | void loop() { 45 | // Get the currently touched pads 46 | currtouched = cap.touched(); 47 | 48 | for (uint8_t i=0; i<12; i++) { 49 | // it if *is* touched and *wasnt* touched before, alert! 50 | if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) { 51 | Serial.print(i); Serial.println(" touched"); 52 | } 53 | // if it *was* touched and now *isnt*, alert! 54 | if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) { 55 | Serial.print(i); Serial.println(" released"); 56 | } 57 | } 58 | 59 | // reset our state 60 | lasttouched = currtouched; 61 | 62 | // comment out this line for detailed data from the sensor! 63 | return; 64 | 65 | // debugging info, what 66 | Serial.print("\t\t\t\t\t\t\t\t\t\t\t\t\t 0x"); Serial.println(cap.touched(), HEX); 67 | Serial.print("Filt: "); 68 | for (uint8_t i=0; i<12; i++) { 69 | Serial.print(cap.filteredData(i)); Serial.print("\t"); 70 | } 71 | Serial.println(); 72 | Serial.print("Base: "); 73 | for (uint8_t i=0; i<12; i++) { 74 | Serial.print(cap.baselineData(i)); Serial.print("\t"); 75 | } 76 | Serial.println(); 77 | 78 | // put a delay so it isn't overwhelming 79 | delay(100); 80 | } -------------------------------------------------------------------------------- /Arduino/libraries/Adafruit_MPR121/keywords.txt: -------------------------------------------------------------------------------- 1 | Adafruit_MPR121 KEYWORD1 2 | begin KEYWORD2 3 | filteredData KEYWORD2 4 | baselineData KEYWORD2 5 | touched KEYWORD2 6 | setThresholds KEYWORD2 -------------------------------------------------------------------------------- /Arduino/libraries/Adafruit_MPR121/library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit MPR121 2 | version=1.0.0 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Arduino library for the MPR121-based capacitive sensors in the Adafruit shop. 6 | paragraph=Designed specifically to work with the MPR121 Breakout in the Adafruit shop. 7 | category=Sensors 8 | url=https://github.com/adafruit/Adafruit_MPR121_Library 9 | architectures=* 10 | -------------------------------------------------------------------------------- /Arduino/libraries/Adafruit_TCS34725/README.md: -------------------------------------------------------------------------------- 1 | #Adafruit TCS34725 Color Sensor Driver # 2 | 3 | This driver is for the Adafruit TCS34725 Breakout. 4 | ------> http://www.adafruit.com/products/1334 5 | 6 | ## About this Driver ## 7 | 8 | These modules use I2C to communicate, 2 pins are required to 9 | interface 10 | 11 | Adafruit invests time and resources providing this open source code, 12 | please support Adafruit and open-source hardware by purchasing 13 | products from Adafruit! 14 | 15 | Written by Kevin (KTOWN) Townsend for Adafruit Industries. 16 | BSD license, check license.txt for more information 17 | All text above must be included in any redistribution 18 | 19 | To download. click the ZIP button in the top bar, and check this tutorial 20 | for instructions on how to install: 21 | http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use -------------------------------------------------------------------------------- /Arduino/libraries/Adafruit_TCS34725/examples/colorview/colorview.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Adafruit_TCS34725.h" 3 | 4 | // Pick analog outputs, for the UNO these three work well 5 | // use ~560 ohm resistor between Red & Blue, ~1K for green (its brighter) 6 | #define redpin 3 7 | #define greenpin 5 8 | #define bluepin 6 9 | // for a common anode LED, connect the common pin to +5V 10 | // for common cathode, connect the common to ground 11 | 12 | // set to false if using a common cathode LED 13 | #define commonAnode true 14 | 15 | // our RGB -> eye-recognized gamma color 16 | byte gammatable[256]; 17 | 18 | 19 | Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X); 20 | 21 | void setup() { 22 | Serial.begin(9600); 23 | Serial.println("Color View Test!"); 24 | 25 | if (tcs.begin()) { 26 | Serial.println("Found sensor"); 27 | } else { 28 | Serial.println("No TCS34725 found ... check your connections"); 29 | while (1); // halt! 30 | } 31 | 32 | // use these three pins to drive an LED 33 | pinMode(redpin, OUTPUT); 34 | pinMode(greenpin, OUTPUT); 35 | pinMode(bluepin, OUTPUT); 36 | 37 | // thanks PhilB for this gamma table! 38 | // it helps convert RGB colors to what humans see 39 | for (int i=0; i<256; i++) { 40 | float x = i; 41 | x /= 255; 42 | x = pow(x, 2.5); 43 | x *= 255; 44 | 45 | if (commonAnode) { 46 | gammatable[i] = 255 - x; 47 | } else { 48 | gammatable[i] = x; 49 | } 50 | //Serial.println(gammatable[i]); 51 | } 52 | } 53 | 54 | 55 | void loop() { 56 | uint16_t clear, red, green, blue; 57 | 58 | tcs.setInterrupt(false); // turn on LED 59 | 60 | delay(60); // takes 50ms to read 61 | 62 | tcs.getRawData(&red, &green, &blue, &clear); 63 | 64 | tcs.setInterrupt(true); // turn off LED 65 | 66 | Serial.print("C:\t"); Serial.print(clear); 67 | Serial.print("\tR:\t"); Serial.print(red); 68 | Serial.print("\tG:\t"); Serial.print(green); 69 | Serial.print("\tB:\t"); Serial.print(blue); 70 | 71 | // Figure out some basic hex code for visualization 72 | uint32_t sum = clear; 73 | float r, g, b; 74 | r = red; r /= sum; 75 | g = green; g /= sum; 76 | b = blue; b /= sum; 77 | r *= 256; g *= 256; b *= 256; 78 | Serial.print("\t"); 79 | Serial.print((int)r, HEX); Serial.print((int)g, HEX); Serial.print((int)b, HEX); 80 | Serial.println(); 81 | 82 | //Serial.print((int)r ); Serial.print(" "); Serial.print((int)g);Serial.print(" "); Serial.println((int)b ); 83 | 84 | analogWrite(redpin, gammatable[(int)r]); 85 | analogWrite(greenpin, gammatable[(int)g]); 86 | analogWrite(bluepin, gammatable[(int)b]); 87 | } 88 | 89 | -------------------------------------------------------------------------------- /Arduino/libraries/Adafruit_TCS34725/examples/colorview/processing/colorview/colorview.pde: -------------------------------------------------------------------------------- 1 | /* For use with the colorview Arduino example sketch 2 | Update the Serial() new call to match your serial port 3 | e.g. COM4, /dev/usbserial, etc! 4 | */ 5 | 6 | 7 | import processing.serial.*; 8 | import java.awt.datatransfer.*; 9 | import java.awt.Toolkit; 10 | 11 | Serial port; 12 | 13 | void setup(){ 14 | size(200,200); 15 | println(Serial.list()); 16 | port = new Serial(this, Serial.list()[1], 9600); //remember to replace COM20 with the appropriate serial port on your computer 17 | } 18 | 19 | 20 | String buff = ""; 21 | 22 | int wRed, wGreen, wBlue, wClear; 23 | String hexColor = "ffffff"; 24 | 25 | 26 | void draw(){ 27 | background(wRed,wGreen,wBlue); 28 | // check for serial, and process 29 | while (port.available() > 0) { 30 | serialEvent(port.read()); 31 | } 32 | } 33 | 34 | void serialEvent(int serial) { 35 | if(serial != '\n') { 36 | buff += char(serial); 37 | } else { 38 | //println(buff); 39 | 40 | int cRed = buff.indexOf("R"); 41 | int cGreen = buff.indexOf("G"); 42 | int cBlue = buff.indexOf("B"); 43 | int clear = buff.indexOf("C"); 44 | if(clear >=0){ 45 | String val = buff.substring(clear+3); 46 | val = val.split("\t")[0]; 47 | wClear = Integer.parseInt(val.trim()); 48 | } else { return; } 49 | 50 | if(cRed >=0){ 51 | String val = buff.substring(cRed+3); 52 | val = val.split("\t")[0]; 53 | wRed = Integer.parseInt(val.trim()); 54 | } else { return; } 55 | 56 | if(cGreen >=0) { 57 | String val = buff.substring(cGreen+3); 58 | val = val.split("\t")[0]; 59 | wGreen = Integer.parseInt(val.trim()); 60 | } else { return; } 61 | 62 | if(cBlue >=0) { 63 | String val = buff.substring(cBlue+3); 64 | val = val.split("\t")[0]; 65 | wBlue = Integer.parseInt(val.trim()); 66 | } else { return; } 67 | 68 | print("Red: "); print(wRed); 69 | print("\tGrn: "); print(wGreen); 70 | print("\tBlue: "); print(wBlue); 71 | print("\tClr: "); println(wClear); 72 | 73 | wRed *= 255; wRed /= wClear; 74 | wGreen *= 255; wGreen /= wClear; 75 | wBlue *= 255; wBlue /= wClear; 76 | 77 | hexColor = hex(color(wRed, wGreen, wBlue), 6); 78 | println(hexColor); 79 | buff = ""; 80 | } 81 | } -------------------------------------------------------------------------------- /Arduino/libraries/Adafruit_TCS34725/examples/tcs34725/tcs34725.pde: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Adafruit_TCS34725.h" 3 | 4 | /* Example code for the Adafruit TCS34725 breakout library */ 5 | 6 | /* Connect SCL to analog 5 7 | Connect SDA to analog 4 8 | Connect VDD to 3.3V DC 9 | Connect GROUND to common ground */ 10 | 11 | /* Initialise with default values (int time = 2.4ms, gain = 1x) */ 12 | // Adafruit_TCS34725 tcs = Adafruit_TCS34725(); 13 | 14 | /* Initialise with specific int time and gain values */ 15 | Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS34725_GAIN_1X); 16 | 17 | void setup(void) { 18 | Serial.begin(9600); 19 | 20 | if (tcs.begin()) { 21 | Serial.println("Found sensor"); 22 | } else { 23 | Serial.println("No TCS34725 found ... check your connections"); 24 | while (1); 25 | } 26 | 27 | // Now we're ready to get readings! 28 | } 29 | 30 | void loop(void) { 31 | uint16_t r, g, b, c, colorTemp, lux; 32 | 33 | tcs.getRawData(&r, &g, &b, &c); 34 | colorTemp = tcs.calculateColorTemperature(r, g, b); 35 | lux = tcs.calculateLux(r, g, b); 36 | 37 | Serial.print("Color Temp: "); Serial.print(colorTemp, DEC); Serial.print(" K - "); 38 | Serial.print("Lux: "); Serial.print(lux, DEC); Serial.print(" - "); 39 | Serial.print("R: "); Serial.print(r, DEC); Serial.print(" "); 40 | Serial.print("G: "); Serial.print(g, DEC); Serial.print(" "); 41 | Serial.print("B: "); Serial.print(b, DEC); Serial.print(" "); 42 | Serial.print("C: "); Serial.print(c, DEC); Serial.print(" "); 43 | Serial.println(" "); 44 | } 45 | -------------------------------------------------------------------------------- /Arduino/libraries/Adafruit_TCS34725/library.properties: -------------------------------------------------------------------------------- 1 | name=Adafruit TCS34725 2 | version=1.0.1 3 | author=Adafruit 4 | maintainer=Adafruit 5 | sentence=Driver for Adafruit's TCS34725 RGB Color Sensor Breakout 6 | paragraph=Driver for Adafruit's TCS34725 RGB Color Sensor Breakout 7 | category=Sensors 8 | url=https://github.com/adafruit/Adafruit_TCS34725 9 | architectures=* 10 | -------------------------------------------------------------------------------- /Arduino/libraries/SparkFun_ISL29125_Breakout/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /Arduino/libraries/SparkFun_ISL29125_Breakout/.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## SparkFun Useful stuff 3 | ################# 4 | 5 | ## AVR Development 6 | *.eep 7 | *.elf 8 | *.lst 9 | *.lss 10 | *.sym 11 | *.d 12 | *.o 13 | *.srec 14 | *.map 15 | 16 | ## Notepad++ backup files 17 | *.bak 18 | 19 | ## BOM files 20 | *bom* 21 | 22 | ################# 23 | ## Eclipse 24 | ################# 25 | 26 | *.pydevproject 27 | .project 28 | .metadata 29 | bin/ 30 | tmp/ 31 | *.tmp 32 | *.bak 33 | *.swp 34 | *~.nib 35 | local.properties 36 | .classpath 37 | .settings/ 38 | .loadpath 39 | 40 | # External tool builders 41 | .externalToolBuilders/ 42 | 43 | # Locally stored "Eclipse launch configurations" 44 | *.launch 45 | 46 | # CDT-specific 47 | .cproject 48 | 49 | # PDT-specific 50 | .buildpath 51 | 52 | 53 | ############# 54 | ## Eagle 55 | ############# 56 | 57 | # Ignore the board and schematic backup files 58 | *.b#? 59 | *.s#? 60 | 61 | 62 | ################# 63 | ## Visual Studio 64 | ################# 65 | 66 | ## Ignore Visual Studio temporary files, build results, and 67 | ## files generated by popular Visual Studio add-ons. 68 | 69 | # User-specific files 70 | *.suo 71 | *.user 72 | *.sln.docstates 73 | 74 | # Build results 75 | [Dd]ebug/ 76 | [Rr]elease/ 77 | *_i.c 78 | *_p.c 79 | *.ilk 80 | *.meta 81 | *.obj 82 | *.pch 83 | *.pdb 84 | *.pgc 85 | *.pgd 86 | *.rsp 87 | *.sbr 88 | *.tlb 89 | *.tli 90 | *.tlh 91 | *.tmp 92 | *.vspscc 93 | .builds 94 | *.dotCover 95 | 96 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 97 | #packages/ 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opensdf 104 | *.sdf 105 | 106 | # Visual Studio profiler 107 | *.psess 108 | *.vsp 109 | 110 | # ReSharper is a .NET coding add-in 111 | _ReSharper* 112 | 113 | # Installshield output folder 114 | [Ee]xpress 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish 128 | 129 | # Others 130 | [Bb]in 131 | [Oo]bj 132 | sql 133 | TestResults 134 | *.Cache 135 | ClientBin 136 | stylecop.* 137 | ~$* 138 | *.dbmdl 139 | Generated_Code #added for RIA/Silverlight projects 140 | 141 | # Backup & report files from converting an old project file to a newer 142 | # Visual Studio version. Backup files are not needed, because we have git ;-) 143 | _UpgradeReport_Files/ 144 | Backup*/ 145 | UpgradeLog*.XML 146 | 147 | 148 | ############ 149 | ## Windows 150 | ############ 151 | 152 | # Windows image file caches 153 | Thumbs.db 154 | 155 | # Folder config file 156 | Desktop.ini 157 | 158 | 159 | ############# 160 | ## Python 161 | ############# 162 | 163 | *.py[co] 164 | 165 | # Packages 166 | *.egg 167 | *.egg-info 168 | dist 169 | build 170 | eggs 171 | parts 172 | bin 173 | var 174 | sdist 175 | develop-eggs 176 | .installed.cfg 177 | 178 | # Installer logs 179 | pip-log.txt 180 | 181 | # Unit test / coverage reports 182 | .coverage 183 | .tox 184 | 185 | #Translations 186 | *.mo 187 | 188 | #Mr Developer 189 | .mr.developer.cfg 190 | 191 | # Mac crap 192 | .DS_Store 193 | -------------------------------------------------------------------------------- /Arduino/libraries/SparkFun_ISL29125_Breakout/LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | License Information 3 | ------------------- 4 | 5 | The hardware is released under [Creative Commons Share-alike 3.0](http://creativecommons.org/licenses/by-sa/3.0/). 6 | 7 | All other code is open source so please feel free to do anything you want with it; you buy me a beer if you use this and we meet someday ([Beerware license](http://en.wikipedia.org/wiki/Beerware)). 8 | 9 | 10 | -------------------------------------------------------------------------------- /Arduino/libraries/SparkFun_ISL29125_Breakout/README.md: -------------------------------------------------------------------------------- 1 | SparkFun ISL29125 Breakout Arduino Library 2 | ========================================== 3 | 4 | [![ISL29125 Breakout](https://cdn.sparkfun.com//assets/parts/9/6/7/7/12829-01.jpg) 5 | *RGB Light Sensor Breakout-ISL29125 (SEN-12829)*](https://www.sparkfun.com/products/12829) 6 | 7 | Supporting code for the ISL29125 RGB Light Sensor. 8 | 9 | Repository Contents 10 | ------------------- 11 | 12 | * **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE. 13 | * **/src** - Source files for the library (.cpp, .h). 14 | * **library.properties** - General library properties for the Arduino package manager. 15 | 16 | Documentation 17 | -------------- 18 | 19 | * **[Hookup Guide](https://learn.sparkfun.com/tutorials/isl29125-rgb-light-sensor-hookup-guide)** - Basic hookup guide for the SparkFun ISL29125 Breakout. 20 | * **[Product Repository](https://github.com/sparkfun/ISL29125_Breakout)** - Main repository (including hardware files) for the SparkFun ISL29125 Breakout. 21 | 22 | 23 | License Information 24 | ------------------- 25 | This product is _**open source**_! 26 | 27 | The **code** is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round! 28 | 29 | Please use, reuse, and modify these files as you see fit. Please maintain attribution to SparkFun Electronics and release anything derivative under the same license. 30 | 31 | Distributed as-is; no warranty is given. 32 | 33 | - Your friends at SparkFun. 34 | -------------------------------------------------------------------------------- /Arduino/libraries/SparkFun_ISL29125_Breakout/examples/ISL29125Basics/ISL29125Basics.ino: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ISL29125_basics.ino 3 | Simple example for using the ISL29125 RGB sensor library. 4 | Jordan McConnell @ SparkFun Electronics 5 | 11 Apr 2014 6 | https://github.com/sparkfun/SparkFun_ISL29125_Breakout_Arduino_Library 7 | 8 | This example declares an SFE_ISL29125 object called RGB_sensor. The 9 | object/sensor is initialized with a basic configuration so that it continuously 10 | samples the light intensity of red, green and blue spectrums. These values are 11 | read from the sensor every 2 seconds and printed to the Serial monitor. 12 | 13 | Developed/Tested with: 14 | Arduino Uno 15 | Arduino IDE 1.0.5 16 | 17 | Requires: 18 | SparkFun_ISL29125_Arduino_Library 19 | 20 | This code is beerware. 21 | Distributed as-is; no warranty is given. 22 | ******************************************************************************/ 23 | 24 | #include 25 | #include "SparkFunISL29125.h" 26 | 27 | // Declare sensor object 28 | SFE_ISL29125 RGB_sensor; 29 | 30 | void setup() 31 | { 32 | // Initialize serial communication 33 | Serial.begin(115200); 34 | 35 | // Initialize the ISL29125 with simple configuration so it starts sampling 36 | if (RGB_sensor.init()) 37 | { 38 | Serial.println("Sensor Initialization Successful\n\r"); 39 | } 40 | } 41 | 42 | // Read sensor values for each color and print them to serial monitor 43 | void loop() 44 | { 45 | // Read sensor values (16 bit integers) 46 | unsigned int red = RGB_sensor.readRed(); 47 | unsigned int green = RGB_sensor.readGreen(); 48 | unsigned int blue = RGB_sensor.readBlue(); 49 | 50 | // Print out readings, change HEX to DEC if you prefer decimal output 51 | Serial.print("Red: "); Serial.println(red,HEX); 52 | Serial.print("Green: "); Serial.println(green,HEX); 53 | Serial.print("Blue: "); Serial.println(blue,HEX); 54 | Serial.println(); 55 | delay(2000); 56 | } 57 | -------------------------------------------------------------------------------- /Arduino/libraries/SparkFun_ISL29125_Breakout/examples/ISL29125Interrupts/ISL29125Interrupts.ino: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ISL29125_interrupts.ino 3 | Example demonstrating use of the ISL29125 RGB sensor library with interrupts. 4 | Jordan McConnell @ SparkFun Electronics 5 | 18 Apr 2014 6 | https://github.com/sparkfun/SparkFun_ISL29125_Breakout_Arduino_Library 7 | 8 | This example shows how to use the ISL29125 sensor using interrupts. It 9 | demonstrates how to make a more advanced configuration to set this up that goes 10 | beyond the basics needed simply to acquire readings from the sensor. Interrupts 11 | are triggered when sensor readings are above or below set thresholds and this 12 | example also shows how to set those up. It also teaches how to read the sensor 13 | after the interrupt and how to read/clear status flags so another interrupt can 14 | be triggered and so you can interpret the status of the sensor. If you plan on 15 | using this sensor in an interrupt driven project, this is the example for you. 16 | 17 | Developed/Tested with: 18 | Arduino Uno 19 | Arduino IDE 1.0.5 20 | 21 | Requires: 22 | SparkFun_ISL29125_Arduino_Library 23 | 24 | This code is beerware. 25 | Distributed as-is; no warranty is given. 26 | ******************************************************************************/ 27 | 28 | #include 29 | #include "SparkFunISL29125.h" 30 | 31 | // Declare sensor object 32 | SFE_ISL29125 RGB_sensor; 33 | 34 | // The number of triggered interrupts 35 | unsigned int i = 0; 36 | 37 | // Set up serial communication, initialize the sensor, and set up interrupts 38 | void setup() 39 | { 40 | // Initialize serial communication 41 | Serial.begin(115200); 42 | 43 | // Initialize the ISL29125 and verify its presence 44 | if (RGB_sensor.init()) 45 | { 46 | Serial.println("Sensor Initialization Successful\n\r"); 47 | } 48 | 49 | // Advanced configuration: Interrupts based solely on red light intensity. ~100ms per sensor reading. 50 | // Config1: CFG1_MODE_R - only read red 51 | // CFG1_10KLUX - 10K Lux is full light scale 52 | // Config2: CFG2_IR_ADJUST_HIGH - common IR filter setting as a starting point, see datasheet if you desire to calibrate it to your exact lighting situation 53 | // Config3: CFG3_R_INT - trigger interrupts based on sensor readings for red light intensity 54 | // CFG3_INT_PRST8 - only trigger interrupt if red sensor reading crosses threshold 8 consecutive times 55 | // For other configuration options, look at the SFE_ISL29125.h file in the SFE_ISL29125_Library folder 56 | RGB_sensor.config(CFG1_MODE_R | CFG1_10KLUX, CFG2_IR_ADJUST_HIGH, CFG3_R_INT | CFG3_INT_PRST8); 57 | 58 | // Enable interrupt 0 (pin 2 on the Uno) which is connected interrupt (int) pin of the ISL29125 59 | // When the interrupt pin goes low (falling edge), call the increment function 60 | attachInterrupt(0, increment, FALLING); 61 | 62 | // Set the red upper threshold (set to 0xFFFF by default) 63 | // An interrupt will trigger when the red sensor value is above this threshold (for 8 consecutive samples) 64 | RGB_sensor.setUpperThreshold(0x0B00); 65 | 66 | // You can also set the red lower threshold if desired (set to 0x0000 by default) 67 | //RGB_sensor.setLowerThreshold(0x0300); 68 | } 69 | 70 | // Continuously check if an interrupt occured 71 | // If so, print out interrupt #, sensor reading for red light, and time since last interrupt to serial monitor 72 | void loop() 73 | { 74 | static unsigned int lasti = 0; // Stores the number of the last interrupt 75 | static unsigned long ms = millis(); // Used to calculate the time between interrupts 76 | uint16_t red_value = 0; // Stores sensor reading for red light intensity 77 | uint8_t flags = 0; // Stores status flags read from the sensor 78 | 79 | // Check if an interrupt has occured, if so, enter the if block 80 | if (lasti != i) 81 | { 82 | // Read the detected light intensity of the red visible spectrum 83 | red_value = RGB_sensor.readRed(); 84 | 85 | // Print out the interrupt # and sensor reading 86 | Serial.print("Interrupt #: "); 87 | Serial.println(i); 88 | Serial.print("Red Sensor Value (HEX): "); 89 | Serial.println(red_value, HEX); 90 | // Print out the # of milliseconds since the last interrupt 91 | Serial.print("Milliseconds since last interrupt: "); 92 | Serial.println(millis() - ms); 93 | Serial.println(); 94 | ms = millis(); // Reset ms so we can start counting milliseconds up to the next interrupt 95 | 96 | // Set lasti to i, so that this if statement is not entered again until another interrupt is triggered 97 | lasti = i; 98 | 99 | // Read and clear the status flags including the interrupt triggered flag 100 | // This must be done otherwise another interrupt from the sensor can not be triggered 101 | flags = RGB_sensor.readStatus(); 102 | 103 | // If you desire to see the reported status of the chip, uncomment the line below 104 | //checkSensorStatus(flags); 105 | } 106 | } 107 | 108 | // ISR - When an interrupt is triggered by the sensor, this function is called and 'i' is incremented by one. 109 | void increment() 110 | { 111 | i++; 112 | } 113 | 114 | // Read status of sensor and report findings to the serial monitor 115 | void checkSensorStatus(uint8_t flags) 116 | { 117 | if (flags & FLAG_INT) 118 | { 119 | Serial.println("Interrupt triggered"); 120 | } 121 | else 122 | { 123 | Serial.println("Interrupt cleared or not triggered yet"); 124 | } 125 | if (flags & FLAG_CONV_DONE) 126 | { 127 | Serial.println("Sensor ADC conversion completed"); 128 | } 129 | else 130 | { 131 | Serial.println("Sensor ADC is still converting or cleared"); 132 | } 133 | if (flags & FLAG_BROWNOUT) 134 | { 135 | Serial.println("Power down or brownout occurred"); 136 | } 137 | else 138 | { 139 | Serial.println("No power down or brownout detected"); 140 | } 141 | if (flags & FLAG_CONV_G) 142 | { 143 | Serial.println("Green under conversion"); 144 | } 145 | else if (flags & FLAG_CONV_R) 146 | { 147 | Serial.println("Red under conversion"); 148 | } 149 | else if (flags & FLAG_CONV_B) 150 | { 151 | Serial.println("Blue under conversion"); 152 | } 153 | else 154 | { 155 | Serial.println("No current RGB conversion"); 156 | } 157 | Serial.println(); 158 | } 159 | -------------------------------------------------------------------------------- /Arduino/libraries/SparkFun_ISL29125_Breakout/examples/ISL29125RGBLED/ISL29125RGBLED.ino: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | ISL29125_RGB_LED.ino 3 | Example for using the ISL29125 RGB sensor library along with an RGB LED. 4 | Jordan McConnell @ SparkFun Electronics 5 | 11 Apr 2014 6 | https://github.com/sparkfun/SparkFun_ISL29125_Breakout_Arduino_Library 7 | 8 | This example declares an SFE_ISL29125 object called RGB_sensor. The 9 | object/sensor is initialized with a basic configuration so that it continuously 10 | samples the light intensity of red, green and blue spectrums. An RGB LED is set 11 | up so that it can be placed above the sensor to change the sensor's readings. 12 | The Red component of the LED is turned on and then sensor readings are printed 13 | to the serial monitor. If this is done in a dark environment, you should notice 14 | the readings for Red will be significantly higher than for green or blue. The 15 | sketch then waits two seconds and does this process again for green, and then 16 | again for blue. Since the RGB LED is on PWM pins, you can change the brightness 17 | and see how this affects the readings. Again, best results in a dark environment. 18 | 19 | Developed/Tested with: 20 | Arduino Uno 21 | Arduino IDE 1.0.5 22 | 23 | Requires: 24 | SparkFun_ISL29125_Arduino_Library 25 | 26 | This code is beerware. 27 | Distributed as-is; no warranty is given. 28 | ******************************************************************************/ 29 | 30 | #include 31 | #include "SparkFunISL29125.h" 32 | 33 | // Declare pins for RGB LED, all PWM pins 34 | uint8_t rPin = 3; 35 | uint8_t gPin = 5; 36 | uint8_t bPin = 6; 37 | 38 | // Declare sensor object 39 | SFE_ISL29125 RGB_sensor; 40 | 41 | void setup() 42 | { 43 | // Initialize serial communication 44 | Serial.begin(115200); 45 | 46 | // Set up pins for RGB LED 47 | pinMode(rPin, OUTPUT); 48 | pinMode(gPin, OUTPUT); 49 | pinMode(bPin, OUTPUT); 50 | 51 | // Initialize the ISL29125 with simple configuration so it starts sampling 52 | if (RGB_sensor.init()) 53 | { 54 | Serial.println("Sensor Initialization Successful\n\r"); 55 | } 56 | } 57 | 58 | // Turns on one color at a time of an RGB LED then prints sensor readings of the sensor to the serial monitor 59 | void loop() 60 | { 61 | // Turn only Red LED on 62 | analogWrite(rPin, 255); 63 | analogWrite(gPin, 0); 64 | analogWrite(bPin, 0); 65 | delay(300); 66 | // Take sensor readings for each color and print them to serial monitor 67 | Serial.println("Red LED ON"); 68 | Serial.print("Red: "); Serial.println(RGB_sensor.readRed(),HEX); 69 | Serial.print("Green: "); Serial.println(RGB_sensor.readGreen(),HEX); 70 | Serial.print("Blue: "); Serial.println(RGB_sensor.readBlue(),HEX); 71 | Serial.println(); 72 | delay(2000); 73 | 74 | // Turn only Green LED on 75 | analogWrite(rPin, 0); 76 | analogWrite(gPin, 255); 77 | analogWrite(bPin, 0); 78 | delay(300); 79 | // Take sensor readings for each color and print them to serial monitor 80 | Serial.println("Green LED ON"); 81 | Serial.print("Red: "); Serial.println(RGB_sensor.readRed(),HEX); 82 | Serial.print("Green: "); Serial.println(RGB_sensor.readGreen(),HEX); 83 | Serial.print("Blue: "); Serial.println(RGB_sensor.readBlue(),HEX); 84 | Serial.println(); 85 | delay(2000); 86 | 87 | // Turn only Blue LED on 88 | analogWrite(rPin, 0); 89 | analogWrite(gPin, 0); 90 | analogWrite(bPin, 255); 91 | delay(300); 92 | // Take sensor readings for each color and print them to serial monitor 93 | Serial.println("Blue LED ON"); 94 | Serial.print("Red: "); Serial.println(RGB_sensor.readRed(),HEX); 95 | Serial.print("Green: "); Serial.println(RGB_sensor.readGreen(),HEX); 96 | Serial.print("Blue: "); Serial.println(RGB_sensor.readBlue(),HEX); 97 | Serial.println(); 98 | delay(2000); 99 | } 100 | -------------------------------------------------------------------------------- /Arduino/libraries/SparkFun_ISL29125_Breakout/library.properties: -------------------------------------------------------------------------------- 1 | name=SparkFun ISL29125 Breakout 2 | version=1.0.1 3 | author=SparkFun Electronics 4 | maintainer=SparkFun Electronics 5 | sentence=Arduino library showing basic functionality for the ISL29125 RGB Light Sensor Breakout Board. 6 | paragraph=The ISL29125 breakout board makes it very easy to sense and record the light intensity of the general red, green, and blue spectrums of visible light while rejecting IR from light sources. 7 | category=Sensors 8 | url=https://github.com/sparkfun/ISL29125_Breakout 9 | architectures=* 10 | -------------------------------------------------------------------------------- /Arduino/libraries/SparkFun_ISL29125_Breakout/src/SparkFunISL29125.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | SparkFunISL29125.cpp 3 | Core implementation file for the ISL29125 RGB sensor library. 4 | Jordan McConnell @ SparkFun Electronics 5 | 25 Mar 2014 6 | https://github.com/sparkfun/ISL29125_Breakout 7 | 8 | This file implements the functions of the SFE_ISL29125 sensor class as well as 9 | providing documentation on what each function does. 10 | 11 | Developed/Tested with: 12 | Arduino Uno 13 | Arduino IDE 1.0.5 14 | 15 | This code is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round! 16 | Distributed as-is; no warranty is given. 17 | ******************************************************************************/ 18 | 19 | #include "SparkFunISL29125.h" 20 | 21 | // Constructor - Creates sensor object and sets I2C address 22 | SFE_ISL29125::SFE_ISL29125(uint8_t addr) 23 | { 24 | _addr = addr; 25 | } 26 | 27 | // Destructor - Deletes sensor object 28 | SFE_ISL29125::~SFE_ISL29125() 29 | { 30 | 31 | } 32 | 33 | // Initialize - returns true if successful 34 | // Starts Wire/I2C Communication 35 | // Verifies sensor is there by checking its device ID 36 | // Resets all registers/configurations to factory default 37 | // Sets configuration registers for the common use case 38 | bool SFE_ISL29125::init() 39 | { 40 | bool ret = true; 41 | uint8_t data = 0x00; 42 | 43 | // Start I2C 44 | Wire.begin(); 45 | 46 | // Check device ID 47 | data = read8(DEVICE_ID); 48 | if (data != 0x7D) 49 | { 50 | ret &= false; 51 | } 52 | 53 | // Reset registers 54 | ret &= reset(); 55 | 56 | // Set to RGB mode, 10k lux, and high IR compensation 57 | ret &= config(CFG1_MODE_RGB | CFG1_10KLUX, CFG2_IR_ADJUST_HIGH, CFG_DEFAULT); 58 | 59 | return ret; 60 | } 61 | 62 | // Reset all registers - returns true if successful 63 | bool SFE_ISL29125::reset() 64 | { 65 | uint8_t data = 0x00; 66 | // Reset registers 67 | write8(DEVICE_ID, 0x46); 68 | // Check reset 69 | data = read8(CONFIG_1); 70 | data |= read8(CONFIG_2); 71 | data |= read8(CONFIG_3); 72 | data |= read8(STATUS); 73 | if (data != 0x00) 74 | { 75 | return false; 76 | } 77 | return true; 78 | } 79 | 80 | // Setup Configuration registers (three registers) - returns true if successful 81 | // Use CONFIG1 variables from SFE_ISL29125.h for first parameter config1, CONFIG2 for config2, 3 for 3 82 | // Use CFG_DEFAULT for default configuration for that register 83 | bool SFE_ISL29125::config(uint8_t config1, uint8_t config2, uint8_t config3) 84 | { 85 | bool ret = true; 86 | uint8_t data = 0x00; 87 | 88 | // Set 1st configuration register 89 | write8(CONFIG_1, config1); 90 | // Set 2nd configuration register 91 | write8(CONFIG_2, config2); 92 | // Set 3rd configuration register 93 | write8(CONFIG_3, config3); 94 | 95 | // Check if configurations were set correctly 96 | data = read8(CONFIG_1); 97 | if (data != config1) 98 | { 99 | ret &= false; 100 | } 101 | data = read8(CONFIG_2); 102 | if (data != config2) 103 | { 104 | ret &= false; 105 | } 106 | data = read8(CONFIG_3); 107 | if (data != config3) 108 | { 109 | ret &= false; 110 | } 111 | return ret; 112 | } 113 | 114 | // Sets upper threshold value for triggering interrupts 115 | void SFE_ISL29125::setUpperThreshold(uint16_t data) 116 | { 117 | write16(THRESHOLD_HL, data); 118 | } 119 | 120 | // Sets lower threshold value for triggering interrupts 121 | void SFE_ISL29125::setLowerThreshold(uint16_t data) 122 | { 123 | write16(THRESHOLD_LL, data); 124 | } 125 | 126 | // Check what the upper threshold is, 0xFFFF by default 127 | uint16_t SFE_ISL29125::readUpperThreshold() 128 | { 129 | return read16(THRESHOLD_HL); 130 | } 131 | 132 | // Check what the upper threshold is, 0x0000 by default 133 | uint16_t SFE_ISL29125::readLowerThreshold() 134 | { 135 | return read16(THRESHOLD_LL); 136 | } 137 | 138 | // Read the latest Sensor ADC reading for the color Red 139 | uint16_t SFE_ISL29125::readRed() 140 | { 141 | return read16(RED_L); 142 | } 143 | 144 | // Read the latest Sensor ADC reading for the color Green 145 | uint16_t SFE_ISL29125::readGreen() 146 | { 147 | return read16(GREEN_L); 148 | } 149 | 150 | // Read the latest Sensor ADC reading for the color Blue 151 | uint16_t SFE_ISL29125::readBlue() 152 | { 153 | return read16(BLUE_L); 154 | } 155 | 156 | // Check status flag register that allows for checking for interrupts, brownouts, and ADC conversion completions 157 | uint8_t SFE_ISL29125::readStatus() 158 | { 159 | return read8(STATUS); 160 | } 161 | 162 | // Generic I2C read register (single byte) 163 | uint8_t SFE_ISL29125::read8(uint8_t reg) 164 | { 165 | Wire.beginTransmission(_addr); 166 | Wire.write(reg); 167 | Wire.endTransmission(); 168 | Wire.beginTransmission(_addr); 169 | Wire.requestFrom(_addr,(uint8_t)1); 170 | uint8_t data = Wire.read(); 171 | Wire.endTransmission(); 172 | 173 | return data; 174 | } 175 | 176 | // Generic I2C write data to register (single byte) 177 | void SFE_ISL29125::write8(uint8_t reg, uint8_t data) 178 | { 179 | Wire.beginTransmission(_addr); 180 | Wire.write(reg); 181 | Wire.write(data); 182 | Wire.endTransmission(); 183 | 184 | return; 185 | } 186 | 187 | // Generic I2C read registers (two bytes, LSB first) 188 | uint16_t SFE_ISL29125::read16(uint8_t reg) 189 | { 190 | uint16_t data = 0x0000; 191 | 192 | Wire.beginTransmission(_addr); 193 | Wire.write(reg); 194 | Wire.endTransmission(); 195 | 196 | Wire.beginTransmission(_addr); 197 | Wire.requestFrom(_addr, (uint8_t)2); // request 2 bytes of data 198 | data = Wire.read(); 199 | data |= (Wire.read() << 8); 200 | Wire.endTransmission(); 201 | 202 | return data; 203 | } 204 | 205 | // Generic I2C write data to registers (two bytes, LSB first) 206 | void SFE_ISL29125::write16(uint8_t reg, uint16_t data) 207 | { 208 | Wire.beginTransmission(_addr); 209 | Wire.write(reg); 210 | Wire.write(data); 211 | Wire.write(data>>8); 212 | Wire.endTransmission(); 213 | } -------------------------------------------------------------------------------- /Arduino/libraries/SparkFun_ISL29125_Breakout/src/SparkFunISL29125.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | SparkFunISL29125.h 3 | Core header file for the ISL29125 RGB sensor library. 4 | Jordan McConnell @ SparkFun Electronics 5 | 25 Mar 2014 6 | https://github.com/sparkfun/ISL29125_Breakout 7 | 8 | This header file declares the SFE_ISL29125 sensor class as well as its various 9 | functions and variables. It also defines sensor specifics including register 10 | addresses and masks for setting/interpreting register data. 11 | 12 | Developed/Tested with: 13 | Arduino Uno 14 | Arduino IDE 1.0.5 15 | 16 | This code is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round! 17 | Distributed as-is; no warranty is given. 18 | ******************************************************************************/ 19 | 20 | #ifndef SFE_ISL29125_h 21 | #define SFE_ISL29125_h 22 | 23 | #include "Wire.h" 24 | 25 | // ISL29125 I2C Address 26 | #define ISL_I2C_ADDR 0x44 27 | 28 | // ISL29125 Registers 29 | #define DEVICE_ID 0x00 30 | #define CONFIG_1 0x01 31 | #define CONFIG_2 0x02 32 | #define CONFIG_3 0x03 33 | #define THRESHOLD_LL 0x04 34 | #define THRESHOLD_LH 0x05 35 | #define THRESHOLD_HL 0x06 36 | #define THRESHOLD_HH 0x07 37 | #define STATUS 0x08 38 | #define GREEN_L 0x09 39 | #define GREEN_H 0x0A 40 | #define RED_L 0x0B 41 | #define RED_H 0x0C 42 | #define BLUE_L 0x0D 43 | #define BLUE_H 0x0E 44 | 45 | // Configuration Settings 46 | #define CFG_DEFAULT 0x00 47 | 48 | // CONFIG1 49 | // Pick a mode, determines what color[s] the sensor samples, if any 50 | #define CFG1_MODE_POWERDOWN 0x00 51 | #define CFG1_MODE_G 0x01 52 | #define CFG1_MODE_R 0x02 53 | #define CFG1_MODE_B 0x03 54 | #define CFG1_MODE_STANDBY 0x04 55 | #define CFG1_MODE_RGB 0x05 56 | #define CFG1_MODE_RG 0x06 57 | #define CFG1_MODE_GB 0x07 58 | 59 | // Light intensity range 60 | // In a dark environment 375Lux is best, otherwise 10KLux is likely the best option 61 | #define CFG1_375LUX 0x00 62 | #define CFG1_10KLUX 0x08 63 | 64 | // Change this to 12 bit if you want less accuracy, but faster sensor reads 65 | // At default 16 bit, each sensor sample for a given color is about ~100ms 66 | #define CFG1_16BIT 0x00 67 | #define CFG1_12BIT 0x10 68 | 69 | // Unless you want the interrupt pin to be an input that triggers sensor sampling, leave this on normal 70 | #define CFG1_ADC_SYNC_NORMAL 0x00 71 | #define CFG1_ADC_SYNC_TO_INT 0x20 72 | 73 | // CONFIG2 74 | // Selects upper or lower range of IR filtering 75 | #define CFG2_IR_OFFSET_OFF 0x00 76 | #define CFG2_IR_OFFSET_ON 0x80 77 | 78 | // Sets amount of IR filtering, can use these presets or any value between 0x00 and 0x3F 79 | // Consult datasheet for detailed IR filtering calibration 80 | #define CFG2_IR_ADJUST_LOW 0x00 81 | #define CFG2_IR_ADJUST_MID 0x20 82 | #define CFG2_IR_ADJUST_HIGH 0x3F 83 | 84 | // CONFIG3 85 | // No interrupts, or interrupts based on a selected color 86 | #define CFG3_NO_INT 0x00 87 | #define CFG3_G_INT 0x01 88 | #define CFG3_R_INT 0x02 89 | #define CFG3_B_INT 0x03 90 | 91 | // How many times a sensor sample must hit a threshold before triggering an interrupt 92 | // More consecutive samples means more times between interrupts, but less triggers from short transients 93 | #define CFG3_INT_PRST1 0x00 94 | #define CFG3_INT_PRST2 0x04 95 | #define CFG3_INT_PRST4 0x08 96 | #define CFG3_INT_PRST8 0x0C 97 | 98 | // If you would rather have interrupts trigger when a sensor sampling is complete, enable this 99 | // If this is disabled, interrupts are based on comparing sensor data to threshold settings 100 | #define CFG3_RGB_CONV_TO_INT_DISABLE 0x00 101 | #define CFG3_RGB_CONV_TO_INT_ENABLE 0x10 102 | 103 | // STATUS FLAG MASKS 104 | #define FLAG_INT 0x01 105 | #define FLAG_CONV_DONE 0x02 106 | #define FLAG_BROWNOUT 0x04 107 | #define FLAG_CONV_G 0x10 108 | #define FLAG_CONV_R 0x20 109 | #define FLAG_CONV_B 0x30 110 | 111 | 112 | class SFE_ISL29125 113 | { 114 | public: 115 | SFE_ISL29125(uint8_t addr = ISL_I2C_ADDR); 116 | ~SFE_ISL29125(); 117 | 118 | bool init(); 119 | bool reset(); 120 | bool config(uint8_t config1, uint8_t config2, uint8_t config3); 121 | 122 | void setUpperThreshold(uint16_t data); 123 | void setLowerThreshold(uint16_t data); 124 | uint16_t readUpperThreshold(); 125 | uint16_t readLowerThreshold(); 126 | 127 | uint16_t readRed(); 128 | uint16_t readGreen(); 129 | uint16_t readBlue(); 130 | 131 | uint8_t readStatus(); 132 | 133 | private: 134 | uint8_t _addr; 135 | 136 | uint8_t read8(uint8_t reg); 137 | void write8(uint8_t reg, uint8_t data); 138 | 139 | uint16_t read16(uint8_t reg); 140 | void write16(uint8_t reg, uint16_t data); 141 | 142 | }; 143 | 144 | #endif -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, The Regents of the University of California. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its 15 | contributors may be used to endorse or promote products derived from this 16 | software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /Processing/BallDrop/BallDrop.pde: -------------------------------------------------------------------------------- 1 | // Processing example for receiving predictions from ESP 2 | // Draws a small ball (circle) dropping from the top of the window 3 | // to the bottom. ESP predictions make the ball move left (class 1) 4 | // and right (class 2). 5 | 6 | import processing.net.*; // include the networking library 7 | 8 | Server server; // will receive predictions from ESP 9 | int x, y; 10 | 11 | void setup() 12 | { 13 | size(400, 800); 14 | server = new Server(this, 5204); // listen on port 5204 15 | 16 | // start at the middle of the top of the window 17 | x = width / 2; 18 | y = 0; 19 | } 20 | 21 | void draw() 22 | { 23 | // check for incoming data 24 | Client client = server.available(); 25 | if (client != null) { 26 | // check for a full line of incoming data 27 | String line = client.readStringUntil('\n'); 28 | if (line != null) { 29 | println(line); 30 | int val = int(trim(line)); // extract the predicted class 31 | if (val == 1) x -= 20; // move left when class 1 occurs 32 | if (val == 2) x += 20; // move right when class 2 occurs 33 | } 34 | } 35 | 36 | // draw 37 | background(0); 38 | fill(0, 255, 0); 39 | ellipse(x, y, 20, 20); // draw the ball at position (x, y) 40 | 41 | y += 3; // drop the ball 42 | if (y > height) y = 0; // if it hits the botton, wrap around to top 43 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESP (Example-based Sensor Predictions) 2 | 3 | [![Build Status](https://travis-ci.org/damellis/ESP.svg?branch=master)](https://travis-ci.org/damellis/ESP) 4 | 5 | This project aims to help novices make sophisticated use of sensors in interactive projects through the application of machine learning. It works on Mac OS X, Windows, and Linux. 6 | 7 | Check out our [paper](http://dl.acm.org/citation.cfm?id=3064735) 8 | and [video](https://youtu.be/5nDCG4vkFP0) for detailed descriptions. 9 | 10 | ## Installation for users 11 | 12 | The easiest way to use ESP is through the [Processing](http://processing.org) Development Environment (PDE). See the [Processing ESP mode](https://github.com/damellis/processing-esp-mode) for details. 13 | 14 | ## Installation for Developers 15 | 16 | Pre-requisites: you'll need git plus Xcode on Mac OS X, Visual Studio on Windows, and CMake on Linux. To install, first clone this repository, then run the setup script: 17 | 18 | ``` 19 | git clone --recursive https://github.com/damellis/ESP.git 20 | cd ESP 21 | ./setup.sh 22 | ``` 23 | 24 | This will clone the relevant git submodules and create some symbolic links. 25 | 26 | ## Running 27 | 28 | The main application is an openFrameworks-based GUI application named, 29 | unsurprisingly, ESP. Below are instructions to run on different platform 30 | (we support Mac OS X, Windows, and Linux). 31 | 32 | Choose the ESP example you want to run by uncommenting the corresponding line at 33 | [user.cpp](https://github.com/damellis/ESP/blob/master/Xcode/ESP/src/user.cpp). See below for a list of available examples. 34 | 35 | Arduino Project Hub has a more comprehensive [tutorial](https://create.arduino.cc/projecthub/mellis/gesture-recognition-using-accelerometer-and-esp-mac-only-71faa1) on how to use the software. 36 | 37 | ### OS X 38 | 39 | Use Xcode to open the project at `Xcode/ESP/ESP.xcodeproj`. Select either the "ESP Debug" or "ESP Release" scheme (not "openFrameworks"). 40 | 41 | We also support using `CMake` on OS X to compile the project: 42 | ```sh 43 | # Compile openFramework by compiling an emptyExample 44 | xcodebuild -configuration Release -target emptyExample \ 45 | -project "third-party/openFrameworks/scripts/templates/osx/emptyExample.xcodeproj" 46 | 47 | # Build ESP 48 | mkdir build 49 | cd build 50 | cmake .. 51 | make -j8 52 | ``` 53 | 54 | ### Linux 55 | 56 | We use `CMake` on Linux to compile the project. The compilation is a bit more 57 | involved, but should be easy to follow: 58 | 59 | ```sh 60 | # Install required package 61 | sudo apt-get -y install doxygen 62 | sudo apt-get -y install cmake 63 | sudo apt-get -y install libblas-dev 64 | 65 | # Then build openFrameworks 66 | sudo third-party/openFrameworks/scripts/ci/linux/install.sh 67 | sudo third-party/openFrameworks/scripts/ci/linux/build.sh 68 | 69 | # Build and install GRT 70 | cd third-party/grt/build 71 | mkdir -p tmp && cd tmp 72 | cmake .. -DBUILD_EXAMPLES=OFF 73 | make 74 | sudo make install 75 | cd ../../../../ 76 | 77 | # Build ESP 78 | mkdir build 79 | cd build 80 | cmake .. 81 | make -j4 82 | ``` 83 | 84 | ### Windows 85 | 86 | See this [setup guide](https://github.com/damellis/ESP/wiki/Windows-Setup-Guide) 87 | 88 | ## Examples 89 | 90 | Many of these examples expect an Arduino board to be connected to the computer and 91 | running an appropriate sketch. Some of the sketches are hosted in this 92 | repository as well (see `Arduino` folder). Some examples are: 93 | 94 | - [user_audio_beat.cpp](http://damellis.github.io/ESP/user\_audio\_beat\_8cpp-example.html): 95 | recognizes periodic sounds (e.g. dialtones, bells ringing, whistling) using an 96 | FFT and support vector machines algorithm. Works with your computer's built-in 97 | microphone. 98 | 99 | - [user_color_sensor.cpp](http://damellis.github.io/ESP/user\_color\_sensor\_8cpp-example.html): 100 | detects objects by color using a naive Bayes classifier. Works with either 101 | the [Adafruit TCS34725 breakout](https://www.adafruit.com/products/1334) 102 | (using the sketch in Arduino/ColorSensor) or the 103 | [SparkFun ISL29125 breakout](https://www.sparkfun.com/products/12829) (using 104 | the sketch in Arduino/ColorSensor_SparkFun_ISL29125). See documentation for 105 | the sensors for hookup information. 106 | 107 | - [user_accelerometer_gesture.cpp](http://damellis.github.io/ESP/user\_accelerometer\_gestures\_8cpp-example.html): 108 | recognizes gestures using a dynamic time warping algorith. Works with either 109 | an [ADXL335 accelerometer](https://www.adafruit.com/products/163) (using the 110 | Arduino/ADXL335 sketch) or the built-in accelerometer on an 111 | [Arduino 101](http://www.arduino.cc/en/Main/ArduinoBoard101) (using the 112 | Arduino/Arduino101_Accelerometer sketch). 113 | 114 | - [user_accelerometer_poses.cpp](http://damellis.github.io/ESP/user\_accelerometer\_poses\_8cpp-example.html): 115 | recognizes the orientations of an object using a naive Bayes classifier. Works 116 | with accelerometers as for the `user_accelerometer_gesture.cpp` example. 117 | 118 | ## API 119 | 120 | See the [online documentation of the ESP API](http://damellis.github.io/ESP/). 121 | 122 | ## Dependencies 123 | 124 | These should be automatically installed by the setup script: 125 | 126 | - [openFrameworks](http://openframeworks.cc/), a C++ toolkit for creative 127 | coding. 128 | 129 | - [GRT](http://www.nickgillian.com/software/grt), Gesture Recognition Toolkit, 130 | a cross-platform, open-source, C++ machine learning library that has been 131 | specifically designed for real-time gesture recognition. Specifically 132 | [our fork of the GRT repository](https://github.com/damellis/grt). 133 | 134 | - [ofxGrt](https://github.com/nickgillian/ofxGrt), an openFrameworks extension 135 | for the Gesture Recognition Toolkit (GRT). Specifically 136 | [our fork of the ofxGrt repository](https://github.com/nebgnahz/ofxGrt/tree/snapshot-for-sensors). 137 | 138 | - [ofxDatGui](https://braitsch.github.io/ofxDatGui/), a framework for building GUIs in openFrameworks. Specifically [our fork of the repository](https://github.com/nebgnahz/ofxDatGui/). 139 | 140 | - [ofxParagraph](https://github.com/braitsch/ofxParagraph), for rendering multi-line text. 141 | 142 | ## License 143 | 144 | See [LICENSE.txt](LICENSE.txt) for licensing information. 145 | -------------------------------------------------------------------------------- /Xcode/ESP/.gitignore: -------------------------------------------------------------------------------- 1 | doc 2 | 3 | ## Ignore Visual Studio temporary files, build results, and 4 | ## files generated by popular Visual Studio add-ons. 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # DNX 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | 50 | *_i.c 51 | *_p.c 52 | *_i.h 53 | *.ilk 54 | *.meta 55 | *.obj 56 | *.pch 57 | *.pdb 58 | *.pgc 59 | *.pgd 60 | *.rsp 61 | *.sbr 62 | *.tlb 63 | *.tli 64 | *.tlh 65 | *.tmp 66 | *.tmp_proj 67 | *.log 68 | *.vspscc 69 | *.vssscc 70 | .builds 71 | *.pidb 72 | *.svclog 73 | *.scc 74 | 75 | # Chutzpah Test files 76 | _Chutzpah* 77 | 78 | # Visual C++ cache files 79 | ipch/ 80 | *.aps 81 | *.ncb 82 | *.opendb 83 | *.opensdf 84 | *.sdf 85 | *.cachefile 86 | *.VC.db 87 | *.VC.VC.opendb 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | *.sap 94 | 95 | # TFS 2012 Local Workspace 96 | $tf/ 97 | 98 | # Guidance Automation Toolkit 99 | *.gpState 100 | 101 | # ReSharper is a .NET coding add-in 102 | _ReSharper*/ 103 | *.[Rr]e[Ss]harper 104 | *.DotSettings.user 105 | 106 | # JustCode is a .NET coding add-in 107 | .JustCode 108 | 109 | # TeamCity is a build add-in 110 | _TeamCity* 111 | 112 | # DotCover is a Code Coverage Tool 113 | *.dotCover 114 | 115 | # NCrunch 116 | _NCrunch_* 117 | .*crunch*.local.xml 118 | nCrunchTemp_* 119 | 120 | # MightyMoose 121 | *.mm.* 122 | AutoTest.Net/ 123 | 124 | # Web workbench (sass) 125 | .sass-cache/ 126 | 127 | # Installshield output folder 128 | [Ee]xpress/ 129 | 130 | # DocProject is a documentation generator add-in 131 | DocProject/buildhelp/ 132 | DocProject/Help/*.HxT 133 | DocProject/Help/*.HxC 134 | DocProject/Help/*.hhc 135 | DocProject/Help/*.hhk 136 | DocProject/Help/*.hhp 137 | DocProject/Help/Html2 138 | DocProject/Help/html 139 | 140 | # Click-Once directory 141 | publish/ 142 | 143 | # Publish Web Output 144 | *.[Pp]ublish.xml 145 | *.azurePubxml 146 | # TODO: Comment the next line if you want to checkin your web deploy settings 147 | # but database connection strings (with potential passwords) will be unencrypted 148 | *.pubxml 149 | *.publishproj 150 | 151 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 152 | # checkin your Azure Web App publish settings, but sensitive information contained 153 | # in these scripts will be unencrypted 154 | PublishScripts/ 155 | 156 | # NuGet Packages 157 | *.nupkg 158 | # The packages folder can be ignored because of Package Restore 159 | **/packages/* 160 | # except build/, which is used as an MSBuild target. 161 | !**/packages/build/ 162 | # Uncomment if necessary however generally it will be regenerated when needed 163 | #!**/packages/repositories.config 164 | # NuGet v3's project.json files produces more ignoreable files 165 | *.nuget.props 166 | *.nuget.targets 167 | 168 | # Microsoft Azure Build Output 169 | csx/ 170 | *.build.csdef 171 | 172 | # Microsoft Azure Emulator 173 | ecf/ 174 | rcf/ 175 | 176 | # Windows Store app package directories and files 177 | AppPackages/ 178 | BundleArtifacts/ 179 | Package.StoreAssociation.xml 180 | _pkginfo.txt 181 | 182 | # Visual Studio cache files 183 | # files ending in .cache can be ignored 184 | *.[Cc]ache 185 | # but keep track of directories ending in .cache 186 | !*.[Cc]ache/ 187 | 188 | # Others 189 | ClientBin/ 190 | ~$* 191 | *~ 192 | *.dbmdl 193 | *.dbproj.schemaview 194 | *.pfx 195 | *.publishsettings 196 | node_modules/ 197 | orleans.codegen.cs 198 | 199 | # Since there are multiple workflows, uncomment next line to ignore bower_components 200 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 201 | #bower_components/ 202 | 203 | # RIA/Silverlight projects 204 | Generated_Code/ 205 | 206 | # Backup & report files from converting an old project file 207 | # to a newer Visual Studio version. Backup files are not needed, 208 | # because we have git ;-) 209 | _UpgradeReport_Files/ 210 | Backup*/ 211 | UpgradeLog*.XML 212 | UpgradeLog*.htm 213 | 214 | # SQL Server files 215 | *.mdf 216 | *.ldf 217 | 218 | # Business Intelligence projects 219 | *.rdl.data 220 | *.bim.layout 221 | *.bim_*.settings 222 | 223 | # Microsoft Fakes 224 | FakesAssemblies/ 225 | 226 | # GhostDoc plugin setting file 227 | *.GhostDoc.xml 228 | 229 | # Node.js Tools for Visual Studio 230 | .ntvs_analysis.dat 231 | 232 | # Visual Studio 6 build log 233 | *.plg 234 | 235 | # Visual Studio 6 workspace options file 236 | *.opt 237 | 238 | # Visual Studio LightSwitch build output 239 | **/*.HTMLClient/GeneratedArtifacts 240 | **/*.DesktopClient/GeneratedArtifacts 241 | **/*.DesktopClient/ModelManifest.xml 242 | **/*.Server/GeneratedArtifacts 243 | **/*.Server/ModelManifest.xml 244 | _Pvt_Extensions 245 | 246 | # Paket dependency manager 247 | .paket/paket.exe 248 | paket-files/ 249 | 250 | # FAKE - F# Make 251 | .fake/ 252 | 253 | # JetBrains Rider 254 | .idea/ 255 | *.sln.iml 256 | -------------------------------------------------------------------------------- /Xcode/ESP/ESP.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 12.00 2 | # Visual Studio 14 3 | VisualStudioVersion = 14.0.25420.1 4 | MinimumVisualStudioVersion = 10.0.40219.1 5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ESP", "ESP.vcxproj", "{7FD42DF7-442E-479A-BA76-D0022F99702A}" 6 | EndProject 7 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "openframeworksLib", "..\..\third-party\openFrameworks\libs\openFrameworksCompiled\project\vs\openframeworksLib.vcxproj", "{5837595D-ACA9-485C-8E76-729040CE4B0B}" 8 | EndProject 9 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ESPlib", "ESPlib.vcxproj", "{6141ABD7-C691-407E-832D-F0FBAAED0781}" 10 | EndProject 11 | Global 12 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 13 | Debug|Win32 = Debug|Win32 14 | Debug|x64 = Debug|x64 15 | Release|Win32 = Release|Win32 16 | Release|x64 = Release|x64 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.ActiveCfg = Debug|Win32 20 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|Win32.Build.0 = Debug|Win32 21 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.ActiveCfg = Debug|x64 22 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Debug|x64.Build.0 = Debug|x64 23 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.ActiveCfg = Release|Win32 24 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|Win32.Build.0 = Release|Win32 25 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.ActiveCfg = Release|x64 26 | {7FD42DF7-442E-479A-BA76-D0022F99702A}.Release|x64.Build.0 = Release|x64 27 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.ActiveCfg = Debug|Win32 28 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|Win32.Build.0 = Debug|Win32 29 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.ActiveCfg = Debug|x64 30 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Debug|x64.Build.0 = Debug|x64 31 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.ActiveCfg = Release|Win32 32 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|Win32.Build.0 = Release|Win32 33 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.ActiveCfg = Release|x64 34 | {5837595D-ACA9-485C-8E76-729040CE4B0B}.Release|x64.Build.0 = Release|x64 35 | {6141ABD7-C691-407E-832D-F0FBAAED0781}.Debug|Win32.ActiveCfg = Debug|Win32 36 | {6141ABD7-C691-407E-832D-F0FBAAED0781}.Debug|Win32.Build.0 = Debug|Win32 37 | {6141ABD7-C691-407E-832D-F0FBAAED0781}.Debug|x64.ActiveCfg = Debug|x64 38 | {6141ABD7-C691-407E-832D-F0FBAAED0781}.Debug|x64.Build.0 = Debug|x64 39 | {6141ABD7-C691-407E-832D-F0FBAAED0781}.Release|Win32.ActiveCfg = Release|Win32 40 | {6141ABD7-C691-407E-832D-F0FBAAED0781}.Release|Win32.Build.0 = Release|Win32 41 | {6141ABD7-C691-407E-832D-F0FBAAED0781}.Release|x64.ActiveCfg = Release|x64 42 | {6141ABD7-C691-407E-832D-F0FBAAED0781}.Release|x64.Build.0 = Release|x64 43 | EndGlobalSection 44 | GlobalSection(SolutionProperties) = preSolution 45 | HideSolutionNode = FALSE 46 | EndGlobalSection 47 | EndGlobal 48 | -------------------------------------------------------------------------------- /Xcode/ESP/ESP.xcodeproj/xcshareddata/xcschemes/ESP Debug.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Xcode/ESP/ESP.xcodeproj/xcshareddata/xcschemes/ESP Release.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Xcode/ESP/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleGetInfoString 6 | ESP.app 7 | CFBundleExecutable 8 | ESP 9 | CFBundleIdentifier 10 | edu.berkeley.eecs.esp 11 | CFBundleName 12 | ESP 13 | CFBundleShortVersionString 14 | 0.01 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundlePackageType 18 | APPL 19 | IFMajorVersion 20 | 0 21 | IFMinorVersion 22 | 1 23 | 24 | -------------------------------------------------------------------------------- /Xcode/ESP/Makefile: -------------------------------------------------------------------------------- 1 | # Attempt to load a config.make file. 2 | # If none is found, project defaults in config.project.make will be used. 3 | ifneq ($(wildcard config.make),) 4 | include config.make 5 | endif 6 | 7 | # make sure the the OF_ROOT location is defined 8 | ifndef OF_ROOT 9 | OF_ROOT=$(realpath ../../third-party/openFrameworks/) 10 | endif 11 | 12 | # call the project makefile! 13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk 14 | -------------------------------------------------------------------------------- /Xcode/ESP/Project.xcconfig: -------------------------------------------------------------------------------- 1 | //THE PATH TO THE ROOT OF OUR OF PATH RELATIVE TO THIS PROJECT. 2 | //THIS NEEDS TO BE DEFINED BEFORE CoreOF.xcconfig IS INCLUDED 3 | OF_PATH = ../../third-party/openFrameworks 4 | 5 | //THIS HAS ALL THE HEADER AND LIBS FOR OF CORE 6 | #include "../../third-party/openFrameworks/libs/openFrameworksCompiled/project/osx/CoreOF.xcconfig" 7 | 8 | //ICONS - NEW IN 0072 9 | ICON_NAME_DEBUG = icon-debug.icns 10 | ICON_NAME_RELEASE = icon.icns 11 | ICON_FILE_PATH = $(OF_PATH)/libs/openFrameworksCompiled/project/osx/ 12 | 13 | //IF YOU WANT AN APP TO HAVE A CUSTOM ICON - PUT THEM IN YOUR DATA FOLDER AND CHANGE ICON_FILE_PATH to: 14 | //ICON_FILE_PATH = bin/data/ 15 | 16 | OTHER_LDFLAGS = $(OF_CORE_LIBS) $(OF_CORE_FRAMEWORKS) 17 | HEADER_SEARCH_PATHS = $(OF_CORE_HEADERS) 18 | -------------------------------------------------------------------------------- /Xcode/ESP/addons.make: -------------------------------------------------------------------------------- 1 | ofxDatGui 2 | ofxGrt 3 | ofxGui 4 | ofxNetwork 5 | ofxOsc 6 | ofxParagraph 7 | -------------------------------------------------------------------------------- /Xcode/ESP/bin/data/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damellis/ESP/33e539728b18db43cb1b653d5c568347c24e3e27/Xcode/ESP/bin/data/.gitkeep -------------------------------------------------------------------------------- /Xcode/ESP/bin/data/ofxbraitsch/fonts/Verdana.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damellis/ESP/33e539728b18db43cb1b653d5c568347c24e3e27/Xcode/ESP/bin/data/ofxbraitsch/fonts/Verdana.ttf -------------------------------------------------------------------------------- /Xcode/ESP/bin/data/ofxbraitsch/ofxdatgui/icon-group-closed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damellis/ESP/33e539728b18db43cb1b653d5c568347c24e3e27/Xcode/ESP/bin/data/ofxbraitsch/ofxdatgui/icon-group-closed.png -------------------------------------------------------------------------------- /Xcode/ESP/bin/data/ofxbraitsch/ofxdatgui/icon-group-open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damellis/ESP/33e539728b18db43cb1b653d5c568347c24e3e27/Xcode/ESP/bin/data/ofxbraitsch/ofxdatgui/icon-group-open.png -------------------------------------------------------------------------------- /Xcode/ESP/bin/data/ofxbraitsch/ofxdatgui/icon-radio-off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damellis/ESP/33e539728b18db43cb1b653d5c568347c24e3e27/Xcode/ESP/bin/data/ofxbraitsch/ofxdatgui/icon-radio-off.png -------------------------------------------------------------------------------- /Xcode/ESP/bin/data/ofxbraitsch/ofxdatgui/icon-radio-on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damellis/ESP/33e539728b18db43cb1b653d5c568347c24e3e27/Xcode/ESP/bin/data/ofxbraitsch/ofxdatgui/icon-radio-on.png -------------------------------------------------------------------------------- /Xcode/ESP/bin/data/ofxbraitsch/ofxdatgui/picker-rainbow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damellis/ESP/33e539728b18db43cb1b653d5c568347c24e3e27/Xcode/ESP/bin/data/ofxbraitsch/ofxdatgui/picker-rainbow.png -------------------------------------------------------------------------------- /Xcode/ESP/bin/data/train1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damellis/ESP/33e539728b18db43cb1b653d5c568347c24e3e27/Xcode/ESP/bin/data/train1.wav -------------------------------------------------------------------------------- /Xcode/ESP/bin/data/train13.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damellis/ESP/33e539728b18db43cb1b653d5c568347c24e3e27/Xcode/ESP/bin/data/train13.wav -------------------------------------------------------------------------------- /Xcode/ESP/bin/data/train14.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damellis/ESP/33e539728b18db43cb1b653d5c568347c24e3e27/Xcode/ESP/bin/data/train14.wav -------------------------------------------------------------------------------- /Xcode/ESP/bin/data/train15.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damellis/ESP/33e539728b18db43cb1b653d5c568347c24e3e27/Xcode/ESP/bin/data/train15.wav -------------------------------------------------------------------------------- /Xcode/ESP/bin/data/train7.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damellis/ESP/33e539728b18db43cb1b653d5c568347c24e3e27/Xcode/ESP/bin/data/train7.wav -------------------------------------------------------------------------------- /Xcode/ESP/bin/data/verdana.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damellis/ESP/33e539728b18db43cb1b653d5c568347c24e3e27/Xcode/ESP/bin/data/verdana.ttf -------------------------------------------------------------------------------- /Xcode/ESP/icon.rc: -------------------------------------------------------------------------------- 1 | // Icon Resource Definition 2 | #define MAIN_ICON 102 3 | 4 | #if defined(_DEBUG) 5 | MAIN_ICON ICON "icon_debug.ico" 6 | #else 7 | MAIN_ICON ICON "icon.ico" 8 | #endif 9 | -------------------------------------------------------------------------------- /Xcode/ESP/libgrt.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damellis/ESP/33e539728b18db43cb1b653d5c568347c24e3e27/Xcode/ESP/libgrt.dylib -------------------------------------------------------------------------------- /Xcode/ESP/openFrameworks-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | ${ICON} 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundlePackageType 16 | APPL 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1.0 21 | 22 | 23 | -------------------------------------------------------------------------------- /Xcode/ESP/src/calibrator.cpp: -------------------------------------------------------------------------------- 1 | #include "calibrator.h" 2 | 3 | const char *CalibrateResult::result_strings_[3] = { "Success", "Warning", "Failure" }; 4 | 5 | const string CalibrateResult::kDefaultSuccessMessage = "Success"; 6 | const string CalibrateResult::kDefaultWarningMessage = "Warning in calibration"; 7 | const string CalibrateResult::kDefaultFailureMessage = "Failed in calibration"; 8 | 9 | CalibrateResult::CalibrateResult(Result result) : result_(result) { 10 | switch (result) { 11 | case SUCCESS: 12 | result_message_ = kDefaultSuccessMessage; 13 | break; 14 | case WARNING: 15 | result_message_ = kDefaultWarningMessage; 16 | break; 17 | case FAILURE: 18 | result_message_ = kDefaultFailureMessage; 19 | break; 20 | } 21 | } 22 | 23 | CalibrateResult::CalibrateResult(Result result, string message) 24 | : result_(result), result_message_(std::move(message)) { 25 | } 26 | 27 | Calibrator& Calibrator::setCalibrateFunction(SimpleCalibrateFunc f) { 28 | simple_calibrate_func_ = f; 29 | calibrate_func_ = nullptr; 30 | return *this; 31 | } 32 | 33 | Calibrator& Calibrator::setCalibrateFunction(CalibrateFunc f) { 34 | simple_calibrate_func_ = nullptr; 35 | calibrate_func_ = f; 36 | return *this; 37 | } 38 | 39 | Calibrator& Calibrator::addCalibrateProcess(CalibrateProcess cp) { 40 | if (!isCalibrateProcessRegistered(cp)) { 41 | registerCalibrateProcess(cp); 42 | calibrate_processes_.push_back(cp); 43 | } 44 | return *this; 45 | } 46 | 47 | using CalibratorCallback = CalibrateProcess::CalibratorCallback; 48 | Calibrator& Calibrator::addCalibrateProcess(const string& name, 49 | const string& description, 50 | const CalibratorCallback cb) { 51 | CalibrateProcess cp(name, description, cb); 52 | return addCalibrateProcess(cp); 53 | } 54 | 55 | vector Calibrator::calibrate(vector input) { 56 | if (calibrate_func_ != nullptr) { 57 | return calibrate_func_(input); 58 | } else { 59 | assert(simple_calibrate_func_ != nullptr); 60 | vector output; 61 | std::transform(input.begin(), input.end(), back_inserter(output), 62 | simple_calibrate_func_); 63 | return output; 64 | } 65 | } 66 | 67 | bool Calibrator::isCalibrated() { 68 | for (const auto& cp : calibrate_processes_) { 69 | if (!cp.isCalibrated()) { 70 | return false; 71 | } 72 | } 73 | return true; 74 | } 75 | 76 | void Calibrator::registerCalibrateProcess(const CalibrateProcess& cp) { 77 | registered_.insert(cp.getName()); 78 | } 79 | 80 | bool Calibrator::isCalibrateProcessRegistered(const CalibrateProcess& cp) { 81 | return registered_.find(cp.getName()) != registered_.end(); 82 | } 83 | 84 | extern void useCalibrator(Calibrator &calibrator); 85 | -------------------------------------------------------------------------------- /Xcode/ESP/src/cli.cpp: -------------------------------------------------------------------------------- 1 | #include "MFCC.h" 2 | #include "matplotlibcpp.h" 3 | #include "training-data-manager.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace plt = matplotlibcpp; 11 | 12 | constexpr uint32_t kNumMaxLabels = 9; 13 | constexpr char kTrainingDataFilename[] = "TrainingData.grt"; 14 | constexpr char kTestDataFilename[] = "TestData.grt"; 15 | constexpr char kPipelineFilename[] = "Pipeline.grt"; 16 | constexpr uint32_t downsample_rate = 5; 17 | constexpr uint32_t sample_rate = 44100 / downsample_rate; 18 | // frame duration = 23 ms (512 samples) 19 | constexpr uint32_t kFFT_WindowSize = 256; 20 | constexpr uint32_t kFFT_HopSize = 128; 21 | constexpr uint32_t DIM = 1; 22 | 23 | int main(int argc, char* argv[]) { 24 | bool draw_sample = false; 25 | bool load_pipeline = false; 26 | char c; 27 | opterr = 0; 28 | while ((c = getopt(argc, argv, "dl")) != -1) { 29 | switch (c) { 30 | case 'd': draw_sample = true; break; 31 | case 'l': load_pipeline = true; break; 32 | default: abort(); 33 | } 34 | } 35 | 36 | // Setup Pipeline 37 | // TODO(benzh) Convert this to user code loading 38 | GRT::GestureRecognitionPipeline pipeline; 39 | 40 | pipeline.addFeatureExtractionModule( 41 | GRT::FFT(kFFT_WindowSize, kFFT_HopSize, 42 | DIM, GRT::FFT::HAMMING_WINDOW, true, false)); 43 | 44 | GRT::MFCC::Options options; 45 | options.sample_rate = sample_rate; 46 | options.fft_size = kFFT_WindowSize / 2; 47 | options.start_freq = 300; 48 | options.end_freq = 8000; 49 | options.num_tri_filter = 26; 50 | options.num_cepstral_coeff = 12; 51 | options.lifter_param = 22; 52 | options.use_vad = true; 53 | options.noise_level = 5; 54 | 55 | pipeline.addFeatureExtractionModule(GRT::MFCC(options)); 56 | pipeline.setClassifier(GRT::GMM(16, true, false, 1, 100, 0.001)); 57 | pipeline.addPostProcessingModule(GRT::ClassLabelFilter(25, 40)); 58 | 59 | TrainingDataManager training_data_manager(kNumMaxLabels); 60 | 61 | if (!load_pipeline) { 62 | // We load the training data and train the model 63 | if (training_data_manager.load(kTrainingDataFilename)) { 64 | auto d = training_data_manager.getSample(1, 2); 65 | 66 | if (draw_sample) { 67 | plt::plot(training_data_manager.getSample(1, 2).getColVector(0)); 68 | plt::save("./sample.png"); 69 | } 70 | 71 | if (pipeline.train(training_data_manager.getAllData())) { 72 | std::cout << "Training Successful" << std::endl;; 73 | pipeline.save(kPipelineFilename); 74 | } else { 75 | std::cout << "Failed to train the model" << std::endl; 76 | return -1; 77 | } 78 | } 79 | } else { 80 | pipeline.load(kPipelineFilename); 81 | } 82 | 83 | GRT::MatrixDouble test_data; 84 | if (!test_data.load(kTestDataFilename)) { 85 | std::cout << "Failed to load test data from " << kTestDataFilename 86 | << std::endl; 87 | return -1; 88 | } 89 | 90 | size_t vec_size = test_data.getNumRows(); 91 | std::vector x(vec_size, 0); 92 | std::vector preds(vec_size, 0); 93 | std::vector audio(vec_size, 0); 94 | std::vector distances1(vec_size, 0); 95 | std::vector distances2(vec_size, 0); 96 | 97 | std::cout << "Running testing" << std::endl; 98 | 99 | // Run test data through 100 | for (uint32_t i = 0; i < test_data.getNumRows(); i++) { 101 | auto td = test_data.getRowVector(i); 102 | pipeline.predict(td); 103 | uint32_t predicted_label = pipeline.getPredictedClassLabel(); 104 | auto ds = pipeline.getClassDistances(); 105 | 106 | audio[i] = td[0]; 107 | x[i] = i; 108 | preds[i] = static_cast(predicted_label); 109 | distances1[i] = ds[0]; 110 | distances2[i] = ds[1]; 111 | } 112 | 113 | // std::cout << "Test finished, plotting ... "; 114 | // plt::plot(x, audio, "b-"); 115 | // plt::save("./audio.png"); 116 | 117 | plt::plot(x, distances1, "r.", x, distances2, "g."); 118 | plt::save("./prediction.png"); 119 | std::cout << "Done" << std::endl; 120 | 121 | return 0; 122 | } 123 | -------------------------------------------------------------------------------- /Xcode/ESP/src/examples/user_accelerometer_gestures.cpp: -------------------------------------------------------------------------------- 1 | /** @example user_accelerometer_gestures.cpp 2 | * Gesture detection using accelerometers. See the associated tutorial. 3 | */ 4 | #include 5 | 6 | ASCIISerialStream stream(115200, 3); 7 | GestureRecognitionPipeline pipeline; 8 | Calibrator calibrator; 9 | TcpOStream oStream("localhost", 5204); 10 | 11 | //std::map key_mapping = { {1, 0}, {2, 0}, {3, ' '} }; 12 | //std::map key_code_mapping = { {1, 0x7C}, {2, 0x7B} }; 13 | //MacOSKeyboardOStream oStream(key_mapping, key_code_mapping); 14 | //MacOSKeyboardOStream oStream(3, 0, 0x7C, 0, 0x7B, ' '); // right, left, space 15 | 16 | MatrixDouble uprightData, upsideDownData; 17 | bool haveUprightData = false, haveUpsideDownData = false; 18 | double range; 19 | vector zeroGs(3); 20 | 21 | vector processAccelerometerData(vector input) 22 | { 23 | vector result(3); 24 | 25 | for (int i = 0; i < 3; i++) { 26 | result[i] = (input[i] - zeroGs[i]) / range; 27 | } 28 | 29 | return result; 30 | } 31 | 32 | CalibrateResult calibrate(const MatrixDouble& data) { 33 | CalibrateResult result = CalibrateResult::SUCCESS; 34 | 35 | // Run checks on newly collected sample. 36 | 37 | // take average of X and Y acceleration as the zero G value 38 | double zG = (data.getMean()[0] + data.getMean()[1]) / 2; 39 | double oG = data.getMean()[2]; // use Z acceleration as one G value 40 | 41 | double r = abs(oG - zG); 42 | vector stddev = data.getStdDev(); 43 | 44 | if (abs(data.getMean()[0] - data.getMean()[1]) / r > 0.1) 45 | result = CalibrateResult(CalibrateResult::WARNING, 46 | "X and Y axes differ by " + std::to_string( 47 | abs(data.getMean()[0] - data.getMean()[1]) / r * 100) + 48 | " percent. Check that accelerometer is flat."); 49 | 50 | if (stddev[0] / r > 0.05 || 51 | stddev[1] / r > 0.05 || 52 | stddev[2] / r > 0.05) 53 | result = CalibrateResult(CalibrateResult::WARNING, 54 | "Accelerometer data is noisy. Check circuit."); 55 | 56 | // If we have both samples, do the actual calibration. 57 | 58 | if (haveUprightData && haveUpsideDownData) { 59 | for (int i = 0; i < 3; i++) { 60 | zeroGs[i] = 61 | (uprightData.getMean()[i] + upsideDownData.getMean()[i]) / 2; 62 | } 63 | 64 | // use half the difference between the two z-axis values (-1 and +1) 65 | // as the range 66 | range = (uprightData.getMean()[2] - upsideDownData.getMean()[2]) / 2; 67 | } 68 | 69 | return result; 70 | } 71 | 72 | CalibrateResult uprightDataCollected(const MatrixDouble& data) 73 | { 74 | uprightData = data; 75 | haveUprightData = true; 76 | return calibrate(data); 77 | } 78 | 79 | CalibrateResult upsideDownDataCollected(const MatrixDouble& data) 80 | { 81 | upsideDownData = data; 82 | haveUpsideDownData = true; 83 | return calibrate(data); 84 | } 85 | 86 | TrainingSampleCheckerResult checkTrainingSample(const MatrixDouble &in) 87 | { 88 | if (in.getNumRows() < 10) 89 | return TrainingSampleCheckerResult(TrainingSampleCheckerResult::WARNING, 90 | "Warning: Sample is short. Did you hold down the key for " 91 | "the whole time you were making the gesture?"); 92 | VectorDouble stddev = in.getStdDev(); 93 | if (*max_element(stddev.begin(), stddev.end()) < 0.1) 94 | return TrainingSampleCheckerResult(TrainingSampleCheckerResult::WARNING, 95 | "Warning: Gesture contains very little movement."); 96 | return TrainingSampleCheckerResult::SUCCESS; 97 | } 98 | 99 | int timeout = 500; // milliseconds 100 | double null_rej = 0.4; 101 | 102 | void updateVariability(double new_null_rej) { 103 | pipeline.getClassifier()->setNullRejectionCoeff(new_null_rej); 104 | pipeline.getClassifier()->recomputeNullRejectionThresholds(); 105 | } 106 | 107 | void updateTimeout(int new_timeout) { 108 | ClassLabelTimeoutFilter *filter = 109 | dynamic_cast 110 | (pipeline.getPostProcessingModule(0)); 111 | assert(filter != nullptr); 112 | filter->setTimeoutDuration(new_timeout); 113 | } 114 | 115 | void setup() 116 | { 117 | stream.setLabelsForAllDimensions({"x", "y", "z"}); 118 | useStream(stream); 119 | useOutputStream(oStream); 120 | 121 | calibrator.setCalibrateFunction(processAccelerometerData); 122 | calibrator.addCalibrateProcess("Upright", 123 | "Rest accelerometer upright on flat surface.", uprightDataCollected); 124 | calibrator.addCalibrateProcess("Upside Down", 125 | "Rest accelerometer upside down on flat surface.", upsideDownDataCollected); 126 | useCalibrator(calibrator); 127 | 128 | DTW dtw(false, true, null_rej); 129 | dtw.enableTrimTrainingData(true, 0.1, 75); 130 | 131 | pipeline.setClassifier(dtw); 132 | pipeline.addPostProcessingModule(ClassLabelTimeoutFilter(timeout)); 133 | usePipeline(pipeline); 134 | 135 | registerTuneable(null_rej, 0.1, 5.0, "Variability", 136 | "How different from the training data a new gesture can be and " 137 | "still be considered the same gesture. The higher the number, the " 138 | "more different it can be.", updateVariability); 139 | registerTuneable(timeout, 1, 3000, 140 | "Timeout", 141 | "How long (in milliseconds) to wait after recognizing a " 142 | "gesture before recognizing another one.", updateTimeout); 143 | 144 | useTrainingSampleChecker(checkTrainingSample); 145 | 146 | setTruePositiveWarningThreshold(0.60); 147 | setFalseNegativeWarningThreshold(0.30); 148 | } 149 | -------------------------------------------------------------------------------- /Xcode/ESP/src/examples/user_accelerometer_gestures_osc.cpp: -------------------------------------------------------------------------------- 1 | /** @example user_accelerometer_gestures_osc.cpp 2 | */ 3 | #include 4 | 5 | OscInputStream stream(8001, "/gyrosc/accel", 3); 6 | GestureRecognitionPipeline pipeline; 7 | 8 | int timeout = 500; // milliseconds 9 | double null_rej = 0.4; 10 | 11 | void setup() { 12 | stream.setLabelsForAllDimensions({"x", "y", "z"}); 13 | useInputStream(stream); 14 | 15 | DTW dtw(false, true, null_rej); 16 | dtw.enableTrimTrainingData(true, 0.1, 75); 17 | 18 | pipeline.setClassifier(dtw); 19 | pipeline.addPostProcessingModule(ClassLabelTimeoutFilter(timeout)); 20 | usePipeline(pipeline); 21 | 22 | registerTuneable( 23 | null_rej, 0.1, 5.0, "Variability", 24 | "How different from the training data a new gesture can be and " 25 | "still be considered the same gesture. The higher the number, the " 26 | "more different it can be.", 27 | [](double new_null_rej) { 28 | pipeline.getClassifier()->setNullRejectionCoeff(new_null_rej); 29 | pipeline.getClassifier()->recomputeNullRejectionThresholds(); 30 | }); 31 | 32 | registerTuneable( 33 | timeout, 1, 3000, "Timeout", 34 | "How long (in milliseconds) to wait after recognizing a " 35 | "gesture before recognizing another one.", 36 | [](double new_timeout) { 37 | ClassLabelTimeoutFilter* filter = 38 | dynamic_cast( 39 | pipeline.getPostProcessingModule(0)); 40 | assert(filter != nullptr); 41 | filter->setTimeoutDuration(new_timeout); 42 | }); 43 | } 44 | -------------------------------------------------------------------------------- /Xcode/ESP/src/examples/user_accelerometer_gestures_simple.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | ASCIISerialStream iStream(115200, 3); 4 | TcpOStream oStream("localhost", 5204); 5 | GestureRecognitionPipeline pipeline; 6 | Calibrator calibrator; 7 | 8 | double zeroG = 0, oneG = 0; 9 | 10 | double processAccelerometerData(double input) { 11 | return (input - zeroG) / (oneG - zeroG); 12 | } 13 | 14 | CalibrateResult restingDataCollected(const MatrixDouble& data) { 15 | // take average of X and Y acceleration as the zero G value 16 | zeroG = (data.getMean()[0] + data.getMean()[1]) / 2; 17 | oneG = data.getMean()[2]; // use Z acceleration as one G value 18 | 19 | double range = abs(oneG - zeroG); 20 | vector stddev = data.getStdDev(); 21 | 22 | if (stddev[0] / range > 0.05 || 23 | stddev[1] / range > 0.05 || 24 | stddev[2] / range > 0.05) 25 | return CalibrateResult(CalibrateResult::WARNING, 26 | "Accelerometer readings are noisy, check circuit."); 27 | 28 | return CalibrateResult::SUCCESS; 29 | } 30 | 31 | TrainingSampleCheckerResult checkTrainingSample(const MatrixDouble &in) { 32 | VectorDouble stddev = in.getStdDev(); 33 | if (*max_element(stddev.begin(), stddev.end()) < 0.1) 34 | return TrainingSampleCheckerResult(TrainingSampleCheckerResult::WARNING, 35 | "Warning: Gesture contains very little movement."); 36 | return TrainingSampleCheckerResult::SUCCESS; 37 | } 38 | 39 | double null_rej = 0.4; 40 | 41 | void updateVariability(double new_null_rej) { 42 | pipeline.getClassifier()->setNullRejectionCoeff(new_null_rej); 43 | pipeline.getClassifier()->recomputeNullRejectionThresholds(); 44 | } 45 | 46 | void setup() { 47 | useInputStream(iStream); 48 | useOutputStream(oStream); 49 | 50 | calibrator.setCalibrateFunction(processAccelerometerData); 51 | calibrator.addCalibrateProcess("Resting", 52 | "Rest accelerometer on flat surface.", restingDataCollected); 53 | useCalibrator(calibrator); 54 | 55 | DTW dtw(false, true, null_rej); 56 | 57 | pipeline.setClassifier(dtw); 58 | usePipeline(pipeline); 59 | 60 | registerTuneable(null_rej, 0.1, 5.0, "Variability", 61 | "How different from the training data a new gesture can be and " 62 | "still be considered the same gesture. The higher the number, the " 63 | "more different it can be.", updateVariability); 64 | 65 | useTrainingSampleChecker(checkTrainingSample); 66 | } 67 | -------------------------------------------------------------------------------- /Xcode/ESP/src/examples/user_accelerometer_poses.cpp: -------------------------------------------------------------------------------- 1 | /** @example user_accelerometer_poses.cpp 2 | * Pose detection using accelerometers. 3 | */ 4 | #include 5 | 6 | ASCIISerialStream stream(115200, 3); 7 | GestureRecognitionPipeline pipeline; 8 | Calibrator calibrator; 9 | TcpOStream oStream("localhost", 5204); 10 | 11 | MatrixDouble uprightData, upsideDownData; 12 | bool haveUprightData = false, haveUpsideDownData = false; 13 | double range; 14 | vector zeroGs(3); 15 | 16 | vector processAccelerometerData(vector input) 17 | { 18 | vector result(3); 19 | 20 | for (int i = 0; i < 3; i++) { 21 | result[i] = (input[i] - zeroGs[i]) / range; 22 | } 23 | 24 | return result; 25 | } 26 | 27 | CalibrateResult calibrate(const MatrixDouble& data) { 28 | CalibrateResult result = CalibrateResult::SUCCESS; 29 | 30 | // Run checks on newly collected sample. 31 | 32 | // take average of X and Y acceleration as the zero G value 33 | double zG = (data.getMean()[0] + data.getMean()[1]) / 2; 34 | double oG = data.getMean()[2]; // use Z acceleration as one G value 35 | 36 | double r = abs(oG - zG); 37 | vector stddev = data.getStdDev(); 38 | 39 | if (stddev[0] / r > 0.05 || 40 | stddev[1] / r > 0.05 || 41 | stddev[2] / r > 0.05) 42 | result = CalibrateResult(CalibrateResult::WARNING, 43 | "Accelerometer seemed to be moving; consider recollecting the " 44 | "calibration sample."); 45 | 46 | if (abs(data.getMean()[0] - data.getMean()[1]) / r > 0.1) 47 | result = CalibrateResult(CalibrateResult::WARNING, 48 | "X and Y axes differ by " + std::to_string( 49 | abs(data.getMean()[0] - data.getMean()[1]) / r * 100) + 50 | " percent. Check that accelerometer is flat."); 51 | 52 | // If we have both samples, do the actual calibration. 53 | 54 | if (haveUprightData && haveUpsideDownData) { 55 | for (int i = 0; i < 3; i++) { 56 | zeroGs[i] = 57 | (uprightData.getMean()[i] + upsideDownData.getMean()[i]) / 2; 58 | } 59 | 60 | // use half the difference between the two z-axis values (-1 and +1) 61 | // as the range 62 | range = (uprightData.getMean()[2] - upsideDownData.getMean()[2]) / 2; 63 | } 64 | 65 | return result; 66 | } 67 | 68 | CalibrateResult uprightDataCollected(const MatrixDouble& data) 69 | { 70 | uprightData = data; 71 | haveUprightData = true; 72 | return calibrate(data); 73 | } 74 | 75 | CalibrateResult upsideDownDataCollected(const MatrixDouble& data) 76 | { 77 | upsideDownData = data; 78 | haveUpsideDownData = true; 79 | return calibrate(data); 80 | } 81 | 82 | double null_rej = 5.0; 83 | bool always_pick_something = false; 84 | 85 | void updateAlwaysPickSomething(bool new_val) { 86 | pipeline.getClassifier()->enableNullRejection(!new_val); 87 | } 88 | 89 | void updateVariability(double new_val) { 90 | pipeline.getClassifier()->setNullRejectionCoeff(new_val); 91 | pipeline.getClassifier()->recomputeNullRejectionThresholds(); 92 | } 93 | 94 | void setup() 95 | { 96 | stream.setLabelsForAllDimensions({"x", "y", "z"}); 97 | useStream(stream); 98 | useOutputStream(oStream); 99 | //useStream(stream); 100 | 101 | calibrator.setCalibrateFunction(processAccelerometerData); 102 | calibrator.addCalibrateProcess("Upright", 103 | "Rest accelerometer upright on flat surface.", uprightDataCollected); 104 | calibrator.addCalibrateProcess("Upside Down", 105 | "Rest accelerometer upside down on flat surface.", upsideDownDataCollected); 106 | useCalibrator(calibrator); 107 | 108 | pipeline.addFeatureExtractionModule(TimeDomainFeatures(10, 1, 3, false, true, true, false, false)); 109 | pipeline.setClassifier(ANBC(false, !always_pick_something, null_rej)); // use scaling, use null rejection, null rejection parameter 110 | // null rejection parameter is multiplied by the standard deviation to determine 111 | // the rejection threshold. the higher the number, the looser the filter; the 112 | // lower the number, the tighter the filter. 113 | 114 | usePipeline(pipeline); 115 | 116 | registerTuneable(always_pick_something, "Always Pick Something", 117 | "Whether to always pick (predict) one of the classes of training data, " 118 | "even if it's not a very good match. If selected, 'Variability' will " 119 | "not be used.", updateAlwaysPickSomething); 120 | registerTuneable(null_rej, 1.0, 25.0, "Variability", 121 | "How different from the training data a new gesture can be and " 122 | "still be considered the same gesture. The higher the number, the more " 123 | "different it can be.", updateVariability); 124 | 125 | setTruePositiveWarningThreshold(0.90); 126 | setFalseNegativeWarningThreshold(0.10); 127 | } 128 | -------------------------------------------------------------------------------- /Xcode/ESP/src/examples/user_accelerometer_walk_detection.cpp: -------------------------------------------------------------------------------- 1 | /** @example user_accelerometer_walk_detection.cpp 2 | 3 | Simple walk detection using an accelerometer. This uses a very simple 4 | algorithm: thresholding the standard deviation of energy (dot product) of the 5 | acceleration vector over a history of samples. The choice of this algorithm 6 | is based on the discussion in "Walk detection and step counting on 7 | unconstrained smartphones" by Agata Brajdic and Robert Harle 8 | http://dl.acm.org/citation.cfm?id=2493449 which suggests that this is as 9 | good (or better) than more complex methods. 10 | 11 | To use, upload the Arduino101_Accelerometer_100Hz to an Arduino 101. After 12 | calibration, place the Arduino 101 in a front pants pocket. 13 | 14 | It's certainly possible to fool this algorithm into thinking that you are 15 | walking when you aren't (e.g. by jumping up and down). It also might require 16 | lowering of the threshold to detect slow walking. But, in general, this should 17 | be at least useful for experimenting. 18 | */ 19 | #include 20 | 21 | ASCIISerialStream stream(9600, 3); 22 | GestureRecognitionPipeline pipeline; 23 | Calibrator calibrator; 24 | TcpOStream oStream("localhost", 5204); 25 | 26 | double zeroG = 0, oneG = 0; 27 | 28 | double processAccelerometerData(double input) 29 | { 30 | return (input - zeroG) / (oneG - zeroG); 31 | } 32 | 33 | CalibrateResult restingDataCollected(const MatrixDouble& data) 34 | { 35 | // take average of X and Y acceleration as the zero G value 36 | zeroG = (data.getMean()[0] + data.getMean()[1]) / 2; 37 | oneG = data.getMean()[2]; // use Z acceleration as one G value 38 | 39 | double range = abs(oneG - zeroG); 40 | vector stddev = data.getStdDev(); 41 | 42 | if (stddev[0] / range > 0.05 || 43 | stddev[1] / range > 0.05 || 44 | stddev[2] / range > 0.05) 45 | return CalibrateResult(CalibrateResult::WARNING, 46 | "Accelerometer seemed to be moving; consider recollecting the " 47 | "calibration sample."); 48 | 49 | if (abs(data.getMean()[0] - data.getMean()[1]) / range > 0.1) 50 | return CalibrateResult(CalibrateResult::WARNING, 51 | "X and Y axes differ by " + std::to_string( 52 | abs(data.getMean()[0] - data.getMean()[1]) / range * 100) + 53 | " percent. Check that accelerometer is flat."); 54 | 55 | return CalibrateResult::SUCCESS; 56 | } 57 | 58 | VectorDouble dotProduct(VectorDouble in) 59 | { 60 | VectorDouble out(1, 0); 61 | 62 | for (int i = 0; i < in.size(); i++) 63 | out[0] += in[i] * in[i]; 64 | 65 | return out; 66 | } 67 | 68 | VectorDouble stddev(VectorDouble v) { 69 | double sum = std::accumulate(v.begin(), v.end(), 0.0); 70 | double mean = sum / v.size(); 71 | 72 | double sq_sum = std::inner_product(v.begin(), v.end(), v.begin(), 0.0); 73 | double stdev = std::sqrt(sq_sum / v.size() - mean * mean); 74 | 75 | return VectorDouble(1, stdev); 76 | } 77 | 78 | double t = 0.6; 79 | VectorDouble threshold(VectorDouble in) { 80 | VectorDouble out(in.size()); 81 | for (int i = 0; i < in.size(); i++) 82 | out[i] = (in[i] > t) ? 1.0 : 0.0; 83 | return out; 84 | } 85 | 86 | void setup() 87 | { 88 | stream.setLabelsForAllDimensions({"x", "y", "z"}); 89 | useStream(stream); 90 | useOutputStream(oStream); 91 | 92 | calibrator.setCalibrateFunction(processAccelerometerData); 93 | calibrator.addCalibrateProcess("Resting", 94 | "Rest accelerometer on flat surface.", restingDataCollected); 95 | useCalibrator(calibrator); 96 | 97 | pipeline.addFeatureExtractionModule(FeatureApply(3, 1, dotProduct)); 98 | pipeline.addFeatureExtractionModule(TimeseriesBuffer(80, 1)); 99 | pipeline.addFeatureExtractionModule(FeatureApply(80, 1, stddev)); 100 | pipeline.addFeatureExtractionModule(FeatureApply(1, 1, threshold)); 101 | usePipeline(pipeline); 102 | 103 | registerTuneable(t, 0, 1.0, "Walking Threshold", 104 | "How much the accelerometer data needs to be " 105 | "changing to be considered walking."); 106 | } 107 | -------------------------------------------------------------------------------- /Xcode/ESP/src/examples/user_audio_beat_detection.cpp: -------------------------------------------------------------------------------- 1 | /** @example user_audio_beat.cpp 2 | * Audio beat detection example. Based on: http://archive.gamedev.net/archive/reference/programming/features/beatdetection/ 3 | */ 4 | #include 5 | 6 | //AudioStream stream(1); 7 | AudioFileStream stream("train1.wav", true); 8 | GestureRecognitionPipeline pipeline; 9 | TcpOStream oStream("localhost", 5204); 10 | ASCIISerialStream oStream2(0, 9600, 3); 11 | 12 | // Audio defaults to 44.1k sampling rate. 13 | uint32_t kFFT_WindowSize = 1024; 14 | uint32_t kFFT_HopSize = 1024; 15 | uint32_t DIM = 1; 16 | uint32_t BINS; 17 | uint32_t BIN_WIDTH_START = 2; 18 | uint32_t BIN_WIDTH_DELTA = 4; 19 | uint32_t HISTORY = 43; 20 | 21 | double C = 2.0; 22 | 23 | VectorDouble increasingBinWidths(VectorDouble in) { 24 | VectorDouble out; 25 | int bin_width = BIN_WIDTH_START; 26 | int i = 0; 27 | while (i < in.size()) { 28 | double val = 0; 29 | if (i + bin_width >= in.size()) bin_width = in.size() - i; 30 | for (int j = 0; j < bin_width; j++) { 31 | val += in[i + j]; 32 | } 33 | out.push_back(val / bin_width); 34 | i += bin_width; 35 | bin_width *= BIN_WIDTH_DELTA; 36 | } 37 | return out; 38 | } 39 | 40 | int getNumIncreasingBins(int in_size) { 41 | int bin_width = BIN_WIDTH_START; 42 | int i = 0, out_size = 0; 43 | while (i < in_size) { 44 | out_size++; 45 | if (i + bin_width >= in_size) bin_width = in_size - i; 46 | std::cout << "Bin " << out_size << ": band " << i << " (" << 44100.0 / 1024 * i << " Hz)" << " to "; 47 | i += bin_width; 48 | std::cout << "band " << (i - 1) << " (" << 44100.0 / 1024 * (i - 1) << " Hz)" << std::endl; 49 | bin_width *= BIN_WIDTH_DELTA; 50 | } 51 | return out_size; 52 | } 53 | 54 | VectorDouble meanAndLast(VectorDouble in) { 55 | VectorDouble out(BINS * 2); 56 | 57 | for (int i = 0; i < BINS; i++) { 58 | double mean = 0; 59 | for (int j = 0; j < HISTORY; j++) { 60 | mean += in[i * HISTORY + j]; 61 | } 62 | mean /= HISTORY; 63 | out[i * 2] = mean; 64 | out[i * 2 + 1] = in[i * HISTORY + HISTORY - 1]; 65 | } 66 | 67 | return out; 68 | } 69 | 70 | VectorDouble detectBeat(VectorDouble in) { 71 | VectorDouble out(BINS, 0.0); 72 | 73 | for (int i = 0; i < BINS; i++) { 74 | if (in[i * 2 + 1] > in[i * 2] * C) out[i] = 1.0; 75 | } 76 | 77 | return out; 78 | } 79 | 80 | void setup() { 81 | stream.setLabelsForAllDimensions({"audio"}); 82 | useInputStream(stream); 83 | useOutputStream(oStream); 84 | useOutputStream(oStream2); 85 | 86 | // pipeline.addFeatureExtractionModule( 87 | // FFT(kFFT_WindowSize, kFFT_HopSize, 88 | // DIM, FFT::RECTANGULAR_WINDOW, true, false)); 89 | 90 | BINS = getNumIncreasingBins(kFFT_WindowSize / 2); 91 | pipeline.addFeatureExtractionModule(FeatureApply(kFFT_WindowSize / 2, BINS, increasingBinWidths)); 92 | pipeline.addFeatureExtractionModule(TimeseriesBuffer(HISTORY, BINS)); 93 | pipeline.addFeatureExtractionModule(FeatureApply(BINS * HISTORY,BINS * 2,meanAndLast)); 94 | pipeline.addFeatureExtractionModule(FeatureApply(BINS * 2, BINS, detectBeat)); 95 | 96 | usePipeline(pipeline); 97 | 98 | registerTuneable(C, 1.0, 5.0, "Beat Threshold", 99 | "How many times louder than the average volume (over the last second) " 100 | "it needs to be to be considered a beat. Applied separately to each " 101 | "frequency band."); 102 | } 103 | -------------------------------------------------------------------------------- /Xcode/ESP/src/examples/user_capacitive_sensing.cpp: -------------------------------------------------------------------------------- 1 | /** @example user_capacitive_sensing.cpp 2 | * Capacitve sensing. 3 | */ 4 | #include 5 | 6 | ASCIISerialStream stream(0, 9600, 12); 7 | GestureRecognitionPipeline pipeline; 8 | 9 | void setup() { 10 | useStream(stream); 11 | 12 | //pipeline.addPreProcessingModule(MovingAverageFilter(5, 3)); 13 | //pipeline.addFeatureExtractionModule(TimeDomainFeatures(10, 1, 3, false, true, true, false, false)); 14 | //pipeline.addPreProcessingModule(Derivative(Derivative::FIRST_DERIVATIVE, 0.1, 12)); 15 | pipeline.setClassifier(ANBC(false, true, 10.0)); // use scaling, use null rejection, null rejection parameter 16 | // null rejection parameter is multiplied by the standard deviation to determine 17 | // the rejection threshold. the higher the number, the looser the filter; the 18 | // lower the number, the tighter the filter. 19 | 20 | usePipeline(pipeline); 21 | } 22 | -------------------------------------------------------------------------------- /Xcode/ESP/src/examples/user_color_sensor.cpp: -------------------------------------------------------------------------------- 1 | /** @example user_color_sensor.cpp 2 | * Color sensing. See documentation on the wiki. 3 | */ 4 | #include 5 | 6 | // Normalize by dividing each dimension by the total magnitude. 7 | // Also add the magnitude as an additional feature. 8 | vector normalize(vector input) { 9 | double magnitude = 0.0; 10 | 11 | for (int i = 0; i < input.size(); i++) magnitude += (input[i] * input[i]); 12 | magnitude = sqrt(magnitude); 13 | for (int i = 0; i < input.size(); i++) input[i] /= magnitude; 14 | 15 | return input; 16 | } 17 | 18 | ASCIISerialStream stream(9600, 3); 19 | GestureRecognitionPipeline pipeline; 20 | TcpOStream oStream("localhost", 5204); 21 | 22 | bool always_pick_something = false; 23 | double null_rej = 5.0; 24 | 25 | void updateAlwaysPickSomething(bool new_val) { 26 | pipeline.getClassifier()->enableNullRejection(!new_val); 27 | } 28 | 29 | void updateVariability(double new_val) { 30 | pipeline.getClassifier()->setNullRejectionCoeff(new_val); 31 | pipeline.getClassifier()->recomputeNullRejectionThresholds(); 32 | } 33 | 34 | void setup() { 35 | stream.useNormalizer(normalize); 36 | stream.setLabelsForAllDimensions({"red", "green", "blue"}); 37 | useStream(stream); 38 | useOutputStream(oStream); 39 | // useStream(stream); 40 | 41 | pipeline.addPreProcessingModule(MovingAverageFilter(5, 3)); 42 | // use scaling, use null rejection, null rejection parameter 43 | pipeline.setClassifier(ANBC(false, !always_pick_something, null_rej)); 44 | 45 | // null rejection parameter is multiplied by the standard deviation to determine 46 | // the rejection threshold. the higher the number, the looser the filter; the 47 | // lower the number, the tighter the filter. 48 | 49 | usePipeline(pipeline); 50 | 51 | registerTuneable(always_pick_something, "Always Pick Something", 52 | "Whether to always pick (predict) one of the classes of training data, " 53 | "even if it's not a very good match. If selected, 'Color Variability' " 54 | "will not be used.", updateAlwaysPickSomething); 55 | registerTuneable(null_rej, 1.0, 25.0, "Color Variability", 56 | "How different from the training data a new color reading can be and " 57 | "still be considered the same color. The higher the number, the more " 58 | "different it can be.", updateVariability); 59 | } 60 | -------------------------------------------------------------------------------- /Xcode/ESP/src/examples/user_speaker.cpp: -------------------------------------------------------------------------------- 1 | /** @example user_speaker.cpp 2 | * Speaker identification with MFCC and GMM. 3 | */ 4 | #include 5 | #include 6 | 7 | constexpr uint32_t kDownsample = 5; 8 | constexpr uint32_t kSampleRate = 44100 / 5; // 8820 9 | constexpr uint32_t kFftWindowSize = 256; // 256 samples => 30 ms, frame size 10 | constexpr uint32_t kFftHopSize = 128; // 128 samples => 15 ms, hop size 11 | constexpr uint32_t DIM = 1; 12 | 13 | AudioStream stream(kDownsample); 14 | GestureRecognitionPipeline pipeline; 15 | TcpOStream oStream("localhost", 5204); 16 | 17 | // Tuneable parameters 18 | int post_duration = 1000; // ms 19 | double post_ratio = 0.7f; // 70% 20 | double noise_level = 5.0f; // Noise level, the unit is not yet standardized) 21 | 22 | void setup() { 23 | stream.setLabelsForAllDimensions({"audio"}); 24 | 25 | pipeline.addFeatureExtractionModule( 26 | FFT(kFftWindowSize, kFftHopSize, 27 | DIM, FFT::HAMMING_WINDOW, true, false)); 28 | 29 | MFCC::Options options; 30 | options.sample_rate = kSampleRate; 31 | options.fft_size = kFftWindowSize / 2; 32 | options.start_freq = 300; 33 | options.end_freq = 3700; 34 | options.num_tri_filter = 26; 35 | options.num_cepstral_coeff = 12; 36 | options.lifter_param = 22; 37 | options.use_vad = true; 38 | options.noise_level = noise_level; 39 | 40 | pipeline.addFeatureExtractionModule(MFCC(options)); 41 | 42 | pipeline.setClassifier(SVM()); 43 | // GMM(16, true, false, 1, 100, 0.001)); 44 | 45 | // In post processing, we wait #n predicitons. If m out of n predictions are 46 | // from the same class, we declare the class as the right one. 47 | // 48 | // n = (duration * sample_rate) / frame_size 49 | // where duration = post_duration 50 | // sample_rate = kSampleRate 51 | // frame_size = kFftHopSize 52 | // m = n * post_ratio 53 | int num_predictions = post_duration / 1000 * kSampleRate / kFftHopSize; 54 | pipeline.addPostProcessingModule( 55 | ClassLabelFilter(num_predictions * post_ratio, num_predictions)); 56 | 57 | auto ratio_updater = [](double new_ratio) { 58 | ClassLabelFilter* filter = 59 | dynamic_cast(pipeline.getPostProcessingModule(0)); 60 | // Recalculate num_predictions as post_duration might have been changed 61 | int num_predictions = post_duration / 1000 * kSampleRate / kFftHopSize; 62 | filter->setMinimumCount(new_ratio * num_predictions); 63 | }; 64 | 65 | auto duration_updater = [](int new_duration) { 66 | ClassLabelFilter* filter = 67 | dynamic_cast(pipeline.getPostProcessingModule(0)); 68 | // Recalculate num_predictions as post_duration might have been changed 69 | int num_predictions = post_duration / 1000 * kSampleRate / kFftHopSize; 70 | filter->setBufferSize(num_predictions); 71 | }; 72 | 73 | auto noise_updater = [](int new_noise_level) { 74 | MFCC *mfcc = dynamic_cast(pipeline.getFeatureExtractionModule(1)); 75 | mfcc->setNoiseLevel(new_noise_level); 76 | }; 77 | 78 | registerTuneable(noise_level, 0, 20, 79 | "Noise Level", 80 | "The threshold for the system to distinguish between " 81 | "ambient noise and speech/sound", 82 | noise_updater); 83 | 84 | registerTuneable(post_duration, 0, 2000, 85 | "Duration", 86 | "Time (in ms) that is considered as a whole " 87 | "for smoothing the prediction", 88 | duration_updater); 89 | 90 | registerTuneable(post_ratio, 0.0f, 1.0f, 91 | "Ratio", 92 | "The portion of time in duration that " 93 | "should be from the same class", 94 | ratio_updater); 95 | 96 | useInputStream(stream); 97 | useOutputStream(oStream); 98 | usePipeline(pipeline); 99 | useLeaveOneOutScoring(false); 100 | setGUIBufferSize(kSampleRate); 101 | } 102 | -------------------------------------------------------------------------------- /Xcode/ESP/src/examples/user_speech_detection.cpp: -------------------------------------------------------------------------------- 1 | // Using algorithm 3 from "A Comparitive Study of Speech Detection Methods" 2 | // by Stefaan Van Gerven and Fei Xie 3 | // http://www.mirlab.org/conference_papers/International_Conference/Eurospeech%201997/pdf/tab/a0199.pdf 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | class LogEnergy : public Filter { 10 | public: 11 | LogEnergy(UINT filterSize = 5,UINT numDimensions = 1) 12 | : Filter("LogEnergy", filterSize, numDimensions) 13 | {} 14 | 15 | double computeFilter(const VectorDouble &buf) { 16 | double energy = 0; 17 | for (int i = 0; i < buf.size(); i++) { 18 | energy += buf[i] * buf[i]; 19 | } 20 | return log(energy); 21 | } 22 | 23 | private: 24 | static RegisterPreProcessingModule< LogEnergy > registerModule; 25 | }; 26 | 27 | RegisterPreProcessingModule< LogEnergy > LogEnergy::registerModule("LogEnergy"); 28 | 29 | AudioStream stream(100); 30 | GestureRecognitionPipeline pipeline; 31 | 32 | double alpha = 4.0, beta = 1.2; 33 | 34 | void setup() { 35 | useInputStream(stream); 36 | pipeline.addPreProcessingModule(LogEnergy(5, 1)); 37 | pipeline.addFeatureExtractionModule(ThresholdDetection(100,1,alpha,beta)); 38 | usePipeline(pipeline); 39 | 40 | registerTuneable(alpha, 1.0, 10.0, "Loudness Threshold", 41 | "How loud (relative to background noise) a sound has to be to count " 42 | "as speech / foreground audio."); 43 | registerTuneable(beta, 1.0, 10.0, "Quietness Threshold", 44 | "How quiest (relative to background noise) the speech / foreground " 45 | "audio has to get to be considered finished."); 46 | } -------------------------------------------------------------------------------- /Xcode/ESP/src/examples/user_sudden_motion.cpp: -------------------------------------------------------------------------------- 1 | /** @example user_sudden_motion.cpp 2 | * Detect sudden motions. 3 | */ 4 | #include 5 | 6 | ASCIISerialStream stream(0, 9600, 3); 7 | GestureRecognitionPipeline pipeline; 8 | Calibrator calibrator; 9 | 10 | double zeroG = 0, oneG = 0; 11 | 12 | double processAccelerometerData(double input) { 13 | return (input - zeroG) / (oneG - zeroG); 14 | } 15 | 16 | CalibrateResult restingDataCollected(const MatrixDouble& data) { 17 | // take average of X and Y acceleration as the zero G value 18 | zeroG = (data.getMean()[0] + data.getMean()[1]) / 2; 19 | oneG = data.getMean()[2]; // use Z acceleration as one G value 20 | 21 | return CalibrateResult::SUCCESS; 22 | } 23 | 24 | int num_dim = 3; 25 | 26 | void setup() { 27 | stream.setLabelsForAllDimensions({"x", "y", "z"}); 28 | useInputStream(stream); 29 | 30 | calibrator.setCalibrateFunction(processAccelerometerData); 31 | calibrator.addCalibrateProcess("Resting", 32 | "Rest accelerometer on flat surface.", restingDataCollected); 33 | useCalibrator(calibrator); 34 | 35 | pipeline.addPreProcessingModule( 36 | Derivative(Derivative::FIRST_DERIVATIVE, 1, num_dim)); 37 | pipeline.addFeatureExtractionModule( 38 | ZeroCrossingCounter(3, 0.1, num_dim, ZeroCrossingCounter::COMBINED_FEATURE_MODE)); 39 | usePipeline(pipeline); 40 | } 41 | -------------------------------------------------------------------------------- /Xcode/ESP/src/examples/user_touche.cpp: -------------------------------------------------------------------------------- 1 | /** @example user_touche.cpp 2 | Touche example. See documentation on the wiki. 3 | */ 4 | 5 | #include 6 | 7 | BinaryIntArraySerialStream stream(115200, 160); 8 | TcpOStream oStream("localhost", 5204); 9 | GestureRecognitionPipeline pipeline; 10 | 11 | void setup() 12 | { 13 | useStream(stream); 14 | useOutputStream(oStream); 15 | 16 | pipeline.setClassifier(SVM(SVM::POLY_KERNEL, SVM::C_SVC, false, true, true, 0.1, 1.0, 0, 0.5, 2)); 17 | usePipeline(pipeline); 18 | 19 | setTruePositiveWarningThreshold(0.90); 20 | setFalseNegativeWarningThreshold(0.10); 21 | 22 | useLeaveOneOutScoring(false); 23 | } -------------------------------------------------------------------------------- /Xcode/ESP/src/iostream.cpp: -------------------------------------------------------------------------------- 1 | #include "iostream.h" 2 | 3 | void ASCIISerialStream::onReceive(uint32_t label) { 4 | serial_->writeByte(label + '0'); 5 | serial_->writeByte('\n'); 6 | } 7 | 8 | void ASCIISerialStream::onReceive(vector data) { 9 | for (int i = 0; i < data.size(); i++) { 10 | string s = to_string(data[i]); 11 | if (i > 0) serial_->writeByte('\t'); 12 | for (int j = 0; j < s.size(); j++) serial_->writeByte(s[j]); 13 | } 14 | if (data.size() > 0) serial_->writeByte('\n'); 15 | } 16 | 17 | void ASCIISerialStream::parseSerial(vector &buffer) { 18 | auto newline = find(buffer.begin(), buffer.end(), '\n'); 19 | if (newline != buffer.end()) { 20 | string s(buffer.begin(), newline); 21 | 22 | buffer.erase(buffer.begin(), ++newline); 23 | 24 | if (data_ready_callback_ != nullptr) { 25 | istringstream iss(s); 26 | vector data; 27 | double d; 28 | 29 | while (iss >> d) data.push_back(d); 30 | 31 | if (data.size() > 0) { 32 | data = normalize(data); 33 | 34 | GRT::MatrixDouble matrix; 35 | matrix.push_back(data); 36 | 37 | data_ready_callback_(matrix); 38 | } 39 | } 40 | } 41 | } 42 | 43 | void BinaryIntArraySerialStream::onReceive(uint32_t label) { 44 | serial_->writeByte(label + '0'); 45 | serial_->writeByte('\n'); 46 | } 47 | 48 | void BinaryIntArraySerialStream::onReceive(vector data) { 49 | for (int i = 0; i < data.size(); i++) { 50 | string s = to_string(data[i]); 51 | if (i > 0) serial_->writeByte('\t'); 52 | for (int j = 0; j < s.size(); j++) serial_->writeByte(s[j]); 53 | } 54 | if (data.size() > 0) serial_->writeByte('\n'); 55 | } 56 | 57 | void BinaryIntArraySerialStream::parseSerial(vector &buffer) { 58 | auto start = std::find(buffer.begin(), buffer.end(), 0); // look for packet start 59 | if (start != buffer.end()) { 60 | buffer.erase(buffer.begin(), start); // advance to start of packet 61 | if (buffer.size() >= 3) { // 0, LSB(n), MSB(n) 62 | unsigned char checksum = 0; 63 | int LSB = buffer[1]; checksum += LSB; 64 | int MSB = buffer[2]; checksum += MSB; 65 | int n = ((MSB & 0x7F) << 7) | (LSB & 0x7F); 66 | if (buffer.size() >= 4 + 2 * n) { 67 | vector vals; 68 | //std::cout << "Got array of " << n << " bytes: " << buffer.size(); 69 | for (int j = 3; j < (3 + 2 * n);) { 70 | LSB = buffer[j++]; checksum += LSB; 71 | MSB = buffer[j++]; checksum += MSB; 72 | int val = ((MSB & 0x7F) << 7) | (LSB & 0x7F); 73 | //std::cout << val << " "; 74 | vals.push_back(val); 75 | } 76 | //std::cout << "(" << (checksum | 0x80) << " <> " << buffer[3 + 2 * n] << ")" << std::endl; 77 | if ((checksum | 0x80) != buffer[3 + 2 * n]) { 78 | ofLog(OF_LOG_WARNING) << "Invalid checksum, discarding serial packet."; 79 | } else if (n != getNumInputDimensions()) { 80 | ofLog(OF_LOG_WARNING) << "Serial packet contains " << n << 81 | " dimensions. Expected " << getNumInputDimensions(); 82 | } else { 83 | GRT::MatrixDouble data(1, n); 84 | for (int i = 0; i < getNumInputDimensions(); i++) { 85 | int b = vals[i]; 86 | data[0][i] = (normalizer_ != nullptr) ? normalizer_(b) : b; 87 | } 88 | if (data_ready_callback_ != nullptr) { 89 | data_ready_callback_(data); 90 | } 91 | 92 | } 93 | 94 | buffer.erase(buffer.begin(), buffer.begin() + (4 + 2 * n)); 95 | } 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Xcode/ESP/src/iostream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "istream.h" 4 | #include "ostream.h" 5 | 6 | class IOStream : public virtual InputStream, public OStream {}; 7 | class IOStreamVector : public virtual InputStream, public OStreamVector {}; 8 | 9 | /** 10 | @brief Input stream for reading ASCII data from a (USB) serial port. 11 | 12 | Data should be formatted as ASCII text, in newline-terminated lines. Each line 13 | consists of whitespace-separated numbers, e.g. 14 | @verbatim 123 45 678 90 @endverbatim 15 | The numbers in each line of text are turned into a single data sample. 16 | 17 | To use an ASCIISerialStream in your application, pass it to useStream() in 18 | your setup() function. 19 | */ 20 | class ASCIISerialStream : public BaseSerialInputStream, public IOStreamVector { 21 | public: 22 | using BaseSerialInputStream::BaseSerialInputStream; // inherit constructors 23 | 24 | virtual void onReceive(uint32_t label); 25 | virtual void onReceive(vector data); 26 | 27 | private: 28 | virtual void parseSerial(vector &buffer); 29 | }; 30 | 31 | class BinaryIntArraySerialStream : public BaseSerialInputStream, public IOStreamVector { 32 | public: 33 | using BaseSerialInputStream::BaseSerialInputStream; // inherit constructors 34 | 35 | virtual void onReceive(uint32_t label); 36 | virtual void onReceive(vector data); 37 | 38 | private: 39 | virtual void parseSerial(vector &buffer); 40 | }; 41 | -------------------------------------------------------------------------------- /Xcode/ESP/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ofApp.h" 2 | #include "ofMain.h" 3 | 4 | int main() { 5 | ofSetupOpenGL(1024, 768, OF_WINDOW); 6 | 7 | #ifdef __APPLE__ 8 | ofSetDataPathRoot("../Resources/data/"); 9 | #elif _WIN32 10 | ofSetDataPathRoot("data/"); 11 | #else 12 | ofSetDataPathRoot("."); 13 | #endif 14 | 15 | ofxDatGui::setAssetPath("./"); 16 | 17 | // this kicks off the running of my app 18 | // can be OF_WINDOW or OF_FULLSCREEN 19 | // pass in width and height too: 20 | ofRunApp(new ofApp()); 21 | } 22 | -------------------------------------------------------------------------------- /Xcode/ESP/src/ofConsoleFileLoggerChannel.cpp: -------------------------------------------------------------------------------- 1 | #include "ofConsoleFileLoggerChannel.h" 2 | 3 | ofConsoleFileLoggerChannel::ofConsoleFileLoggerChannel() {} 4 | 5 | ofConsoleFileLoggerChannel::ofConsoleFileLoggerChannel(const string & path, bool append) : 6 | fileLogger(path, append) {} 7 | 8 | void ofConsoleFileLoggerChannel::close() { 9 | fileLogger.close(); 10 | } 11 | 12 | void ofConsoleFileLoggerChannel::setFile(const string & path,bool append) { 13 | fileLogger.setFile(path, append); 14 | } 15 | 16 | void ofConsoleFileLoggerChannel::log( 17 | ofLogLevel level, const string &module, const string &message) { 18 | if (level >= consoleLogLevel) consoleLogger.log(level, module, message); 19 | if (level >= fileLogLevel) fileLogger.log(level, module, message); 20 | } 21 | 22 | void ofConsoleFileLoggerChannel::log(ofLogLevel level, const string & module, const char* format, ...){ 23 | va_list args; 24 | va_start(args, format); 25 | log(level, module, format, args); 26 | va_end(args); 27 | } 28 | 29 | void ofConsoleFileLoggerChannel::log( 30 | ofLogLevel level, const string & module, const char* format, va_list args) { 31 | if (level >= consoleLogLevel) consoleLogger.log(level, module, format, args); 32 | if (level >= fileLogLevel) fileLogger.log(level, module, format, args); 33 | } -------------------------------------------------------------------------------- /Xcode/ESP/src/ofConsoleFileLoggerChannel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /// \brief A logger channel that logs its messages to the console and a log file. 6 | class ofConsoleFileLoggerChannel: public ofBaseLoggerChannel{ 7 | public: 8 | /// \brief Create an ofConsoleFileLoggerChannel. 9 | ofConsoleFileLoggerChannel(); 10 | 11 | /// \brief Create an ofConsoleFileLoggerChannel with parameters. 12 | /// \param path The file path for the log file. 13 | /// \param append True if the log data should be added to an existing file. 14 | ofConsoleFileLoggerChannel(const string & path, bool append); 15 | 16 | /// \brief Set the log file. 17 | /// \param path The file path for the log file. 18 | /// \param append True if the log data should be added to an existing file. 19 | void setFile(const string & path,bool append=false); 20 | 21 | void log(ofLogLevel level, const string & module, const string & message); 22 | void log(ofLogLevel level, const string & module, const char* format, ...) OF_PRINTF_ATTR(4, 5); 23 | void log(ofLogLevel level, const string & module, const char* format, va_list args); 24 | 25 | /// \brief CLose the log file. 26 | void close(); 27 | 28 | /// \brief Set the minimum log level for the console log. 29 | /// 30 | /// Note that this is additional level of filtering beyond that 31 | /// provided by the global ofSetLogLevel(). Anything below that log 32 | /// level will not be logged, regardless of the value of the 33 | /// console-specific log level. 34 | /// \param level the log level to apply to the console log (defaults to 35 | /// OF_LOG_VERBOSE) 36 | void setConsoleLogLevel(ofLogLevel level) { consoleLogLevel = level; } 37 | 38 | /// \brief Set the minimum log level for the file log. 39 | /// 40 | /// Note that this is additional level of filtering beyond that 41 | /// provided by the global ofSetLogLevel(). Anything below that log 42 | /// level will not be logged, regardless of the value of the 43 | /// file-specific log level. 44 | /// \param level the log level to apply to the file log (defaults to 45 | /// OF_LOG_VERBOSE) 46 | void setFileLogLevel(ofLogLevel level) { fileLogLevel = level; } 47 | 48 | private: 49 | ofConsoleLoggerChannel consoleLogger; 50 | ofFileLoggerChannel fileLogger; 51 | 52 | ofLogLevel consoleLogLevel = OF_LOG_VERBOSE; 53 | ofLogLevel fileLogLevel = OF_LOG_VERBOSE; 54 | }; -------------------------------------------------------------------------------- /Xcode/ESP/src/ofYesNoDialog.cpp: -------------------------------------------------------------------------------- 1 | // https://forum.openframeworks.cc/t/how-about-a-yesno-dialogue-box/14001 2 | 3 | #include "ofConstants.h" 4 | #include "ofYesNoDialog.h" 5 | 6 | #ifdef TARGET_OSX 7 | // ofSystemUtils.cpp is configured to build as 8 | // objective-c++ so as able to use Cocoa dialog panels 9 | // This is done with this compiler flag 10 | // -x objective-c++ 11 | // http://www.yakyak.org/viewtopic.php?p=1475838&sid=1e9dcb5c9fd652a6695ac00c5e957822#p1475838 12 | 13 | #include 14 | #endif 15 | 16 | #if defined( TARGET_LINUX ) && defined (OF_USING_GTK) 17 | #include 18 | #include "ofGstUtils.h" 19 | #include "Poco/Condition.h" 20 | 21 | static void initGTK(){ 22 | static bool initialized = false; 23 | if(!initialized){ 24 | #if !defined(TARGET_RASPBERRY_PI) 25 | XInitThreads(); 26 | #endif 27 | int argc=0; char **argv = nullptr; 28 | gtk_init (&argc, &argv); 29 | ofGstUtils::startGstMainLoop(); 30 | initialized = true; 31 | } 32 | } 33 | #endif 34 | 35 | //------------------------------------------------------------------------------ 36 | bool ofSystemYesNoDialog(string title,string message){ 37 | 38 | 39 | #ifdef TARGET_WIN32 40 | int length = strlen(title.c_str()); 41 | wchar_t * widearray = new wchar_t[length+1]; 42 | memset(widearray, 0, sizeof(wchar_t)*(length+1)); 43 | mbstowcs(widearray, title.c_str(), length); 44 | int length2 = strlen(message.c_str()); 45 | wchar_t * widearray2 = new wchar_t[length2+1]; 46 | memset(widearray2, 0, sizeof(wchar_t)*(length2+1)); 47 | mbstowcs(widearray2, message.c_str(), length2); 48 | int dialogueResult = MessageBoxW(NULL, widearray2, widearray, MB_OKCANCEL); 49 | delete widearray; 50 | delete widearray2; 51 | return dialogueResult == 1; 52 | #endif 53 | 54 | 55 | #ifdef TARGET_OSX 56 | NSAlert *alert = [[[NSAlert alloc] init] autorelease]; 57 | [alert addButtonWithTitle:@"OK"]; 58 | [alert addButtonWithTitle:@"Cancel"]; 59 | [alert setMessageText:[NSString stringWithCString:title.c_str() 60 | encoding:NSUTF8StringEncoding]]; 61 | [alert setInformativeText:[NSString stringWithCString:message.c_str() 62 | encoding:NSUTF8StringEncoding]]; 63 | 64 | NSInteger returnCode = [alert runModal]; 65 | 66 | return returnCode == NSAlertFirstButtonReturn; 67 | 68 | #endif 69 | //only works for pc and mac // shouldn't be hard to do the linux version though 70 | #if defined( TARGET_LINUX ) && defined (OF_USING_GTK) 71 | initGTK(); 72 | GtkWidget* dialog = gtk_message_dialog_new (NULL, (GtkDialogFlags) 0, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL, "%s", title.c_str()); 73 | gint response = gtk_dialog_run (GTK_DIALOG (dialog)); 74 | gtk_widget_destroy (dialog); 75 | return response == GTK_RESPONSE_OK; 76 | #endif 77 | 78 | #ifdef TARGET_ANDROID 79 | ofxAndroidAlertBox(title); 80 | #endif 81 | } 82 | -------------------------------------------------------------------------------- /Xcode/ESP/src/ofYesNoDialog.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | bool ofSystemYesNoDialog(string title="Alert",string message=""); -------------------------------------------------------------------------------- /Xcode/ESP/src/ofxGrtSettings.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // ofxGrtSettings.h 3 | // 4 | // Created by luca lolli on 11/08/2016. 5 | // Updated: nickgillian: 26/09/2016 6 | // 7 | #include "ofxGrtSettings.h" 8 | 9 | //We need to declare our static non-const variable after being definid in the header 10 | std::shared_ptr ofxGrtSettings::mVariables; 11 | 12 | ofTrueTypeFont ofxGrtSettings::variables::fontSmall; 13 | ofTrueTypeFont ofxGrtSettings::variables::fontNormal; 14 | ofTrueTypeFont ofxGrtSettings::variables::fontLarge; 15 | std::string ofxGrtSettings::variables::fontFile = "verdana.ttf"; 16 | ofColor ofxGrtSettings::variables::activeTextColor = {255,255,255}; 17 | ofColor ofxGrtSettings::variables::gridColor = {64,64,64}; 18 | ofColor ofxGrtSettings::variables::axisColor = {192,192,192}; 19 | ofColor ofxGrtSettings::variables::backgroundColor = {0,0,0}; 20 | ofColor ofxGrtSettings::variables::disabledTextColor = {128,128,128}; 21 | int ofxGrtSettings::variables::titleTextSpacer = -12; 22 | int ofxGrtSettings::variables::axisTicksSize = 5; 23 | int ofxGrtSettings::variables::info_margin = 15; 24 | 25 | -------------------------------------------------------------------------------- /Xcode/ESP/src/ostream.cpp: -------------------------------------------------------------------------------- 1 | #include "ostream.h" 2 | #include "ofUtils.h" 3 | 4 | #ifdef TARGET_WIN32 5 | #define _WINSOCKAPI_ 6 | #define WIN32_LEAN_AND_MEAN 7 | #include 8 | #include 9 | #include 10 | #endif 11 | 12 | #include 13 | #include "ofxTCPClient.h" 14 | 15 | #if __APPLE__ 16 | #include 17 | #endif 18 | 19 | void MacOSKeyboardOStream::sendKey(char c) { 20 | #if __APPLE__ 21 | if (ofGetElapsedTimeMillis() < elapsed_time_ + kGracePeriod) { 22 | return; 23 | } 24 | elapsed_time_ = ofGetElapsedTimeMillis(); 25 | 26 | // Get the process number for the front application. 27 | ProcessSerialNumber psn = { 0, kNoProcess }; 28 | GetFrontProcess( &psn ); 29 | 30 | UniChar uni_char = c; 31 | CGEventRef key_down = CGEventCreateKeyboardEvent(NULL, 0, true); 32 | CGEventRef key_up = CGEventCreateKeyboardEvent(NULL, 0, false); 33 | CGEventKeyboardSetUnicodeString(key_down, 1, &uni_char); 34 | CGEventKeyboardSetUnicodeString(key_up, 1, &uni_char); 35 | CGEventPostToPSN(&psn, key_down); 36 | CGEventPostToPSN(&psn, key_up); 37 | CFRelease(key_down); 38 | CFRelease(key_up); 39 | #endif 40 | } 41 | 42 | void MacOSKeyboardOStream::sendKeyCode(uint16_t key) { 43 | #if __APPLE__ 44 | if (ofGetElapsedTimeMillis() < elapsed_time_ + kGracePeriod) { 45 | return; 46 | } 47 | elapsed_time_ = ofGetElapsedTimeMillis(); 48 | 49 | // Get the process number for the front application. 50 | ProcessSerialNumber psn = { 0, kNoProcess }; 51 | GetFrontProcess( &psn ); 52 | 53 | CGEventRef key_down = CGEventCreateKeyboardEvent(NULL, key, true); 54 | CGEventRef key_up = CGEventCreateKeyboardEvent(NULL, key, false); 55 | CGEventPostToPSN(&psn, key_down); 56 | CGEventPostToPSN(&psn, key_up); 57 | CFRelease(key_down); 58 | CFRelease(key_up); 59 | #endif 60 | } 61 | 62 | void MacOSKeyboardOStream::sendString(const std::string& str) { 63 | #if __APPLE__ 64 | // Get the process number for the front application. 65 | ProcessSerialNumber psn = { 0, kNoProcess }; 66 | GetFrontProcess( &psn ); 67 | 68 | UniChar s[str.length()]; 69 | for (uint32_t i = 0; i < str.length(); i++) { 70 | s[i] = str[i]; 71 | } 72 | 73 | CGEventRef e = CGEventCreateKeyboardEvent(NULL, 0, true); 74 | CGEventKeyboardSetUnicodeString(e, str.length(), s); 75 | CGEventPostToPSN(&psn, e); 76 | CFRelease(e); 77 | #endif 78 | } 79 | 80 | void MacOSMouseOStream::clickMouse(pair mouse) { 81 | #if __APPLE__ 82 | if (ofGetElapsedTimeMillis() < elapsed_time_ + kGracePeriod) { 83 | return; 84 | } 85 | elapsed_time_ = ofGetElapsedTimeMillis(); 86 | 87 | doubleClick(mouse); 88 | #endif 89 | } 90 | 91 | void MacOSMouseOStream::doubleClick(pair mouse, int clickCount) { 92 | #if __APPLE__ 93 | CGPoint point = CGPointMake(mouse.first, mouse.second); 94 | CGEventRef theEvent = CGEventCreateMouseEvent( 95 | NULL, kCGEventLeftMouseDown, point, kCGMouseButtonLeft); 96 | 97 | ProcessSerialNumber psn = { 0, kNoProcess }; 98 | GetFrontProcess( &psn ); 99 | 100 | CGEventSetIntegerValueField(theEvent, kCGMouseEventClickState, clickCount); 101 | CGEventPostToPSN(&psn, theEvent); 102 | CGEventSetType(theEvent, kCGEventLeftMouseUp); 103 | CGEventPostToPSN(&psn, theEvent); 104 | CGEventSetType(theEvent, kCGEventLeftMouseDown); 105 | CGEventPostToPSN(&psn, theEvent); 106 | CGEventSetType(theEvent, kCGEventLeftMouseUp); 107 | CGEventPostToPSN(&psn, theEvent); 108 | CFRelease(theEvent); 109 | #endif 110 | } 111 | 112 | bool TcpOStream::start() { 113 | if (client_ == nullptr) { 114 | client_ = new ofxTCPClient(); 115 | } 116 | has_started_ = client_->setup(server_, port_); 117 | return has_started_; 118 | } 119 | 120 | void TcpOStream::sendString(const string& tosend) { 121 | if (client_ != nullptr && client_->isConnected()) { 122 | client_->sendRaw(tosend); 123 | } 124 | 125 | // If not connected, we start a new thread that tries to connect 126 | if (!client_->isConnected() && !is_in_retry_) { 127 | is_in_retry_ = true; 128 | auto t = std::thread([this] () { 129 | while (!this->client_->setup(server_, port_)) { 130 | std::this_thread::sleep_for(std::chrono::seconds(1)); 131 | } 132 | is_in_retry_ = false; 133 | }); 134 | t.detach(); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /Xcode/ESP/src/plotter.cpp: -------------------------------------------------------------------------------- 1 | #include "plotter.h" 2 | 3 | using std::string; 4 | 5 | Plotter::Plotter() : 6 | initialized_(false), is_content_modified_(false), is_in_renaming_(false), 7 | lock_ranges_(false), minY_(0), maxY_(0) { 8 | // Constructor 9 | } 10 | 11 | bool Plotter::setup(uint32_t num_dimensions, string title, string subtitle) { 12 | num_dimensions_ = num_dimensions; 13 | title_ = title; 14 | subtitle_ = subtitle; 15 | 16 | colors_.resize(num_dimensions_); 17 | // Setup the default colors_ 18 | if (num_dimensions >= 1) colors_[0] = ofColor(255, 0, 0); // red 19 | if (num_dimensions >= 2) colors_[1] = ofColor(0, 255, 0); // green 20 | if (num_dimensions >= 3) colors_[2] = ofColor(0, 0, 255); // blue 21 | 22 | // Randomize the remaining colors_ 23 | for (uint32_t n = 3; n < num_dimensions_; n++){ 24 | colors_[n][0] = ofRandom(50, 255); 25 | colors_[n][1] = ofRandom(50, 255); 26 | colors_[n][2] = ofRandom(50, 255); 27 | } 28 | 29 | initialized_ = true; 30 | return true; 31 | } 32 | 33 | bool Plotter::setData(const GRT::MatrixDouble& data) { 34 | x_start_ = 0; 35 | x_end_ = 0; 36 | data_.clear(); 37 | for (int i = 0; i < data.getNumRows(); i++) push_back(data.getRowVector(i)); 38 | is_content_modified_ = true; 39 | return true; 40 | } 41 | 42 | bool Plotter::clearContentModifiedFlag() { 43 | is_content_modified_ = false; 44 | return true; 45 | } 46 | 47 | bool Plotter::push_back(const vector& data_point) { 48 | data_.push_back(data_point); 49 | for (double d : data_point) { 50 | if (d > maxY_) { maxY_ = d; } 51 | if (d < minY_) { minY_ = d; } 52 | } 53 | is_content_modified_ = true; 54 | return true; 55 | } 56 | 57 | bool Plotter::setRanges(float minY, float maxY, bool lockRanges) { 58 | if (minY > maxY) { return false; } 59 | 60 | default_minY_ = minY_ = minY; 61 | default_maxY_ = maxY_ = maxY; 62 | lock_ranges_ = lockRanges; 63 | return true; 64 | } 65 | 66 | std::pair Plotter::getRanges() { 67 | return lock_ranges_ ? 68 | std::make_pair(default_minY_, default_maxY_) : 69 | std::make_pair(minY_, maxY_); 70 | } 71 | 72 | bool Plotter::setColorPalette(const vector& colors) { 73 | if (colors.size() == num_dimensions_) { 74 | colors_ = colors; 75 | return true; 76 | } else { 77 | return false; 78 | } 79 | } 80 | 81 | bool Plotter::setTitle(const string& title) { 82 | title_ = title; 83 | return true; 84 | } 85 | 86 | void Plotter::renameTitleStart() { 87 | is_in_renaming_ = true; 88 | } 89 | 90 | void Plotter::renameTitleDone() { 91 | is_in_renaming_ = false; 92 | } 93 | 94 | const string& Plotter::getTitle() const { 95 | return title_; 96 | } 97 | 98 | bool Plotter::draw(uint32_t x, uint32_t y, uint32_t w, uint32_t h) { 99 | x_ = x; 100 | y_ = y; 101 | w_ = w; 102 | h_ = h; 103 | 104 | if (!initialized_) return false; 105 | 106 | ofPushMatrix(); 107 | ofPushStyle(); 108 | 109 | ofEnableAlphaBlending(); 110 | ofTranslate(x, y); 111 | 112 | // Draw the background 113 | ofSetColor(background_color_); 114 | ofFill(); 115 | ofDrawRectangle(0, 0, w, h); 116 | 117 | // Draw the selection. 118 | ofSetColor(0x1F, 0x1F, 0x1F); 119 | if (x_start_ > 0 && x_end_ > x_start_) { 120 | ofDrawRectangle(x_start_, 0, x_end_ - x_start_, h); 121 | } 122 | 123 | // Draw the axis lines 124 | ofSetColor(grid_color_); 125 | ofDrawLine(-5, h, w+5, h); // X Axis 126 | ofDrawLine(0, -5, 0, h+5); // Y Axis 127 | 128 | // Draw the timeseries 129 | float xPos = 0; 130 | float x_step = 1.0 * w_ / data_.getNumRows(); 131 | 132 | uint32_t index = 0; 133 | ofNoFill(); 134 | for(uint32_t n = 0; n < num_dimensions_; n++){ 135 | xPos = 0; 136 | ofSetColor(colors_[n][0], colors_[n][1], colors_[n][2]); 137 | ofBeginShape(); 138 | for(uint32_t i = 0; i < data_.getNumRows(); i++){ 139 | float min = lock_ranges_ ? default_minY_ : minY_; 140 | float max = lock_ranges_ ? default_maxY_ : maxY_; 141 | ofVertex(xPos, ofMap(data_[i][n], min, max, h, 0, true)); 142 | xPos += x_step; 143 | } 144 | ofEndShape(false); 145 | } 146 | 147 | // Draw the title 148 | ofSetColor(text_color_); 149 | int ofBitmapFontHeight = 14; 150 | int textX = 10; 151 | int textY = ofBitmapFontHeight + 5; 152 | if (title_ != ""){ 153 | string display_title = title_; 154 | 155 | // If modified and not in renaming, show a start 156 | if (is_content_modified_ && !is_in_renaming_) { 157 | display_title += "*"; 158 | } 159 | ofSetColor(0xFF, 0xFF, 0xFF); 160 | ofDrawBitmapString(display_title, textX, textY); 161 | } 162 | 163 | if (subtitle_ != "") { 164 | ofSetColor(0x99, 0x99, 0x99); 165 | ofDrawBitmapString(subtitle_, textX, textY + 15); 166 | } 167 | 168 | ofPopStyle(); 169 | ofPopMatrix(); 170 | return true; 171 | } 172 | 173 | bool Plotter::reset() { 174 | if (!initialized_) return false; 175 | x_start_ = 0; 176 | x_end_ = 0; 177 | minY_ = 0; 178 | maxY_ = 0; 179 | data_.clear(); 180 | return true; 181 | } 182 | 183 | bool Plotter::clearData() { 184 | if (!initialized_) return false; 185 | data_.clear(); 186 | return true; 187 | } 188 | -------------------------------------------------------------------------------- /Xcode/ESP/src/stream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include 5 | 6 | class Stream { 7 | public: 8 | Stream() : has_started_(false) {} 9 | 10 | /** 11 | Start the stream. 12 | */ 13 | virtual bool start() { has_started_ = true; return true; } 14 | virtual void stop() { has_started_ = false; } 15 | 16 | void toggle() { 17 | if (has_started_) { stop(); } 18 | else { start(); } 19 | } 20 | 21 | bool hasStarted() { return has_started_; } 22 | 23 | protected: 24 | std::atomic_bool has_started_; 25 | }; 26 | -------------------------------------------------------------------------------- /Xcode/ESP/src/training-data-manager.h: -------------------------------------------------------------------------------- 1 | /** @file training-data-manager.h 2 | * @brief TrainingDataManager class that manages the training data and 3 | * abstracts out common operations on the data. 4 | * 5 | * @author Ben Zhang (benzh) 6 | * @bug Currently we are not doing bound-checking. Operations over invalid 7 | * label/index will cause crashing 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | using std::vector; 18 | 19 | /** 20 | * @brief TrainingDataManager class encloses GRT::TimeSeriesClassificationData 21 | * and improves upon by adding utility functions that relabel, delete or trim 22 | * some training samples. 23 | * 24 | * This class will take the sole mutable ownership of the enclosed data. All 25 | * operations over the training data have to gone through this class. 26 | * 27 | * Training data can be viewed as a collection of training samples, where each 28 | * sample consists of a label (which class this sample belongs to) and the data 29 | * (a time-series data). 30 | * 31 | * A few key augmentation to the underlying TimeSeriesClassificationData: 32 | * 1. Edit (relabel, delete or trim individual samples). 33 | * 2. Name individual sample. 34 | * 35 | * Each individual sample is addressable by (label, index) tuple. Label starts 36 | * from 1 and index starts from 0. 37 | */ 38 | class TrainingDataManager { 39 | public: 40 | // Constructor 41 | TrainingDataManager(uint32_t num_classes); 42 | 43 | // Set the dimension of the training data 44 | bool setNumDimensions(uint32_t dim); 45 | 46 | // Set the name of the training data 47 | bool setDatasetName(const std::string name); 48 | 49 | // Set the name of the training data 50 | bool setDatasetName(const char* const name); 51 | 52 | GRT::TimeSeriesClassificationData getAllData() { return data_; } 53 | 54 | uint32_t getNumLabels() { return num_classes_; } 55 | 56 | uint32_t getTotalNumSamples() { return data_.getNumSamples(); } 57 | 58 | // ================================================= 59 | // Functions that enables per-sample naming 60 | // ================================================= 61 | 62 | /// @brief This will modify the default name for this label, changing it 63 | /// from "Label X" to `name`. 64 | bool setNameForLabel(const std::string name, uint32_t label); 65 | std::string getLabelName(uint32_t label); 66 | 67 | /// @brief Format the sample name. 68 | /// Default label name is "Label X", and the sample name is "Label X [Y]" 69 | /// Default name can be changed by `setNameForLabel`. 70 | std::string getSampleName(uint32_t label, uint32_t index); 71 | bool setSampleName(uint32_t, uint32_t, const std::string); 72 | 73 | // ================================================= 74 | // Functions that simplifies editing 75 | // ================================================= 76 | 77 | /// @brief Add new sample. Returns false if the label is larger than 78 | /// configured number of classes. 79 | bool addSample(uint32_t label, const GRT::MatrixDouble& sample); 80 | 81 | uint32_t getNumSampleForLabel(uint32_t label); 82 | 83 | /// @brief Get the sample by label and index. 84 | GRT::MatrixDouble getSample(uint32_t label, uint32_t index); 85 | 86 | /// @brief Remove sample by label and the index. 87 | bool deleteSample(uint32_t label, uint32_t index); 88 | 89 | /// @brief Remove all samples 90 | bool deleteAllSamples(); 91 | 92 | /// @brief Remove all samples 93 | bool deleteAllSamplesWithLabel(uint32_t label); 94 | 95 | /// @brief Relabel a sample from `label` to `new_label`. 96 | bool relabelSample(uint32_t label, uint32_t index, uint32_t new_label); 97 | 98 | /// @brief Trim sample. What's left will be [start, end], closed interval. 99 | bool trimSample(uint32_t label, uint32_t index, uint32_t start, 100 | uint32_t end); 101 | 102 | // ================================================= 103 | // Functions that manage per-sample scores 104 | // ================================================= 105 | 106 | bool hasSampleScore(uint32_t label, uint32_t index); 107 | double getSampleScore(uint32_t label, uint32_t index); 108 | bool setSampleScore(uint32_t label, uint32_t index, double score); 109 | 110 | bool hasSampleClassLikelihoods(uint32_t label, uint32_t index); 111 | vector getSampleClassLikelihoods(uint32_t label, uint32_t index); 112 | bool setSampleClassLikelihoods(uint32_t label, uint32_t index, 113 | vector likelihoods); 114 | 115 | // ================================================= 116 | // Functions for saving/loading training data 117 | // ================================================= 118 | 119 | inline bool save(const std::string& filename) { 120 | return data_.save(filename); 121 | } 122 | 123 | bool load(const std::string& filename); 124 | 125 | private: 126 | uint32_t num_classes_; 127 | 128 | // Name simulates Option type. If `Name.first` is true, then 129 | // the name is valid; else use the default name. 130 | using Name = std::pair; 131 | vector> training_sample_names_; 132 | vector default_label_names_; 133 | 134 | // Score simulates Option type. If `Score.first` is true, then 135 | // the score is valid; else use the default score. 136 | using Score = std::pair; 137 | vector> training_sample_scores_; 138 | 139 | // Probability that the sample belongs to each class (e.g. when the model 140 | // is trained on all other samples). If ClassLikelihoods.first is true, 141 | // then vector is valid. 142 | using ClassLikelihoods = std::pair>; 143 | vector> training_sample_class_likelihoods_; 144 | 145 | // This variable tracks the number of samples for each label. Although We 146 | // can get the number with TimeSeriesClassificationData::getClassData and 147 | // then getNumSamples. Caching the information here helps with bound checks! 148 | // 149 | // The use of this class requires index not beyond the 150 | // num_samples_per_label_. 151 | vector num_samples_per_label_; 152 | 153 | // The underlying data store backed up by GRT's TimeSeriesClassificationData 154 | GRT::TimeSeriesClassificationData data_; 155 | 156 | // Disallow copy and assign 157 | TrainingDataManager(TrainingDataManager&) = delete; 158 | void operator=(TrainingDataManager) = delete; 159 | }; 160 | -------------------------------------------------------------------------------- /Xcode/ESP/src/training.cpp: -------------------------------------------------------------------------------- 1 | #include "training.h" 2 | 3 | const string TrainingSampleCheckerResult::kDefaultSuccessMessage = "Success"; 4 | const string TrainingSampleCheckerResult::kDefaultWarningMessage = "Warning"; 5 | const string TrainingSampleCheckerResult::kDefaultFailureMessage = "Error"; 6 | 7 | TrainingSampleCheckerResult::TrainingSampleCheckerResult(Result result) : result_(result) { 8 | switch (result) { 9 | case SUCCESS: 10 | result_message_ = kDefaultSuccessMessage; 11 | break; 12 | case WARNING: 13 | result_message_ = kDefaultWarningMessage; 14 | break; 15 | case FAILURE: 16 | result_message_ = kDefaultFailureMessage; 17 | break; 18 | } 19 | } 20 | 21 | TrainingSampleCheckerResult::TrainingSampleCheckerResult(Result result, string message) 22 | : result_(result), result_message_(std::move(message)) { 23 | } 24 | -------------------------------------------------------------------------------- /Xcode/ESP/src/training.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /** 6 | @brief TrainingSampleCheckerResult indicates the result of a check of a training sample. 7 | 8 | There are three supported result: SUCCESS, WARNING, FAILURE. An optional string 9 | description can be supplied to better assist user figuring out why the 10 | training sample fails. This class is used as the return value for the functions 11 | passed to useTrainingSampleChecker(). 12 | 13 | You can create a TrainingSampleCheckerResult like this: 14 | 15 | return TrainingSampleCheckerResult(TrainingSampleCheckerResult::FAILURE, "Error: Something went wrong."); 16 | 17 | Or just use the Result directly if you don't want to supply a custom message: 18 | 19 | return TrainingSampleCheckerResult::SUCCESS; // use default message 20 | */ 21 | class TrainingSampleCheckerResult { 22 | public: 23 | enum Result { 24 | SUCCESS, 25 | WARNING, 26 | FAILURE, 27 | }; 28 | 29 | TrainingSampleCheckerResult(Result result); 30 | TrainingSampleCheckerResult(Result result, string message); 31 | 32 | Result getResult() const { return result_; } 33 | string getMessage() const { return result_message_; } 34 | 35 | private: 36 | Result result_; 37 | string result_message_; 38 | 39 | static const string kDefaultSuccessMessage; 40 | static const string kDefaultWarningMessage; 41 | static const string kDefaultFailureMessage; 42 | }; 43 | 44 | /** 45 | @brief function that takes a constant reference to a GRT MatrixDouble and 46 | returns a TrainingSampleCheckerResult 47 | 48 | The training sample checker functions passed to useTrainingSampleChecker() 49 | take a const reference to a GRT MatrixDouble and return a 50 | TrainingSampleCheckerResult, e.g. 51 | 52 | TrainingSampleCheckerResult myChecker(const MatrixDouble &data) 53 | */ 54 | typedef TrainingSampleCheckerResult (*TrainingSampleChecker)( 55 | const GRT::MatrixDouble&); 56 | -------------------------------------------------------------------------------- /Xcode/ESP/src/tuneable.cpp: -------------------------------------------------------------------------------- 1 | #include "tuneable.h" 2 | 3 | #include 4 | 5 | #include "ofApp.h" 6 | 7 | static std::map allTuneables; 8 | 9 | void Tuneable::onSliderEvent(ofxDatGuiSliderEvent e) { 10 | for (const auto& t : allTuneables) { 11 | void* data_ptr = t.second->getDataAddress(); 12 | void* ui_ptr = t.second->getUIAddress(); 13 | if (e.target == ui_ptr) { 14 | if (t.second->getType() == Tuneable::INT_RANGE) { 15 | int* value = static_cast(data_ptr); 16 | int set_value = std::round(e.value); 17 | *value = set_value; 18 | 19 | // Because slider only supports double, we have to manually 20 | // round it to match integer semantics. 21 | e.target->setValue(set_value); 22 | 23 | if (t.second->int_cb_ != nullptr) { 24 | t.second->int_cb_(*value); 25 | } else { 26 | ((ofApp *) ofGetAppPtr())->reloadPipelineModules(); 27 | } 28 | 29 | ESP_EVENT("Tune " + t.second->title_ + " " + t.second->toString()); 30 | } else { 31 | double* value = static_cast(data_ptr); 32 | *value = e.value; 33 | 34 | if (t.second->double_cb_ != nullptr) { 35 | t.second->double_cb_(*value); 36 | } else { 37 | ((ofApp *) ofGetAppPtr())->reloadPipelineModules(); 38 | } 39 | ESP_EVENT("Tune " + t.second->title_ + " " + t.second->toString()); 40 | } 41 | } 42 | } 43 | } 44 | 45 | void Tuneable::onToggleEvent(ofxDatGuiButtonEvent e) { 46 | for (const auto& t : allTuneables) { 47 | void* data_ptr = t.second->getDataAddress(); 48 | void* ui_ptr = t.second->getUIAddress(); 49 | if (e.target == ui_ptr) { 50 | bool* value = static_cast(data_ptr); 51 | *value = e.enabled; 52 | 53 | if (t.second->bool_cb_ != nullptr) { 54 | t.second->bool_cb_(*value); 55 | } else { 56 | ((ofApp *) ofGetAppPtr())->reloadPipelineModules(); 57 | } 58 | ESP_EVENT("Tune " + t.second->title_ + " " + t.second->toString()); 59 | } 60 | } 61 | } 62 | 63 | void registerTuneable(int& value, int min, int max, 64 | const string& title, 65 | const string& description, 66 | std::function cb) { 67 | void* address = &value; 68 | if (allTuneables.find(address) != allTuneables.end()) { 69 | return; 70 | } 71 | 72 | Tuneable* t = new Tuneable(&value, min, max, title, description, cb); 73 | allTuneables[address] = t; 74 | ((ofApp *) ofGetAppPtr())->registerTuneable(t); 75 | } 76 | 77 | void registerTuneable(double& value, double min, double max, 78 | const string& title, 79 | const string& description, 80 | std::function cb) { 81 | void* address = &value; 82 | if (allTuneables.find(address) != allTuneables.end()) { 83 | return; 84 | } 85 | 86 | Tuneable* t = new Tuneable(&value, min, max, title, description, cb); 87 | allTuneables[address] = t; 88 | ((ofApp *) ofGetAppPtr())->registerTuneable(t); 89 | } 90 | 91 | void registerTuneable(bool& value, 92 | const string& title, 93 | const string& description, 94 | std::function cb) { 95 | void* address = &value; 96 | if (allTuneables.find(address) != allTuneables.end()) { 97 | return; 98 | } 99 | 100 | Tuneable* t = new Tuneable(&value, title, description, cb); 101 | allTuneables[address] = t; 102 | ((ofApp *) ofGetAppPtr())->registerTuneable(t); 103 | } 104 | -------------------------------------------------------------------------------- /Xcode/ESP/src/user.cpp: -------------------------------------------------------------------------------- 1 | #include "user.h" 2 | 3 | // This is a hack. 4 | // Otherwise, we will need to create a target for each user application. 5 | //#include "examples/user_audio_beat_detection.cpp" 6 | //#include "examples/user_color_sensor.cpp" 7 | #include "examples/user_accelerometer_gestures.cpp" 8 | //#include "examples/user_accelerometer_gestures_simple.cpp" 9 | //#include "examples/user_accelerometer_gestures_osc.cpp" 10 | //#include "examples/user_accelerometer_poses.cpp" 11 | //#include "examples/user_accelerometer_walk_detection.cpp" 12 | //#include "examples/user_capacitive_sensing.cpp" 13 | //#include "examples/user_speech_detection.cpp" 14 | //#include "examples/user_speaker.cpp" 15 | //#include "examples/user_sudden_motion.cpp" 16 | //#include "examples/user_touche.cpp" 17 | -------------------------------------------------------------------------------- /Xcode/ESP/src/user.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void setup(); 4 | -------------------------------------------------------------------------------- /cmake/DetectArch.cmake: -------------------------------------------------------------------------------- 1 | ## Adapted from https://github.com/credentials/elvira 2 | 3 | set(arch_detection_code " 4 | #if defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM) 5 | #if defined(__ARM_ARCH_7__) \\ 6 | || defined(__ARM_ARCH_7A__) \\ 7 | || defined(__ARM_ARCH_7R__) \\ 8 | || defined(__ARM_ARCH_7M__) \\ 9 | || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 7) \\ 10 | || (defined(_M_ARM) && _M_ARM-0 >= 7) 11 | #error cmake_ARCH armv7 12 | #elif defined(__ARM_ARCH_6__) \\ 13 | || defined(__ARM_ARCH_6J__) \\ 14 | || defined(__ARM_ARCH_6T2__) \\ 15 | || defined(__ARM_ARCH_6Z__) \\ 16 | || defined(__ARM_ARCH_6K__) \\ 17 | || defined(__ARM_ARCH_6ZK__) \\ 18 | || defined(__ARM_ARCH_6M__) \\ 19 | || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 6) \\ 20 | || (defined(_M_ARM) && _M_ARM-0 >= 6) 21 | #error cmake_ARCH armv6 22 | #elif defined(__ARM_ARCH_5TEJ__) \\ 23 | || (defined(__TARGET_ARCH_ARM) && __TARGET_ARCH_ARM-0 >= 5) \\ 24 | || (defined(_M_ARM) && _M_ARM-0 >= 5) 25 | #error cmake_ARCH armv5 26 | #else 27 | #error cmake_ARCH arm 28 | #endif 29 | #elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) 30 | #error cmake_ARCH x86_64 31 | #elif defined(__i386) || defined(__i386__) || defined(_M_IX86) 32 | #error cmake_ARCH x86_32 33 | #elif defined(__mips) || defined(__mips__) || defined(_M_MRX000) 34 | #if defined(_MIPS_ARCH_MIPS64) || defined(__mips64) || (defined(__mips) && __mips >= 64) 35 | #error cmake_ARCH mips64 36 | #elif defined(_MIPS_ARCH_MIPS32) || defined(__mips32) || (defined(__mips) && __mips >= 32) 37 | #error cmake_ARCH mips32 38 | #elif defined(_MIPS_ARCH_MIPS5) || (defined(__mips) && __mips >= 5) 39 | #error cmake_ARCH mips5 40 | #elif defined(_MIPS_ARCH_MIPS4) || (defined(__mips) && __mips >= 4) 41 | #error cmake_ARCH mips4 42 | #elif defined(_MIPS_ARCH_MIPS3) || (defined(__mips) && __mips >= 3) 43 | #error cmake_ARCH mips3 44 | #elif defined(_MIPS_ARCH_MIPS2) || (defined(__mips) && __mips >= 2) 45 | #error cmake_ARCH mips2 46 | #elif defined(_MIPS_ARCH_MIPS1) || (defined(__mips) && __mips >= 1) 47 | #error cmake_ARCH mips1 48 | #else 49 | #error cmake_ARCH mips 50 | #endif 51 | #endif 52 | 53 | #error cmake_ARCH unknown 54 | ") 55 | 56 | macro(set_arch_flags arch) 57 | if (${arch} STREQUAL "armv7") 58 | set(ARMV7 ON) 59 | set(ARMV6 ON) 60 | set(ARMV5 ON) 61 | set(ARM ON) 62 | endif() 63 | if (${arch} STREQUAL "armv6") 64 | set(ARMV6 ON) 65 | set(ARMV5 ON) 66 | set(ARM ON) 67 | endif() 68 | if (${arch} STREQUAL "armv5") 69 | set(ARMV5 ON) 70 | set(ARM ON) 71 | endif() 72 | if (${arch} STREQUAL "arm") 73 | set(ARM ON) 74 | endif() 75 | if (${arch} STREQUAL "x86_64") 76 | set(AMD64 ON) 77 | set(X64 ON) 78 | set(X86_64 ON) 79 | endif() 80 | if (${arch} STREQUAL "x86_32") 81 | set(I386 ON) 82 | set(X86 ON) 83 | set(X86_32 ON) 84 | endif() 85 | if (${arch} STREQUAL "mips64") 86 | set(MIPS64 ON) 87 | set(MIPS ON) 88 | endif() 89 | if (${arch} STREQUAL "mips32") 90 | set(MIPS32 ON) 91 | set(MIPS ON) 92 | endif() 93 | if (${arch} STREQUAL "mips5") 94 | set(MIPS5 ON) 95 | set(MIPS ON) 96 | endif() 97 | if (${arch} STREQUAL "mips4") 98 | set(MIPS4 ON) 99 | set(MIPS ON) 100 | endif() 101 | if (${arch} STREQUAL "mips3") 102 | set(MIPS3 ON) 103 | set(MIPS ON) 104 | endif() 105 | if (${arch} STREQUAL "mips2") 106 | set(MIPS2 ON) 107 | set(MIPS ON) 108 | endif() 109 | if (${arch} STREQUAL "mips1") 110 | set(MIPS1 ON) 111 | set(MIPS ON) 112 | endif() 113 | if (${arch} STREQUAL "mips") 114 | set(MIPS ON) 115 | endif() 116 | endmacro() 117 | 118 | macro(detect_arch) 119 | file(WRITE "${CMAKE_BINARY_DIR}/arch.c" "${arch_detection_code}") 120 | 121 | enable_language(C) 122 | 123 | # Detect the architecture in a rather creative way... 124 | # This compiles a small C program which is a series of ifdefs that selects a 125 | # particular #error preprocessor directive whose message string contains the 126 | # target architecture. The program will always fail to compile (both because 127 | # file is not a valid C program, and obviously because of the presence of the 128 | # #error preprocessor directives... but by exploiting the preprocessor in this 129 | # way, we can detect the correct target architecture even when cross-compiling, 130 | # since the program itself never needs to be run (only the compiler/preprocessor) 131 | try_run( 132 | run_result_unused 133 | compile_result_unused 134 | "${CMAKE_BINARY_DIR}" 135 | "${CMAKE_BINARY_DIR}/arch.c" 136 | COMPILE_OUTPUT_VARIABLE ARCH 137 | CMAKE_FLAGS 138 | ) 139 | 140 | # Parse the architecture name from the compiler output 141 | string(REGEX MATCH "cmake_ARCH ([a-zA-Z0-9_]+)" ARCH "${ARCH}") 142 | 143 | # Get rid of the value marker leaving just the architecture name 144 | string(REPLACE "cmake_ARCH " "" ARCH "${ARCH}") 145 | 146 | # If we are compiling with an unknown architecture this variable should 147 | # already be set to "unknown" but in the case that it's empty (i.e. due 148 | # to a typo in the code), then set it to unknown 149 | if (NOT ARCH) 150 | set(ARCH unknown) 151 | endif() 152 | message(STATUS "Detected architecture: ${ARCH}") 153 | set_arch_flags(ARCH) 154 | endmacro() 155 | -------------------------------------------------------------------------------- /cmake/FindCairo.cmake: -------------------------------------------------------------------------------- 1 | # Once done, this will define 2 | # 3 | # CAIRO_FOUND - system has Cairo 4 | # CAIRO_INCLUDE_DIRS - the Cairo include directories 5 | # CAIRO_LIBRARIES - link these to use Cairo 6 | # 7 | # Copyright (C) 2012 Raphael Kubo da Costa 8 | # 9 | # Redistribution and use in source and binary forms, with or without 10 | # modification, are permitted provided that the following conditions 11 | # are met: 12 | # 1. Redistributions of source code must retain the above copyright 13 | # notice, this list of conditions and the following disclaimer. 14 | # 2. Redistributions in binary form must reproduce the above copyright 15 | # notice, this list of conditions and the following disclaimer in the 16 | # documentation and/or other materials provided with the distribution. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS 19 | # IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20 | # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS 22 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 | # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 | # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | FIND_PACKAGE(PkgConfig) 31 | PKG_CHECK_MODULES(PC_CAIRO cairo) # FIXME: After we require CMake 2.8.2 we can pass QUIET to this call. 32 | 33 | FIND_PATH(CAIRO_INCLUDE_DIRS 34 | NAMES cairo.h 35 | HINTS ${PC_CAIRO_INCLUDEDIR} 36 | ${PC_CAIRO_INCLUDE_DIRS} 37 | PATH_SUFFIXES cairo 38 | ) 39 | 40 | FIND_LIBRARY(CAIRO_LIBRARIES 41 | NAMES cairo 42 | HINTS ${PC_CAIRO_LIBDIR} 43 | ${PC_CAIRO_LIBRARY_DIRS} 44 | ) 45 | 46 | IF (CAIRO_INCLUDE_DIRS) 47 | IF (EXISTS "${CAIRO_INCLUDE_DIRS}/cairo-version.h") 48 | FILE(READ "${CAIRO_INCLUDE_DIRS}/cairo-version.h" CAIRO_VERSION_CONTENT) 49 | 50 | STRING(REGEX MATCH "#define +CAIRO_VERSION_MAJOR +([0-9]+)" _dummy "${CAIRO_VERSION_CONTENT}") 51 | SET(CAIRO_VERSION_MAJOR "${CMAKE_MATCH_1}") 52 | 53 | STRING(REGEX MATCH "#define +CAIRO_VERSION_MINOR +([0-9]+)" _dummy "${CAIRO_VERSION_CONTENT}") 54 | SET(CAIRO_VERSION_MINOR "${CMAKE_MATCH_1}") 55 | 56 | STRING(REGEX MATCH "#define +CAIRO_VERSION_MICRO +([0-9]+)" _dummy "${CAIRO_VERSION_CONTENT}") 57 | SET(CAIRO_VERSION_MICRO "${CMAKE_MATCH_1}") 58 | 59 | SET(CAIRO_VERSION "${CAIRO_VERSION_MAJOR}.${CAIRO_VERSION_MINOR}.${CAIRO_VERSION_MICRO}") 60 | ENDIF () 61 | ENDIF () 62 | 63 | # FIXME: Should not be needed anymore once we start depending on CMake 2.8.3 64 | SET(VERSION_OK TRUE) 65 | IF (Cairo_FIND_VERSION) 66 | IF (Cairo_FIND_VERSION_EXACT) 67 | IF ("${Cairo_FIND_VERSION}" VERSION_EQUAL "${CAIRO_VERSION}") 68 | # FIXME: Use IF (NOT ...) with CMake 2.8.2+ to get rid of the ELSE block 69 | ELSE () 70 | SET(VERSION_OK FALSE) 71 | ENDIF () 72 | ELSE () 73 | IF ("${Cairo_FIND_VERSION}" VERSION_GREATER "${CAIRO_VERSION}") 74 | SET(VERSION_OK FALSE) 75 | ENDIF () 76 | ENDIF () 77 | ENDIF () 78 | 79 | INCLUDE(FindPackageHandleStandardArgs) 80 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cairo DEFAULT_MSG CAIRO_INCLUDE_DIRS CAIRO_LIBRARIES VERSION_OK) 81 | -------------------------------------------------------------------------------- /cmake/FindFontconfig.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find the Fontconfig 2 | # Once done this will define 3 | # 4 | # FONTCONFIG_FOUND - system has Fontconfig 5 | # FONTCONFIG_INCLUDE_DIR - The include directory to use for the fontconfig headers 6 | # FONTCONFIG_LIBRARIES - Link these to use FONTCONFIG 7 | # FONTCONFIG_DEFINITIONS - Compiler switches required for using FONTCONFIG 8 | 9 | # Copyright (c) 2006,2007 Laurent Montel, 10 | # 11 | # Redistribution and use in source and binary forms, with or without 12 | # modification, are permitted provided that the following conditions 13 | # are met: 14 | # 15 | # 1. Redistributions of source code must retain the copyright 16 | # notice, this list of conditions and the following disclaimer. 17 | # 2. Redistributions in binary form must reproduce the copyright 18 | # notice, this list of conditions and the following disclaimer in the 19 | # documentation and/or other materials provided with the distribution. 20 | # 3. The name of the author may not be used to endorse or promote products 21 | # derived from this software without specific prior written permission. 22 | # 23 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | # 34 | 35 | if (FONTCONFIG_LIBRARIES AND FONTCONFIG_INCLUDE_DIR) 36 | 37 | # in cache already 38 | set(FONTCONFIG_FOUND TRUE) 39 | 40 | else (FONTCONFIG_LIBRARIES AND FONTCONFIG_INCLUDE_DIR) 41 | 42 | if (NOT WIN32) 43 | # use pkg-config to get the directories and then use these values 44 | # in the find_path() and find_library() calls 45 | find_package(PkgConfig) 46 | pkg_check_modules(PC_FONTCONFIG fontconfig) 47 | 48 | set(FONTCONFIG_DEFINITIONS ${PC_FONTCONFIG_CFLAGS_OTHER}) 49 | endif (NOT WIN32) 50 | 51 | find_path(FONTCONFIG_INCLUDE_DIR fontconfig/fontconfig.h 52 | PATHS 53 | ${PC_FONTCONFIG_INCLUDEDIR} 54 | ${PC_FONTCONFIG_INCLUDE_DIRS} 55 | /usr/X11/include 56 | ) 57 | 58 | find_library(FONTCONFIG_LIBRARIES NAMES fontconfig 59 | PATHS 60 | ${PC_FONTCONFIG_LIBDIR} 61 | ${PC_FONTCONFIG_LIBRARY_DIRS} 62 | ) 63 | 64 | include(FindPackageHandleStandardArgs) 65 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(Fontconfig DEFAULT_MSG FONTCONFIG_LIBRARIES FONTCONFIG_INCLUDE_DIR) 66 | 67 | mark_as_advanced(FONTCONFIG_LIBRARIES FONTCONFIG_INCLUDE_DIR) 68 | 69 | endif (FONTCONFIG_LIBRARIES AND FONTCONFIG_INCLUDE_DIR) 70 | -------------------------------------------------------------------------------- /cmake/FindFreeImage.cmake: -------------------------------------------------------------------------------- 1 | # Find the FreeImage library. 2 | # 3 | # This module defines 4 | # FREEIMAGE_FOUND - True if FREEIMAGE was found. 5 | # FREEIMAGE_INCLUDE_DIRS - Include directories for FREEIMAGE headers. 6 | # FREEIMAGE_LIBRARIES - Libraries for FREEIMAGE. 7 | # 8 | # To specify an additional directory to search, set FREEIMAGE_ROOT. 9 | # 10 | # Copyright (c) 2010, Ewen Cheslack-Postava 11 | # Based on FindSQLite3.cmake by: 12 | # Copyright (c) 2006, Jaroslaw Staniek, 13 | # Extended by Siddhartha Chaudhuri, 2008. 14 | # 15 | # Redistribution and use is allowed according to the terms of the BSD license. 16 | # 17 | 18 | SET(FREEIMAGE_FOUND FALSE) 19 | SET(FREEIMAGE_INCLUDE_DIRS) 20 | SET(FREEIMAGE_LIBRARIES) 21 | 22 | SET(SEARCH_PATHS 23 | $ENV{ProgramFiles}/freeimage/include 24 | $ENV{SystemDrive}/freeimage/include 25 | $ENV{ProgramFiles}/freeimage 26 | $ENV{SystemDrive}/freeimage 27 | ) 28 | IF(FREEIMAGE_ROOT) 29 | SET(SEARCH_PATHS 30 | ${FREEIMAGE_ROOT} 31 | ${FREEIMAGE_ROOT}/include 32 | ${SEARCH_PATHS} 33 | ) 34 | ENDIF() 35 | 36 | FIND_PATH(FREEIMAGE_INCLUDE_DIRS 37 | NAMES FreeImage.h 38 | PATHS ${SEARCH_PATHS} 39 | NO_DEFAULT_PATH) 40 | IF(NOT FREEIMAGE_INCLUDE_DIRS) # now look in system locations 41 | FIND_PATH(FREEIMAGE_INCLUDE_DIRS NAMES FreeImage.h) 42 | ENDIF(NOT FREEIMAGE_INCLUDE_DIRS) 43 | 44 | SET(FREEIMAGE_LIBRARY_DIRS) 45 | IF(FREEIMAGE_ROOT) 46 | SET(FREEIMAGE_LIBRARY_DIRS ${FREEIMAGE_ROOT}) 47 | IF(EXISTS "${FREEIMAGE_ROOT}/lib") 48 | SET(FREEIMAGE_LIBRARY_DIRS ${FREEIMAGE_LIBRARY_DIRS} ${FREEIMAGE_ROOT}/lib) 49 | ENDIF() 50 | IF(EXISTS "${FREEIMAGE_ROOT}/lib/static") 51 | SET(FREEIMAGE_LIBRARY_DIRS ${FREEIMAGE_LIBRARY_DIRS} ${FREEIMAGE_ROOT}/lib/static) 52 | ENDIF() 53 | ENDIF() 54 | 55 | # FREEIMAGE 56 | # Without system dirs 57 | FIND_LIBRARY(FREEIMAGE_LIBRARY 58 | NAMES freeimage 59 | PATHS ${FREEIMAGE_LIBRARY_DIRS} 60 | NO_DEFAULT_PATH 61 | ) 62 | IF(NOT FREEIMAGE_LIBRARY) # now look in system locations 63 | FIND_LIBRARY(FREEIMAGE_LIBRARY NAMES freeimage) 64 | ENDIF(NOT FREEIMAGE_LIBRARY) 65 | 66 | SET(FREEIMAGE_LIBRARIES) 67 | IF(FREEIMAGE_LIBRARY) 68 | SET(FREEIMAGE_LIBRARIES ${FREEIMAGE_LIBRARY}) 69 | ENDIF() 70 | 71 | IF(FREEIMAGE_INCLUDE_DIRS AND FREEIMAGE_LIBRARIES) 72 | SET(FREEIMAGE_FOUND TRUE) 73 | IF(NOT FREEIMAGE_FIND_QUIETLY) 74 | MESSAGE(STATUS "Found FreeImage: headers at ${FREEIMAGE_INCLUDE_DIRS}, libraries at ${FREEIMAGE_LIBRARY_DIRS} :: ${FREEIMAGE_LIBRARIES}") 75 | ENDIF(NOT FREEIMAGE_FIND_QUIETLY) 76 | ELSE(FREEIMAGE_INCLUDE_DIRS AND FREEIMAGE_LIBRARIES) 77 | SET(FREEIMAGE_FOUND FALSE) 78 | IF(FREEIMAGE_FIND_REQUIRED) 79 | MESSAGE(STATUS "FreeImage not found") 80 | ENDIF(FREEIMAGE_FIND_REQUIRED) 81 | ENDIF(FREEIMAGE_INCLUDE_DIRS AND FREEIMAGE_LIBRARIES) 82 | 83 | MARK_AS_ADVANCED(FREEIMAGE_INCLUDE_DIRS FREEIMAGE_LIBRARIES) 84 | -------------------------------------------------------------------------------- /cmake/FindGLib.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Glib and its components (gio, gobject etc) 2 | # Once done, this will define 3 | # 4 | # GLIB_FOUND - system has Glib 5 | # GLIB_INCLUDE_DIRS - the Glib include directories 6 | # GLIB_LIBRARIES - link these to use Glib 7 | # 8 | # Optionally, the COMPONENTS keyword can be passed to find_package() 9 | # and Glib components can be looked for. Currently, the following 10 | # components can be used, and they define the following variables if 11 | # found: 12 | # 13 | # gio: GLIB_GIO_LIBRARIES 14 | # gobject: GLIB_GOBJECT_LIBRARIES 15 | # gmodule: GLIB_GMODULE_LIBRARIES 16 | # gthread: GLIB_GTHREAD_LIBRARIES 17 | # 18 | # Note that the respective _INCLUDE_DIR variables are not set, since 19 | # all headers are in the same directory as GLIB_INCLUDE_DIRS. 20 | # 21 | # Copyright (C) 2012 Raphael Kubo da Costa 22 | # 23 | # Redistribution and use in source and binary forms, with or without 24 | # modification, are permitted provided that the following conditions 25 | # are met: 26 | # 1. Redistributions of source code must retain the above copyright 27 | # notice, this list of conditions and the following disclaimer. 28 | # 2. Redistributions in binary form must reproduce the above copyright 29 | # notice, this list of conditions and the following disclaimer in the 30 | # documentation and/or other materials provided with the distribution. 31 | # 32 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS 33 | # IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 34 | # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 35 | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS 36 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 37 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 38 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 39 | # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 40 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 41 | # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 42 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 43 | 44 | find_package(PkgConfig) 45 | pkg_check_modules(PC_GLIB QUIET glib-2.0) 46 | 47 | find_library(GLIB_LIBRARIES 48 | NAMES glib-2.0 49 | HINTS ${PC_GLIB_LIBDIR} 50 | ${PC_GLIB_LIBRARY_DIRS} 51 | ) 52 | 53 | # Files in glib's main include path may include glibconfig.h, which, 54 | # for some odd reason, is normally in $LIBDIR/glib-2.0/include. 55 | get_filename_component(_GLIB_LIBRARY_DIR ${GLIB_LIBRARIES} PATH) 56 | find_path(GLIBCONFIG_INCLUDE_DIR 57 | NAMES glibconfig.h 58 | HINTS ${PC_LIBDIR} ${PC_LIBRARY_DIRS} ${_GLIB_LIBRARY_DIR} 59 | ${PC_GLIB_INCLUDEDIR} ${PC_GLIB_INCLUDE_DIRS} 60 | PATH_SUFFIXES glib-2.0/include 61 | ) 62 | 63 | find_path(GLIB_INCLUDE_DIR 64 | NAMES glib.h 65 | HINTS ${PC_GLIB_INCLUDEDIR} 66 | ${PC_GLIB_INCLUDE_DIRS} 67 | PATH_SUFFIXES glib-2.0 68 | ) 69 | 70 | set(GLIB_INCLUDE_DIRS ${GLIB_INCLUDE_DIR} ${GLIBCONFIG_INCLUDE_DIR}) 71 | 72 | # Version detection 73 | if (EXISTS "${GLIBCONFIG_INCLUDE_DIR}/glibconfig.h") 74 | file(READ "${GLIBCONFIG_INCLUDE_DIR}/glibconfig.h" GLIBCONFIG_H_CONTENTS) 75 | string(REGEX MATCH "#define GLIB_MAJOR_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}") 76 | set(GLIB_VERSION_MAJOR "${CMAKE_MATCH_1}") 77 | string(REGEX MATCH "#define GLIB_MINOR_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}") 78 | set(GLIB_VERSION_MINOR "${CMAKE_MATCH_1}") 79 | string(REGEX MATCH "#define GLIB_MICRO_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_H_CONTENTS}") 80 | set(GLIB_VERSION_MICRO "${CMAKE_MATCH_1}") 81 | set(GLIB_VERSION "${GLIB_VERSION_MAJOR}.${GLIB_VERSION_MINOR}.${GLIB_VERSION_MICRO}") 82 | endif () 83 | 84 | # Additional Glib components. We only look for libraries, as not all of them 85 | # have corresponding headers and all headers are installed alongside the main 86 | # glib ones. 87 | foreach (_component ${GLIB_FIND_COMPONENTS}) 88 | if (${_component} STREQUAL "gio") 89 | find_library(GLIB_GIO_LIBRARIES NAMES gio-2.0 HINTS ${_GLIB_LIBRARY_DIR}) 90 | set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GIO_LIBRARIES) 91 | elseif (${_component} STREQUAL "gobject") 92 | find_library(GLIB_GOBJECT_LIBRARIES NAMES gobject-2.0 HINTS ${_GLIB_LIBRARY_DIR}) 93 | set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GOBJECT_LIBRARIES) 94 | elseif (${_component} STREQUAL "gmodule") 95 | find_library(GLIB_GMODULE_LIBRARIES NAMES gmodule-2.0 HINTS ${_GLIB_LIBRARY_DIR}) 96 | set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GMODULE_LIBRARIES) 97 | elseif (${_component} STREQUAL "gthread") 98 | find_library(GLIB_GTHREAD_LIBRARIES NAMES gthread-2.0 HINTS ${_GLIB_LIBRARY_DIR}) 99 | set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GTHREAD_LIBRARIES) 100 | elseif (${_component} STREQUAL "gio-unix") 101 | # gio-unix is compiled as part of the gio library, but the include paths 102 | # are separate from the shared glib ones. Since this is currently only used 103 | # by WebKitGTK+ we don't go to extraordinary measures beyond pkg-config. 104 | pkg_check_modules(GIO_UNIX QUIET gio-unix-2.0) 105 | endif () 106 | endforeach () 107 | 108 | include(FindPackageHandleStandardArgs) 109 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLIB REQUIRED_VARS GLIB_INCLUDE_DIRS GLIB_LIBRARIES ${ADDITIONAL_REQUIRED_VARS} 110 | VERSION_VAR GLIB_VERSION) 111 | 112 | mark_as_advanced( 113 | GLIBCONFIG_INCLUDE_DIR 114 | GLIB_GIO_LIBRARIES 115 | GLIB_GIO_UNIX_LIBRARIES 116 | GLIB_GMODULE_LIBRARIES 117 | GLIB_GOBJECT_LIBRARIES 118 | GLIB_GTHREAD_LIBRARIES 119 | GLIB_INCLUDE_DIR 120 | GLIB_INCLUDE_DIRS 121 | GLIB_LIBRARIES 122 | ) 123 | -------------------------------------------------------------------------------- /cmake/FindGObject.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find GObject 2 | # Once done this will define 3 | # 4 | # GOBJECT_FOUND - system has GObject 5 | # GOBJECT_INCLUDE_DIR - the GObject include directory 6 | # GOBJECT_LIBRARIES - the libraries needed to use GObject 7 | # GOBJECT_DEFINITIONS - Compiler switches required for using GObject 8 | 9 | # Copyright (c) 2006, Tim Beaulen 10 | # 11 | # Redistribution and use is allowed according to the terms of the BSD license. 12 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 13 | 14 | 15 | IF (GOBJECT_INCLUDE_DIR AND GOBJECT_LIBRARIES) 16 | # in cache already 17 | SET(GObject_FIND_QUIETLY TRUE) 18 | ELSE (GOBJECT_INCLUDE_DIR AND GOBJECT_LIBRARIES) 19 | SET(GObject_FIND_QUIETLY FALSE) 20 | ENDIF (GOBJECT_INCLUDE_DIR AND GOBJECT_LIBRARIES) 21 | 22 | IF (NOT WIN32) 23 | # use pkg-config to get the directories and then use these values 24 | # in the FIND_PATH() and FIND_LIBRARY() calls 25 | FIND_PACKAGE(PkgConfig) 26 | PKG_CHECK_MODULES(PC_GOBJECT gobject-2.0) 27 | #MESSAGE(STATUS "DEBUG: GObject include directory = ${GOBJECT_INCLUDE_DIRS}") 28 | #MESSAGE(STATUS "DEBUG: GObject link directory = ${GOBJECT_LIBRARY_DIRS}") 29 | #MESSAGE(STATUS "DEBUG: GObject CFlags = ${GOBJECT_CFLAGS}") 30 | SET(GOBJECT_DEFINITIONS ${PC_GOBJECT_CFLAGS_OTHER}) 31 | ENDIF (NOT WIN32) 32 | 33 | FIND_PATH(GOBJECT_INCLUDE_DIR gobject.h 34 | PATHS 35 | ${PC_GOBJECT_INCLUDEDIR} 36 | ${PC_GOBJECT_INCLUDE_DIRS} 37 | PATH_SUFFIXES glib-2.0/gobject/ 38 | ) 39 | 40 | FIND_LIBRARY(_GObjectLibs NAMES gobject-2.0 41 | PATHS 42 | ${PC_GOBJECT_LIBDIR} 43 | ${PC_GOBJECT_LIBRARY_DIRS} 44 | ) 45 | FIND_LIBRARY(_GModuleLibs NAMES gmodule-2.0 46 | PATHS 47 | ${PC_GOBJECT_LIBDIR} 48 | ${PC_GOBJECT_LIBRARY_DIRS} 49 | ) 50 | FIND_LIBRARY(_GThreadLibs NAMES gthread-2.0 51 | PATHS 52 | ${PC_GOBJECT_LIBDIR} 53 | ${PC_GOBJECT_LIBRARY_DIRS} 54 | ) 55 | FIND_LIBRARY(_GLibs NAMES glib-2.0 56 | PATHS 57 | ${PC_GOBJECT_LIBDIR} 58 | ${PC_GOBJECT_LIBRARY_DIRS} 59 | ) 60 | 61 | SET( GOBJECT_LIBRARIES ${_GObjectLibs} ${_GModuleLibs} ${_GThreadLibs} ${_GLibs} ) 62 | 63 | IF (GOBJECT_INCLUDE_DIR AND GOBJECT_LIBRARIES) 64 | SET(GOBJECT_FOUND TRUE) 65 | ELSE (GOBJECT_INCLUDE_DIR AND GOBJECT_LIBRARIES) 66 | SET(GOBJECT_FOUND FALSE) 67 | ENDIF (GOBJECT_INCLUDE_DIR AND GOBJECT_LIBRARIES) 68 | 69 | IF (GOBJECT_FOUND) 70 | IF (NOT GObject_FIND_QUIETLY) 71 | MESSAGE(STATUS "Found GObject libraries: ${GOBJECT_LIBRARIES}") 72 | MESSAGE(STATUS "Found GObject includes : ${GOBJECT_INCLUDE_DIR}") 73 | ENDIF (NOT GObject_FIND_QUIETLY) 74 | ELSE (GOBJECT_FOUND) 75 | IF (GObject_FIND_REQUIRED) 76 | MESSAGE(STATUS "Could NOT find GObject") 77 | ENDIF(GObject_FIND_REQUIRED) 78 | ENDIF (GOBJECT_FOUND) 79 | 80 | MARK_AS_ADVANCED(GOBJECT_INCLUDE_DIR _GObjectLibs _GModuleLibs _GThreadLibs _GLibs) 81 | -------------------------------------------------------------------------------- /cmake/FindGStreamer.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find GStreamer and its plugins 2 | # Once done, this will define 3 | # 4 | # GSTREAMER_FOUND - system has GStreamer 5 | # GSTREAMER_INCLUDE_DIRS - the GStreamer include directories 6 | # GSTREAMER_LIBRARIES - link these to use GStreamer 7 | # 8 | # Additionally, gstreamer-base is always looked for and required, and 9 | # the following related variables are defined: 10 | # 11 | # GSTREAMER_BASE_INCLUDE_DIRS - gstreamer-base's include directory 12 | # GSTREAMER_BASE_LIBRARIES - link to these to use gstreamer-base 13 | # 14 | # Optionally, the COMPONENTS keyword can be passed to find_package() 15 | # and GStreamer plugins can be looked for. Currently, the following 16 | # plugins can be searched, and they define the following variables if 17 | # found: 18 | # 19 | # gstreamer-app: GSTREAMER_APP_INCLUDE_DIRS and GSTREAMER_APP_LIBRARIES 20 | # gstreamer-audio: GSTREAMER_AUDIO_INCLUDE_DIRS and GSTREAMER_AUDIO_LIBRARIES 21 | # gstreamer-fft: GSTREAMER_FFT_INCLUDE_DIRS and GSTREAMER_FFT_LIBRARIES 22 | # gstreamer-gl: GSTREAMER_GL_INCLUDE_DIRS and GSTREAMER_GL_LIBRARIES 23 | # gstreamer-mpegts: GSTREAMER_MPEGTS_INCLUDE_DIRS and GSTREAMER_MPEGTS_LIBRARIES 24 | # gstreamer-pbutils: GSTREAMER_PBUTILS_INCLUDE_DIRS and GSTREAMER_PBUTILS_LIBRARIES 25 | # gstreamer-tag: GSTREAMER_TAG_INCLUDE_DIRS and GSTREAMER_TAG_LIBRARIES 26 | # gstreamer-video: GSTREAMER_VIDEO_INCLUDE_DIRS and GSTREAMER_VIDEO_LIBRARIES 27 | # 28 | # Copyright (C) 2012 Raphael Kubo da Costa 29 | # 30 | # Redistribution and use in source and binary forms, with or without 31 | # modification, are permitted provided that the following conditions 32 | # are met: 33 | # 1. Redistributions of source code must retain the above copyright 34 | # notice, this list of conditions and the following disclaimer. 35 | # 2. Redistributions in binary form must reproduce the above copyright 36 | # notice, this list of conditions and the following disclaimer in the 37 | # documentation and/or other materials provided with the distribution. 38 | # 39 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS 40 | # IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 41 | # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42 | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS 43 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 44 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 45 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 46 | # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 47 | # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 48 | # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 49 | # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 50 | 51 | find_package(PkgConfig) 52 | 53 | # Helper macro to find a GStreamer plugin (or GStreamer itself) 54 | # _component_prefix is prepended to the _INCLUDE_DIRS and _LIBRARIES variables (eg. "GSTREAMER_AUDIO") 55 | # _pkgconfig_name is the component's pkg-config name (eg. "gstreamer-1.0", or "gstreamer-video-1.0"). 56 | # _library is the component's library name (eg. "gstreamer-1.0" or "gstvideo-1.0") 57 | macro(FIND_GSTREAMER_COMPONENT _component_prefix _pkgconfig_name _library) 58 | 59 | string(REGEX MATCH "(.*)>=(.*)" _dummy "${_pkgconfig_name}") 60 | if ("${CMAKE_MATCH_2}" STREQUAL "") 61 | pkg_check_modules(PC_${_component_prefix} "${_pkgconfig_name} >= ${GStreamer_FIND_VERSION}") 62 | else () 63 | pkg_check_modules(PC_${_component_prefix} ${_pkgconfig_name}) 64 | endif () 65 | set(${_component_prefix}_INCLUDE_DIRS ${PC_${_component_prefix}_INCLUDE_DIRS}) 66 | 67 | find_library(${_component_prefix}_LIBRARIES 68 | NAMES ${_library} 69 | HINTS ${PC_${_component_prefix}_LIBRARY_DIRS} ${PC_${_component_prefix}_LIBDIR} 70 | ) 71 | endmacro() 72 | 73 | # ------------------------ 74 | # 1. Find GStreamer itself 75 | # ------------------------ 76 | 77 | # 1.1. Find headers and libraries 78 | FIND_GSTREAMER_COMPONENT(GSTREAMER gstreamer-1.0 gstreamer-1.0) 79 | FIND_GSTREAMER_COMPONENT(GSTREAMER_BASE gstreamer-base-1.0 gstbase-1.0) 80 | 81 | # ------------------------- 82 | # 2. Find GStreamer plugins 83 | # ------------------------- 84 | 85 | FIND_GSTREAMER_COMPONENT(GSTREAMER_APP gstreamer-app-1.0 gstapp-1.0) 86 | FIND_GSTREAMER_COMPONENT(GSTREAMER_AUDIO gstreamer-audio-1.0 gstaudio-1.0) 87 | FIND_GSTREAMER_COMPONENT(GSTREAMER_FFT gstreamer-fft-1.0 gstfft-1.0) 88 | FIND_GSTREAMER_COMPONENT(GSTREAMER_GL gstreamer-gl-1.0>=1.8.0 gstgl-1.0) 89 | FIND_GSTREAMER_COMPONENT(GSTREAMER_MPEGTS gstreamer-mpegts-1.0>=1.4.0 gstmpegts-1.0) 90 | FIND_GSTREAMER_COMPONENT(GSTREAMER_PBUTILS gstreamer-pbutils-1.0 gstpbutils-1.0) 91 | FIND_GSTREAMER_COMPONENT(GSTREAMER_TAG gstreamer-tag-1.0 gsttag-1.0) 92 | FIND_GSTREAMER_COMPONENT(GSTREAMER_VIDEO gstreamer-video-1.0 gstvideo-1.0) 93 | 94 | # ------------------------------------------------ 95 | # 3. Process the COMPONENTS passed to FIND_PACKAGE 96 | # ------------------------------------------------ 97 | set(_GSTREAMER_REQUIRED_VARS GSTREAMER_INCLUDE_DIRS GSTREAMER_LIBRARIES GSTREAMER_VERSION GSTREAMER_BASE_INCLUDE_DIRS GSTREAMER_BASE_LIBRARIES) 98 | 99 | foreach (_component ${GStreamer_FIND_COMPONENTS}) 100 | set(_gst_component "GSTREAMER_${_component}") 101 | string(TOUPPER ${_gst_component} _UPPER_NAME) 102 | 103 | list(APPEND _GSTREAMER_REQUIRED_VARS ${_UPPER_NAME}_INCLUDE_DIRS ${_UPPER_NAME}_LIBRARIES) 104 | endforeach () 105 | 106 | include(FindPackageHandleStandardArgs) 107 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(GStreamer REQUIRED_VARS _GSTREAMER_REQUIRED_VARS 108 | VERSION_VAR GSTREAMER_VERSION) 109 | 110 | mark_as_advanced( 111 | GSTREAMER_APP_INCLUDE_DIRS 112 | GSTREAMER_APP_LIBRARIES 113 | GSTREAMER_AUDIO_INCLUDE_DIRS 114 | GSTREAMER_AUDIO_LIBRARIES 115 | GSTREAMER_BASE_INCLUDE_DIRS 116 | GSTREAMER_BASE_LIBRARIES 117 | GSTREAMER_FFT_INCLUDE_DIRS 118 | GSTREAMER_FFT_LIBRARIES 119 | GSTREAMER_GL_INCLUDE_DIRS 120 | GSTREAMER_GL_LIBRARIES 121 | GSTREAMER_INCLUDE_DIRS 122 | GSTREAMER_LIBRARIES 123 | GSTREAMER_MPEGTS_INCLUDE_DIRS 124 | GSTREAMER_MPEGTS_LIBRARIES 125 | GSTREAMER_PBUTILS_INCLUDE_DIRS 126 | GSTREAMER_PBUTILS_LIBRARIES 127 | GSTREAMER_TAG_INCLUDE_DIRS 128 | GSTREAMER_TAG_LIBRARIES 129 | GSTREAMER_VIDEO_INCLUDE_DIRS 130 | GSTREAMER_VIDEO_LIBRARIES 131 | ) 132 | -------------------------------------------------------------------------------- /cmake/FindGrt.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015 by Ben Zhang 3 | # 4 | # Author(s): 5 | # Ben Zhang, May 2016 6 | # 7 | # Try to find GRT 8 | # Once done this will define 9 | # GRT_FOUND - System has Grt 10 | # GRT_INCLUDE_DIR - The Grt include directories 11 | # GRT_LIBRARY - The libraries needed to use Grt 12 | # 13 | 14 | find_package(PkgConfig) 15 | pkg_check_modules(PC_GRT QUIET libgrt) 16 | 17 | find_path(GRT_INCLUDE_DIR 18 | NAMES GRT/GRT.h 19 | HINTS ${PC_LIBDIR} ${PC_LIBRARY_DIRS} ${_GRT_LIBRARY_DIR} 20 | ${PC_GRT_INCLUDEDIR} ${PC_GRT_INCLUDE_DIRS} 21 | PATH_SUFFIXES grt 22 | ) 23 | 24 | find_library( 25 | GRT_LIBRARY NAMES grt 26 | HINTS ${PC_GRT_LIBDIR} ${PC_GRT_LIBRARY_DIRS} 27 | ) 28 | 29 | include(FindPackageHandleStandardArgs) 30 | find_package_handle_standard_args( 31 | grt 32 | REQUIRED_VARS GRT_LIBRARY GRT_INCLUDE_DIR 33 | ) 34 | 35 | if(GRT_LIBRARY AND GRT_INCLUDE_DIR) 36 | SET(GRT_FOUND TRUE) 37 | else(GRT_LIBRARY AND GRT_INCLUDE_DIR) 38 | SET(GRT_FOUND FALSE) 39 | endif(GRT_LIBRARY AND GRT_INCLUDE_DIR) 40 | 41 | mark_as_advanced(GRT_INCLUDE_DIR GRT_LIBRARY) 42 | -------------------------------------------------------------------------------- /cmake/FindRtAudio.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2015 by Idiap Research Institute 3 | # 4 | # See the file COPYING for the licence associated with this software. 5 | # 6 | # Author(s): 7 | # Phil Garner, November 2015 8 | # 9 | # ...but basically copied from FindSndFile in libube, in turn from the examples 10 | # on the web. 11 | # 12 | 13 | # 14 | # Try to find RtAudio 15 | # Once done this will define 16 | # RTAUDIO_FOUND - System has RtAudio 17 | # RTAUDIO_INCLUDE_DIR - The RtAudio include directories 18 | # RTAUDIO_LIBRARIES - The libraries needed to use RtAudio 19 | # RTAUDIO_DEFINITIONS - Compiler switches required for using RtAudio 20 | # RTAUDIO_VERSION_STRING - the version of RtAudio found 21 | # 22 | 23 | find_package(PkgConfig) 24 | pkg_check_modules(PC_RTAUDIO QUIET librtaudio) 25 | 26 | set(RTAUDIO_DEFINITIONS ${PC_RTAUDIO_CFLAGS_OTHER}) 27 | set(RTAUDIO_VERSION_STRING ${PC_RTAUDIO_VERSION}) 28 | 29 | find_path( 30 | RTAUDIO_INCLUDE_DIR RtAudio.h 31 | HINTS ${PC_RTAUDIO_INCLUDEDIR} ${PC_RTAUDIO_INCLUDE_DIRS} 32 | ) 33 | 34 | find_library( 35 | RTAUDIO_LIBRARIES NAMES rtaudio 36 | HINTS ${PC_RTAUDIO_LIBDIR} ${PC_RTAUDIO_LIBRARY_DIRS} 37 | ) 38 | 39 | include(FindPackageHandleStandardArgs) 40 | find_package_handle_standard_args( 41 | RtAudio 42 | REQUIRED_VARS RTAUDIO_LIBRARIES RTAUDIO_INCLUDE_DIR 43 | VERSION_VAR RTAUDIO_VERSION_STRING 44 | ) 45 | 46 | mark_as_advanced(RTAUDIO_INCLUDE_DIR RTAUDIO_LIBRARIES) 47 | -------------------------------------------------------------------------------- /setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ## Stop on any error. 4 | set -e 5 | 6 | ## PLATFORM will be modified after executing get_platform platform 7 | ## It will be either osx, linux32 or linux64 8 | PLATFORM= 9 | ## Depending on the PLATFORM, calling set_of_url will overwrite OF_RELEASE 10 | OF_RELEASE= 11 | 12 | get_platform () { 13 | ## 1. OS 14 | case $(uname -s) in 15 | Linux) 16 | case $(uname -m) in 17 | x86) arch=32 ;; 18 | i?86) arch=32 ;; 19 | ia64) arch=64 ;; 20 | amd64) arch=64 ;; 21 | x86_64) arch=64 ;; 22 | armv6l) arch=armv6l ;; 23 | armv7l) arch=armv6l ;; 24 | *) 25 | echo "Non-32/64 architecture ... Really?!" 26 | exit -1 27 | ;; 28 | esac 29 | PLATFORM=linux$arch 30 | ;; 31 | Darwin) 32 | PLATFORM=osx 33 | ;; 34 | *) 35 | echo "Only supporting Linux or OS X" 36 | exit -1 37 | ;; 38 | esac 39 | } 40 | 41 | OF_PREFIX=https://openframeworks.cc/versions/v0.9.3 42 | get_of () { 43 | case $PLATFORM in 44 | osx) 45 | OF_RELEASE=${OF_PREFIX}/of_v0.9.3_osx_release.zip 46 | curl $OF_RELEASE > third-party/of.zip 47 | unzip -q third-party/of.zip -d third-party 48 | ;; 49 | linux64) 50 | OF_RELEASE=${OF_PREFIX}/of_v0.9.3_linux64_release.tar.gz 51 | curl $OF_RELEASE > third-party/of.tar.gz 52 | tar -zxf third-party/of.tar.gz -C third-party 53 | ;; 54 | linux32) 55 | OF_RELEASE=${OF_PREFIX}/of_v0.9.3_linux32_release.tar.gz 56 | curl $OF_RELEASE > third-party/of.tar.gz 57 | tar -zxf third-party/of.tar.gz -C third-party 58 | ;; 59 | linuxarmv6l) 60 | OF_RELEASE=${OF_PREFIX}/of_v0.9.3_linuxarmv6l_release.tar.gz 61 | curl $OF_RELEASE > third-party/of.tar.gz 62 | tar -zxf third-party/of.tar.gz -C third-party 63 | ;; 64 | esac 65 | } 66 | 67 | get_platform 68 | 69 | get_of 70 | 71 | cd third-party 72 | mkdir -p openFrameworks 73 | ( cd of_v0.9.3_$PLATFORM\_release && tar cf - . ) | (cd openFrameworks && tar xpf - ) 74 | rm -rf of_v0.9.3_$PLATFORM\_release/ 75 | cd .. 76 | 77 | case $PLATFORM in 78 | osx) 79 | ## Remove files that depend on QuickTime.h, which isn't in Sierra. 80 | grep -vi 'ofQt' third-party/openFrameworks/libs/openFrameworksCompiled/project/osx/openFrameworksLib.xcodeproj/project.pbxproj > project.pbxproj 81 | mv project.pbxproj third-party/openFrameworks/libs/openFrameworksCompiled/project/osx/openFrameworksLib.xcodeproj/project.pbxproj 82 | ;; 83 | esac 84 | 85 | git submodule init 86 | git submodule update 87 | 88 | ln -s $(pwd)/third-party/ofxGrt/ third-party/openFrameworks/addons/ofxGrt 89 | ln -s $(pwd)/third-party/ofxDatGui/ third-party/openFrameworks/addons/ofxDatGui 90 | ln -s $(pwd)/third-party/ofxParagraph/ third-party/openFrameworks/addons/ofxParagraph 91 | 92 | echo "Done" 93 | -------------------------------------------------------------------------------- /update-xcode-grt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | if [ -z "$1" ] 5 | then 6 | SRC_DYLIB=third-party/grt/build/tmp/libgrt.dylib 7 | else 8 | SRC_DYLIB=third-party/grt/build/$1/libgrt.dylib 9 | fi 10 | 11 | cp ${SRC_DYLIB} Xcode/ESP 12 | install_name_tool -id @executable_path/../Frameworks/libgrt.dylib Xcode/ESP/libgrt.dylib 13 | --------------------------------------------------------------------------------