You are on page 1of 4

/****************************************************************************

Header file for Hoops


based on the Gen2 Events and Services Framework
Author: Kacyn Fujii Date: 11/2/14
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
#ifndef Hoop_H
#define Hoop_H
//// Event Definitions
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
// Public Function Prototypes
void InitHoops( void );
void MoveHoopUp(uint8_t);
void MoveHoopDown(uint8_t);
#endif
//#define test
/****************************************************************************
Module
Hoop.c
Description
Service module for lift hoop caps
Author: Kacyn Fujii Date: 11/2/14
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
/* include header files for this service
*/
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "Game.h"
#include "EventCheckers.h"
#include "GeneralBase.h"
#include "TargetLED.h"
#include "PWMTiva.h"
#include
#include
#include
#include
#include
#include
#include

<stdint.h>
<stdbool.h>
<stdio.h>
"driverlib/sysctl.h"
"driverlib/pin_map.h"
"driverlib/gpio.h"
"driverlib/pwm.h"

#include
#include
#include
#include
#include
#include
#include
#include

"ES_Port.h"
"termio.h"
"inc/hw_memmap.h"
"inc/hw_types.h"
"inc/hw_gpio.h"
"inc/hw_sysctl.h"
"driverlib/gpio.h"
"hoop.h"

/*----------------------------- Module Defines ----------------------------*/


#define clrScrn()
printf("\x1b[2J")
#define ALL_BITS (0xff<<2)
/*---------------------------- Module Functions ---------------------------*/
/* prototypes for private functions for this machine.They should be functions
relevant to the behavior of this state machine
*/
uint8_t decodeHoopNum(uint8_t hoopNum);
void MoveHoopUp(uint8_t hoopNum);
void MoveHoopDown(uint8_t hoopNum);

/*------------------------------ Module Code ------------------------------*/


/****************************************************************************
Function
InitHoops
Parameters
nothing
Returns
nothing
Description
initialize all PWM pins needed for servos
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
void InitHoops( void )
{
//Init all PWM pins
PWM_TIVA_Init();
//Set PWM frequency for group 0
PWM_TIVA_SetFreq(50, 0);
//Set PWM frequency for group 1
PWM_TIVA_SetFreq(50, 1);
}
/****************************************************************************
Function
decodeHoopNum
Parameters
uint8_t, the bit number indicate the hoop
Returns
uint8_t, translated channel number

Description
translate the hoop number from bit number to direct number control servo
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
uint8_t decodeHoopNum(uint8_t hoopNum) {
// return 2, if input is BIT0HI
if(hoopNum == BIT0HI) return 2; //right hoop
// return 3, if input is BIT1HI
else if(hoopNum == BIT1HI) return 3; //center hoop
// return 0, if input is BIT2HI
else if(hoopNum == BIT2HI) return 0; //left hoop
else return 4;//error
}
/****************************************************************************
Function
MoveHoopUp
Parameters
uint8_t, the bit number indicate the hoop
Returns
nothing
Description
Open the corresponding hoop with the input
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
void MoveHoopUp(uint8_t hoopNum)
{
//translate the servo channel number by input
uint8_t channelNum = decodeHoopNum(hoopNum);
//set pulse width at this servo channel, to lift cap
PWM_TIVA_SetPulseWidth(800,channelNum);
}
/****************************************************************************
Function
MoveHoopDown
Parameters
uint8_t, the bit number indicate the hoop
Returns
nothing
Description
Close the corresponding hoop with the input
Final Edit: Dongao Yang 11/25/14
****************************************************************************/
void MoveHoopDown(uint8_t hoopNum) {
//translate the servo channel number by input
uint8_t channelNum = decodeHoopNum(hoopNum);
//set pulse width at this servo channel, to close cap
PWM_TIVA_SetPulseWidth(3300,channelNum);

}
// test harness
#ifdef test
int main()
{
SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN
| SYSCTL_XTAL_16MHZ);
TERMIO_Init();
clrScrn();
InitHoops();
ES_Return_t ErrorType;
puts("test harness for hoop");
while(1)
{
MoveHoopUp(1);
MoveHoopUp(2);
MoveHoopUp(3);
getchar();
MoveHoopDown(1);
MoveHoopDown(2);
MoveHoopDown(3);
getchar();
}
}
#endif

You might also like