Пример #1
0
static void handle_release(input_device *dev, struct input_event *ev) {
    if (dev->touch_pos.y < (gr_fb_height() - virtualkey_h)) {
        if(dev->slide_right == 1) {
            ev->type = EV_KEY;
            ev->code = KEY_ENTER;
            ev->value = 2;
            vibrate(VIBRATOR_TIME_MS);
        } else if(dev->slide_left == 1) {
            ev->type = EV_KEY;
            ev->code = KEY_BACK;
            ev->value = 2;
            vibrate(VIBRATOR_TIME_MS);
        }
    }
#ifdef USE_VIRTUAL_KEY
    else {
        ev->type = EV_KEY;
        ev->code=ui_get_virtualkey_pressed(dev);
        ev->value = 2;
        vibrate(VIBRATOR_TIME_MS);
    }
    //clear button pressed down effect.
    if (virtualkey_pressed == 1 && ui_handle_key(ev->code, 1) == NO_ACTION) {
        pthread_mutex_lock(&gUpdateMutex);
        draw_virtualkeys_locked();
        gr_flip();
        pthread_mutex_unlock(&gUpdateMutex);
        virtualkey_pressed = 0;
    }
#endif
    reset_touch(dev);
}
float Controller::movement()
{
    // Movement for the character
    float movement = 0.0f;

    // Get all the current states of controller 1
    XInputGetState(0, controllerState);

    // LB is Pressed...
    if (controllerState->Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER)
    {
        // Go Left and Vibrate
        movement = -1.3f;
        vibrate(0.5, 0);
    }

    // RB is Pressed...
    if (controllerState->Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER)
    {
        // Go Right and Vibrate
        movement = 1.3f;
        vibrate(0, 0.5);
    }

    // Retrun speed of the ship
    return movement;
}
Пример #3
0
DWORD WINAPI XInputSetStateEx
(
__in DWORD             dwUserIndex,						// Index of the gamer associated with the device
__in XINPUT_VIBRATION_EX* pVibration					// The vibration information to send to the controller
)
{
	writeLog("XInputSetStateEx", "controllerInit = %d - dwUserIndex = %d \n", controllerInit, dwUserIndex);
	if (!controllerInit)
	{
		connectController(true);
	}

	if (controllerInit && dwUserIndex >= 0 && dwUserIndex < 4 && controllerHandler[dwUserIndex])
	{
		// We're receiving as XInput [0 ~ 65535], need to be [0 ~ 255] !!
		int leftTriggerVal = iround(((float)pVibration->wLeftTriggerMotorSpeed / 65535) * 255);
		int rightTriggerVal = iround(((float)pVibration->wRightTriggerMotorSpeed / 65535) * 255);
		int leftVal = iround(((float)pVibration->wLeftMotorSpeed / 65535) * 255);
		int rightVal = iround(((float)pVibration->wRightMotorSpeed / 65535) * 255);

		vibrate(leftTriggerVal, rightTriggerVal, leftVal, rightVal, dwUserIndex);

		writeLog("XInputSetStateEx", "return ERROR_SUCCESS\n");
		return ERROR_SUCCESS;
	}
	else
	{
		writeLog("XInputSetStateEx", "return ERROR_DEVICE_NOT_CONNECTED\n");
		return ERROR_DEVICE_NOT_CONNECTED;
	}
}
Пример #4
0
static void timer_complete(){
	//buzz, display, the whole nine
	running = false;
	text_layer_set_text(text_layer, "00:00");
	vibrate();
	display_time();
}
dword imgbtn_oninput(void * x, int action, ATEV * atev) {
  ACONTROLP ctl  = (ACONTROLP) x;
  IMGBTNDP  d  = (IMGBTNDP) ctl->d;
  dword msg = 0;
  
  switch (action) {
    case ATEV_MOUSEDN: {
        vibrate(30);
        d->pushed = 1;
        msg = aw_msg(0, 1, 0, 0);
        ctl->ondraw(ctl);
      }
      break;
      
    case ATEV_MOUSEUP: {
        d->pushed = 0;
        
        if (aw_touchoncontrol(ctl, atev->x, atev->y)) {
          msg = aw_msg(d->touchmsg, 1, 0, 0);
        }
        else {
          msg = aw_msg(0, 1, 0, 0);
        }
        
        ctl->ondraw(ctl);
      }
      break;
      
    case ATEV_SELECT: {
        if (atev->d) {
          vibrate(30);
          d->pushed = 1;
          msg = aw_msg(0, 1, 0, 0);
          ctl->ondraw(ctl);
        }
        else {
          d->pushed = 0;
          msg = aw_msg(d->touchmsg, 1, 0, 0);
          ctl->ondraw(ctl);
        }
      }
      break;
  }
  
  return msg;
}
Пример #6
0
HRESULT notification_exec(BSTR callback_id, BSTR action, BSTR args, VARIANT *result)
{
	if(!wcscmp(action, L"alert") || !wcscmp(action, L"confirm"))
		return show_dialog(callback_id, args);
	if (!wcscmp(action, L"vibrate"))
		return vibrate(callback_id, args);
	if (!wcscmp(action, L"beep"))
		return beep(callback_id, args);

	return DISP_E_MEMBERNOTFOUND;
}
Пример #7
0
void do_vibrate(int milliseconds)
{
#ifdef __ANDROID__
    std::string vibrate_key = "vibration_enabled";
    if (DataManager::get_bool_from_data(vibrate_key, true))
    {
        vibrate(milliseconds);
    };
#else
#endif

};
dword accb_oninput(void * x,int action,ATEV * atev){
  ACONTROLP ctl  = (ACONTROLP) x;
  ACCBDP  d  = (ACCBDP) ctl->d;
  dword msg = 0;
  switch (action){
    case ATEV_MOUSEDN:
      {
        vibrate(30);
        d->pushed=1;
        msg=aw_msg(0,1,0,0);
        ctl->ondraw(ctl);
      }
      break;
    case ATEV_MOUSEUP:
      {
        d->pushed=0;
        if (aw_touchoncontrol(ctl,atev->x,atev->y))
          d->checked = !d->checked;
        msg=aw_msg(0,1,0,0);
        ctl->ondraw(ctl);
      }
      break;
    case ATEV_SELECT:
      {
        if (atev->d){
          vibrate(30);
          d->pushed=1;
        }
        else{
          d->pushed=0;
          d->checked = !d->checked;
        }
        msg=aw_msg(0,1,0,0);
        ctl->ondraw(ctl);
      }
      break;
  }
  return msg;
}
Пример #9
0
//records on shot in sram (20seconds) returns the number of records
//need to add error checking on high byte of address (only 0 and 1)
void add_inc()
{
  if(add_l==255 && add_m==255 && add_h==1){vibrate(1000);uart_puts("MEM OVERFLOW");while(1){}}
  
  if(add_l==255)
  {
    add_l=0;
    if(add_m==255)
    {
      add_m=0;
      add_h=1;
    }
    else{add_m++;} 
    
  } 
  else{add_l++;}

}//end add_inc
Пример #10
0
void SmSnDevice::setup() {
    setupPins();

    setColor(RGB_YELLOW);

    //morse = createMorse();

/*
    droidspeak = createDroidspeak();
    if (droidspeak) {
        droidspeak->speakPowerUpPhrase();
    }
*/

    osc.beginSerial();

    bundleIn = new OSCBundle();

    setupOther();

    // delay the serial open phrase until the random number generator has been seeded
    setColor(RGB_GREEN);
    /*
    if (droidspeak) {
        droidspeak->speakSerialOpenPhrase();
    }
    */
    setColor(RGB_BLACK);

    vibrate(500);
    osc.sendInfo("%s is ready", osc.getPrefix());

    loopCount = 0;
    loopThreshold = 100;
    // initial value for loop time gets us through the first half second or so
    loopTime = 4.0/1000;
    loopStartTime = millis();
}
Пример #11
0
/* Returns non-zero when the event should be consumed */
static int vk_modify(struct ev *e, struct input_event *ev)
{
    static int downX = -1, downY = -1;
    static int discard = 0;
    static int last_virt_key = 0;
    static int lastWasSynReport = 0;
    static int touchReleaseOnNextSynReport = 0;
	static int use_tracking_id_negative_as_touch_release = 0; // On some devices, type: 3  code: 39  value: -1, aka EV_ABS ABS_MT_TRACKING_ID -1 indicates a true touch release
    int i;
    int x, y;

    // This is used to ditch useless event handlers, like an accelerometer
    if (e->ignored)     return 1;

    if (ev->type == EV_REL && ev->code == REL_Z)
    {
        // This appears to be an accelerometer or another strange input device. It's not the touchscreen.
#ifdef _EVENT_LOGGING
        printf("EV: Device disabled due to non-touchscreen messages.\n");
#endif
        e->ignored = 1;
        return 1;
    }

#ifdef _EVENT_LOGGING
    printf("EV: %s => type: %x  code: %x  value: %d\n", e->deviceName, ev->type, ev->code, ev->value);
#endif

	// Handle keyboard events, value of 1 indicates key down, 0 indicates key up
	if (ev->type == EV_KEY) {
		return 0;
	}

    if (ev->type == EV_ABS) {
        switch (ev->code) {

        case ABS_X: //00
            e->p.synced |= 0x01;
            e->p.x = ev->value;
#ifdef _EVENT_LOGGING
            printf("EV: %s => EV_ABS  ABS_X  %d\n", e->deviceName, ev->value);
#endif
            break;

        case ABS_Y: //01
            e->p.synced |= 0x02;
            e->p.y = ev->value;
#ifdef _EVENT_LOGGING
            printf("EV: %s => EV_ABS  ABS_Y  %d\n", e->deviceName, ev->value);
#endif
            break;

        case ABS_MT_POSITION: //2a
            e->mt_p.synced = 0x03;
            if (ev->value == (1 << 31))
            {
                e->mt_p.x = 0;
                e->mt_p.y = 0;
                lastWasSynReport = 1;
            }
            else
            {
                lastWasSynReport = 0;
                e->mt_p.x = (ev->value & 0x7FFF0000) >> 16;
                e->mt_p.y = (ev->value & 0xFFFF);
            }
            break;

        case ABS_MT_TOUCH_MAJOR: //30
            if (ev->value == 0)
            {
#ifndef TW_IGNORE_MAJOR_AXIS_0
                // We're in a touch release, although some devices will still send positions as well
                e->mt_p.x = 0;
                e->mt_p.y = 0;
                touchReleaseOnNextSynReport = 1;
#endif
            }
#ifdef _EVENT_LOGGING
            printf("EV: %s => EV_ABS  ABS_MT_TOUCH_MAJOR  %d\n", e->deviceName, ev->value);
#endif
            break;

		case ABS_MT_PRESSURE: //3a
                    if (ev->value == 0)
            {
                // We're in a touch release, although some devices will still send positions as well
                e->mt_p.x = 0;
                e->mt_p.y = 0;
                touchReleaseOnNextSynReport = 1;
            }
#ifdef _EVENT_LOGGING
            printf("EV: %s => EV_ABS  ABS_MT_PRESSURE  %d\n", e->deviceName, ev->value);
#endif
            break;

		case ABS_MT_POSITION_X: //35
            e->mt_p.synced |= 0x01;
            e->mt_p.x = ev->value;
#ifdef _EVENT_LOGGING
            printf("EV: %s => EV_ABS  ABS_MT_POSITION_X  %d\n", e->deviceName, ev->value);
#endif
            break;

        case ABS_MT_POSITION_Y: //36
            e->mt_p.synced |= 0x02;
            e->mt_p.y = ev->value;
#ifdef _EVENT_LOGGING
            printf("EV: %s => EV_ABS  ABS_MT_POSITION_Y  %d\n", e->deviceName, ev->value);
#endif
            break;

        case ABS_MT_TOUCH_MINOR: //31
#ifdef _EVENT_LOGGING
            printf("EV: %s => EV_ABS ABS_MT_TOUCH_MINOR %d\n", e->deviceName, ev->value);
#endif
            break;

        case ABS_MT_WIDTH_MAJOR: //32
#ifdef _EVENT_LOGGING
            printf("EV: %s => EV_ABS ABS_MT_WIDTH_MAJOR %d\n", e->deviceName, ev->value);
#endif
            break;

        case ABS_MT_WIDTH_MINOR: //33
#ifdef _EVENT_LOGGING
            printf("EV: %s => EV_ABS ABS_MT_WIDTH_MINOR %d\n", e->deviceName, ev->value);
#endif
            break;

        case ABS_MT_TRACKING_ID: //39
            if (ev->value < 0) {
                e->mt_p.x = 0;
                e->mt_p.y = 0;
                touchReleaseOnNextSynReport = 2;
                use_tracking_id_negative_as_touch_release = 1;
#ifdef _EVENT_LOGGING
                if (use_tracking_id_negative_as_touch_release)
                    printf("using ABS_MT_TRACKING_ID value -1 to indicate touch releases\n");
#endif
            }
#ifdef _EVENT_LOGGING
            printf("EV: %s => EV_ABS ABS_MT_TRACKING_ID %d\n", e->deviceName, ev->value);
#endif
            break;

#ifdef _EVENT_LOGGING
        // These are for touch logging purposes only
        case ABS_MT_ORIENTATION: //34
            printf("EV: %s => EV_ABS ABS_MT_ORIENTATION %d\n", e->deviceName, ev->value);
			return 1;
            break;

		case ABS_MT_TOOL_TYPE: //37
            LOGI("EV: %s => EV_ABS ABS_MT_TOOL_TYPE %d\n", e->deviceName, ev->value);
			return 1;
            break;

        case ABS_MT_BLOB_ID: //38
            printf("EV: %s => EV_ABS ABS_MT_BLOB_ID %d\n", e->deviceName, ev->value);
			return 1;
            break;

		case ABS_MT_DISTANCE: //3b
            printf("EV: %s => EV_ABS ABS_MT_DISTANCE %d\n", e->deviceName, ev->value);
			return 1;
            break;
#endif

        default:
            // This is an unhandled message, just skip it
            return 1;
        }

        if (ev->code != ABS_MT_POSITION)
        {
            lastWasSynReport = 0;
            return 1;
        }
    }

    // Check if we should ignore the message
    if (ev->code != ABS_MT_POSITION && (ev->type != EV_SYN || (ev->code != SYN_REPORT && ev->code != SYN_MT_REPORT)))
    {
        lastWasSynReport = 0;
        return 0;
    }

#ifdef _EVENT_LOGGING
    if (ev->type == EV_SYN && ev->code == SYN_REPORT)       printf("EV: %s => EV_SYN  SYN_REPORT\n", e->deviceName);
    if (ev->type == EV_SYN && ev->code == SYN_MT_REPORT)    printf("EV: %s => EV_SYN  SYN_MT_REPORT\n", e->deviceName);
#endif

    // Discard the MT versions
    if (ev->code == SYN_MT_REPORT)      return 0;

    if (((lastWasSynReport == 1 || touchReleaseOnNextSynReport == 1) && !use_tracking_id_negative_as_touch_release) || (use_tracking_id_negative_as_touch_release && touchReleaseOnNextSynReport == 2))
    {
        // Reset the value
        touchReleaseOnNextSynReport = 0;

        // We are a finger-up state
        if (!discard)
        {
            // Report the key up
            ev->type = EV_ABS;
            ev->code = 0;
            ev->value = (downX << 16) | downY;
        }
        downX = -1;
        downY = -1;
        if (discard)
        {
            discard = 0;

            // Send the keyUp event
            ev->type = EV_KEY;
            ev->code = last_virt_key;
            ev->value = 0;
        }
        return 0;
    }
    lastWasSynReport = 1;

    // Retrieve where the x,y position is
    if (e->p.synced & 0x03)
    {
        vk_tp_to_screen(&e->p, &x, &y);
    }
    else if (e->mt_p.synced & 0x03)
    {
        vk_tp_to_screen(&e->mt_p, &x, &y);
    }
    else
    {
        // We don't have useful information to convey
        return 1;
    }

#ifdef RECOVERY_TOUCHSCREEN_SWAP_XY
    x ^= y;
    y ^= x;
    x ^= y;
#endif
#ifdef RECOVERY_TOUCHSCREEN_FLIP_X
    x = gr_fb_width() - x;
#endif
#ifdef RECOVERY_TOUCHSCREEN_FLIP_Y
    y = gr_fb_height() - y;
#endif

#ifdef TW_HAS_LANDSCAPE
    switch(gr_get_rotation())
    {
        case 0:
        default:
            break;
        case 90:
#ifdef RECOVERY_TOUCHSCREEN_FLIP_X
            x = gr_fb_width() - x;
#endif
#ifdef RECOVERY_TOUCHSCREEN_FLIP_Y
            y = gr_fb_height() - y;
#endif

            x ^= y;
            y ^= x;
            x ^= y;

#ifndef RECOVERY_TOUCHSCREEN_FLIP_X
            y = gr_fb_height() - y;
#endif
            break;
        case 180:
            y = gr_fb_height() - y;
            x = gr_fb_width() - x;
            break;
        case 270:
#ifdef RECOVERY_TOUCHSCREEN_FLIP_X
            x = gr_fb_width() - x;
#endif
#ifdef RECOVERY_TOUCHSCREEN_FLIP_Y
            y = gr_fb_height() - y;
#endif

            x ^= y;
            y ^= x;
            x ^= y;

#ifdef RECOVERY_TOUCHSCREEN_FLIP_X
            y = gr_fb_height() - y;
#endif
#ifndef RECOVERY_TOUCHSCREEN_FLIP_Y
            x = gr_fb_width() - x;
#endif
            break;
    }
#endif

#ifdef _EVENT_LOGGING
    printf("EV: x: %d  y: %d\n", x, y);
#endif

    // Clear the current sync states
    e->p.synced = e->mt_p.synced = 0;

    // If we have nothing useful to report, skip it
    if (x == -1 || y == -1)     return 1;

    // On first touch, see if we're at a virtual key
    if (downX == -1)
    {
        // Attempt mapping to virtual key
        for (i = 0; i < e->vk_count; ++i)
        {
            int xd = ABS(e->vks[i].centerx - x);
            int yd = ABS(e->vks[i].centery - y);

            if (xd < e->vks[i].width/2 && yd < e->vks[i].height/2)
            {
                ev->type = EV_KEY;
                ev->code = e->vks[i].scancode;
                ev->value = 1;

                last_virt_key = e->vks[i].scancode;

                vibrate(VIBRATOR_TIME_MS);

                // Mark that all further movement until lift is discard,
                // and make sure we don't come back into this area
                discard = 1;
                downX = 0;
                return 0;
            }
        }
    }

    // If we were originally a button press, discard this event
    if (discard)
    {
        return 1;
    }

    // Record where we started the touch for deciding if this is a key or a scroll
    downX = x;
    downY = y;

    ev->type = EV_ABS;
    ev->code = 1;
    ev->value = (x << 16) | y;
    return 0;
}
static void * acime2_loopthread(void * cookie) {
  ACONTROLP ctl   = (ACONTROLP) cookie;
  ACIMEDP  d      = (ACIMEDP) ctl->d;
  long lt         = d->loopTick;
  byte pd         = d->pushedId;
  byte ft         = 0;
  
  while (1) {
    usleep(40000);
    
    if ((lt == d->loopTick) && (pd == d->pushedId)) {
      if (ft > 15) {
        if (pd == 30) {
          //-- SPACE
          acime2_sendmsg(ctl, 32, 0, 0);
        }
        else if (pd == 27) {
          //-- Backspace
          acime2_sendmsg(ctl, 8, 0, 0);
        }
        else if (pd == 35) {
          acime2_sendmsg(ctl, 37, 1, 1);  /* left */
        }
        else if (pd == 36) {
          acime2_sendmsg(ctl, 38, 1, 1);  /* up */
        }
        else if (pd == 37) {
          acime2_sendmsg(ctl, 40, 1, 1);  /* down */
        }
        else if (pd == 38) {
          acime2_sendmsg(ctl, 39, 1, 1);  /* right */
        }
        else if (!d->on123) {
          byte keyID = d->pushedId;
          char c = 0;
          
          if ((pd < 27) && (pd != 19)) {
            d->pushedId    = 254;
            int n = pd;
            
            if (n > 19) {
              n--;
            }
            
            int np = (d->onShift) ? 0 : 1;
            c = acime2_charlist[np][n];
            d->keyD[keyID] = 0;
            vibrate(30);
            acime2_sendmsg(ctl, (byte) c, 0, 0);
            
            if (d->onShift == 1) {
              d->onShift = 0;
              int i;
              
              for (i = 0; i < ACIME2_BTNCNT; i++) {
                d->keyD[i] = 0;
              }
            }
            
            ctl->ondraw(ctl);
            aw_draw(ctl->win);
          }
          
          break;
        }
      }
      
      if (ft <= 15) {
        ft++;
      }
    }
    else {
      break;
    }
  }
  
  return NULL;
}
dword acime2_oninput(void * x, int action, ATEV * atev) {
  ACONTROLP ctl   = (ACONTROLP) x;
  ACIMEDP  d      = (ACIMEDP) ctl->d;
  dword msg = 0;
  
  switch (action) {
    case ATEV_MOUSEUP: {
        if (d->pushedId < ACIME2_BTNCNT) {
          int keyID = d->pushedId;
          d->keyD[keyID]  = 0;
          d->pushedId     = 255;
          acime2_action(ctl, keyID, 1);
          
          if (((keyID < 27) && (keyID != 19)) || (keyID == 30) || (keyID == 29) || (keyID == 31)) {
            if (d->onShift == 1) {
              d->onShift = 0;
              int i;
              
              for (i = 0; i < ACIME2_BTNCNT; i++) {
                d->keyD[i] = 0;
              }
            }
          }
          
          ctl->ondraw(ctl);
          msg = aw_msg(0, 1, 0, 0);
        }
        else {
          d->pushedId = 255;
        }
      }
      break;
      
    case ATEV_MOUSEDN:
    case ATEV_MOUSEMV: {
        if ((d->pushedId != 200) && (d->pushedId != 254)) {
          int clientX = atev->x - ctl->x;
          int clientY = atev->y - ctl->y;
          
          if (clientY >= 0) {
            int i;
            
            for (i = 1; i < 5; i++) {
              if (clientY < (i * d->btnH)) {
                break;
              }
            }
            
            int r = i;
            byte idpos[5][2] = {
              {0,  9},
              {10, 18},
              {19, 27},
              {28, 32},
              {33, 38}
            };
            
            for (i = idpos[r - 1][0]; i < idpos[r - 1][1]; i++) {
              if (clientX < (d->keyX[i] + d->keyW[i])) {
                break;
              }
            }
            
            if (d->pushedId != i) {
              msg = aw_msg(0, 1, 0, 0);
              
              if (d->pushedId < ACIME2_BTNCNT) {
                d->keyD[d->pushedId]  = 0;
              }
              
              d->pushedId = i;
              acime2_action(ctl, i, 0);
              d->keyD[i]  = 0;
              ctl->ondraw(ctl);
              
              if (action == ATEV_MOUSEDN) {
                vibrate(30);
              }
            }
          }
        }
      }
      break;
  }
  
  return msg;
}
Пример #14
0
static void data_handler(AccelData *data, uint32_t num_samples) {
  handlerKey = 1;
  // Store the accelerometer data
  a_buffer_x[buffer_index] = data[0].x;
  a_buffer_y[buffer_index] = data[0].y;
  a_buffer_z[buffer_index] = data[0].z;
  
  if (buffer_index == 0 && !firstA) {
    j_buffer_x[buffer_index] = (a_buffer_x[buffer_index] - a_buffer_x[userBufferSize-1]) * SAMPLING_RATE / FACTOR;
    j_buffer_y[buffer_index] = (a_buffer_y[buffer_index] - a_buffer_y[userBufferSize-1]) * SAMPLING_RATE / FACTOR;
    j_buffer_z[buffer_index] = (a_buffer_z[buffer_index] - a_buffer_z[userBufferSize-1]) * SAMPLING_RATE / FACTOR;
  }
  else if(!firstA) {
    j_buffer_x[buffer_index] = (a_buffer_x[buffer_index] - a_buffer_x[buffer_index-1]) * SAMPLING_RATE / FACTOR;
    j_buffer_y[buffer_index] = (a_buffer_y[buffer_index] - a_buffer_y[buffer_index-1]) * SAMPLING_RATE / FACTOR;
    j_buffer_z[buffer_index] = (a_buffer_z[buffer_index] - a_buffer_z[buffer_index-1]) * SAMPLING_RATE / FACTOR;
  }
  else {
    firstA = 0;
  }
  
  /*
  * Jolt values are taken to be the squares of the 
  * actual jolts
  */
  int xJolt = 0;
  int yJolt = 0;
  int zJolt = 0;
  for (int i = 0; i < userBufferSize; i++) {
    xJolt += j_buffer_x[i]*j_buffer_x[i];
    yJolt += j_buffer_y[i]*j_buffer_y[i];
    zJolt += j_buffer_z[i]*j_buffer_z[i];
  }
  //square of the average magnitude of acceleration
  int jolt = (xJolt + yJolt + zJolt) / userBufferSize;
  
    // Long lived buffer
  static char message[128];
  static int keep = 0;
  static int load = 0;
  
  if (load < 2*SAMPLING_RATE) {
    text_layer_set_font(s_output_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
    text_layer_set_text_alignment(s_output_layer, GTextAlignmentLeft);
    text_layer_set_text(s_output_layer, "\n\nLoading...");
    load++;
  }
  else if (firstPass || keep <= 0){
    keep = 0;
    text_layer_set_font(s_output_layer, fonts_get_system_font(FONT_KEY_DROID_SERIF_28_BOLD));
    text_layer_set_text_alignment(s_output_layer, GTextAlignmentLeft);
    text_layer_set_text(s_output_layer, "\n  Auto\n      Wake");
  }
  else {
    keep--;
  }
    
  if (debug) {
    // Compose string of debug data
    snprintf(message, sizeof(message), 
      "X: %d  \nY: %d  \nZ: %d\nAverage Jolt: \n%d\nFirst: %s", 
      xJolt/userBufferSize, yJolt/userBufferSize, zJolt/userBufferSize,
      jolt - STILL,
      firstPass ? "True" : "False"
    );
    text_layer_set_font(s_debug_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
    //Show the data
    text_layer_set_text(s_debug_layer, message);
  }
  
  if ((abs(jolt - STILL) < iSensitivity) && !firstPass) {
    if (bSound) {
      ring();
    }
    if (bVibration) {
      vibrate();
    }
    text_layer_set_font(s_output_layer, fonts_get_system_font(FONT_KEY_DROID_SERIF_28_BOLD));
    text_layer_set_text_alignment(s_output_layer, GTextAlignmentCenter);
    text_layer_set_text(s_output_layer, "\nWAKE\nUP!!");
    keep = 3*SAMPLING_RATE;
  }
  
  // Increment buffer index
  buffer_index++;
  if (buffer_index >= userBufferSize) { 
    // Resets the buffer index
    buffer_index = 0;
    // Not first
    firstPass = 0;
  }
    
  handlerKey = 0;
}
Пример #15
0
int main(int argc, char **argv)
{
	int xboxControllerCounter = 0;
	usb_init();
	usb_find_busses();
	usb_find_devices();

	busses = usb_get_busses();

	for (bus = busses; bus; bus = bus->next)
	{
		for (dev = bus->devices; dev; dev = dev->next)
		{
			if (dev->descriptor.idVendor == idVendor && dev->descriptor.idProduct == idProduct && xboxControllerCounter < 4)
			{
				std::cout << "Found Xbox One Controller\n";
				controllerHandler[xboxControllerCounter] = (XboxOneControllerHandler*)malloc(sizeof(XboxOneControllerHandler));
				controllerHandler[xboxControllerCounter]->handle = usb_open(dev);

				if (usb_set_configuration(controllerHandler[xboxControllerCounter]->handle, configuration) < 0)
				{
					std::cout << "usb_set_configuration (" << usb_strerror() << ")." << std::endl;
					exit(EXIT_FAILURE);
				}

				if (usb_claim_interface(controllerHandler[xboxControllerCounter]->handle, interface) < 0)
				{
					std::cout << "usb_claim_interface (" << usb_strerror() << ")." << std::endl;
					exit(EXIT_FAILURE);
				}

				// Initialise
				char data[] = { 0x05, 0x20 };
				if (usb_interrupt_write(controllerHandler[xboxControllerCounter]->handle, endpointOut, (char*)data, sizeof(data), timeout) < 0)
				{
					std::cout << "usb_interrupt_write (" << usb_strerror() << ").\n";
				}

				std::cout << "Initialised Xbox One Controller number: " << xboxControllerCounter << std::endl << std::endl;

				std::cout << "Shake it ";
				// Motors are 0 - 255
				vibrate(50, 50, 50, 50, xboxControllerCounter);
				Sleep(500);
				vibrate(0, 0, 0, 0, xboxControllerCounter);

				std::cout << "and Listen - Press any key to exit." << std::endl << std::endl;

				bool receive_data = true;
				while (receive_data)
				{
					uint8_t raw_data[64];

					int ret = usb_interrupt_read(controllerHandler[xboxControllerCounter]->handle, endpointIn, (char*)raw_data, sizeof(raw_data), timeout);
					if (ret < 0)
					{
						std::cout << "usb_interrupt_read (" << usb_strerror() << ")." << std::endl;
						break;
					}

					char tag = raw_data[0];
					char code = raw_data[1];
					char data[62];

					int i = 0;
					for (int j = 2; j < 64; ++j)
					{
						data[i] = raw_data[j];
						i++;
					}

					switch (tag)
					{
					case 0x07:
						if ((data[2] & 0x01) != 0)
						{
							std::cout << "Guide" << std::endl;
						}
						break;
					case 0x20:
						decode(data);
						break;
					}

					if (_kbhit())
					{
						while (_kbhit()) _getch();
						receive_data = false;
					}
				}

				usb_release_interface(controllerHandler[xboxControllerCounter]->handle, interface);
				usb_close(controllerHandler[xboxControllerCounter]->handle);
			}
		}
	}

	return 0;
}
Пример #16
0
/* Returns non-zero when the event should be consumed */
static int vk_modify(struct ev *e, struct input_event *ev)
{
    int i;
    int x, y;

    if (ev->type == EV_KEY) {
        if (ev->code == BTN_TOUCH)
            e->p.pressed = ev->value;
        return 0;
    }

    if (ev->type == EV_ABS) {
        switch (ev->code) {
        case ABS_X:
            e->p.x = ev->value;
            return !vk_inside_display(e->p.x, &e->p.xi, gr_fb_width());
        case ABS_Y:
            e->p.y = ev->value;
            return !vk_inside_display(e->p.y, &e->p.yi, gr_fb_height());
        case ABS_MT_POSITION_X:
            if (e->mt_idx) return 1;
            e->mt_p.x = ev->value;
            return !vk_inside_display(e->mt_p.x, &e->mt_p.xi, gr_fb_width());
        case ABS_MT_POSITION_Y:
            if (e->mt_idx) return 1;
            e->mt_p.y = ev->value;
            return !vk_inside_display(e->mt_p.y, &e->mt_p.yi, gr_fb_height());
        case ABS_MT_TOUCH_MAJOR:
            if (e->mt_idx) return 1;
            if (e->sent)
                e->mt_p.pressed = (ev->value > 0);
            else
                e->mt_p.pressed = (ev->value > PRESS_THRESHHOLD);
            return 0;
        }

        return 0;
    }

    if (ev->type != EV_SYN)
        return 0;

    if (ev->code == SYN_MT_REPORT) {
        /* Ignore the rest of the points */
        ++e->mt_idx;
        return 1;
    }
    if (ev->code != SYN_REPORT)
        return 0;

    /* Report complete */

    e->mt_idx = 0;

    if (!e->p.pressed && !e->mt_p.pressed) {
        /* No touch */
        e->sent = 0;
        return 0;
    }

    if (!(e->p.pressed && vk_tp_to_screen(&e->p, &x, &y)) &&
            !(e->mt_p.pressed && vk_tp_to_screen(&e->mt_p, &x, &y))) {
        /* No touch inside vk area */
        return 0;
    }

    if (e->sent) {
        /* We've already sent a fake key for this touch */
        return 1;
    }

    /* The screen is being touched on the vk area */
    e->sent = 1;

    for (i = 0; i < e->vk_count; ++i) {
        int xd = ABS(e->vks[i].centerx - x);
        int yd = ABS(e->vks[i].centery - y);
        if (xd < e->vks[i].width/2 && yd < e->vks[i].height/2) {
            /* Fake a key event */
            ev->type = EV_KEY;
            ev->code = e->vks[i].scancode;
            ev->value = 1;

            vibrate(VIBRATOR_TIME_MS);
            return 0;
        }
    }

    return 1;
}
Пример #17
0
static int input_callback(int fd, short revents, void *data)
{
    struct input_event ev;
    int ret;
    int fake_key = 0;
    gr_surface surface = gVirtualKeys;

    ret = ev_get_input(fd, revents, &ev);
    if (ret)
        return -1;

#ifdef BOARD_TOUCH_RECOVERY
    if (touch_handle_input(fd, ev))
      return 0;
#endif

    if (ev.type == EV_SYN) {
        return 0;
    } else if (ev.type == EV_REL) {
        if (ev.code == REL_Y) {
            // accumulate the up or down motion reported by
            // the trackball.  When it exceeds a threshold
            // (positive or negative), fake an up/down
            // key event.
            rel_sum += ev.value;
            if (rel_sum > 3) {
                fake_key = 1;
                ev.type = EV_KEY;
                ev.code = KEY_DOWN;
                ev.value = 1;
                rel_sum = 0;
            } else if (rel_sum < -3) {
                fake_key = 1;
                ev.type = EV_KEY;
                ev.code = KEY_UP;
                ev.value = 1;
                rel_sum = 0;
            }
        }
    } else {
        rel_sum = 0;
    }

    if (ev.type == 3 && ev.code == 48 && ev.value != 0) {
        if (in_touch == 0) {
            in_touch = 1; //starting to track touch...
            reset_gestures();
        }
    } else if (ev.type == 3 && ev.code == 48 && ev.value == 0) {
            //finger lifted! lets run with this
            ev.type = EV_KEY; //touch panel support!!!
            int keywidth = gr_get_width(surface) / 4;
            int keyoffset = (gr_fb_width() - gr_get_width(surface)) / 2;
            if (touch_y > (gr_fb_height() - gr_get_height(surface)) && touch_x > 0) {
                //they lifted in the touch panel region
                if (touch_x < (keywidth + keyoffset)) {
                    //down button
                    ev.code = KEY_DOWN;
                    reset_gestures();
                } else if (touch_x < ((keywidth * 2) + keyoffset)) {
                    //up button
                    ev.code = KEY_UP;
                    reset_gestures();
                } else if (touch_x < ((keywidth * 3) + keyoffset)) {
                    //back button
                    ev.code = KEY_BACK;
                    reset_gestures();
                } else {
                    //enter key
                    ev.code = KEY_ENTER;
                    reset_gestures();
                }
                vibrate(VIBRATOR_TIME_MS);
            }
            if (slide_right == 1) {
                ev.code = KEY_ENTER;
                slide_right = 0;
            } else if (slide_left == 1) {
                ev.code = KEY_BACK;
                slide_left = 0;
            }

            ev.value = 1;
            in_touch = 0;
            reset_gestures();
    } else if (ev.type == 3 && ev.code == 53) {
        old_x = touch_x;
        touch_x = ev.value;
        if (old_x != 0)
            diff_x += touch_x - old_x;

	if (touch_y < (gr_fb_height() - gr_get_height(surface))) {
            if (diff_x > (gr_fb_width() / 4)) {
                slide_right = 1;
                reset_gestures();
    } else if(diff_x < ((gr_fb_width() / 4) * -1)) {
                slide_left = 1;
                reset_gestures();
            }
        } else {
            input_buttons();
            //reset_gestures();
        }
    } else if (ev.type == 3 && ev.code == 54) {
        old_y = touch_y;
        touch_y = ev.value;
        if (old_y != 0)
            diff_y += touch_y - old_y;

    if (touch_y < (gr_fb_height() - gr_get_height(surface))) {
            if (diff_y > 25) {
                ev.code = KEY_DOWN;
                ev.type = EV_KEY;
                reset_gestures();
	} else if (diff_y < -25) {
                ev.code = KEY_UP;
                ev.type = EV_KEY;
                reset_gestures();
            }
        } else {
            input_buttons();
            //reset_gestures();
        }
    }

    if (ev.type != EV_KEY || ev.code > KEY_MAX)
        return 0;

    pthread_mutex_lock(&key_queue_mutex);
    if (!fake_key) {
        // our "fake" keys only report a key-down event (no
        // key-up), so don't record them in the key_pressed
        // table.
        key_pressed[ev.code] = ev.value;
    }
    const int queue_max = sizeof(key_queue) / sizeof(key_queue[0]);
    if (ev.value > 0 && key_queue_len < queue_max) {
        key_queue[key_queue_len++] = ev.code;

        if (boardEnableKeyRepeat) {
            struct timeval now;
            gettimeofday(&now, NULL);

            key_press_time[ev.code] = (now.tv_sec * 1000) + (now.tv_usec / 1000);
            key_last_repeat[ev.code] = 0;
        }

        pthread_cond_signal(&key_queue_cond);
    }
    pthread_mutex_unlock(&key_queue_mutex);

    if (ev.value > 0 && device_toggle_display(key_pressed, ev.code)) {
        pthread_mutex_lock(&gUpdateMutex);
        show_text = !show_text;
        if (show_text) show_text_ever = 1;
        update_screen_locked();
        pthread_mutex_unlock(&gUpdateMutex);
    }

    if (ev.value > 0 && device_reboot_now(key_pressed, ev.code)) {
        android_reboot(ANDROID_RB_RESTART, 0, 0);
    }

    return 0;
}
Пример #18
0
/* Translate Event */
static byte aipTranslateEvent(AIP_EVP e, struct input_event * ev){
  static int downX                        = -1;
  static int downY                        = -1;
  static int discard                      = 0;
  static int lastWasSynReport             = 0;
  static int touchReleaseOnNextSynReport  = 0;
  int i;
  int x, y;
  
  /* Not Used */
  if (e->ignored){
    return 1;
  }
  
  if ((ev->type==EV_REL) && (ev->code == REL_Z)){
    /*  This appears to be an accelerometer or
        another strange input device.
        It's not the touchscreen.
     */
    e->ignored = 1;
    return AIP_TRANS_IGNONE;
  }

	/*  Handle keyboard events, value of 1
	    indicates key down, 0 indicates key up
	 */
	if (ev->type == EV_KEY) {
		return AIP_TRANS_KEY;
	}

  /* Possibly Touchscreen */
  if (ev->type == EV_ABS) {
    switch (ev->code) {
      case AIP_ABS_X:
        {
          e->p.synced |= 0x01;
          e->p.x = ev->value;
          printf("EV: %s => ABS_X  %d\n", e->device_name, ev->value);
        }
        break;

      case AIP_ABS_Y:
        {
          e->p.synced |= 0x02;
          e->p.y = ev->value;
          printf("EV: %s => ABS_Y  %d\n", e->device_name, ev->value);
        }
        break;

      case AIP_ABS_MT_POSITION:
        {
          e->mt_p.synced = 0x03;
          if (ev->value == (1 << 31)){
              e->mt_p.x = 0;
              e->mt_p.y = 0;
              lastWasSynReport = 1;
          }
          else{
              lastWasSynReport = 0;
              e->mt_p.x = (ev->value & 0x7FFF0000) >> 16;
              e->mt_p.y = (ev->value & 0xFFFF);
          }
        }
        break;

        case AIP_ABS_MT_TOUCH_MAJOR:
          {
            if (ev->value == 0)
            {
                e->mt_p.x = 0;
                e->mt_p.y = 0;
                touchReleaseOnNextSynReport = 1;
            }
          }
          break;

		    case AIP_ABS_MT_PRESSURE:
		      {
            if (ev->value == 0){
                e->mt_p.x = 0;
                e->mt_p.y = 0;
                touchReleaseOnNextSynReport = 1;
            }
          }
          break;

		    case AIP_ABS_MT_POSITION_X:
		      {
            e->mt_p.synced |= 0x01;
            e->mt_p.x = ev->value;
          }
          break;

        case AIP_ABS_MT_POSITION_Y:
          {
            e->mt_p.synced |= 0x02;
            e->mt_p.y = ev->value;
          }
          break;
        default:
          {
            return AIP_TRANS_NONE;
          }
    }

    if (ev->code != AIP_ABS_MT_POSITION){
        lastWasSynReport = 0;
        return AIP_TRANS_NONE;
    }
  }

  if (ev->code != AIP_ABS_MT_POSITION && 
      (ev->type != EV_SYN || 
        (ev->code != AIP_SYN_REPORT && ev->code != AIP_SYN_MT_REPORT)
      )
     ){
    lastWasSynReport = 0;
    return AIP_TRANS_NONE;
  }
  if (ev->code == AIP_SYN_MT_REPORT){
    return AIP_TRANS_NONE;
  }

  if (lastWasSynReport == 1 || touchReleaseOnNextSynReport == 1){
    /* Reset the value */
    touchReleaseOnNextSynReport = 0;
    
    /* We are a finger-up state */
    if (!discard){
      if ((downX<0)||(downY<0)){
        discard=1;
      }
      else{
        /* Report the key up */
        ev->type = EV_ABS;
        ev->code = 0;
        ev->value = (downX << 16) | downY;
      }
    }
    
    downX = -1;
    downY = -1;
    if (discard){
      discard = 0;
      return AIP_TRANS_NONE;
    }
    return AIP_TRANS_TOUCH;
  }
  
  lastWasSynReport = 1;
  if (e->p.synced & 0x03){
    aipCalculateTouch(&e->p, &x, &y);
  }
  else if (e->mt_p.synced & 0x03){
    aipCalculateTouch(&e->mt_p, &x, &y);
  }
  else{
    return AIP_TRANS_NONE;
  }

  /* Swap & Flip Handler */
  if (_aip->touch_swap_xy){
    x ^= y;
    y ^= x;
    x ^= y;
  }
  if (_aip->touch_flip_x){
    x = agw() - x;
  }
  if (_aip->touch_flip_y){
    y = agh() - y;
  }
  
  /* Clear the current sync states */
  e->p.synced = e->mt_p.synced = 0;

  /* If we have nothing useful to report, skip it */
  if (x == -1 || y == -1){
    return AIP_TRANS_NONE;
  }

  /* On first touch, see if we're at a virtual key */
  if (downX == -1){
    /* Attempt mapping to virtual key */
    for (i=0; i<e->vkn; ++i){
      int xd = abs(e->vks[i].x - x);
      int yd = abs(e->vks[i].y - y);

      if (xd < e->vks[i].w/2 && yd < e->vks[i].h/2){
          ev->type = EV_KEY;
          ev->code = e->vks[i].scan;
          ev->value= 0;
          
          vibrate(30);
          
          discard = 1;
          downX = 0;
          return AIP_TRANS_KEY;
      }
    }
  }
  
  if ((x<0)||(y<0)){
    discard=1;
  }

  /* If we were originally a button press, discard this event */
  if (discard){
      return AIP_TRANS_NONE;
  }

  /* Record where we started the touch for
     deciding if this is a key or a scroll */
  downX = x;
  downY = y;
  
  ev->type = EV_ABS;
  ev->code = 1;
  ev->value = (x << 16) | y;
  return AIP_TRANS_TOUCH;
}
Пример #19
0
int atouch_wait_ex(ATEV *atev, byte calibratingtouch){
  atev->x = -1;
  atev->y = -1;
  // if (prev_was_key) ui_clear_key_queue();
  while (1){
    int key = ui_wait_key();
    
    //-- Custom Message
    if (key==atouch_message_code){
      atev->msg = atouch_message_value;
      atev->d   = 0;
      atev->x   = 0;
      atev->y   = 0;
      atev->k   = 0;
      ui_clear_key_queue();
      atouch_message_value = 0;
      return ATEV_MESSAGE;
    }
    
    atev->d = ui_key_pressed(key);
    atev->k = key;
    
    if (key==evtouch_code){
      if ((evtouch_x>0)&&(evtouch_y>0)){
        //-- GENERIC TOUCH SCREEN INPUT EVENT
        if (((evtouch_x<=agw())&&(evtouch_y<=agh()))||(calibratingtouch)){
          atev->x = evtouch_x;
          atev->y = evtouch_y;
          evtouch_locked=0;
          switch(evtouch_state){
            case 1:  return ATEV_MOUSEDN; break;
            case 2:  return ATEV_MOUSEMV; break;
            default: return ATEV_MOUSEUP; break;
          }
        }
        //-- CAPIATIVE KEY INPUT EVENT
        else if(evtouch_y>(agh()+(agdp()*10))){
          int capiative_btnsz = agw()/4;
          if (evtouch_state==0){
            atev->d = 0;
            if (evtouch_x<capiative_btnsz){
              vibrate(30);
              atev->k = KEY_HOME;
              evtouch_locked=0;
              return ATEV_SELECT;
            }
            else if (evtouch_x<(capiative_btnsz*2)){
              vibrate(30);
              atev->k = KEY_MENU;
              evtouch_locked=0;
              return ATEV_MENU;
            }
            else if (evtouch_x<(capiative_btnsz*3)){
              vibrate(30);
              atev->k = KEY_BACK;
              evtouch_locked=0;
              return ATEV_BACK;
            }
            else if (evtouch_x<(capiative_btnsz*4)){
              vibrate(30);
              atev->k = KEY_SEARCH;
              evtouch_locked=0;
              return ATEV_MENU;
            }
          }
          // home,menu,back,search
        }
      }
      evtouch_locked=0;
    }
    else if ((key!=0)&&(key==acfg()->ckey_up))      return ATEV_UP;
    else if ((key!=0)&&(key==acfg()->ckey_down))    return ATEV_DOWN;
    else if ((key!=0)&&(key==acfg()->ckey_select))  return ATEV_SELECT;
    else if ((key!=0)&&(key==acfg()->ckey_back))    return ATEV_BACK;
    else if ((key!=0)&&(key==acfg()->ckey_menu))    return ATEV_MENU;
    else{
      /* DEFINED KEYS */
      switch (key){
        /* RIGHT */
        case KEY_RIGHT: return ATEV_RIGHT; break;
        /* LEFT */
        case KEY_LEFT:  return ATEV_LEFT; break;
        
        /* DOWN */
        case KEY_DOWN:
        case KEY_CAPSLOCK:
        case KEY_VOLUMEDOWN:
          return ATEV_DOWN; break;
        
        /* UP */
        case KEY_UP:
        case KEY_LEFTSHIFT:
        case KEY_VOLUMEUP:
          return ATEV_UP; break;
        
        /* SELECT */
        case KEY_LEFTBRACE:
        case KEY_POWER:
        case KEY_HOME:
        case BTN_MOUSE:
        case KEY_ENTER:
        case KEY_CENTER:
        case KEY_CAMERA:
        case KEY_F21:
        case KEY_SEND:
          return ATEV_SELECT; break;
        
        /* SHOW MENU */
        case KEY_SEARCH:
        case 229:
        case KEY_MENU:
          return ATEV_MENU; break;
        
        /* BACK */
        case KEY_END:
        case KEY_BACKSPACE:
        case KEY_BACK:
          return ATEV_BACK; break;
      }
    }
  }
  return 0;
}
Пример #20
0
// This is the actual Android example. You don't have to write any platform
// specific code, unless you want to use things not directly exposed.
// ('vibrate()' in this example; undefine 'USE_JNI' above to disable it)
int main(int argc, char *argv[])
{
    sf::VideoMode screen(sf::VideoMode::getDesktopMode());

    sf::RenderWindow window(screen, "");
    window.setFramerateLimit(30);

    sf::Texture texture;
    if(!texture.loadFromFile("image.png"))
        return EXIT_FAILURE;

    sf::Sprite image(texture);
    image.setPosition(screen.width / 2, screen.height / 2);
    image.setOrigin(texture.getSize().x/2, texture.getSize().y/2);

    sf::Font font;
    if (!font.loadFromFile("sansation.ttf"))
        return EXIT_FAILURE;

    sf::Text text("Tap anywhere to move the logo.", font, 64);
    text.setFillColor(sf::Color::Black);
    text.setPosition(10, 10);

    // Loading canary.wav fails for me for now; haven't had time to test why

    /*sf::Music music;
    if(!music.openFromFile("canary.wav"))
        return EXIT_FAILURE;

    music.play();*/

    sf::View view = window.getDefaultView();

    sf::Color background = sf::Color::White;

    // We shouldn't try drawing to the screen while in background
    // so we'll have to track that. You can do minor background
    // work, but keep battery life in mind.
    bool active = true;

    while (window.isOpen())
    {
        sf::Event event;

        while (active ? window.pollEvent(event) : window.waitEvent(event))
        {
            switch (event.type)
            {
                case sf::Event::Closed:
                    window.close();
                    break;
                case sf::Event::KeyPressed:
                    if (event.key.code == sf::Keyboard::Escape)
                        window.close();
                    break;
                case sf::Event::Resized:
                    view.setSize(event.size.width, event.size.height);
                    view.setCenter(event.size.width/2, event.size.height/2);
                    window.setView(view);
                    break;
                case sf::Event::LostFocus:
                    background = sf::Color::Black;
                    break;
                case sf::Event::GainedFocus:
                    background = sf::Color::White;
                    break;
                
                // On Android MouseLeft/MouseEntered are (for now) triggered,
                // whenever the app loses or gains focus.
                case sf::Event::MouseLeft:
                    active = false;
                    break;
                case sf::Event::MouseEntered:
                    active = true;
                    break;
                case sf::Event::TouchBegan:
                    if (event.touch.finger == 0)
                    {
                        image.setPosition(event.touch.x, event.touch.y);
#if defined(USE_JNI)
                        vibrate(sf::milliseconds(10));
#endif
                    }
                    break;
            }
        }

        if (active)
        {
            window.clear(background);
            window.draw(image);
            window.draw(text);
            window.display();
        }
        else {
            sf::sleep(sf::milliseconds(100));
        }
    }
}
void vibrate(int offMsec)
{
	vibrate(offMsec, GetLedCount() - 1);
}
dword accheck_oninput(void * x,int action,ATEV * atev){
  ACONTROLP ctl= (ACONTROLP) x;
  ACCHECKDP d  = (ACCHECKDP) ctl->d;
  dword msg = 0;
  switch (action){
    case ATEV_MOUSEDN:
      {
        d->prevTouchY  = atev->y;
        akinetic_downhandler(&d->akin,atev->y);
        
        int touchpos = atev->y - ctl->y + d->scrollY;
        int i;
        for (i=0;i<d->itemn;i++){
          if ((touchpos>=d->items[i]->y)&&(touchpos<d->items[i]->y+d->items[i]->h)){
            ac_regpushwait(
              ctl,&d->prevTouchY,&d->invalidDrawItem,i
            );
            break;
          }
        }
      }
      break;
    case ATEV_MOUSEUP:
      {
        if ((d->prevTouchY!=-50)&&(abs(d->prevTouchY-atev->y)<agdp()*5)){
          d->prevTouchY=-50;
          int touchpos = atev->y - ctl->y + d->scrollY;
          
          int i;
          for (i=0;i<d->itemn;i++){
            if ((!d->items[i]->isTitle)&&(touchpos>=d->items[i]->y)&&(touchpos<d->items[i]->y+d->items[i]->h)){
              d->items[i]->checked = (d->items[i]->checked)?0:1;
              if ((d->touchedItem != -1)&&(d->touchedItem!=i)){
                int tmptouch=d->touchedItem;
                d->touchedItem = -1;
                accheck_redrawitem(ctl,tmptouch);
              }
              
              int prevfocus = d->focusedItem;
              d->focusedItem= i;
              d->touchedItem= i;
              if ((prevfocus!=-1)&&(prevfocus!=i)){
                accheck_redrawitem(ctl,prevfocus);
              }
              
              
              accheck_redrawitem(ctl,i);
              ctl->ondraw(ctl);
              aw_draw(ctl->win);
              vibrate(30);              
              break;
            }
          }
          
          if ((d->scrollY<0)||(d->scrollY>d->maxScrollY)){
            ac_regbounce(ctl,&d->scrollY,d->maxScrollY);
          }
        }
        else{
          if (akinetic_uphandler(&d->akin,atev->y)){
            ac_regfling(ctl,&d->akin,&d->scrollY,d->maxScrollY);
          }
          else if ((d->scrollY<0)||(d->scrollY>d->maxScrollY)){
            ac_regbounce(ctl,&d->scrollY,d->maxScrollY);
          }
        }
        if (d->touchedItem != -1){
          usleep(30);
          int tmptouch=d->touchedItem;
          d->touchedItem = -1;
          accheck_redrawitem(ctl,tmptouch);
          ctl->ondraw(ctl);
          msg=aw_msg(0,1,0,0);
        }
      }
      break;
    case ATEV_MOUSEMV:
      {
        byte allowscroll=1;
        if (atev->y!=0){
          if (d->prevTouchY!=-50){
            if (abs(d->prevTouchY-atev->y)>=agdp()*5){
              d->prevTouchY=-50;
              if (d->touchedItem != -1){
                int tmptouch=d->touchedItem;
                d->touchedItem = -1;
                accheck_redrawitem(ctl,tmptouch);
                ctl->ondraw(ctl);
                aw_draw(ctl->win);
              }
            }
            else
              allowscroll=0;
          }
          if (allowscroll){
            int mv = akinetic_movehandler(&d->akin,atev->y);
            if (mv!=0){
              if ((d->scrollY<0)&&(mv<0)){
                float dumpsz = 0.6-(0.6*(((float) abs(d->scrollY))/(ctl->h/4)));
                d->scrollY+=floor(mv*dumpsz);
              }
              else if ((d->scrollY>d->maxScrollY)&&(mv>0)){
                float dumpsz = 0.6-(0.6*(((float) abs(d->scrollY-d->maxScrollY))/(ctl->h/4)));
                d->scrollY+=floor(mv*dumpsz);
              }
              else
                d->scrollY+=mv;
  
              if (d->scrollY<0-(ctl->h/4)) d->scrollY=0-(ctl->h/4);
              if (d->scrollY>d->maxScrollY+(ctl->h/4)) d->scrollY=d->maxScrollY+(ctl->h/4);
              msg=aw_msg(0,1,0,0);
              ctl->ondraw(ctl);
            }
          }
        }
      }
      break;
      case ATEV_SELECT:
      {
        if ((d->focusedItem>-1)&&(d->draweditemn>0)){
          if (atev->d){
            if ((d->touchedItem != -1)&&(d->touchedItem!=d->focusedItem)){
              int tmptouch=d->touchedItem;
              d->touchedItem = -1;
              accheck_redrawitem(ctl,tmptouch);
            }
            vibrate(30);
            d->touchedItem=d->focusedItem;
            accheck_redrawitem(ctl,d->focusedItem);
            ctl->ondraw(ctl);
            msg=aw_msg(0,1,0,0);
          }
          else{
            if ((d->touchedItem != -1)&&(d->touchedItem!=d->focusedItem)){
              int tmptouch=d->touchedItem;
              d->touchedItem = -1;
              accheck_redrawitem(ctl,tmptouch);
            }
            d->items[d->focusedItem]->checked = (d->items[d->focusedItem]->checked)?0:1;
            d->touchedItem=-1;
            accheck_redrawitem(ctl,d->focusedItem);
            ctl->ondraw(ctl);
            msg=aw_msg(0,1,0,0);
          }
        }
      }
      break;
      case ATEV_DOWN:
        {
          if ((d->focusedItem<d->itemn-1)&&(d->draweditemn>0)){
            int prevfocus = d->focusedItem;
            d->focusedItem++;
            while(d->items[d->focusedItem]->isTitle){
              d->focusedItem++;
              if (d->focusedItem>d->itemn-1){
                d->focusedItem = prevfocus;
                return 0;
              }
            }
            accheck_redrawitem(ctl,prevfocus);
            accheck_redrawitem(ctl,d->focusedItem);
            ctl->ondraw(ctl);
            msg=aw_msg(0,1,1,0);
            
            int reqY = d->items[d->focusedItem]->y - round((ctl->h/2) - (d->items[d->focusedItem]->h/2));
            ac_regscrollto(
              ctl,
              &d->scrollY,
              d->maxScrollY,
              reqY,
              &d->focusedItem,
              d->focusedItem
            );
          }
        }
      break;
      case ATEV_UP:
        {
          if ((d->focusedItem>0)&&(d->draweditemn>0)){
            int prevfocus = d->focusedItem;
            d->focusedItem--;
            while(d->items[d->focusedItem]->isTitle){
              d->focusedItem--;
              if (d->focusedItem<0){
                d->focusedItem = prevfocus;
                return 0;
              }
            }
            accheck_redrawitem(ctl,prevfocus);
            accheck_redrawitem(ctl,d->focusedItem);
            ctl->ondraw(ctl);
            msg=aw_msg(0,1,1,0);
            
            int reqY = d->items[d->focusedItem]->y - round((ctl->h/2) - (d->items[d->focusedItem]->h/2));
            ac_regscrollto(
              ctl,
              &d->scrollY,
              d->maxScrollY,
              reqY,
              &d->focusedItem,
              d->focusedItem
            );
          }
        }
      break;
  }
  return msg;
}
dword afbox_oninput(void * x,int action,ATEV * atev){
  ACONTROLP ctl= (ACONTROLP) x;
  AFBOXDP d  = (AFBOXDP) ctl->d;
  dword msg = 0;
  switch (action){
    case 444:
      {
        // printf("HOLDED: %i - %s",d->touchedItem,d->items[d->touchedItem]->title);
        vibrate(30);
        int tmptouch=d->touchedItem;
        int tmpfocus=d->focusedItem;
        d->selectedId  = tmptouch;
        d->focusedItem = tmptouch;
        d->touchedItem = -1;
        if (tmpfocus!=tmptouch) afbox_redrawitem_ex(ctl,tmpfocus);
        afbox_redrawitem_ex(ctl,tmptouch);
        ctl->ondraw(ctl);
        msg=aw_msg(d->holdmsg,1,0,0);
        atouch_send_message(msg);
      }
      break;
    case ATEV_MOUSEDN:
      {
        d->prevTouchY  = atev->y;
        akinetic_downhandler(&d->akin,atev->y);
        
        int touchpos = atev->y - ctl->y + d->scrollY;
        int i;
        for (i=0;i<d->itemn;i++){
          if ((touchpos>=d->items[i]->y)&&(touchpos<d->items[i]->y+d->items[i]->h)){
            ac_regpushwait(
              ctl,&d->prevTouchY,&d->invalidDrawItem,i
            );
            break;
          }
        }
      }
      break;
    case ATEV_MOUSEUP:
      {
        byte is_holded = 0;
        if (d->lasttouch==-1) is_holded=1;
        d->lasttouch=0;
        byte ag_check_msg = 0;
        if ((d->prevTouchY!=-50)&&(abs(d->prevTouchY-atev->y)<agdp()*5)){
          d->prevTouchY=-50;
          int touchpos = atev->y - ctl->y + d->scrollY;
          
          byte oncheckpush=((d->check_n>0)||(atev->x>((ctl->x+ctl->w)-(agdp()*32))))?1:0;
          
          if (d->boxtype!=0) oncheckpush=0;
          
          int i;
          for (i=0;i<d->itemn;i++){
            if ((!d->items[i]->isTitle)&&(touchpos>=d->items[i]->y)&&(touchpos<d->items[i]->y+d->items[i]->h)){
              
              if ((oncheckpush)&&(!is_holded)){
                d->items[i]->checked = (d->items[i]->checked)?0:1;
                if (d->items[i]->checked)
                  d->check_n++;
                else
                  d->check_n--;
                ag_check_msg = d->changemsg;
              }
              
              if ((d->touchedItem != -1)&&(d->touchedItem!=i)){
                int tmptouch=d->touchedItem;
                d->touchedItem = -1;
                afbox_redrawitem_ex(ctl,tmptouch);
              }
              
              int prevfocus = d->focusedItem;
              d->focusedItem= i;
              d->touchedItem= i;
              if ((prevfocus!=-1)&&(prevfocus!=i)){
                afbox_redrawitem_ex(ctl,prevfocus);
              }
              
              
              afbox_redrawitem_ex(ctl,i);
              ctl->ondraw(ctl);
              aw_draw(ctl->win);
              
              if (!is_holded){
                vibrate(30);
                
                if (!oncheckpush){
                  ag_check_msg = d->touchmsg;
                  d->selectedId=i;
                  msg=aw_msg(ag_check_msg,1,0,0);
                }
              }
              break;
            }
          }
          if ((d->scrollY<0)||(d->scrollY>d->maxScrollY)){
            ac_regbounce(ctl,&d->scrollY,d->maxScrollY);
          }
        }
        else{
          if (akinetic_uphandler(&d->akin,atev->y)){
            ac_regfling(ctl,&d->akin,&d->scrollY,d->maxScrollY);
          }
          else if ((d->scrollY<0)||(d->scrollY>d->maxScrollY)){
            ac_regbounce(ctl,&d->scrollY,d->maxScrollY);
          }
        }
        if (d->touchedItem != -1){
          usleep(30);
          int tmptouch=d->touchedItem;
          d->touchedItem = -1;
          afbox_redrawitem_ex(ctl,tmptouch);
          ctl->ondraw(ctl);
          msg=aw_msg(ag_check_msg,1,0,0);
        }
      }
      break;
    case ATEV_MOUSEMV:
      {
        byte allowscroll=1;
        if (atev->y!=0){
          if (d->prevTouchY!=-50){
            if (abs(d->prevTouchY-atev->y)>=agdp()*5){
              d->prevTouchY=-50;
              if (d->touchedItem != -1){
                int tmptouch=d->touchedItem;
                d->touchedItem = -1;
                afbox_redrawitem_ex(ctl,tmptouch);
                ctl->ondraw(ctl);
                aw_draw(ctl->win);
              }
            }
            else
              allowscroll=0;
          }
          if (allowscroll){
            d->lasttouch=0;
            int mv = akinetic_movehandler(&d->akin,atev->y);
            if (mv!=0){
              if ((d->scrollY<0)&&(mv<0)){
                float dumpsz = 0.6-(0.6*(((float) abs(d->scrollY))/(ctl->h/4)));
                d->scrollY+=floor(mv*dumpsz);
              }
              else if ((d->scrollY>d->maxScrollY)&&(mv>0)){
                float dumpsz = 0.6-(0.6*(((float) abs(d->scrollY-d->maxScrollY))/(ctl->h/4)));
                d->scrollY+=floor(mv*dumpsz);
              }
              else
                d->scrollY+=mv;
  
              if (d->scrollY<0-(ctl->h/4)) d->scrollY=0-(ctl->h/4);
              if (d->scrollY>d->maxScrollY+(ctl->h/4)) d->scrollY=d->maxScrollY+(ctl->h/4);
              msg=aw_msg(0,1,0,0);
              ctl->ondraw(ctl);
            }
          }
        }
      }
      break;
      case ATEV_SEARCH:
      {
        d->lasttouch=0;
        if (d->boxtype==0){
          if ((d->focusedItem>-1)&&(d->draweditemn>0)){
            if (atev->d){
              if ((d->touchedItem != -1)&&(d->touchedItem!=d->focusedItem)){
                int tmptouch=d->touchedItem;
                d->touchedItem = -1;
                afbox_redrawitem_ex(ctl,tmptouch);
              }
              vibrate(30);
              d->touchedItem=d->focusedItem;
              afbox_redrawitem_ex(ctl,d->focusedItem);
              ctl->ondraw(ctl);
              msg=aw_msg(0,1,0,0);
            }
            else{
              d->items[d->focusedItem]->checked = (d->items[d->focusedItem]->checked)?0:1;
              if (d->items[d->focusedItem]->checked)
                d->check_n++;
              else
                d->check_n--;
              d->touchedItem=-1;
              afbox_redrawitem_ex(ctl,d->focusedItem);
              ctl->ondraw(ctl);
              msg=aw_msg(d->changemsg,1,0,0);
            }
          }
        }
      }
      break;
      case ATEV_SELECT:
        {
          d->lasttouch=0;
          if ((d->focusedItem>-1)&&(d->draweditemn>0)){
            if (atev->d){
              if ((d->touchedItem != -1)&&(d->touchedItem!=d->focusedItem)){
                int tmptouch=d->touchedItem;
                d->touchedItem = -1;
                afbox_redrawitem_ex(ctl,tmptouch);
              }
              vibrate(30);
              d->touchedItem=d->focusedItem;
              afbox_redrawitem_ex(ctl,d->focusedItem);
              ctl->ondraw(ctl);
              msg=aw_msg(0,1,0,0);
            }
            else{
              if ((d->check_n>0)&&(d->boxtype==0)){
                d->items[d->focusedItem]->checked = (d->items[d->focusedItem]->checked)?0:1;
                if (d->items[d->focusedItem]->checked)
                  d->check_n++;
                else
                  d->check_n--;
                d->touchedItem=-1;
                afbox_redrawitem_ex(ctl,d->focusedItem);
                ctl->ondraw(ctl);
                msg=aw_msg(d->changemsg,1,0,0);
              }
              else{
                if ((d->touchedItem != -1)&&(d->touchedItem!=d->focusedItem)){
                  int tmptouch=d->touchedItem;
                  d->touchedItem = -1;
                  afbox_redrawitem_ex(ctl,tmptouch);
                }
                d->selectedId=d->focusedItem;
                d->touchedItem=-1;
                afbox_redrawitem_ex(ctl,d->focusedItem);
                ctl->ondraw(ctl);
                msg=aw_msg(d->touchmsg,1,0,0);
              }
            }
          }
        }
        break;
      case ATEV_DOWN:
        {
          d->lasttouch=0;
          if ((d->focusedItem<d->itemn-1)&&(d->draweditemn>0)){
            int prevfocus = d->focusedItem;
            d->focusedItem++;
            while(d->items[d->focusedItem]->isTitle){
              d->focusedItem++;
              if (d->focusedItem>d->itemn-1){
                d->focusedItem = prevfocus;
                d->selectedId  = d->focusedItem;
                return 0;
              }
            }
            d->selectedId  = d->focusedItem;
            afbox_redrawitem_ex(ctl,prevfocus);
            afbox_redrawitem_ex(ctl,d->focusedItem);
            ctl->ondraw(ctl);
            msg=aw_msg(0,1,1,0);
            
            int reqY = d->items[d->focusedItem]->y - round((ctl->h/2) - (d->items[d->focusedItem]->h/2));
            ac_regscrollto(
              ctl,
              &d->scrollY,
              d->maxScrollY,
              reqY,
              &d->focusedItem,
              d->focusedItem
            );
          }
        }
      break;
      case ATEV_UP:
        {
          d->lasttouch=0;
          if ((d->focusedItem>0)&&(d->draweditemn>0)){
            int prevfocus = d->focusedItem;
            d->focusedItem--;
            while(d->items[d->focusedItem]->isTitle){
              d->focusedItem--;
              if (d->focusedItem<0){
                d->focusedItem = prevfocus;
                d->selectedId  = d->focusedItem;
                return 0;
              }
            }
            d->selectedId  = d->focusedItem;
            afbox_redrawitem_ex(ctl,prevfocus);
            afbox_redrawitem_ex(ctl,d->focusedItem);
            ctl->ondraw(ctl);
            msg=aw_msg(0,1,1,0);
            
            int reqY = d->items[d->focusedItem]->y - round((ctl->h/2) - (d->items[d->focusedItem]->h/2));
            ac_regscrollto(
              ctl,
              &d->scrollY,
              d->maxScrollY,
              reqY,
              &d->focusedItem,
              d->focusedItem
            );
          }
        }
      break;
  }
  return msg;
}