Skip to content

Commit

Permalink
fix gyro parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kanzure committed Feb 24, 2013
1 parent dbeec54 commit b023a3c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions python/emokit/emotiv.py
Expand Up @@ -161,10 +161,13 @@ def __init__(self, data, sensors):
g_battery = self.battery_percent()
self.counter = 128
self.sync = self.counter == 0xe9
self.gyroX = ord(data[29]) - 106
self.gyroY = ord(data[30]) - 105

# the RESERVED byte stores the least significant 4 bits for gyroX and gyroY
self.gyroX = ((ord(data[29]) << 4) | (ord(data[31]) >> 4))
self.gyroY = ((ord(data[30]) << 4) | (ord(data[31]) & 0xFF))

This comment has been minimized.

Copy link
@nh2

nh2 May 8, 2013

0xFF? The whole byte?

This comment has been minimized.

Copy link
@kanzure

kanzure May 8, 2013

Author Member

According to my disassembly notes, yes. I don't have a device, so I can't confirm. I am pretty sure it's right. However, the previous implementation is confirmed-wrong.

This comment has been minimized.

Copy link
@nh2

nh2 May 8, 2013

What I mean is: ord(data[31]) >> 4 means the the top 4 bits in the byte are the 4 low bits of gyroX we are looking for: XXXX____.

I'd expect the low bits of gyroY then to be ____XXXX, so & 0x0F?!

This comment has been minimized.

Copy link
@nh2

nh2 May 8, 2013

Hey, I verified this plotting gyroY via feedgnuplot. It has to be & 0x0F.

sensors['X']['value'] = self.gyroX
sensors['Y']['value'] = self.gyroY

for name, bits in sensorBits.items():
value = self.get_level(self.rawData, bits)
setattr(self, name, (value,))
Expand Down

0 comments on commit b023a3c

Please sign in to comment.