/** \file rpi_selector.c * \brief This module is used to manage selector on gpio */ /*************************************************************************************************** * Includes **************************************************************************************************/ #include "rpi_selector.h" #include #include #include /*************************************************************************************************** * Preprocessor Constants and Macros **************************************************************************************************/ /*************************************************************************************************** * Type and Contant Definitions **************************************************************************************************/ unsigned const selectorPinNumber = 4; /* TODO use GPIO function from ../gpio/gipo.h (same pin number) */ int selectorPins[4] = {26, 27, 6, 5}; char modeStr[] = "0 | 0 | 0 | 0 \n"; /*************************************************************************************************** * Persistent Variables **************************************************************************************************/ /*************************************************************************************************** * Internal Function Prototypes **************************************************************************************************/ /*************************************************************************************************** * External Function Definitions **************************************************************************************************/ void selector_setup() { wiringPiSetupGpio(); for (size_t i = 0; i < selectorPinNumber; ++i) { pinMode(selectorPins[i], INPUT); pullUpDnControl(selectorPins[i], PUD_DOWN); } } int selector_get_position() { for (size_t i = 0; i < selectorPinNumber; ++i) { if (digitalRead(selectorPins[i])) { return i; } } return -1; } char *selector_tostr() { for (size_t i = 0; i < selectorPinNumber; ++i) { modeStr[i * 4] = digitalRead(selectorPins[i]) ? '1' : '0'; } return modeStr; } /*************************************************************************************************** * Internal Function Definitions **************************************************************************************************/