#include "testApp.h" //-------------------------------------------------------------- testApp::~testApp(){ ard.disconnect(); // closes the serial port connection saveSettings("settings.xml"); } //-------------------------------------------------------------- void testApp::setup(){ loadSettings("settings.xml"); ofBackground(0,0,0); ///ofSetVerticalSync(true); //some model / light stuff glEnable (GL_DEPTH_TEST); glShadeModel (GL_SMOOTH); glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable (GL_COLOR_MATERIAL); printf("loading %s at %f,%f,%f",model_name.c_str(),model_x,model_y,model_z); //load the bottle model - the 3ds and the texture file need to be in the same folder model.loadModel(model_name, 1); model.setRotation(0, 180, 1, 0, 0); //model.setRotation(0, 90, 0, 1, 0); model.setPosition(model_x, model_y, model_z); calibrator_label.loadMovie("calibrator_label.mov"); calibrator_label.setLoopState(OF_LOOP_NORMAL); calibrator_label.play(); //ofDisableArbTex(); mode=DISPLAY; transTime=0; transition=false; whichClip=1; //0 is black switchClip=1; //0 is black texture.loadMovie(clips[whichClip]); texture.setLoopState(OF_LOOP_NORMAL); texture.play(); light=true; mixAmount=1.0; camWidth = 320; // try to grab at this size. camHeight = 240; vidGrabber.setVerbose(true); vidGrabber.listDevices(); vidGrabber.setDeviceID(0); grabberAvailable=vidGrabber.initGrabber(camWidth,camHeight); //printf("asked for 320 by 240 - actual size is %i by %i\n", vidGrabber.width, vidGrabber.height); videoInverted = new unsigned char[camWidth*camHeight*3]; videoTexture.allocate(camWidth,camHeight, GL_RGB); ard.connect("/dev/ttyUSB0", 57600); ofAddListener(ard.EInitialized, this, &testApp::setupArduino); bSetupArduino = false; bSwitchArduino = false; } //-------------------------------------------------------------- void testApp::update(){ texture.idleMovie(); calibrator_label.idleMovie(); //mixAmount=sin(ofGetElapsedTimef())+1.0; doTransition(); if (mode==GRAB) { vidGrabber.grabFrame(); if (vidGrabber.isFrameNew()){ int totalPixels = camWidth*camHeight*3; unsigned char * pixels = vidGrabber.getPixels(); for (int i = 0; i < totalPixels; i+=3){ unsigned int bright= (pixels[i]>>2)+ (pixels[i+1]>>1)+(pixels[i+1]>>2); //(0.2126*R) + (0.7152*G) + (0.0722*B) videoInverted[i] = (unsigned char)((226*bright)>>8); videoInverted[i+1] = (unsigned char)((200*bright)>>8); videoInverted[i+2] = (unsigned char)((20*bright)>>8); } videoTexture.loadData(videoInverted, camWidth,camHeight, GL_RGB); } } updateArduino(); } //-------------------------------------------------------------- void testApp::setupArduino(const int & version) { // remove listener because we don't need it anymore ofRemoveListener(ard.EInitialized, this, &testApp::setupArduino); // this is where you setup all the pins and pin modes, etc for (int i = 0; i < 13; i++){ ard.sendDigitalPinMode(i, ARD_OUTPUT); } ard.sendDigitalPinMode(7, ARD_INPUT); bSetupArduino = true; printf("arduino ready\n"); } //-------------------------------------------------------------- void testApp::updateArduino(){ // update the arduino, get any data or messages. ard.update(); // do not send anything until the arduino has been set up if (bSetupArduino) { if (bSwitchArduino!=ard.getDigital(7)) { bSwitchArduino=ard.getDigital(7); printf("pin 7 %i\n",bSwitchArduino); if (!bSwitchArduino) { whichClip=max(1,switchClip); transTime=ofGetElapsedTimef()+0.5; } else { switchClip=whichClip; whichClip=0; transTime=ofGetElapsedTimef()+0.1; } transition=true; } } } //-------------------------------------------------------------- void testApp::draw(){ for (int i=0;i': whichClip=max(1,(whichClip+1)%numClips); transTime=ofGetElapsedTimef()+1.0; transition=true; break; case '/': light=!light; printf(light?"LIGHT ON\n":"LIGHT OFF\n"); break; case '`': ard.disconnect(); // closes the serial port connection printf("arduino disconnected\n"); break; } } void testApp::doTransition(){ if (transition) { if (ofGetElapsedTimef()>transTime) { texture.stop(); texture.loadMovie(clips[whichClip]); texture.play(); transition=false; } } mixAmount=min(abs(ofGetElapsedTimef()-transTime),1.0f); if (whichClip==0&&!transition) mixAmount=0; } //-------------------------------------------------------------- void testApp::keyReleased(int key){ if (activeView<0) for (int i=0;ikeys; XML.getAttributeNames("settings", keys, 0); mapsettings; for (int k=0;kkeys; XML.getAttributeNames("settings", keys, 0); for (int k=0;k