|
| 1 | +import odroid_wiringpi as wiringpi |
| 2 | + |
| 3 | +TIME_HIGH_LOCK = 275 |
| 4 | +TIME_LOW_LOCK1 = 9900 |
| 5 | +TIME_LOW_LOCK2 = 2675 |
| 6 | + |
| 7 | +TIME_HIGH_DATA = 275 # 310 or 275 or 220 |
| 8 | +TIME_LOW_DATA_LONG = 1225 # 1340 or 1225 or 1400 |
| 9 | +TIME_LOW_DATA_SHORT = 275 # 310 or 275 or 350 |
| 10 | + |
| 11 | +def sendBit(pin: int, b: bool): |
| 12 | + if b: |
| 13 | + wiringpi.digitalWrite(pin, wiringpi.HIGH) |
| 14 | + wiringpi.delayMicroseconds(TIME_HIGH_DATA) |
| 15 | + wiringpi.digitalWrite(pin, wiringpi.LOW) |
| 16 | + wiringpi.delayMicroseconds(TIME_LOW_DATA_LONG) |
| 17 | + else: |
| 18 | + wiringpi.digitalWrite(pin, wiringpi.HIGH) |
| 19 | + wiringpi.delayMicroseconds(TIME_HIGH_DATA) |
| 20 | + wiringpi.digitalWrite(pin, wiringpi.LOW) |
| 21 | + wiringpi.delayMicroseconds(TIME_LOW_DATA_SHORT) |
| 22 | + |
| 23 | +def sendPair(pin: int, b: bool): |
| 24 | + sendBit(pin, b) |
| 25 | + sendBit(pin, not b) |
| 26 | + |
| 27 | +def sendWord(pin: int, word: int, bits: int): |
| 28 | + for bit in reversed(range(bits)): |
| 29 | + if word & (1 << bit): |
| 30 | + sendPair(pin, True) |
| 31 | + else: |
| 32 | + sendPair(pin, False) |
| 33 | + |
| 34 | +def transmit(pin: int, sender: int, group: bool, button: int, onoff: bool): |
| 35 | + # Start lock |
| 36 | + wiringpi.digitalWrite(pin, wiringpi.HIGH); |
| 37 | + wiringpi.delayMicroseconds(TIME_HIGH_LOCK); |
| 38 | + wiringpi.digitalWrite(pin, wiringpi.LOW); |
| 39 | + wiringpi.delayMicroseconds(TIME_LOW_LOCK1); |
| 40 | + wiringpi.digitalWrite(pin, wiringpi.HIGH); |
| 41 | + wiringpi.delayMicroseconds(TIME_HIGH_LOCK); |
| 42 | + wiringpi.digitalWrite(pin, wiringpi.LOW); |
| 43 | + wiringpi.delayMicroseconds(TIME_LOW_LOCK2); |
| 44 | + wiringpi.digitalWrite(pin, wiringpi.HIGH); |
| 45 | + |
| 46 | + # Sender code (26 bits) |
| 47 | + sendWord(pin, sender, 26); |
| 48 | + |
| 49 | + # Group bit |
| 50 | + sendPair(pin, group); |
| 51 | + |
| 52 | + # On/off bit |
| 53 | + sendPair(pin, onoff); |
| 54 | + |
| 55 | + # Button number (4 bits) |
| 56 | + sendWord(pin, button, 4); |
| 57 | + |
| 58 | + # End lock |
| 59 | + wiringpi.digitalWrite(pin, wiringpi.HIGH); |
| 60 | + wiringpi.delayMicroseconds(TIME_HIGH_LOCK); |
| 61 | + wiringpi.digitalWrite(pin, wiringpi.LOW); |
| 62 | + |
| 63 | + # Delay before next transmission |
| 64 | + wiringpi.delay(10) |
0 commit comments