Skip to content

Commit

Permalink
Remove 'medium' pulsation
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcooper committed Jul 28, 2024
1 parent 2f5fff0 commit 4b74c16
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 28 deletions.
10 changes: 5 additions & 5 deletions client/src/main/player/Buttons.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
let ledState
$: if (playDisabled) {
ledState = 0
ledState = 0 // LED_OFF
} else if (isPaused) {
ledState = 2
ledState = 2 // LED_FLASH
} else if (overdue) {
ledState = 5
ledState = 4 // LED_PULSATE_FAST
} else if (overtime) {
ledState = 3
ledState = 3 // LED_PULSATE_SLOW
} else {
ledState = 1
ledState = 1 // LED_ON
}
$: setLED(ledState)
Expand Down
11 changes: 4 additions & 7 deletions controller/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@

config = Config()
BOOT_TIME = time.monotonic()
PULSATE_PERIODS = {
c.LED_PULSATE_SLOW: config.pulsate_period_slow,
c.LED_PULSATE_MEDIUM: config.pulsate_period_medium,
c.LED_PULSATE_FAST: config.pulsate_period_fast,
}
SHOULD_DEBUG_PRINT = config.debug or config.serial
SHOULD_DEBUG_SEND_MIDI_MESSAGE = config.debug_messages_over_midi

Expand Down Expand Up @@ -54,8 +49,10 @@ def on_led_change(self, num):
led.solid(num == c.LED_ON)
elif num == c.LED_FLASH:
led.pulsate(period=config.flash_period, flash=True)
elif num in PULSATE_PERIODS:
led.pulsate(period=PULSATE_PERIODS[num])
elif num == c.LED_PULSATE_SLOW:
led.pulsate(period=config.pulsate_period_slow)
elif num == c.LED_PULSATE_FAST:
led.pulsate(period=config.pulsate_period_fast)
else:
debug(f"WARNING: Invalid LED control msg: {num}")
self.send_obj("error", f"Invalid MIDI control number {num}")
Expand Down
3 changes: 1 addition & 2 deletions controller/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
# In seconds
flash_period = 1.0
pulsate_period_slow = 2.25
pulsate_period_medium = 1.25
pulsate_period_fast = 0.6
"""

Expand All @@ -66,7 +65,7 @@ class Config:
pwm_frequency: int
flash_period: float
pulsate_period_slow: float
pulsate_period_medium: float

pulsate_period_fast: float

def __init__(self, *, from_boot=False):
Expand Down
5 changes: 2 additions & 3 deletions controller/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# General
VERSION = "v0.3.24"
VERSION = "v0.3.25"
PRODUCT_NAME = "Tomato Button Box"

# Kindly assigned by pid.codes (https://pid.codes/1209/7111/)
Expand All @@ -17,8 +17,7 @@
LED_ON = 1
LED_FLASH = 2
LED_PULSATE_SLOW = 3
LED_PULSATE_MEDIUM = 4
LED_PULSATE_FAST = LED_RANGE_MAX = 5
LED_PULSATE_FAST = LED_RANGE_MAX = 4

# System Exclusive
SYSEX_NON_COMMERCIAL = 0x7D # Non-commercial sysex prefix
Expand Down
9 changes: 3 additions & 6 deletions controller/test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,11 @@ <h1>Tomato MIDI Controller Tester</h1>
<button @click="led(0, 'off')">OFF</button>
<button @click="led(1, 'on')">ON</button>
<button @click="led(2, 'flash')">Flash</button>
<button @click="led(3, 'pulsate slow')">Pulse/slow</button>
<button @click="led(4, 'pulsate fast')">Pulse/fast</button>
<button @click="led(5, 'invalid')">Invalid</button>
<button @click="invalidMidiMsg()">Invalid MIDI</button>
<br>
<strong>Pulse:</strong>
<button @click="led(3, 'pulsate slow')">Slow</button>
<button @click="led(4, 'pulsate medium')">Medium</button>
<button @click="led(5, 'pulsate fast')">Fast</button>
<button @click="led(6, 'invalid')">Invalid</button>
<br>
<strong>Simulate Button Press:</strong>
<button @click="sysex('simulate/press')">Press</button>
<button @click="sysex('simulate/release')">Release</button>
Expand Down
10 changes: 5 additions & 5 deletions controller/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ def update(self):
current_time = time.monotonic()
elapsed = (current_time - self._pulsate_started) % self._period
half_period = self._period / 2
fading_in = elapsed < half_period
fading_out = elapsed < half_period

if self._flash_while_pulsating:
duty = 0xFFFF if fading_in else 0x0000
duty = 0xFFFF if fading_out else 0x0000
else:
if fading_in:
duty = int(self._min_duty + self._duty_delta * (elapsed / half_period))
if fading_out:
duty = 0xFFFF - int(self._min_duty + self._duty_delta * (elapsed / half_period))
else:
duty = int(self._max_duty - self._duty_delta * ((elapsed - half_period) / half_period))
duty = 0xFFFF - int(self._max_duty - self._duty_delta * ((elapsed - half_period) / half_period))
self._pwm.duty_cycle = duty


Expand Down

0 comments on commit 4b74c16

Please sign in to comment.