Ejemplo n.º 1
0
void APP_HandleEvent(byte event) {
  switch(event) {
    case EVNT1_INIT:
      LED1_On(); WAIT1_Waitms(200); 
      LED2_On(); WAIT1_Waitms(200); 
      LED3_On(); WAIT1_Waitms(200); 
      LED4_On(); WAIT1_Waitms(200);
      LED1_Off(); LED2_Off(); LED3_Off(); LED4_Off();
      break;
    case EVNT1_SW1_PRESSED:
      LED1_On(); WAIT1_Waitms(200); LED1_Off();
      break;
    case EVNT1_SW2_PRESSED:
      LED2_On(); WAIT1_Waitms(200); LED2_Off();
      break;
    case EVNT1_SW3_PRESSED:
      LED3_On(); WAIT1_Waitms(200); LED3_Off();
      break;
    case EVNT1_SW4_PRESSED:
      LED4_On(); WAIT1_Waitms(200); LED4_Off();
      break;
    case EVNT1_SW1_LONG_PRESSED:
      LED1_On(); WAIT1_Waitms(500); LED1_Off();
      break;
    case EVNT1_SW2_LONG_PRESSED:
      LED2_On(); WAIT1_Waitms(500); LED2_Off();
      break;
    case EVNT1_SW3_LONG_PRESSED:
      LED3_On(); WAIT1_Waitms(500); LED3_Off();
      break;
    case EVNT1_SW4_LONG_PRESSED:
      LED4_On(); WAIT1_Waitms(500); LED4_Off();
      break;
  } /* switch */
}
Ejemplo n.º 2
0
/*!
 * \brief LED test routine.
 * This routine tests if:
 * - we can turn the LEDs properly on and off
 * - if we can negate them
 * - if we can set an LED value
 * - if we can get the LED value
 * If the test fails, the program will hanging in an endless loop
 */
void LED_Test(void) {
  bool isOn = TRUE;

  LED1_On();
  LED2_On();
  LED3_On();

  LED1_Off();
  LED2_Off();
  LED3_Off();

  LED1_Neg();
  LED2_Neg();
  LED3_Neg();

  LED1_On();
/*
 if (!LED1_Get()) {
   LED3_Off();
  }

  LED1_Off();
  if (LED1_Get()) {
    for(;;){}; /* error
  }
  LED1_Put(isOn);
  if (!LED1_Get()) {
    for(;;){}; /* error
  }
  */
}
Ejemplo n.º 3
0
/*lint -save  -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
  /* Write your local variable definition here */

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

  /* Write your code here */
  LED1_On();
  WAIT1_Waitms(100);
  LED1_Off();

  LED2_On();
  WAIT1_Waitms(100);
  LED2_Off();

  LED3_On();
  WAIT1_Waitms(100);
  LED3_Off();

  CDC_Run();

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
Ejemplo n.º 4
0
void APP_Run(void) {
  LED1_On();
  LED1_Off();
  LED2_On();
  LED2_Off();
  LED3_On();
  LED3_Off();
#if PL_HAS_SHELL
  SHELL_Init();
#endif
#if PL_HAS_ESC
  ESC_Init();
#endif
  if (FRTOS1_xTaskCreate(
      AppTask,  /* pointer to the task */
      "Main", /* task name for kernel awareness debugging */
      configMINIMAL_STACK_SIZE, /* task stack size */
      (void*)NULL, /* optional task startup argument */
      tskIDLE_PRIORITY,  /* initial priority */
      (xTaskHandle*)NULL /* optional task handle to create */
    ) != pdPASS)
  {
    for(;;){} /* error! probably out of memory */
  }
  FRTOS1_vTaskStartScheduler();
  for(;;) {}
}
Ejemplo n.º 5
0
void APP_Start(void) {
  PL_Init(); /* platform initialization */
  //TEST_Test();
  EVNT_SetEvent(EVNT_INIT); /* set initial event */
#if PL_HAS_RTOS
  if (FRTOS1_xTaskCreate(AppTask, (signed portCHAR *)"App", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL) != pdPASS) {
    for(;;){} /* error */
  }
  RTOS_Run();
#else
  APP_Loop();
#endif
#if 0
  for(;;) {
#if PL_HAS_MEALY
    MEALY_Step();
#else
    LED1_On();
    WAIT1_Waitms(300);
    LED1_Off();
    LED2_On();
    WAIT1_Waitms(300);
    LED2_Off();
    LED3_On();
    WAIT1_Waitms(300);
    LED3_Off();
#endif
  }
#endif
  /* just in case we leave the main application loop */
  PL_Deinit();
}
Ejemplo n.º 6
0
/*
** ===================================================================
**     Method      :  LED1_SetRatio16 (component LED)
**     Description :
**         Method to specify the duty cycle. If using a PWM pin, this
**         means the duty cycle is set. For On/off pins, values smaller
**         0x7FFF means off, while values greater means on.
**     Parameters  :
**         NAME            - DESCRIPTION
**         ratio           - Ratio value, where 0 means 'off' and
**                           0xffff means 'on'
**     Returns     : Nothing
** ===================================================================
*/
void LED1_SetRatio16(word ratio)
{
  /* on/off LED: binary on or off */
  if (ratio<(0xffff/2)) {
    LED1_Off();
  } else {
    LED1_On();
  }
}
Ejemplo n.º 7
0
/****************************************************************************
  Function:
    void SetLEDs(BYTE setting)

  Summary:
    change the LED settings of the boards

  Description:
    change the LED settings of the boards

  Precondition:
    None

  Parameters:
    BYTE setting - bitmap for desired LED setting (1 = On, 0 = Off)
        bit 0 = LED 0
        bit 1 = LED 1
        bit 2 = LED 2
        ...
        bit 7 = LED 7

  Return Values:
    None

  Remarks:
    None
  ***************************************************************************/
static void SetLEDs(BYTE setting)
{
    if((setting & 0x01) == 0x01) { LED0_On(); } else { LED0_Off(); }
    if((setting & 0x02) == 0x02) { LED1_On(); } else { LED1_Off(); }
    if((setting & 0x04) == 0x04) { LED2_On(); } else { LED2_Off(); }
    if((setting & 0x08) == 0x08) { LED3_On(); } else { LED3_Off(); }
    if((setting & 0x10) == 0x10) { LED4_On(); } else { LED4_Off(); }
    if((setting & 0x20) == 0x20) { LED5_On(); } else { LED5_Off(); }
    if((setting & 0x40) == 0x40) { LED6_On(); } else { LED6_Off(); }
    if((setting & 0x80) == 0x80) { LED7_On(); } else { LED7_Off(); }
}
Ejemplo n.º 8
0
static void APP_HandleEvent(EVNT_Handle event) {
  switch(event) {
  case EVNT_INIT:
    LED1_On(); WAIT1_Waitms(500); LED1_Off();
    break;
#if PL_NOF_KEYS>=1
  case EVNT_SW1_PRESSED:
    LED1_Neg();
  #if PL_HAS_BUZZER
    (void)BUZ_Beep(300, 500);
  #endif
  #if PL_HAS_REMOTE
    if (REMOTE_GetOnOff()) {
      REMOTE_SetOnOff(FALSE);
    } else {
      REMOTE_SetOnOff(TRUE);
    }
  #endif
    break;
#endif
#if PL_NOF_KEYS>=2
  case EVNT_SW2_PRESSED:
    LED2_Neg();
#if PL_HAS_REMOTE && PL_APP_ACCEL_CONTROL_SENDER
    //(void)RSTDIO_SendToTxStdio(RSTDIO_QUEUE_TX_IN, "buzzer buz 800 400\r\n", sizeof("buzzer buz 800 400\r\n")-1);
#endif
    break;
#endif
#if PL_NOF_KEYS>=3
  case EVNT_SW3_PRESSED:
    LED3_Neg();
    break;
#endif
#if PL_NOF_KEYS>=4
  case EVNT_SW4_PRESSED:
    LED4_Neg();
    break;
#endif
#if PL_HAS_LED_HEARTBEAT
  case EVNT_LED_HEARTBEAT:
    LED4_Neg();
    break;
#endif
  default:
#if PL_HAS_RADIO
    //RADIO_AppHandleEvent(event);
#endif
    break;
  }
}
Ejemplo n.º 9
0
/*lint -save  -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
  /* Write your local variable definition here */
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/

#if PL_HAS_SD_CARD
  /* SD card detection: PTE6 with pull-down! */
  PORT_PDD_SetPinPullSelect(PORTE_BASE_PTR, 6, PORT_PDD_PULL_DOWN);
  PORT_PDD_SetPinPullEnable(PORTE_BASE_PTR, 6, PORT_PDD_PULL_ENABLE);
#endif
#if PL_HAS_KEYS
  /* SW3: PTA4 */
  PORT_PDD_SetPinPullSelect(PORTA_BASE_PTR, 4, PORT_PDD_PULL_UP);
  PORT_PDD_SetPinPullEnable(PORTA_BASE_PTR, 4, PORT_PDD_PULL_ENABLE);
  /* SW2: PTC6 */
  PORT_PDD_SetPinPullSelect(PORTC_BASE_PTR, 6, PORT_PDD_PULL_UP);
  PORT_PDD_SetPinPullEnable(PORTC_BASE_PTR, 6, PORT_PDD_PULL_ENABLE);
#endif
#if PL_HAS_BLUETOOTH
  /* pull up Rx pin (PTC14) for Bluetooth module */
  PORT_PDD_SetPinPullSelect(PORTC_BASE_PTR, 14, PORT_PDD_PULL_UP);
  PORT_PDD_SetPinPullEnable(PORTC_BASE_PTR, 14, PORT_PDD_PULL_ENABLE);
#endif
  LED1_On();
  WAIT1_Waitms(50);
  LED1_Off();
  WAIT1_Waitms(50);
  LED2_On();
  WAIT1_Waitms(50);
  LED2_Off();
  WAIT1_Waitms(50);
  LED3_On();
  WAIT1_Waitms(50);
  LED3_Off();
  WAIT1_Waitms(50);
  APP_Start();

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
Ejemplo n.º 10
0
void Cpu_OnLLSWakeUpINT(void)
{
  uint32_t tmp;
  
  tmp = Cpu_GetLLSWakeUpFlags();
  if (tmp&LLWU_INT_MODULE0) { /* LPTMR */
#if 0
    LED1_On(); /* red */
    WAIT1_Waitms(1);
    LED1_Off(); /* red */
    WAIT1_Waitms(100);
#endif
    LPTMR_PDD_ClearInterruptFlag(LPTMR0_BASE_PTR); /* Clear interrupt flag */
  }
}
Ejemplo n.º 11
0
Archivo: LED.c Proyecto: sgabre/Blinky
void Led_On(uint8 led)
{
  switch(led)
  {
      case eGreen:
          LED0_On();
      break;

    case eBlue:
        LED1_On();
      break;

    default:
      break;
  }
}
Ejemplo n.º 12
0
void APP_Run(void) {
#if configUSE_TRACE_HOOKS
  if (RTOSTRC1_uiTraceStart()==0) {
    for(;;){} /* error starting trace recorder. Not setup for enough queues/tasks/etc? */
  }
#endif

#if PL_HAS_SD_CARD
  /* SD card detection: PTB16 with pull-down! */
  PORT_PDD_SetPinPullSelect(PORTB_BASE_PTR, 16, PORT_PDD_PULL_DOWN);
  PORT_PDD_SetPinPullEnable(PORTB_BASE_PTR, 16, PORT_PDD_PULL_ENABLE);
#endif
#if PL_HAS_PUSH_BUTTONS
  /* SW2: PTC1 */
  PORT_PDD_SetPinPullSelect(PORTC_BASE_PTR, 1, PORT_PDD_PULL_UP);
  PORT_PDD_SetPinPullEnable(PORTC_BASE_PTR, 1, PORT_PDD_PULL_ENABLE);
  /* SW3: PTB17 */
  PORT_PDD_SetPinPullSelect(PORTB_BASE_PTR, 17, PORT_PDD_PULL_UP);
  PORT_PDD_SetPinPullEnable(PORTB_BASE_PTR, 17, PORT_PDD_PULL_ENABLE);
#endif

  LED1_On();
  LED1_Off();
  LED2_On();
  LED2_Off();
  LED3_On();
  LED3_Off();
#if PL_HAS_SHELL
  SHELL_Init();
#endif
#if PL_HAS_ESC
  ESC_Init();
#endif
  if (FRTOS1_xTaskCreate(
      AppTask,  /* pointer to the task */
      "Main", /* task name for kernel awareness debugging */
      configMINIMAL_STACK_SIZE, /* task stack size */
      (void*)NULL, /* optional task startup argument */
      tskIDLE_PRIORITY,  /* initial priority */
      (xTaskHandle*)NULL /* optional task handle to create */
    ) != pdPASS)
  {
    for(;;){} /* error! probably out of memory */
  }
  FRTOS1_vTaskStartScheduler();
  for(;;) {}
}
Ejemplo n.º 13
0
/*lint -save  -e970 Disable MISRA rule (6.3) checking. */
int main(void)
/*lint -restore Enable MISRA rule (6.3) checking. */
{
  /* Write your local variable definition here */

  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  PE_low_level_init();
  /*** End of Processor Expert internal initialization.                    ***/
  LED2_On();
  WAIT1_Waitms(1000);
  LED2_Off();
  
#if PL_HAS_LOW_POWER
  LP_Init();
#endif
#if PL_HAS_RTOS
  if (FRTOS1_xTaskCreate(BlinkTask, "Blink", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL) != pdPASS) {
    for(;;){} /* error */
  }
#endif
#if PL_HAS_SHELL
  SHELL_Init();
#endif
#if PL_HAS_RTOS
  PEX_RTOS_START();
#endif
  for(;;) {
    LP_EnterPowerMode(LP_WAIT);
    LED1_On();
    WAIT1_Waitms(20);
    LED1_Off();
  }

  /* For example: for(;;) { } */

  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;){}
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
Ejemplo n.º 14
0
void APP_Run(void) {
  uint8_t res=ERR_OK;
  uint8_t xyz[3];
  
  LED1_On();
  LED2_On();
  LED3_On();
  res = MMA8451_Init();
  while (res==ERR_OK) {
    res = MMA8451_GetRawXYZ(&xyz[0]);
    LED1_Put(xyz[0]>50);
    LED2_Put(xyz[1]>50);
    LED3_Put(xyz[2]>50);
  }
  LED1_Off();
  LED2_Off();
  LED3_Off();
}
Ejemplo n.º 15
0
void FlashFailed(int warning)
{
	int infinite = 1;
	int repeats = 0;
	if (warning) {
		infinite = 0;
		repeats = 3;
	}

	while(infinite || repeats > 0) {
		LED1_On();
		WAIT1_Waitms(200);
		LED1_Off();
		WAIT1_Waitms(200);

		if (!infinite) {
			repeats--;
		}
	}
}
Ejemplo n.º 16
0
void LED_Test(void) {
#if PL_CONFIG_NOF_LED>=1
	LED1_On();
	WAIT1_Waitms(500);
	LED1_Off();
#endif
#if PL_CONFIG_NOF_LED>=2
	LED2_On();
	WAIT1_Waitms(500);
	LED2_Off();
#endif
#if PL_CONFIG_NOF_LED>=3
	LED3_On();
	WAIT1_Waitms(500);
	LED3_Off();
#endif
#if PL_CONFIG_NOF_LED>=4
	#error "only 3 LED ;)"
#endif
}
Ejemplo n.º 17
0
void APP_HandleEvent(byte event) {
  switch(event) {
    case EVNT1_INIT:
      LED1_On(); LED2_On(); LED3_On(); LED4_On();
      WAIT1_Waitms(500);
      LED1_Off(); LED2_Off(); LED3_Off(); LED4_Off();
      break;
    case EVNT1_BTN1_PRESSED:
#if HAS_SOUND
      RTOS_StartSounder(300);
#endif
      LED4_Neg();
      SHELL_SendStr("SW1 pressed!\r\n");
      break;
    case EVNT1_BTN2_PRESSED:
#if HAS_SOUND
      RTOS_StartSounder(500);
#endif
      LED5_Neg();
      SHELL_SendStr("SW2 pressed!\r\n");
      break;
    case EVNT1_BTN3_PRESSED:
#if HAS_SOUND
      RTOS_StartSounder(700);
#endif
      LED7_Neg();
      SHELL_SendStr("SW3 pressed!\r\n");
      break;
    case EVNT1_BTN4_PRESSED:
#if HAS_SOUND
      RTOS_StartSounder(900);
#endif
      LED8_Neg();
      SHELL_SendStr("SW4 pressed!\r\n");
      break;
    default:
      break;
  } /* switch */
}
Ejemplo n.º 18
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);
  }
}
Ejemplo n.º 19
0
void APP_Run(void) {
  int16_t x,y,z;
  uint8_t res;
  #define ACCEL_VAL  2000

  res = FX1_Enable(); /* enable accelerometer (just in case) */
  if (res!=ERR_OK) {
    Err();
  }
  if (FAT1_Init()!=ERR_OK) {
    Err();
  }
  if (FAT1_mount(0, &fileSystemObject) != FR_OK) { /* mount file system */
    Err();
  }
  for(;;) {
    //LED1_Neg();
    x = FX1_GetX();
    y = FX1_GetY();
    z = FX1_GetZ();
    if (x>ACCEL_VAL || x<-ACCEL_VAL) {
      LED1_On();
      LED2_Off();
      LED3_Off();
    } else if (y>ACCEL_VAL || y<-ACCEL_VAL) {
      LED1_Off();
      LED2_On();
      LED3_Off();
    } else if (z>ACCEL_VAL || z<-ACCEL_VAL) {
      LED1_Off();
      LED2_Off();
      LED3_On();
    }
    LogToFile(x, y, z);
    WAIT1_Waitms(1000);
  }
}
Ejemplo n.º 20
0
uint8_t REMOTE_ParseCommand(const unsigned char *cmd, bool *handled, const CLS1_StdIOType *io) {
  uint8_t res = ERR_OK;

  if (UTIL1_strcmp((char*)cmd, (char*)CLS1_CMD_HELP)==0 || UTIL1_strcmp((char*)cmd, (char*)"remote help")==0) {
    REMOTE_PrintHelp(io);
    *handled = TRUE;
  } else if (UTIL1_strcmp((char*)cmd, (char*)CLS1_CMD_STATUS)==0 || UTIL1_strcmp((char*)cmd, (char*)"remote status")==0) {
    REMOTE_PrintStatus(io);
    *handled = TRUE;
  } else if (UTIL1_strcmp((char*)cmd, (char*)"remote on")==0) {
    REMOTE_isOn = TRUE;
    LED1_On();
    *handled = TRUE;
  } else if (UTIL1_strcmp((char*)cmd, (char*)"remote off")==0) {
#if PL_CONFIG_HAS_MOTOR
    MOT_SetSpeedPercent(MOT_GetMotorHandle(MOT_MOTOR_LEFT), 0);
    MOT_SetSpeedPercent(MOT_GetMotorHandle(MOT_MOTOR_RIGHT), 0);
#endif
    REMOTE_isOn = FALSE;
    LED1_Off();
    *handled = TRUE;
  } else if (UTIL1_strcmp((char*)cmd, (char*)"remote verbose on")==0) {
    REMOTE_isVerbose = TRUE;
    *handled = TRUE;
  } else if (UTIL1_strcmp((char*)cmd, (char*)"remote verbose off")==0) {
    REMOTE_isVerbose = FALSE;
    *handled = TRUE;
  } else if (UTIL1_strcmp((char*)cmd, (char*)"remote joystick on")==0) {
    REMOTE_useJoystick = TRUE;
    *handled = TRUE;
  } else if (UTIL1_strcmp((char*)cmd, (char*)"remote joystick off")==0) {
    REMOTE_useJoystick = FALSE;
    *handled = TRUE;
  }
  return res;
}
Ejemplo n.º 21
0
void SystemTick(void)
{
    SystemTickCnt++;

#ifdef LED1_On
    if(LED_Mask & 2)
    {
        LED_Mask &= 0xFD;
        LED1_On();
    }
    else
        LED1_Off();
#endif  //  LED1_On

#ifdef LED2_On
    if(LED_Mask & 4)
    {
        LED_Mask &= 0xFB;
        LED2_On();
    }
    else
        LED2_Off();
#endif  //  LED2_On
}
Ejemplo n.º 22
0
static void KillMe(void* param) {
  LED1_On(); /* LED of death! */
  vTaskDelete(NULL); /* suicide! */
}
Ejemplo n.º 23
0
static void Err(void) {
  LED1_On();
  LED2_On();
  LED3_On();
  for(;;){}
}
Ejemplo n.º 24
0
void accelTest(void){
	uint8_t res = ERR_OK;
	int8_t dataX = 0;

	deviceData.handle = I2C1_Init(&deviceData);

#if 0
	uint8_t data = 0;
	int8_t i = 2;




	WAIT1_WaitCycles(25);
	res = LIS2DH12TR_ReadReg(0x0f, &data, sizeof(data));
	WAIT1_WaitCycles(25);
	res = LIS2DH12TR_WriteReg(0x20, 0b01111111);
	WAIT1_WaitCycles(25);
	res = LIS2DH12TR_WriteReg(0x23, 0b00100000);

	for(;;){
		WAIT1_WaitCycles(25);
		res = LIS2DH12TR_ReadReg(0x29, &dataX, 1U);

		if(dataX > i){
			LED1_On();
			i = -1;
		} else if(dataX < i){
			LED1_Off();
			i = 1;
		}
	}
#else

#define MASK_LED1	0x04
#define MASK_LED2	0x02
#define MASK_LED3	0x01
#define PIXEL_TIME_MS	1

	uint8_t img[] = {7,2,7,0,7,7,7,0,7,4,4,0,7,4,7};

	WAIT1_WaitCycles(25);
	res = LIS2DH12TR_WriteReg(0x20, 0b01111111);
	WAIT1_WaitCycles(25);
	res = LIS2DH12TR_WriteReg(0x23, 0b00100000);
	WAIT1_WaitCycles(25);

	bool swipeRight = FALSE;
	bool swipeLeft = FALSE;

	uint8_t right = 0;
	uint8_t left = 0;

	uint8_t prevAccelValue = 0;
	uint8_t lengthOfImage = sizeof(img);

	while(1){
		//WAIT1_WaitCycles(25);
		WAIT1_Waitms(1);
		res = LIS2DH12TR_ReadReg(0x29, &dataX, 1U);

		if(dataX < prevAccelValue){
			right++;
			if(right == 3){
				swipeRight = TRUE;
				right = 0;
			}
		} /*else if(dataX > prevAccelValue){
			left++;
			if(left == 3){
				swipeLeft = TRUE;
				left = 0;
			}
		}*/
		prevAccelValue = dataX;

		if ((dataX > 40) & swipeRight){

			WAIT1_Waitms(10);

			for(int i=0; i<lengthOfImage; i++){
				LED1_Put(img[i] & MASK_LED1);
				LED2_Put(img[i] & MASK_LED2);
				LED3_Put(img[i] & MASK_LED3);

				WAIT1_Waitms(PIXEL_TIME_MS);

				LED1_Off();
				LED2_Off();
				LED3_Off();

				WAIT1_Waitms(PIXEL_TIME_MS);
			}
			swipeRight = FALSE;
		} /*else if ((dataX < 40) & swipeLeft){

			WAIT1_Waitms(10);

			for(int i=(lengthOfImage-1); i>=0; i--){
				LED1_Put(img[i] & MASK_LED1);
				LED2_Put(img[i] & MASK_LED2);
				LED3_Put(img[i] & MASK_LED3);

				WAIT1_Waitms(PIXEL_TIME_MS);

				LED1_Off();
				LED2_Off();
				LED3_Off();

				WAIT1_Waitms(PIXEL_TIME_MS);
			}
			swipeLeft = FALSE;
		}*/
		//prevAccelValue = 0;
	}
#endif
}
Ejemplo n.º 25
0
/*! \brief Handles the Events */
static void APP_EventHandler(EVNT_Handle event) {
	uint8_t err;
  switch(event) {
    case EVNT_INIT:
      LED1_On();
      vTaskDelay(50/portTICK_RATE_MS);
      LED1_Off();
      LED2_On();
      vTaskDelay(50/portTICK_RATE_MS);
      LED2_Off();
      LED3_On();
      vTaskDelay(50/portTICK_RATE_MS);
      LED3_Off();
      break;
    case EVENT_LED_HEARTBEAT:
      LED2_Neg();
      break;
    case EVNT_SW1_PRESSED:
      lastKeyPressed = 1;
      LED1_On();
      vTaskDelay(50/portTICK_RATE_MS);
      LED1_Off();
      //EVNT_SetEvent(EVNT_REF_START_STOP_CALIBRATION);
#if PL_HAS_FIGHT_MODE
      FIGHT_SetState(FIGHT_STATE_COUNTDOWN);
      break;
#endif

#if PL_HAS_LINE_SENSOR
    case EVNT_REF_START_STOP_CALIBRATION: //Create event again, because the event is handled in the "Reflectance.c" directly.
    	if(!EVNT_EventIsSet(EVNT_REF_START_STOP_CALIBRATION))
    	{
    		EVNT_SetEvent(EVNT_REF_START_STOP_CALIBRATION);
    	}

      break;
#endif

#if PL_IS_FRDM
    case EVNT_SW2_PRESSED:
      lastKeyPressed = 2;
      LED1_On();
      vTaskDelay(50/portTICK_RATE_MS);
      LED1_Off();
      break;
    case EVNT_SW3_PRESSED:
      lastKeyPressed = 3;
      LED1_On();
      vTaskDelay(50/portTICK_RATE_MS);
      LED1_Off();
      break;
    case EVNT_SW4_PRESSED:
      lastKeyPressed = 4;
      LED1_On();
      vTaskDelay(50/portTICK_RATE_MS);
      LED1_Off();
      break;
    case EVNT_SW5_PRESSED:
      lastKeyPressed = 5;
      LED1_On();
      vTaskDelay(50/portTICK_RATE_MS);
      LED1_Off();
      break;
    case EVNT_SW6_PRESSED:
      lastKeyPressed = 6;
      LED1_On();
      vTaskDelay(50/portTICK_RATE_MS);
      LED1_Off();
      break;
    case EVNT_SW7_PRESSED:
      lastKeyPressed = 7;
      LED1_On();
      vTaskDelay(50/portTICK_RATE_MS);
      LED1_Off();
      break;
#endif
    default:
      break;
  }
}
Ejemplo n.º 26
0
static void APP_EvntHandler(EVNT_Handle event) {
	switch (event) {
	case EVNT_INIT:
		LED1_On();
		WAIT1_Waitms(100);
		LED1_Off();
		break;

#if PL_HAS_LED_HEARTBEAT
		case EVNT_LED_HEARTBEAT:
		LED3_Neg();
		break;
#endif
#if PL_NOF_KEYS>=1
	case EVNT_SW1_PRESSED:

		if (REF_IsCalibrated()) {
			STR_Start();
		}

		break;

	case EVNT_SW1_LPRESSED:
#if PL_HAS_LINE_SENSOR
		LED4_On();
		WAIT1_Waitms(500);
		EVNT_SetEvent(EVNT_REF_START_STOP_CALIBRATION);
		DRV_Drive_Forward(40);
		WAIT1_Waitms(300);
		DRV_Drive_Forward(-60);
		WAIT1_Waitms(200);
		DRV_Drive_Forward(0);
		EVNT_SetEvent(EVNT_REF_START_STOP_CALIBRATION);
		WAIT1_Waitms(500);
		if (REF_IsCalibrated()) {
			LED4_Off();
		}
		break;
		
#endif
		break;
#endif
#if PL_NOF_KEYS>=2
		case EVNT_SW2_PRESSED:
		LED2_Neg();
		break;
#endif
#if PL_NOF_KEYS>=3
		case EVNT_SW3_PRESSED:
		LED3_Neg();
		break;
#endif
#if PL_NOF_KEYS>=4
		case EVNT_SW4_PRESSED:
		LED4_Neg();
		break;
#endif

	default:
		break;
	}
}
Ejemplo n.º 27
0
void usb_run(void)
{
	usbmidi_scheduler_state_t usbschedstate;
	usbmidi_scheduler_state_t intercoreschedstate;
	midicmd_t cmd;

	usb_timeout_counter_handle = TMOUT1_GetCounter(2);

	midiin_reset(&midiin1_state);
	midiin1_state.GetCharsInRxBuf = MIDIUART1_GetCharsInRxBuf;
	midiin1_state.RecvChar = MIDIUART1_RecvChar;

	midiin_reset(&midiin2_state);
	midiin2_state.GetCharsInRxBuf = MIDIUART2_GetCharsInRxBuf;
	midiin2_state.RecvChar = MIDIUART2_RecvChar;

	midiout_reset(&midiout1_state);
	midiout1_state.OutBufSize = MIDIUART1_OUT_BUF_SIZE;
	midiout1_state.GetCharsInTxBuf = MIDIUART1_GetCharsInTxBuf;
	midiout1_state.SendChar = MIDIUART1_SendChar;
	midiout1_state.CounterExpired = TMOUT1_CounterExpired;
	midiout1_state.SetCounter = TMOUT1_SetCounter;
	midiout1_state.midiout_counterhandle = TMOUT1_GetCounter(10);

	midiout_reset(&midiout2_state);
	midiout2_state.OutBufSize = MIDIUART2_OUT_BUF_SIZE;
	midiout2_state.GetCharsInTxBuf = MIDIUART2_GetCharsInTxBuf;
	midiout2_state.SendChar = MIDIUART2_SendChar;
	midiout2_state.CounterExpired = TMOUT1_CounterExpired;
	midiout2_state.SetCounter = TMOUT1_SetCounter;
	midiout2_state.midiout_counterhandle = TMOUT1_GetCounter(10);

	usbmidi_scheduler_reset(&usbschedstate);
	usbschedstate.RecvByte = usbmidi_receive;
	usbschedstate.bus_count = 5;
	usbschedstate.CanTransmit[0] = intercore_can_transmit;
	usbschedstate.CanTransmit[1] = midiout_can_transmit;
	usbschedstate.CanTransmit[2] = midiout_can_transmit;
	usbschedstate.CanTransmit[3] = intercore_can_transmit;
	usbschedstate.CanTransmit[4] = intercore_can_transmit;
	usbschedstate.Transmit[0] = intercore_transmit;
	usbschedstate.Transmit[1] = midiout_transmit;
	usbschedstate.Transmit[2] = midiout_transmit;
	usbschedstate.Transmit[3] = intercore_transmit;
	usbschedstate.Transmit[4] = intercore_transmit;
	usbschedstate.TransmitHook[0] = sysex_process;
	usbschedstate.TransmitHook[1] = NULL;
	usbschedstate.TransmitHook[2] = NULL;
	usbschedstate.TransmitHook[3] = NULL;
	usbschedstate.TransmitHook[4] = NULL;
	usbschedstate.busstate[0] = NULL;
	usbschedstate.busstate[1] = &midiout1_state;
	usbschedstate.busstate[2] = &midiout2_state;
	usbschedstate.busstate[3] = NULL;
	usbschedstate.busstate[4] = NULL;

	usbmidi_scheduler_reset(&intercoreschedstate);
	intercoreschedstate.RecvByte = intercore_receive;
	intercoreschedstate.bus_count = 5;
	intercoreschedstate.CanTransmit[0] = usbmidi_can_transmit;
	intercoreschedstate.CanTransmit[1] = midiout_can_transmit;
	intercoreschedstate.CanTransmit[2] = midiout_can_transmit;
	intercoreschedstate.CanTransmit[3] = usbmidi_can_transmit;
	intercoreschedstate.CanTransmit[4] = usbmidi_can_transmit;
	intercoreschedstate.Transmit[0] = usbmidi_transmit;
	intercoreschedstate.Transmit[1] = midiout_transmit;
	intercoreschedstate.Transmit[2] = midiout_transmit;
	intercoreschedstate.Transmit[3] = usbmidi_transmit;
	intercoreschedstate.Transmit[4] = usbmidi_transmit;
	intercoreschedstate.TransmitHook[0] = NULL;
	intercoreschedstate.TransmitHook[1] = NULL;
	intercoreschedstate.TransmitHook[2] = NULL;
	intercoreschedstate.TransmitHook[3] = NULL;
	intercoreschedstate.TransmitHook[4] = NULL;
	intercoreschedstate.busstate[0] = NULL;
	intercoreschedstate.busstate[1] = &midiout1_state;
	intercoreschedstate.busstate[2] = &midiout2_state;
	intercoreschedstate.busstate[3] = NULL;
	intercoreschedstate.busstate[4] = NULL;

	COREUART_Init();
	DMAT1_AllocateChannel(DMAT1_DeviceData);
	DMAT1_EnableChannel(DMAT1_DeviceData);
	//UART0_C2 &= ~(1 << 5); /* Clear RIE */
	UART0_C5 |= (1 << 5); /* RDMAE=1 Enable DMA */
	COREUART_Enable();

	intercore_sync_master();

    for(;;) {
    	if (USBMIDI1_App_Task(midi_buffer, sizeof(midi_buffer)) == ERR_BUSOFF) {
    		LED1_Off();
    		usbmidi_scheduler_reset(&usbschedstate);
    		UsbMidiRx_Init();
    		UsbMidiTx_Init();
    	}
    	else {
    		LED1_On();
    		if (sysex_flashing | slave_initialized) {
    			// Ignore intercore bus during flashing
    			usbschedstate.CanTransmit[0] = NULL;
    		}
    		usbmidi_scheduler(&usbschedstate);
    	}

    	if (TMOUT1_CounterExpired(usb_timeout_counter_handle)) {
    		// No data going out on USB, reset queue!
    		EnterCritical();
    		UsbMidiTx_Init();
    		ExitCritical();
    	}

    	if (!(sysex_flashing || slave_initialized)) {
    		usbmidi_scheduler(&intercoreschedstate);
    	}

    	int repeat = 1;
    	while (repeat) {
    		repeat = 0;
			int ready = midiin_receive(&cmd, &midiin1_state);
			if (ready) {
				repeat = 1;
				cmd.header &= 0x0F;
				cmd.header |= (0x1 << 4);
				if (usbmidi_can_transmit(4, NULL)) {
					usbmidi_transmit(cmd, NULL);
				}
				//if (intercore_can_transmit(4, NULL)) {
					intercore_transmit(cmd, NULL);
				//}
			}
			ready = midiin_receive(&cmd, &midiin2_state);
			if (ready) {
				repeat = 1;
				cmd.header &= 0x0F;
				cmd.header |= (0x2 << 4);
				if (usbmidi_can_transmit(4, NULL)) {
					usbmidi_transmit(cmd, NULL);
				}
				//if (intercore_can_transmit(4, NULL)) {
					intercore_transmit(cmd, NULL);
				//}
			}
    	}
    }
}
Ejemplo n.º 28
0
static void REMOTE_HandleMotorMsg(int16_t direction, int16_t speedMode, int16_t z) {
  #define SCALE_DOWN 30
  #define MIN_VALUE  250 /* values below this value are ignored */
  #define DRIVE_DOWN 1

#define SCALE_FROM_PERCENT (16383/100)
#define NORMAL_SPEED (20 * SCALE_FROM_PERCENT)
#define FAST_SPEED (80 * SCALE_FROM_PERCENT)
#define FAST_TURN (30 * SCALE_FROM_PERCENT)

  if (!REMOTE_isOn) {
	  LED1_Off();
    return;
  }

  LED1_On();

  if(speedMode == 4) {
	  // left handed
	  LED2_On();
	  MAZE_SetTurnHandleLeft(TRUE);
	  LF_StartFollowing();
  }

  if(speedMode == 5) {
	  // right handed
	  LED2_On();
	  MAZE_SetTurnHandleLeft(FALSE);
	  LF_StartFollowing();
  }

  switch(direction) {
  case 0:											// straight
	  if(speedMode == 0){
		  DRV_SetSpeed(0, 0);
	  } else if (speedMode == 1) {
		  DRV_SetSpeed(NORMAL_SPEED, NORMAL_SPEED);
	  } else if (speedMode == 2) {
		  DRV_SetSpeed(FAST_SPEED,FAST_SPEED );
	  } else if (speedMode == 3){
		  DRV_SetSpeed( -NORMAL_SPEED, -NORMAL_SPEED );
	  }
	  break;

  case 1:											// right
	  if(speedMode == 0){
		  DRV_SetSpeed(NORMAL_SPEED, 0);
	  } else if (speedMode == 1) {
		  DRV_SetSpeed(FAST_SPEED, NORMAL_SPEED);
	  } else if (speedMode == 2) {
		  DRV_SetSpeed(FAST_SPEED,FAST_TURN );
	  } else if (speedMode == 3){
		  DRV_SetSpeed( -FAST_SPEED, -NORMAL_SPEED );
	  }
	  break;

  case 2:											// left
	  if(speedMode == 0){
		  DRV_SetSpeed(0, NORMAL_SPEED);
	  } else if (speedMode == 1) {
		  DRV_SetSpeed(NORMAL_SPEED, FAST_SPEED);
	  } else if (speedMode == 2) {
		  DRV_SetSpeed(FAST_TURN,FAST_SPEED );
	  } else if (speedMode == 3){
		  DRV_SetSpeed( -NORMAL_SPEED, -FAST_SPEED );
	  }
	  break;

  }
  /*
  if (z<-900) { /* have a way to stop motor: turn FRDM USB port side up or down
#if PL_CONFIG_HAS_DRIVE
    DRV_SetSpeed(0, 0);
#else
    MOT_SetSpeedPercent(MOT_GetMotorHandle(MOT_MOTOR_LEFT), 0);
    MOT_SetSpeedPercent(MOT_GetMotorHandle(MOT_MOTOR_RIGHT), 0);
#endif
  } else if ((directionVal>MIN_VALUE || directionVal<-MIN_VALUE) && (speedVal>MIN_VALUE || speedVal<-MIN_VALUE)) {
    int16_t speed, speedL, speedR;
    
    speed = speedVal/SCALE_DOWN;
    if (directionVal<0) {
      if (speed<0) {
        speedR = speed+(directionVal/SCALE_DOWN);
      } else {
        speedR = speed-(directionVal/SCALE_DOWN);
      }
      speedL = speed;
    } else {
      speedR = speed;
      if (speed<0) {
        speedL = speed-(directionVal/SCALE_DOWN);
      } else {
        speedL = speed+(directionVal/SCALE_DOWN);
      }
    }
#if PL_CONFIG_HAS_DRIVE
    DRV_SetSpeed(speedL*SCALE_DOWN/DRIVE_DOWN, speedR*SCALE_DOWN/DRIVE_DOWN);
#else
    MOT_SetSpeedPercent(MOT_GetMotorHandle(MOT_MOTOR_LEFT), speedL);
    MOT_SetSpeedPercent(MOT_GetMotorHandle(MOT_MOTOR_RIGHT), speedR);
#endif
  } else if (speedVal>100 || speedVal<-100) { //* speed
#if PL_CONFIG_HAS_DRIVE
    DRV_SetSpeed(speedVal, speedVal);
#else
    MOT_SetSpeedPercent(MOT_GetMotorHandle(MOT_MOTOR_LEFT), -speedVal/SCALE_DOWN);
    MOT_SetSpeedPercent(MOT_GetMotorHandle(MOT_MOTOR_RIGHT), -speedVal/SCALE_DOWN);
#endif
  } else if (directionVal>100 || directionVal<-100) { //* direction
#if PL_CONFIG_HAS_DRIVE
    DRV_SetSpeed(directionVal/DRIVE_DOWN, -directionVal/DRIVE_DOWN);
#else
    MOT_SetSpeedPercent(MOT_GetMotorHandle(MOT_MOTOR_LEFT), -directionVal/SCALE_DOWN);
    MOT_SetSpeedPercent(MOT_GetMotorHandle(MOT_MOTOR_RIGHT), (directionVAl/SCALE_DOWN));
#endif
  } else { //* device flat on the table?
#if PL_CONFIG_HAS_DRIVE
    DRV_SetSpeed(0, 0);
#else
    MOT_SetSpeedPercent(MOT_GetMotorHandle(MOT_MOTOR_LEFT), 0);
    MOT_SetSpeedPercent(MOT_GetMotorHandle(MOT_MOTOR_RIGHT), 0);
#endif

  }  */
}
Ejemplo n.º 29
0
static void APP_EventHandler(EVNT_Handle event) {
	#if PL_HAS_LINE_SENSOR

	#endif
	static uint16_t buzzer = 1000;
	switch(event){
	case EVNT_INIT:
	    LED1_On();
	    WAIT1_Waitms(100);
	    LED1_Off();
#if PL_HAS_BUZZER
	    BUZ_Beep(1000,400);
#endif
	    break;
	case EVNT_HEARTBEAT:
		//LED1_Off();
		break;
	case EVNT_SW_A_RELEASED:
		//BUZ_Beep(2000,2000);
		break;
	case EVNT_SW_A_PRESSED:
		#if PL_HAS_BUZZER
			BUZ_Beep(1000,10);
            #if PL_HAS_BATTLE
			    BATTLE_changeState(BATTLE_STATE_WAIT);
            #endif /* PL_HAS_BATTLE */
		#endif
		break;
	case EVNT_SW_A_LPRESSED:
		#if PL_HAS_LINE_SENSOR
			LED1_Neg();
			EVNT_SetEvent(EVNT_REF_START_STOP_CALIBRATION);
		#endif
		break;
	case EVNT_SW_B_PRESSED:
		LED2_Neg();
		LED3_Neg();
		#if PL_HAS_SHELL
			CLS1_SendStr("SW B pressed\n",CLS1_GetStdio()->stdOut);
		#endif
		break;
	case EVNT_SW_C_PRESSED:
		LED1_Neg();
		LED2_Neg();
		#if PL_HAS_SHELL
			CLS1_SendStr("SW C pressed\n",CLS1_GetStdio()->stdOut);
		#endif
		break;
	case EVNT_SW_D_PRESSED:
		LED1_Neg();
		#if PL_HAS_SHELL
			CLS1_SendStr("SW D pressed\n",CLS1_GetStdio()->stdOut);
		#endif
		break;
	case EVNT_SW_E_PRESSED:
		LED2_Neg();
		#if PL_HAS_SHELL
				CLS1_SendStr("SW E pressed\n",CLS1_GetStdio()->stdOut);
		#endif
		break;
	case EVNT_SW_F_PRESSED:
		LED3_Neg();
		#if PL_HAS_SHELL
			CLS1_SendStr("SW F pressed\n",CLS1_GetStdio()->stdOut);
		#endif
		break;
	case EVNT_SW_G_PRESSED:
		LED1_Neg();
		LED2_Neg();
		LED3_Neg();
		#if PL_HAS_SHELL
			CLS1_SendStr("SW g pressed\n",CLS1_GetStdio()->stdOut);
		#endif
		break;
	case EVNT_REF_START_STOP_CALIBRATION:

		break;
	default:
		break;
	}
}