Professional Documents
Culture Documents
Spaceship
Spaceship
Spaceship
Module
Spaceship.c
Revision
1.0.1
Description
This is a Service to update space ship location in galaga
Notes
History
When Who What/Why
-------------- --- --------
10/30/20 EM Created File
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
/* include header files for this state machine as well as any machines at the
next lower level in the hierarchy that are sub-machines to this machine
*/
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "Spaceship.h"
#include "UpdateOLED.h"
#include "PIC32_AD_Lib.h"
#include "Gameplay.h"
/*----------------------------- Module Defines ----------------------------*/
#define DEFAULT_SHIP_POS 3
#define OLED_TEST
#define SPACESHIP 1
#define PROJECTILE 2
#define ENEMY_SHIP 3
// with the introduction of Gen2, we need a module level Priority var as well
static uint8_t MyPriority;
static uint32_t CalibrationJoystickLocation[2];
static int16_t ShipPositionX;
static uint8_t deltaT;
static uint8_t TimeDiscretization;
Parameters
uint8_t : the priorty of this service
Returns
bool, false if error in initialization, true otherwise
Description
Saves away the priority, initializes input pins to be read for joystick
movement
Notes
Author
Andrew Low
****************************************************************************/
bool InitSpaceship(uint8_t Priority)
{
ES_Event_t ThisEvent;
MyPriority = Priority;
// put us into the Initial PseudoState
CurrentState = InitSpaceshipState;
// Sets ANSEL and TRIS bits on pins B2 and B3 to read analog input values
ANSELBbits.ANSB2 = 1;
TRISBbits.TRISB2 = 1;
ANSELBbits.ANSB3 = 1;
TRISBbits.TRISB3 = 1;
/****************************************************************************
Function
PostSpaceship
Parameters
ES_Event_t ThisEvent, the event to post to the queue
Returns
boolean False if the Enqueue operation failed, True otherwise
Description
Posts an event to this state machine's queue
Notes
Author
Andrew Low
****************************************************************************/
bool PostSpaceship(ES_Event_t ThisEvent)
{
return ES_PostToService(MyPriority, ThisEvent);
}
/****************************************************************************
Function
RunSpaceship
Parameters
ES_Event_t : the event to process
Returns
ES_Event_t, ES_NO_EVENT if no error ES_ERROR otherwise
Description
add your description here
Notes
uses nested switch/case to implement the machine.
Author
Andrew Low
****************************************************************************/
ES_Event_t RunSpaceship(ES_Event_t ThisEvent)
{
ES_Event_t ReturnEvent;
ReturnEvent.EventType = ES_NO_EVENT; // assume no errors
switch(CurrentState)
{
case InitSpaceshipState: // Initial pseudo state
{
if(ThisEvent.EventType == ES_INIT)
{
// Initializes JOYSTICK_TIMER to a time of 250 ms
ES_Timer_InitTimer(JOYSTICK_TIMER, TIME_STEP_JOYSTICK);
}
}
break;
case ES_GAME_OVER: // Game Over event
{
// Sets CurrentState to TitleState
CurrentState = TitleState;
}
}
}
break;
}
return ReturnEvent;
}
/****************************************************************************
Function
QuerySpaceship
Parameters
None
Returns
SpaceshipState_t variable
Description
Returns the current state of the service
Notes
Author
Andrew Low
****************************************************************************/
SpaceshipState_t QuerySpaceship(void)
{
return CurrentState;
}
/****************************************************************************
Function
QuerySpaceshipPosition
Parameters
None
Returns
uint8_t variable
Description
Returns the current position of the TIE fighter
Notes
Author
Andrew Low
****************************************************************************/
uint8_t QuerySpaceshipPosition(void){
return ShipPositionX;
}