Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
What/Why
-------Created
*/
/*
*****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
/* include header files for the framework and this service
*/
#include
#include
#include
#include
"ES_Configure.h"
"ES_Framework.h"
"ES_DeferRecall.h"
"ES_ShortTimer.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
"inc/hw_memmap.h"
"inc/hw_types.h"
"inc/hw_gpio.h"
"inc/hw_sysctl.h"
"driverlib/sysctl.h"
"driverlib/pin_map.h"
"driverlib/gpio.h"
"driverlib/timer.h"
"driverlib/interrupt.h"
#include "Plants.h"
#include "BITDEFS.h"
#include "SceneSM.h"
#ifndef ALL_BITS
#define ALL_BITS (0xff<<2)
#endif
#define PLANT1_INPUT BIT3HI
#define PLANT2_INPUT BIT4HI
#define PLANT3_INPUT BIT5HI
//Module variables
//************************************
//Required: Static uint16_t TimeOfLastRise1,TimeOfLastFall1
static uint16_t TimeOfLastRise1;
static uint16_t TimeOfLastFall1;
static uint16_t TimeOfLastRise2;
static uint16_t TimeOfLastFall2;
static uint16_t TimeOfLastRise3;
static uint16_t TimeOfLastFall3;
static uint16_t LastInputState1=0;
static uint16_t LastInputState2=0;
static uint16_t LastInputState3=0;
static bool Plant1State=0;
static bool Plant2State=0;
static bool Plant3State=0;
static uint8_t MyPriority;
NextState=Plants_Waiting_Rise;
puts("Plants_Service_GO!!!");
}
}
break;
case(Plants_Waiting_Rise):{
if(ThisEvent.EventType == ES_RISING_EDGE_PLANT_1) {
TimeOfLastRise1 = ThisEvent.EventParam;
NextState = Plants_Waiting_Fall;
//puts("plant1");
}
if(ThisEvent.EventType == ES_RISING_EDGE_PLANT_2) {
TimeOfLastRise2 = ThisEvent.EventParam;
NextState = Plants_Waiting_Fall;
//puts("plant2");
if(ThisEvent.EventType == ES_RISING_EDGE_PLANT_3) {
TimeOfLastRise3 = ThisEvent.EventParam;
NextState = Plants_Waiting_Fall;
//puts("plant3");
}
if(ThisEvent.EventType==ES_RESET){
//tells all plants that they are no longer
grown (motors must actually pull them down on ES_RESET, this assumes motor
service will do this on ES_RESET)
PlantConstantReset();
//puts("plants RESET");
NextState=Plants_Idle;
//RESET ALL PLANT RELATED STATICS!
}
}
break;
case(Plants_Waiting_Fall):{
uint8_t PlantNum = 0;
if(ThisEvent.EventType == ES_FALLING_EDGE_PLANT_1) {
TimeOfLastFall1 = ThisEvent.EventParam;
NextState = Plants_Waiting_Rise;
}
if(ThisEvent.EventType == ES_FALLING_EDGE_PLANT_2) {
TimeOfLastFall2 = ThisEvent.EventParam;
NextState = Plants_Waiting_Rise;
}
if(ThisEvent.EventType == ES_FALLING_EDGE_PLANT_3) {
TimeOfLastFall3 = ThisEvent.EventParam;
NextState = Plants_Waiting_Rise;
}
PlantNum=BeaconSpotted();
// printf("%d",PlantNum);
if (PlantNum !=0){
//puts("\n\r grow!");
//printf("%u",PlantNum);
Event2Post.EventType=ES_GROW;
Event2Post.EventParam=PlantNum;
//Post To the Motor Service responsible for raising the
plants.
}
CurrentState=NextState;
return ReturnEvent;
}
/****************************************************************************
Function
PlantConstantReset
Parameters
void
Returns
nothing
Description
Notes
Author
****************************************************************************/
uint8_t BeaconSpotted(void){
uint16_t LastPulseWidth1;
uint16_t LastPulseWidth2;
uint16_t LastPulseWidth3;
uint8_t PlantNum = 0;
//puts("\n\r looking for the beacon gonna grow some plaaannttts");
uint16_t LowerTime=5; //assuming microseconds, this is the high time
uint16_t HigherTime=10;
//puts("\r\n beacon Spotted");
if(Plant1State==0){
//Checks the Current State of
Plant1, if it hasnt grown, it checks for an incoming signal
LastPulseWidth1=(TimeOfLastFall1 - TimeOfLastRise1);
//checking incoming signal
if(LastPulseWidth1>LowerTime &&LastPulseWidth1<HigherTime){ //is it
our signal with a high time of ~7 milliseconds?
PlantNum=1;
//first plant has seen the liiiighhht!
Plant1State=1;
//plant 1 has grown, dont try this again until plant 1 has died
//puts("plant1 LIVESSS");
}
}
if(Plant2State==0){
//Checks the Current State of Plant2,
if it hasnt grown, it checks for an incoming signal
LastPulseWidth2=(TimeOfLastFall2 - TimeOfLastRise2);
//checking incoming signal
//printf("\r\n PW2= %u",LastPulseWidth2);
//puts("made it here");
if(LastPulseWidth2>LowerTime &&LastPulseWidth2<HigherTime){ //is it
our signal with a high time of ~7 milliseconds?
PlantNum=2;
//second plant has seen the liiiighhht! Praise the sun!
Plant2State=1;
//plant 2 has grown, dont try this again until plant 2 has died
//puts("plant2 LIVESSS");
}
}
if(Plant3State==0){
//Checks the Current State of Plant3,
if it hasnt grown, it checks for an incoming signal
LastPulseWidth3=(TimeOfLastFall3 - TimeOfLastRise3);
//checking incoming signal
if(LastPulseWidth3>LowerTime &&LastPulseWidth3<HigherTime){ //is it
our signal with a high time of ~7 milliseconds?
PlantNum=3;
//Third plant is a happy plant
Plant3State=1;
//plant 3 has grown, dont try this again until plant 3 is dead
//puts("plant3 LIVESSS");
return PlantNum;
}
/****************************************************************************
Function
Input_Plant_Init
Parameters
void
Returns
nothing
Description
Notes
Author
Notes
Author
}
else{output=0;
//puts("\r\n 0 input \r\n");
}
//figure out how to read pins.
return output; //pin state.
}
if(WhichPlant==2){
uint8_t input=0x00;
input=(HWREG(GPIO_PORTA_BASE+
(GPIO_O_DATA+ALL_BITS))&PLANT2_INPUT);
bool output=0;
//printf(("My unsigned integer: %u \r\n"), input);
if((input!=0)){
output=1;
//puts("\r\n hi input \r\n");
}
else{output=0;
//puts("\r\n 0 input \r\n");
}
//figure out how to read pins.
return output; //pin state.
}
if(WhichPlant==3){
uint8_t input=0x00;
input=(HWREG(GPIO_PORTA_BASE+
(GPIO_O_DATA+ALL_BITS))&PLANT3_INPUT);
bool output=0;
//printf(("My unsigned integer: %u \r\n"), input);
if((input!=0)){
output=1;
//puts("\r\n hi input \r\n");
}
else{output=0;
//puts("\r\n 0 input \r\n");
}
//figure out how to read pins.
return output; //pin state.
}
}
//~~~~~~~~~~~~~~~~~~~~~~//
///EVENT CHECKERS BELOW///
//~~~~~~~~~~~~~~~~~~~~~~//
/****************************************************************************
Function
CheckLightPlant1Events
Parameters
void
Returns
bool = a bool indicating if event happened (true) or not (false).
Description
Notes
Author
VALUE
EdgeEvent.EventType=ES_RISING_EDGE_PLANT_1;
TimeOfLastRise1=ES_Timer_GetTime();
//printf(("Plant 1 Rise Time= %u"), TimeOfLastRise1);
EdgeEvent.EventParam=TimeOfLastRise1;
//TIMER
Description
Notes
Author
Maxwell Perham, 11/14/2016
****************************************************************************/
bool CheckLightPlant2Events(void){
VALUE
EdgeEvent.EventType=ES_RISING_EDGE_PLANT_2;
TimeOfLastRise2=ES_Timer_GetTime();
//printf(("\n\r Plant 2 Rise Time= %u"), TimeOfLastRise2);
EdgeEvent.EventParam=TimeOfLastRise2;
//TIMER
Notes
Author
has changed
high
VALUE