Created
August 20, 2017 00:01
-
-
Save patrick-samy/358fd2fe479c38b1d96daea601a4fb7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import smbus | |
bus = smbus.SMBus(1) | |
v = bus.read_byte_data(0x57, 0xff) | |
if v != 17: | |
print "wrong part ID" | |
exit(1) | |
bus.write_byte_data(0x57, 0x06, 0x03) | |
p = bus.read_byte_data(0x57, 0x07) | |
bus.write_byte_data(0x57, 0x07, (p & 0xfc) | 0x03) | |
p = bus.read_byte_data(0x57, 0x07) | |
bus.write_byte_data(0x57, 0x07, (p & 0xe3) | (0x01 << 2)) | |
bus.write_byte_data(0x57, 0x09, 0x0f << 4 | 0x0f) | |
p = bus.read_byte_data(0x57, 0x07) | |
bus.write_byte_data(0x57, 0x07, p | (1 << 6)) | |
alpha = 0.95 | |
dcw = 0.0 | |
lpf = [ 0.0, 0.0 ] | |
while True: | |
buffer = bus.read_i2c_block_data(0x57, 0x05, 4) | |
rawIRValue = (buffer[0] << 8) | buffer[1] | |
rawRedValue = (buffer[2] << 8) | buffer[3] | |
olddcw = dcw | |
dcw = rawIRValue + alpha * dcw | |
irACValue = dcw - olddcw | |
lpf[0] = lpf[1] | |
lpf[1] = (2.452372752527856026e-1 * (-irACValue)) + (0.50952544949442879485 * lpf[0]) | |
print (lpf[0] + lpf[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment