Ejemplo n.º 1
0
		uint8_t handleButton(T dt, uint8_t state, uint8_t value) {
			if (state & ButtonStateDebounce) {
				return handleDebounce(dt, state);
			}

		 	return handlePress(dt, state, value);
		}
Ejemplo n.º 2
0
///--------------------------------------------------------------
void Scene2::tuioPressed(ofTouchEventArgs &touch)
{
    TuioCursor *myCursor = makeCursor(touch.id, touch.x, touch.y);

    ofVec2f screenCoords = TUIOHandler::tuioToScreenCoords(touch.x, touch.y);
    handlePress(InteractionSourceTuio, int(screenCoords.x), int(screenCoords.y), myCursor);
}
Ejemplo n.º 3
0
///--------------------------------------------------------------
void Scene2::tuioReceiverPressed(TUIOReceiverEvent &cursor)
{
    TuioCursor *myCursor = makeCursor(cursor.sourceId, cursor.sessionId, cursor.cursorId,
                                      cursor.x, cursor.y, cursor.xSpeed, cursor.ySpeed, cursor.motionAccel);

    ofVec2f screenCoords = TUIOHandler::tuioToScreenCoords(cursor.x, cursor.y);
    handlePress(InteractionSourceTuio, int(screenCoords.x), int(screenCoords.y), myCursor);
}
Ejemplo n.º 4
0
int RemoteExpress::loop(){
	int result = 0;
	if (irrecv.decode(&remoteResults)){
		if (remoteResults.value == REPEAT){
			handleRepeat();
		}
		else{
			lastCode = remoteResults.value;
			lastCodeTime = millis();
			result = handlePress(remoteResults.value);
		}

		irrecv.resume();
	}

	return result;
}
Ejemplo n.º 5
0
/*
 * main.c
 * Initializes the robot
 * Waits for a new IR packet to be recieved, then handles the request
 */
void main(void) {
	
    initMSP430();				//initialize system
    initIR();

    P1DIR |= BIT0 | BIT6;				// Enable updates to the LED
   	P1OUT &= ~(BIT0 | BIT6);			// An turn the LED off

    GO_STOP;

    while(1){
    	if(packetIndex == 34){
    		handlePress();
    		_delay_cycles(LONG_T);
    		initIR();
    	}
    }

}
Ejemplo n.º 6
0
void handleModeState(int x, int y, int pressure)
{         
    static int waitStable=0;
    static uint16_t accelTimeX=0,accelTimeY=0;
    static uint8_t puffActive=0, sipActive=0, puffCount=0, sipCount=0;
    int strongDirThreshold;
    float moveVal;

    currentTime = millis();
    timeDifference = currentTime - previousTime;
    previousTime = currentTime;
    accelFactor= timeDifference / 100000000.0f;      

    if (pressure>previousPressure) pressureRising=1; else pressureRising=0;
    if (pressure<previousPressure) pressureFalling=1; else pressureFalling=0;
    previousPressure=pressure;

    if (settings.stickMode == STICKMODE_ALTERNATIVE) 
      strongDirThreshold=0;
    else strongDirThreshold= STRONGMODE_MOUSE_JOYSTICK_THRESHOLD;
    
     switch (modeState)  {                                   // handle strong sip and puff actions
      
        case MODESTATE_IDLE:   // IDLE
           if (pressure > settings.sp) { 
               modeState=MODESTATE_ENTER_STRONGPUFF_MODE;
               makeTone(TONE_ENTER_STRONGPUFF,0 );             
               }
           if (pressure < settings.ss ) { 
                 modeState=MODESTATE_ENTER_STRONGSIP_MODE;      
                 makeTone(TONE_ENTER_STRONGSIP,0 );             
             }
             break;
             
        case MODESTATE_ENTER_STRONGPUFF_MODE:     // puffed strong, wait for release          
            if (pressure < settings.tp)
               waitStable++;
            else waitStable=0;
            if (waitStable>=STRONGMODE_STABLETIME)
                modeState=MODESTATE_STRONGPUFF_MODE_ACTIVE;
            break;

        case MODESTATE_STRONGPUFF_MODE_ACTIVE:    // strong puff mode active
           if (y<-strongDirThreshold) { 
             makeTone(TONE_EXIT_STRONGPUFF,0 );
             handlePress(STRONGPUFF_UP_BUTTON); handleRelease(STRONGPUFF_UP_BUTTON);
             modeState=MODESTATE_RETURN_TO_IDLE;
           }
           else if (x<-strongDirThreshold) { 
             makeTone(TONE_EXIT_STRONGPUFF,0 );
             handlePress(STRONGPUFF_LEFT_BUTTON); handleRelease(STRONGPUFF_LEFT_BUTTON);
             modeState=MODESTATE_RETURN_TO_IDLE;
           }
           else if (x>strongDirThreshold) { 
             makeTone(TONE_EXIT_STRONGPUFF,0 ); 
             handlePress(STRONGPUFF_RIGHT_BUTTON); handleRelease(STRONGPUFF_RIGHT_BUTTON);
             modeState=MODESTATE_RETURN_TO_IDLE;
           }
           else if (y>strongDirThreshold) { 
             makeTone(TONE_EXIT_STRONGPUFF,0 ); 
             handlePress(STRONGPUFF_DOWN_BUTTON); handleRelease(STRONGPUFF_DOWN_BUTTON);
             modeState=MODESTATE_RETURN_TO_IDLE;
          }
           else { 
                  waitStable++; 
                  if (waitStable>STRONGMODE_EXIT_TIME) {  // no stick movement occurred: perform strong puff action
                    waitStable=0; 
                    handlePress(STRONGPUFF_BUTTON); 
                    handleRelease(STRONGPUFF_BUTTON);
                    modeState=MODESTATE_RETURN_TO_IDLE;
                  } 
                }
           break;

        case MODESTATE_ENTER_STRONGSIP_MODE:   // sipped strong, wait for release          
            if (pressure > settings.ts)
               waitStable++;
            else waitStable=0;
            if (waitStable>=STRONGMODE_STABLETIME)
                modeState=MODESTATE_STRONGSIP_MODE_ACTIVE;
            break;
  
        case MODESTATE_STRONGSIP_MODE_ACTIVE:   // strong sip mode active          
           if (y<-strongDirThreshold) { 
             makeTone(TONE_EXIT_STRONGSIP,0 );
             handlePress(STRONGSIP_UP_BUTTON); handleRelease(STRONGSIP_UP_BUTTON);
             modeState=MODESTATE_RETURN_TO_IDLE;
           }
           else if (x<-strongDirThreshold) { 
             makeTone(TONE_EXIT_STRONGSIP,0 );
             handlePress(STRONGSIP_LEFT_BUTTON); handleRelease(STRONGSIP_LEFT_BUTTON);
             modeState=MODESTATE_RETURN_TO_IDLE;
           }
           else if (x>strongDirThreshold) { 
             makeTone(TONE_EXIT_STRONGSIP,0 ); 
             handlePress(STRONGSIP_RIGHT_BUTTON); handleRelease(STRONGSIP_RIGHT_BUTTON);
             modeState=MODESTATE_RETURN_TO_IDLE;
           }
           else if (y>strongDirThreshold) { 
             makeTone(TONE_EXIT_STRONGSIP,0 ); 
             handlePress(STRONGSIP_DOWN_BUTTON); handleRelease(STRONGSIP_DOWN_BUTTON);
             modeState=MODESTATE_RETURN_TO_IDLE;
          }
          else {
             waitStable++; 
             if (waitStable>STRONGMODE_EXIT_TIME) {    // no stick movement occurred: perform strong sip action
                waitStable=0; 
                handlePress(STRONGSIP_BUTTON); 
                handleRelease(STRONGSIP_BUTTON);
                modeState=MODESTATE_RETURN_TO_IDLE;
              }
           }
           break;

       case MODESTATE_RETURN_TO_IDLE:
             waitStable++;
             if (waitStable>STRONGMODE_IDLE_TIME)
             {
                waitStable=0;
                modeState=MODESTATE_IDLE;
                initDebouncers();
                puffActive=0;sipActive=0;
             }
            break;             
        default: break; 
      }


      if (modeState==MODESTATE_IDLE)
      {  
           for (int i=0;i<NUMBER_OF_PHYSICAL_BUTTONS;i++)    // update button press / release events
              handleButton(i, digitalRead(input_map[i]) == LOW ? 1 : 0);

           switch (puffActive)  {
            case 0:
               if (pressure > settings.tp)   // handle single puff actions
               {  
                 makeTone(TONE_INDICATE_PUFF,0);
                 puffActive=1;puffCount=0;
               }  
               break;
            case 1:  
                 if (!pressureRising)
                 { 
                    if (puffCount++>SIP_PUFF_SETTLE_TIME) 
                    {
                       puffActive=2; 
                       handlePress(PUFF_BUTTON); 
                    }
                 } else if (puffCount) puffCount--;
                 break;
              // handleButton(PUFF_BUTTON, 0); 
            case 2:
                 if (pressure < settings.tp) { 
                    handleRelease(PUFF_BUTTON); 
                    puffActive=0; 
                 }
           }

 
           switch (sipActive)  {
            case 0:
               if (pressure < settings.ts)   // handle single sip actions
               {  
                 makeTone(TONE_INDICATE_SIP,0);
                 sipActive=1;sipCount=0;
               }  
               break;
            case 1:  
                 if (!pressureFalling)
                 { 
                    if (sipCount++>SIP_PUFF_SETTLE_TIME) 
                    {
                       sipActive=2; 
                       handlePress(SIP_BUTTON); 
                    }
                 } else if (sipCount) sipCount--;
                 break;
              // handleButton(SIP_BUTTON, 0); 
            case 2:
                 if (pressure > settings.ts) { 
                    handleRelease(SIP_BUTTON); 
                    sipActive=0; 
                 }
           }

           if ((moveX!=0) || (moveY!=0))   // handle movement induced by button actions  
           {
              if (mouseMoveCount++%4==0)
                 Mouse.move(moveX, moveY);
                 if(isBluetoothAvailable()) mouseBT(moveX,moveY,0);
           }
        
           if (settings.stickMode == STICKMODE_MOUSE) {   // handle mouse mode

                float max_speed= settings.ms / 10.0f;
  
                if (x==0) accelTimeX=0;
                else if (accelTimeX < ACCELTIME_MAX) accelTimeX+=settings.ac;
                if (y==0) accelTimeY=0;
                else if (accelTimeY < ACCELTIME_MAX) accelTimeY+=settings.ac;
                
                moveVal=x*settings.ax*accelFactor*accelTimeX;
                if (moveVal>max_speed) moveVal=max_speed;
                if (moveVal< -max_speed) moveVal=-max_speed;
                accumXpos+=moveVal;
  
                moveVal=y*settings.ay*accelFactor*accelTimeY;
                if (moveVal>max_speed) moveVal=max_speed;
                if (moveVal< -max_speed) moveVal=-max_speed;
                accumYpos+=moveVal;
  
                
                int xMove = (int)accumXpos;
                int yMove = (int)accumYpos;
                
                Mouse.move(xMove, yMove);
                if(isBluetoothAvailable() && (xMove != 0 || yMove != 0)) mouseBT(xMove,yMove,0);
                accumXpos -= xMove;
                accumYpos -= yMove;
            }
            else if (settings.stickMode==STICKMODE_ALTERNATIVE){ // handle alternative actions mode
                handleButton(UP_BUTTON,  y<0 ? 1 : 0);
                handleButton(DOWN_BUTTON,  y>0 ? 1 : 0);
                handleButton(LEFT_BUTTON,  x<0 ? 1 : 0);
                handleButton(RIGHT_BUTTON,  x>0 ? 1 : 0);
            }
            else  {                                          // handle joystick modes 2,3 and 4
              if (y==0) accumYpos = 512;
              else accumYpos = 512+(float)y*settings.ay/50.0f;
              
              if (x==0) accumXpos = 512;
              else  accumXpos = 512+(float)x*settings.ax/50.0f;
  
              if (accumXpos<0) accumXpos=0; if (accumXpos>1023) accumXpos=1023;
              if (accumYpos<0) accumYpos=0; if (accumYpos>1023) accumYpos=1023;
              
              switch (settings.stickMode) {
                case STICKMODE_JOYSTICK_XY:
                  Joystick.X (accumXpos);
                  Joystick.Y (accumYpos);
                  break;
                case STICKMODE_JOYSTICK_ZR:
                  Joystick.Z (accumXpos);
                  Joystick.Zrotate (accumYpos);
                  break;
                case STICKMODE_JOYSTICK_SLIDERS:
                  Joystick.sliderLeft (accumXpos);
                  Joystick.sliderRight (accumYpos);
                  break;
                }
            }
      }
}
Ejemplo n.º 7
0
///--------------------------------------------------------------
void Scene2::mousePressed(int x, int y, int button)
{
    handlePress(InteractionSourceMouse, x, y);
}