2013-03-18 18:57:51 -04:00
|
|
|
from miscope import miio
|
2013-09-21 07:04:07 -04:00
|
|
|
from miscope.com.uart2csr.host.uart2csr import *
|
|
|
|
|
|
|
|
from csr import *
|
2012-09-13 07:18:03 -04:00
|
|
|
|
|
|
|
#==============================================================================
|
|
|
|
# P A R A M E T E R S
|
|
|
|
#==============================================================================
|
|
|
|
|
2013-09-21 07:04:07 -04:00
|
|
|
uart = Uart2Csr(3, 115200)
|
|
|
|
|
|
|
|
class MiIoCtrl():
|
|
|
|
def __init__(self, bus):
|
|
|
|
self.bus = bus
|
|
|
|
|
|
|
|
def write(self, value):
|
|
|
|
miio_o_write(self.bus, value)
|
2012-09-16 05:49:16 -04:00
|
|
|
|
2013-09-21 07:04:07 -04:00
|
|
|
def read(self):
|
|
|
|
return miio_i_read(self.bus)
|
2012-09-13 07:18:03 -04:00
|
|
|
|
2013-09-21 07:04:07 -04:00
|
|
|
miio = MiIoCtrl(uart)
|
2012-09-13 07:18:03 -04:00
|
|
|
|
2012-09-16 05:49:16 -04:00
|
|
|
def led_anim0():
|
|
|
|
for i in range(10):
|
2013-09-21 07:04:07 -04:00
|
|
|
miio.write(0xA5)
|
2012-09-16 05:49:16 -04:00
|
|
|
time.sleep(0.1)
|
2013-09-21 07:04:07 -04:00
|
|
|
miio.write(0x5A)
|
2012-09-16 05:49:16 -04:00
|
|
|
time.sleep(0.1)
|
2012-09-13 07:18:03 -04:00
|
|
|
|
2012-09-16 05:49:16 -04:00
|
|
|
def led_anim1():
|
|
|
|
for j in range(4):
|
2013-03-18 18:57:51 -04:00
|
|
|
#Led <<
|
2012-09-16 05:49:16 -04:00
|
|
|
ledData = 1
|
|
|
|
for i in range(8):
|
2013-09-21 07:04:07 -04:00
|
|
|
miio.write(ledData)
|
2012-09-16 05:49:16 -04:00
|
|
|
time.sleep(i*i*0.0020)
|
|
|
|
ledData = (ledData<<1)
|
|
|
|
#Led >>
|
|
|
|
ledData = 128
|
|
|
|
for i in range(8):
|
2013-09-21 07:04:07 -04:00
|
|
|
miio.write(ledData)
|
2012-09-16 05:49:16 -04:00
|
|
|
time.sleep(i*i*0.0020)
|
|
|
|
ledData = (ledData>>1)
|
2012-09-13 07:18:03 -04:00
|
|
|
|
|
|
|
#==============================================================================
|
2013-09-21 07:04:07 -04:00
|
|
|
# T E S T M I I O
|
2012-09-13 07:18:03 -04:00
|
|
|
#==============================================================================
|
|
|
|
|
2013-03-22 07:35:12 -04:00
|
|
|
print("- Led Animation...")
|
2012-09-16 05:49:16 -04:00
|
|
|
led_anim0()
|
|
|
|
time.sleep(1)
|
|
|
|
led_anim1()
|
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
print("- Read Switch: ",end=' ')
|
2013-09-21 07:04:07 -04:00
|
|
|
print("%02X" %miio.read())
|