int main(int argc, char **argv) { setShowLogs(1); DomoDevice dev = attachDomoDevice ("DomoSy-Arduino-5141-9267"); DomoDevice dev2 = attachDomoDevice ("DomoSy-Arduino-1633-3668"); if (dev.fd != -1 && dev2.fd != -1 ) { setPinModeAsOutput (&dev, 22); setPinModeAsOutput (&dev, 23); setPinModeAsInput (&dev2, 22); setPinModeAsOutput (&dev2, 23); int i = 0; /*for (i = 0; i < 5; i ++) { setPinHigh (&dev, 23); setPinLow (&dev2, 23); sleep(2); setPinHigh (&dev2, 23); setPinLow (&dev, 23); sleep(2); }*/ setPinHigh (&dev, 23); sleep(2); setPinHigh (&dev, 22); setPinLow (&dev, 23); printf("Pin status=%d\n", getPinStatus(&dev2, 22)); if (getPinStatus(&dev2, 22)==1) setPinHigh (&dev2, 23); sleep(2); setPinLow (&dev, 23); detachDomoDevice (&dev); detachDomoDevice (&dev2); } else { printf("Can not open UUGear device.\n"); } //cleanupDomo(); return 0; }
int main(int argc, char **argv) { setShowLogs(1); DomoDevice dev = attachDomoDevice ("DomoSy-Arduino-1633-3668"); if (dev.fd != -1 ) { setMasterButton(&dev, pinMap[12]); setPinAsButton(&dev, pinMap[12]); char* response; int errorcode; response=waitForStringBlock(&dev, &errorcode); if (atoi(response)==pinMap[12]) { setPinModeAsOutput (&dev, pinMap[13]); // for debug sleep(1); setPinHigh (&dev, pinMap[13]); usleep(0.5*1000*1000); setPinLow (&dev, pinMap[13]); } } else { printf("Can not open device.\n"); } detachDomoDevice (&dev); return 0; }
// This function actually sends power to the specified pin in morse code form static void soundAlarm(int * code, int pin){ for(int i = 0; i < code.length(); i++){ if(getCarState() == ALARMING){ switch(code[i]){ case MORSE_DOT: case MORSE_DASH: setPinHigh(pin, "HIGH"); break; case MORSE_PAUSE: case MORSE_LETTER_SPACE: case MORSE_WORD_SPACE: default: setPin(pin, "LOW"); break; } } } setPinLow(pin, "LOW"); // return to natural state (TODO: What if natural state is high) }
void writeData(uint8_t cmd, uint16_t address, uint8_t data){ setPinHigh(CLK_PIN); setPinLow(CLK_PIN); setPinToInput(IO_PIN); int i=31; uint8_t bData; int Tcmd = cmd << 24 ; int Taddr = address << 8; uint32_t fullData = Tcmd + Taddr + data; printf("%x\n", fullData); while(i!=0){ bData = fullData >> i & 0x00000001; if (bData == 0x00000000) sendBitLow(IO_PIN); else sendBitHigh(IO_PIN); printf("%x", bData); i--; } }
uint8_t readData(uint8_t cmd, uint16_t address){ setPinLow(CLK_PIN); setPinHigh(CLK_PIN); setPinToInput(IO_PIN); writeTurnaroundIO(IO_PIN); int i = 23; uint32_t Tcmd, fullData, bData; Tcmd = cmd << 16; fullData = Tcmd + address; printf("%x\n", fullData); while(i!=0){ bData = fullData >> i & 0x00000001; if (bData == 0x00000000) sendBitLow(IO_PIN); else sendBitHigh(IO_PIN); printf("%x", bData); i--; } readTurnaroundIO(IO_PIN); return readBit(IO_PIN); }
/* *@brief Perform write-to-read turnaround *@param pinNo is the pin to do turnaround *@steps 1) set IO pin as output * 2) set CLK pin high * 3) set CLK pin low */ void writeTurnaroundIO(int pinNo){ setPinToOutput(pinNo); setPinHigh(CLK_PIN); setPinLow(CLK_PIN); }
/* *@brief Perform write-to-read turnaround *@param pinNo is the pin to do turnaround *@steps 1) set IO pin as input * 2) set CLK pin low * 3) set CLK pin high */ void readTurnaroundIO(int pinNo){ setPinToInput(IO_PIN); setPinLow(CLK_PIN); setPinHigh(CLK_PIN); }
void sendBitHigh(int pinNo){ setPinLow(CLK_PIN); setPinHigh(CLK_PIN); setPinHigh(IO_PIN); setPinToInput(pinNo); }
uint32_t readBit(int pinNo){ setPinHigh(CLK_PIN); setPinLow(CLK_PIN); return readPin(pinNo); }