//--------------------------
void threadedSerial::threadedFunction() 
{
	while( isThreadRunning() != 0 ){
		if( lock() ){
			haveInput[0] = 0;
			haveInput[1] = 0;
			haveInput[2] = 0;
			
			readSerial(); // this is the threaded serial polling call
            
            OSCtime = ofGetElapsedTimeMillis();
            if(OSCtime >= (OSCprevTime + OSCsendingInterval) ) {
                
                for(int i = 0; i < NUMOSCSENDERS; i++) {
                    if(senderActive[i]) {
                        if(i == resetID){
                            sendOSC( i, true );
                        }else{
                            sendOSC( i, false );
                        }
                    }
                }
                OSCprevTime = OSCtime;
            }
            
            usleep(500);	//mac sleeps in microseconds = 1/2 millisecond interval for serialThread
			unlock();
		}
	}
}
Exemple #2
0
void nebulaEye::update()
{
  parameterSync.update();
  updateOSC();
  video.update();
  if(video.isFrameNew() || mouseTest){
    if ( mouseTest ){
      ofxCv::toOf(testimg,img);
      zone.unregister();
    } else {
      img = video.getPixels();
      zone._register();
    }
    zone.update(img);
    cv::Mat cvimg = ofxCv::toCv(img);
    cv::Mat maskedImg;
    cvimg.copyTo(maskedImg,~zone.mask[0]);
    bgSub.update(maskedImg);
    flow.update(img);

    if (pix_share.getSource() == nebulaPix_share::SOURCE_FLOW) pix_share.setPixels(flow.getUCFlow());

    if ( bgSub.enabled ){
      contour.update(bgSub.m_fgmask);
      if (pix_share.getSource() == nebulaPix_share::SOURCE_FGMASK) pix_share.setPixels(bgSub.m_fgmask);
    } else {
      contour.update(ofxCv::toCv(img));
    }

    sendOSC();
    recordCSVData();
  }
}
Exemple #3
0
//==============================================================================
void Ambix_encoderAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
    // Use this method as the place to do any pre-playback
    // initialisation that you need..
    SampleRate = sampleRate;
    
    // init meter dsp
    _my_meter_dsp.setAudioParams((int)SampleRate, samplesPerBlock);
    _my_meter_dsp.setParams(0.5f, 20.0f);
#if WITH_OSC
    sendOSC();
#endif
}
Exemple #4
0
void Ambix_encoderAudioProcessor::timerCallback() // check if new values and call send osc
{

    if (osc_out)
    {
        if (_azimuth_param != azimuth_param ||
            _elevation_param != elevation_param ||
            _size_param != size_param ||
            _rms != rms ||
            _dpk != dpk)
            
            sendOSC();
        
    }
}
Exemple #5
0
void Canvas::blobOff( int x, int y, int id, int order ) {
    sendOSC("/destroy", id, 1.0*x/width, 1.0*y/height);
}
Exemple #6
0
void Canvas::blobMoved( int x, int y, int id, int order) {
    sendOSC("/update", id, 1.0*x/width, 1.0*y/height);	
}
Exemple #7
0
void Canvas::blobOn( int x, int y, int id, int order ) {
    sendOSC("/create", id, 1.0*x/width, 1.0*y/height);
}
Exemple #8
0
int main(int argc, char** argv) {
    printf("i2c c test.\n");
    int fd[2];
    unsigned char buf[10];
    char *fileName = "/dev/i2c-1";
    int addr[2] = {0x29, 0x39}; // Adressen der Chips

    openPort(&fd[0]);
    openPort(&fd[1]);
    addSlave(addr[0], &fd[0]);
    addSlave(addr[1], &fd[1]);

    int i;

    int readcount[2] = {0, 1};
    double maxlux = 0.0;
    int maxCh0 = 0;


    //Variablen zur Berechnung des Lichteinfalls
    int cLow[2] = {65536, 65536};
    int cHigh[2] = {0, 0};
    double cc[2] = {0.0, 0.0};
    double maxcc[2] = {0.0, 0.0};
    double lastcc[2] = {0.0, 0.0};
    double epsilon = 0.01;

    //Variablen zur Aktivierung der Dosen:

    int active[2] = {0, 0};
    double actThr = 0.1; //Schwellenwert um Verdunklung zu erkennen

    //initialisiere OSC:

    lo_address oscaddr = initOSC("192.168.1.8", "7777");

    while(1) {
        for(i = 0; i < 2; i++) {
            cc[i] = readLight(&fd[i], &cLow[i], &cHigh[i]);
            readcount[i]++;
            if(cc[i] > maxcc[i]) {
                maxcc[i] = cc[i];
            }
            if(readcount[i] >= 3) {
                if(active[i]) {
                    if((lastcc[i] > maxcc[i] + epsilon) || (lastcc[i] < maxcc[i] - epsilon)) {
                        //Lichtintensitaet hat sich signifikant geaendert -> Ausgabe!
                        printf("%d Licht: %f\n", i, maxcc[i]);
                        if(i == 0) sendOSC(&oscaddr, "/licht0", maxcc[i]);
                        else if(i == 1) sendOSC(&oscaddr, "/licht1", maxcc[i]);
                        lastcc[i] = maxcc[i];
                    }
                }
                else {
                    if(maxcc[i] > (1.0 - actThr)) {
                        printf("Dose %d ist jetzt aktiv.\n", i);
                        active[i] = 1;
                    }
                }
                readcount[i] = 0;
                maxcc[i] = 0.0;
            }
        }

        /* lo_address t = lo_address_new("192.168.1.8", "7777");

        if(lo_send(t, "/light", "f", cc) == -1) {
        printf("OSC Fehler: %s\n", lo_address_errstr(t));
        }*/
        
        usleep(13 * 1000);

    }
    return 0;
}