108
K
A
DAK
AMX Event Manager
#include "amx831cf.h" /* AMX C Interface Header */
static AMXID motorgroup;
static unsigned char motorstatus;
#define MOTORPORT 0x65 /* Motor status port */
#define MOTORON 0x01 /* Motor on */
#define MOTORMAX 0x02 /* Motor at maximum speed */
#define MOTOREVT (MOTORON + MOTORMAX)
void cdecl tpmotor( /* Motor Timer Procedure */
AMXID timerid, void *unused) /* Unused parameters */
{unsigned int status;
status = ajinb(MOTORPORT) & MOTOREVT;
/* If a change in motor status occurs */
/* Update motor status */
/* Signal that changes have occurred */
if (status != motorstatus) {
motorstatus = status;
ajevsig(motorgroup, MOTOREVT, status);
}
}
void cdecl rrmotor(void) /* Motor Restart Procedure */
{AMXID timerid;
motorstatus = ajinb(MOTORPORT) & MOTOREVT;
/* If an event group is available */
/* Set the initial event states to match the motor status */
/* If a 100 ms periodic timer can be created */
/* Start it to go off at the next AMX system tick */
if (ajevcre(&motorgroup, motorstatus, "EVMT") == AEROK) {
if (ajtmcre(&timerid, ajtmcnv(100), tpmotor,
NULL, "TMMT") == AEROK)
ajtmwr(timerid, 1); /* Start timer */
}
}