int Tentacle::processPin(int number, int value) { if( number < 0 || number >= numPins) { return -1; } Tentacle::Action action = configuredPinActions[number]; switch(action) { case Tentacle::Action_digitalWrite: digitalWrite(number, value); return value; break; case Tentacle::Action_pwmWrite: case Tentacle::Action_analogWrite: analogWrite(number, value); return value; break; default: break; } return processPin(number); }
/**************************************************************** * Main ****************************************************************/ int main(int argc, char **argv) { /* This variable is a file pointer to the file interface for the GPIO device driver which controls the input pin. */ uint32_t gpio_fd; // This is the file ID for the input file. uint8_t gpioSwitchP1 = 48; //Input Switch for Player 1 (GPIO1_16) uint8_t gpioSwitchP2 = 49; //Input Switch for Player 2 (GPIO0_26) uint8_t gpioLEDP1= 44; //Output LED light for Player 1 (GPIO1_12) uint8_t gpioLEDP2= 26; //Output LED light for Player 2 (GPIO0_26) char ioPort[56]; // This is the IO port that is to be referenced. if (argc < 3) { exit(-1); } // Set the signal callback for Ctrl-C signal(SIGINT, signal_handler); // Convert the input into the appropriate parameters. char player1[32]; char player2[32]; strcpy(player1, argv[1]); strcpy(player2, argv[2]); printf("Welcome to the game of Anticipation, %s and %s!", player1, player2); // Setup the input ports (void)gpio_export(gpioSwitchP1); (void)gpio_set_dir(gpioSwitchP1, 0); (void)gpio_set_edge(gpioSwitchP1, GPIO_BOTH_EDGES); // Both indicates that an interrupt will fire on both a rising and falling edge. gpio_fd = gpio_fd_open(gpioSwitchP1); (void)gpio_export(gpioSwitchP2); (void)gpio_set_dir(gpioSwitchP2, 0); (void)gpio_set_edge(gpioSwitchP2, GPIO_BOTH_EDGES); // Both indicates that an interrupt will fire on both a rising and falling edge. gpio_fd = gpio_fd_open(gpioSwitchP2); // Setup the output ports (void)gpio_export(gpioLEDP1); (void)gpio_set_dir(gpioLEDP1, 1); (void)gpio_fd_open(gpioLEDP1); (void)gpio_export(gpioLEDP2); (void)gpio_set_dir(gpioLEDP2, 1); (void)gpio_fd_open(gpioLEDP2); //GAME STUFF HERE // Start the process pin routine which will handle processing the pin. processPin(gpio_fd, gpioLEDP1, gpioSwitchP1); //*********************************************************************** // cleanup the executing system // Close the pins gpio_fd_close(gpio_fd); // Unexport the pins. gpio_unexport(gpioSwitchP1); gpio_unexport(gpioSwitchP2); gpio_unexport(gpioLEDP1); gpio_unexport(gpioLEDP2); printf("Peace out girl scout\n"); return 0; }