Skip to content

Commit

Permalink
Add rpm/compass blend mode, minor logic refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
slabua committed Mar 24, 2024
1 parent 9be32ba commit affc74c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
48 changes: 32 additions & 16 deletions OLED/picomotodash_neopx.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

MODE_RPM = 0
MODE_COMPASS = 1
MODE_BLEND = 2


class NEOPX:
Expand All @@ -29,42 +30,57 @@ def map_range(self, value, in_range, out_range):
(a, b), (c, d) = in_range, out_range
return (value - a) / (b - a) * (d - c) + c

def off(self):
for i in range(self.n):
self.np[i] = (0, 0, 0)
self.np.write()

def set_np(self, i, rgb_tuple):
self.np[i] = rgb_tuple
self.np.write()

def set_np_rpm(self, rpm):
self.off()

upto = rpm // 1000
for i in range(24, self.n):
if i < upto + 24:
self.np[i] = (2, 2, 0)
else:
self.np[i] = (0, 0, 0)
for i in range(24, upto + 24):
self.np[i] = (2, 2, 0)

self.np.write()

def set_np_compass(self, heading):
# PLACEHOLDER
# TODO Update logic
for i in range(24, self.n):
self.np[i] = (0, 0, 0)

self.off()

i = int(self.map_range(heading, (0, 360), (34, 24)))
self.np[i] = (0, 0, 5)

self.np.write()

def set_np_blend(self, rpm, heading):
# TODO Update logic

self.off()

upto = rpm // 1000
for i in range(24, upto + 24):
self.np[i] = (2, 2, 0)

i = int(self.map_range(heading, (0, 360), (34, 24)))
self.np[i] = (0, 0, 5)

self.np.write()

def update(self, value):
def update(self, rpm, heading):
# TODO Update logic

if self.mode == MODE_RPM:
self.set_np_rpm(value)
self.set_np_rpm(rpm)
elif self.mode == MODE_COMPASS:
self.set_np_compass(value)

def off(self):
for i in range(self.n):
self.np[i] = (0, 0, 0)
self.np.write()
self.set_np_compass(heading)
elif self.mode == MODE_BLEND:
self.set_np_blend(rpm, heading)

def __enter__(self):
return self
Expand Down
2 changes: 1 addition & 1 deletion OLED/picomotodash_oled_ws10d.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def thread1(PWM2RPM_FACTOR):
HEADING = mpu.heading
HEADING = moving_avg(5) # 9

# neopixel_ring.update(HEADING)
# neopixel_ring.update(RPM_ESTIMATE, HEADING)

# print(key0.value(), key1.value())

Expand Down

0 comments on commit affc74c

Please sign in to comment.