Skip to content

Commit

Permalink
Add the BufferedKnob experimental class to facilitate re-using prior …
Browse files Browse the repository at this point in the history
…ADC readings
  • Loading branch information
chrisib committed Mar 19, 2024
1 parent ac05257 commit 30da8f1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions software/firmware/experimental/knobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,23 @@ def build(self) -> "KnobBank":
@staticmethod
def builder(knob: Knob) -> Builder:
return KnobBank.Builder(knob)


class BufferedKnob(Knob):
"""A knob whose value remains fixed until .update(...) is called
This allows multiple uses of .percent(), .choice(...), etc... without forcing a re-read of
the ADC value
:param knob: The knob to wrap
"""

def __init__(self, knob):
super().__init__(knob.pin_id)
self.value = 0

def _sample_adc(self, samples=None):
return self.value

def update(self, samples=None):
self.value = super()._sample_adc(samples)

0 comments on commit 30da8f1

Please sign in to comment.