Exemplo n.º 1
0
static portTASK_FUNCTION(MainTask, pvParameters) {
  (void)pvParameters; /* parameter not used */
  TRACE_Init();
  MMA1_Init(); /* enable accelerometer, if not already enabled */
  SHELL_Init();
  for(;;) {
    LED1_Neg();
    FRTOS1_vTaskDelay(1000/portTICK_RATE_MS);
  }
}
Exemplo n.º 2
0
uint8_t ACCEL_LowLevelInit(void) {
  uint8_t res;
  
  res = MMA1_Init(); /* this might communicate to the device using I2C, so it needs interrupts enabled */
  if (res!=ERR_OK) {
    return res;
  }
  res = ACCEL_Enable();
  if (res!=ERR_OK) {
    return res;
  }
  res = MMA1_SetFastMode(FALSE); /* disable fast mode of the sensor: otherwise we cannot read individual sensor values */
  if (res!=ERR_OK) {
    return res;
  }
  return ERR_OK;
}
Exemplo n.º 3
0
static portTASK_FUNCTION(MainTask, pvParameters) {
  unsigned char lcdBuf[sizeof("1234")];
  uint16_t cntr;
  
  (void)pvParameters; /* parameter not used */
  TRACE_Init();
  MMA1_Init(); /* enable accelerometer, if not already enabled */
  MAG1_Enable(); /* enable magnetometer */
  SHELL_Init();
  cntr = 0;
  for(;;) {
    UTIL1_Num16uToStrFormatted(lcdBuf, sizeof(lcdBuf), cntr, '0', 4);
    vfnLCD_Write_Msg(lcdBuf);
    cntr++;
    if (cntr>9999) { /* can only display 4 digits */
      cntr = 0;
    }
#if APP_USE_KEY_COMPONENT
    KEY1_ScanKeys(); /* using component in polling mode: poll keys, this will create events as needed. */
    EVNT1_HandleEvent();
#else
    if (SW1_GetVal()==0) { /* button pressed */
      FRTOS1_vTaskDelay(50/portTICK_RATE_MS); /* wait to debounce */
      while (SW1_GetVal()==0) { /* still pressed? */
        LED1_On();
      }
    }
    if (SW3_GetVal()==0) { /* button pressed */
      FRTOS1_vTaskDelay(50/portTICK_RATE_MS); /* wait to debounce */
      while (SW3_GetVal()==0) { /* still pressed? */
        LED2_On();
      }
    }
#endif
    LED1_Neg();
    FRTOS1_vTaskDelay(50/portTICK_RATE_MS);
  }
}
Exemplo n.º 4
0
/*---------------------------------------------------------------------------*/
static int
configure(int type, int value)
{
  switch (type)
    {
  case SENSORS_HW_INIT:
    return MMA1_Init();
  case SENSORS_ACTIVE:
    if (value)
      {
        activate();
      }
    else
      {
        deactivate();
      }
    return 1;
  case ACC_FAST_MODE:
    MMA1_SetFastMode(value);
    return 1;
    }
  return 0;
}
Exemplo n.º 5
0
void APP_Run(void) {
  int cnt=0; /* counter to slow down LED blinking */
  uint8_t res;
  int16_t xyz[3];
#if 0
  res = MMA1_Init();
  if (res!=ERR_OK) {
    Err();
  }
  res = MMA1_SetFastMode(FALSE);
  if (res!=ERR_OK) {
    Err();
  }
  res = MMA1_Enable(); /* enable accelerometer */
  if (res!=ERR_OK) {
    Err();
  }
#endif
  for(;;) {
    WAIT1_Waitms(10);
#if 0
    /* implement 'air-mouse' movement */
    xyz[0] = MMA1_GetX();
    xyz[1] = MMA1_GetY();
    xyz[3] = MMA1_GetZ();
    /* y axis */
    if (xyz[1]>AIR_THRESHOLD) {
      (void)HIDK2_Move(0, 2); /* moving the cursor left */
    } else if (xyz[1]<-AIR_THRESHOLD) {
      (void)HIDK2_Move(0, -2); /* moving the cursor right */
    }
    /* x axis */
    if (xyz[0]>AIR_THRESHOLD) {
      (void)HIDK2_Move(-2, 0); /* moving the cursor up */
    } else if (xyz[0]<-AIR_THRESHOLD) {
      (void)HIDK2_Move(2, 0); /* moving the cursor down */
    }
#endif
    cnt++;
    if (HIDM1_App_Task()==ERR_BUSOFF) {
      if ((cnt%128)==0) { /* just slow down blinking */
        LED1_Neg(); /* red LED */
        LED2_Off();
      }
    } else {
      if ((cnt%128)==0) { /* just slow down blinking */
        LED1_Off();
        LED2_Neg(); /* green LED */
      }
      if (SW2_GetVal()==0) { /* button pressed */
        WAIT1_Waitms(100); /* wait for debouncing */
        if (SW2_GetVal()==0) { /* still pressed */
          //(void)HIDK2_Send(0, 8, 8); /* raw move message */
          
          //(void)HIDK2_Send(HIDK2_MOUSE_LEFT, 0, 0); /* send left mouse button */
          //(void)HIDK2_Send(0, 0, 0); /* send release button message */
          
          //(void)HIDK2_Move(-8, 0); /* moving the cursor up */
          
          //HIDK2_Click(HIDK2_MOUSE_LEFT); /* left mouse click */
          
          HIDM1_Click(HIDM1_MOUSE_RIGHT); /* right mouse click */
        }
        while(SW2_GetVal()==0) {} /* wait until button is released */
      }
      if (SW3_GetVal()==0) { /* button pressed */
        WAIT1_Waitms(100); /* wait for debouncing */
        if (SW3_GetVal()==0) { /* still pressed */
          HIDM1_Click(HIDM1_MOUSE_LEFT); /* left mouse click */
        }
        while(SW3_GetVal()==0) {} /* wait until button is released */
      }
    }
  }
}