int main(int argc, char const *argv[]) { if(argc > 1) { if(strcmp("-dv", argv[1]) == 0) { debug = 2; printf("RUNNING IN VERBOSE DEBUG MODE.\n"); } if(strcmp("-d", argv[1]) == 0) { debug = 1; printf("RUNNING IN DEBUG MODE.\n"); } } mmap_setup(); gpio_setup(); lcd = getLCD(); lcdClear(lcd); lcdPuts(lcd, " MASTERMIND "); delay(500); printf("\nBeginning Game\n"); int g = game(); if(g) { printf("You win!\n"); // display win LED writePin(YELLOW_LED, HIGH); blink(RED_LED, 3, 300); writePin(YELLOW_LED, LOW); lcdWin(); } else { printf("You Lose, Sorry!\n"); lcdLose(); } delay(5000); lcdClear(lcd); unmap(); return 0; }
void SX1509::pinDir(byte pin, byte inOut) { // The SX1509 RegDir registers: REG_DIR_B, REG_DIR_A // 0: IO is configured as an output // 1: IO is configured as an input byte modeBit; if ((inOut == OUTPUT) || (inOut == ANALOG_OUTPUT)) modeBit = 0; else modeBit = 1; unsigned int tempRegDir = readWord(REG_DIR_B); if (modeBit) tempRegDir |= (1<<pin); else tempRegDir &= ~(1<<pin); writeWord(REG_DIR_B, tempRegDir); // If INPUT_PULLUP was called, set up the pullup too: if (inOut == INPUT_PULLUP) writePin(pin, HIGH); if (inOut == ANALOG_OUTPUT) { ledDriverInit(pin); } }
void RPi2DOutSI::onReceiveEvent(TstEventParams pa_stEventParams) { FZRTE_INFO("InputEvent Recvd : [%s]", c_uniqueIdService::getInstance().getUniqueNameFor(pa_stEventParams.m_unEventID).c_str()); if ((pa_stEventParams.m_unEventID == m_unGlobalEventID) && (pa_stEventParams.m_ptrMemAddr)) { writePin(m_nPin,*pa_stEventParams.m_ptrMemAddr); FZRTE_INFO("RPi2DOutSI : Writing Pin : %d to %d", m_nPin, *pa_stEventParams.m_ptrMemAddr); } }
RPi2DOutSI::RPi2DOutSI(AppBlocInfo pa_stSrvIntrfInfo, stMappingElem *pa_stDataMapElem, stSIParams pa_stParams) : CSI_base(pa_stParams) { FZRTE_INFO("--- Raspberry Pi2 Digital Output Service Interface ---"); if ((pa_stDataMapElem) && (pa_stDataMapElem->memSize)) { m_memSize = pa_stDataMapElem->memSize; m_memMapAddr = new FzrteByte[m_memSize]; if (NULL == m_memMapAddr) { FZRTE_ERROR("RPi2DOutSI : Cannot able to create memory Map address"); } else { if (pa_stParams.paramsList.size() != 3) { FZRTE_ERROR("RPi2DOutSI : No Valid Parameter Provided to Initialise... "); } else { m_nPin = atoi(pa_stParams.paramsList["PinNum"].c_str()); int m_nPud = 0; //default to PI_PUD_UP or 0 if ((!strcmp("PI_PUD_DOWN", pa_stParams.paramsList["PinCtrl"].c_str())) || (!strcmp("1", pa_stParams.paramsList["PinCtrl"].c_str()))) m_nPud = 1; else if ((!strcmp("PI_PUD_OFF", pa_stParams.paramsList["PinCtrl"].c_str())) || (!strcmp("2", pa_stParams.paramsList["PinCtrl"].c_str()))) m_nPud = 2; if (initialise(m_nPin, m_nPud)) { int m_nVal = 1; // default to HIGH or 1 if ((!strcmp("LOW", pa_stParams.paramsList["InitVal"].c_str())) || (!strcmp("0", pa_stParams.paramsList["InitVal"].c_str()))) m_nVal = 0; #ifdef POSIX //before writing the initial value toggle once // as we don't know the intial value, toggle twice for(int i = 0; i < 2; i++){ writePin(m_nPin, 1); gpioDelay(500000); writePin(m_nPin, 0); gpioDelay(500000); } #endif writePin(m_nPin, m_nVal); } } } } }
// _____________________________________________________________________ // Cette callback permet d'effectuer une écriture sur le port lorsqu'une data "RaspiOut_GPIO_<i>" // est écrite. void CRaspiGPIO::onDataChangeWrite(QVariant state) { // récupère la data et par son nom, on connaitra le numéro de GPIO concerné CData* data = qobject_cast<CData*>(sender()); if (!data) return; bool ok; unsigned int gpio_num = data->getName().remove(PREFIX_RASPI_OUT_DATANAME).toInt(&ok); if (ok) { writePin(gpio_num, state.toBool()); } }
// _____________________________________________________________________ void CRaspiGPIO::onWritePinChange(bool state) { QCheckBox* checkbox = qobject_cast<QCheckBox*>(sender()); if( checkbox != NULL ) { QString objectName = checkbox->objectName(); bool ok; unsigned int gpio_num = objectName.remove(PREFIX_CHECKBOX_WRITE).toInt(&ok); if (ok) { writePin(gpio_num, state); } } }
void SX1509::digitalWrite(byte pin, byte highLow) { writePin(pin, highLow); }
void Display::switchDigit(uint8_t pin, bool state) { if(pin == DIG_3) writePin(&PORTD, pin, state); else writePin(&PORTB, pin, state); }