Skip to content

Commit

Permalink
bug fixes, update fw version
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyWu98 committed Oct 16, 2023
1 parent 8494325 commit d09675d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
Binary file modified APP/binaries/firmware.uf2
Binary file not shown.
23 changes: 21 additions & 2 deletions APP/firmware_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

BUFFER_SIZE = 128 * 1024

CURR_FW_VERSION = 2

class SameFileError(OSError):
"""Raised when source and destination are the same file."""

Expand Down Expand Up @@ -245,21 +247,38 @@ def enable_update(self):
def set_stop_listener_callback(self, callback):
self.stop_listener_callback = callback

def check_version(self, version):
if version < CURR_FW_VERSION:
if messagebox.askokcancel("Firmware Update", f"Current Firmware version is {version}, update to version {CURR_FW_VERSION} (latest)?"):
return True
elif version == CURR_FW_VERSION:
if messagebox.askokcancel("Firmware Update", f"Current Firmware version {version} is already latest, update anyway?"):
return True
else:
if messagebox.askokcancel("Firmware Update", f"Current Firmware version is future version {version} not supported by this version of fluxapp, downgrade to version {CURR_FW_VERSION}?"):
return True
return False

def upload_firmware_callback(self):
try:
self.stop_listener_callback()
assert self.fluxpad is not None
self.fluxpad.open()
version = self.fluxpad.get_version()
self.fluxpad.close()

if not self.check_version(version):
return

progress = upload_firmware_threaded(self.fluxpad.port, self.fw_bin_path)
while progress.update_event.wait(timeout=10):
print("waited")
with progress.lock:
self.label_progress.configure(text=progress.current_step)
self.progressbar_update.configure(value=progress.progress_percent)
progress.update_event.clear()
self.progressbar_update.update()
self.label_progress.update()
if progress.is_done:
print("isdone")
break
if progress.error_string:
raise Exception(progress.error_string)
Expand Down
14 changes: 13 additions & 1 deletion APP/fluxapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,17 @@ def on_save_to_fluxpad(self):
else:
messagebox.showinfo("Saved settings", "Saved settings to FLUXPAD")


def is_windows_11():
version_info = platform.uname()
if version_info.system == 'Windows' and version_info.release == '10':
# Check for Windows 11 specific version number (10.0.22000 and above)
windows_version = version_info.version.split('.')
if len(windows_version) >= 3 and int(windows_version[2]) >= 22000:
return True
return False


if __name__ == "__main__":

logging.basicConfig(level=logging.DEBUG)
Expand All @@ -1555,7 +1566,8 @@ def on_save_to_fluxpad(self):
use_sv_ttk.set_theme("light")

WIDTH = 500
if platform.system() == "Windows" and platform.release() == "11":
if is_windows_11():
# For some reason windows 11 windows are bigger
HEIGHT = 660
else:
HEIGHT = 620
Expand Down
24 changes: 23 additions & 1 deletion APP/fluxpad_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def find_fluxpad_port():
class CommandType(enum.Enum):
WRITE = "w"
READ = "r"
VERSION = "v"


class LightingMode(enum.IntEnum):
Expand All @@ -41,6 +42,7 @@ class RGBMode(enum.IntEnum):

class MessageKey:
COMMAND = "cmd"
VERSION = "V"
TOKEN = "tkn"
KEY_ID = "key"
KEY_TYPE = "k_t"
Expand Down Expand Up @@ -534,11 +536,23 @@ def height_mm(self, dummy: int):
"""Dummy function for read cmd, doesn't actually set height_mm"""
self.data[MessageKey.HEIGHT] = 0

class VersionReadMessage(BaseMessage):

# VERSION
@property
def version(self):
return self.data[MessageKey.VERSION]

@version.setter
def version(self, version: int):
self._assert_uint8(version)
self.data[MessageKey.VERSION] = version

# class KeySettingMessage(DigitalSettingsMessage, AnalogSettingsMessage, EncoderSettingsMessage, AnalogCalibrationMessage, AnalogReadMessage):
# """Composite class of all settings types"""
# pass

AnyMessage = TypeVar("AnyMessage", DigitalSettingsMessage, AnalogSettingsMessage, EncoderSettingsMessage, AnalogCalibrationMessage, AnalogReadMessage, RGBSettingsMessage, Union[DigitalSettingsMessage, AnalogSettingsMessage, EncoderSettingsMessage, AnalogCalibrationMessage, AnalogReadMessage, RGBSettingsMessage])
AnyMessage = TypeVar("AnyMessage", DigitalSettingsMessage, AnalogSettingsMessage, EncoderSettingsMessage, AnalogCalibrationMessage, AnalogReadMessage, RGBSettingsMessage, VersionReadMessage, Union[DigitalSettingsMessage, AnalogSettingsMessage, EncoderSettingsMessage, AnalogCalibrationMessage, AnalogReadMessage, RGBSettingsMessage])


class Fluxpad:
Expand Down Expand Up @@ -603,6 +617,11 @@ def send_read_request(self, message: AnyMessage) -> AnyMessage:

message.command = CommandType.READ
return self._send_request(message)

def get_version(self) -> int:
message = VersionReadMessage()
message.command = CommandType.VERSION
return self._send_request(message).version


class FluxpadListener():
Expand Down Expand Up @@ -737,6 +756,9 @@ def _set_key_ids(self):
key_settings.key_id = key_id
key_id += 1

def get_version(self, fluxpad: Fluxpad):
return fluxpad.get_version()

def load_from_keypad(self, fluxpad: Fluxpad):
"""Load all settings from the given connected fluxpad"""

Expand Down
2 changes: 1 addition & 1 deletion FW/fluxpad_rp2040_pio/src/flux_arduino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#define HZ_TO_PERIOD_US(x) (1000000 / (x))

#define VERSION 1
#define VERSION 2

// PIN DEFINITIONS
constexpr uint32_t ENC_A_PIN = 23u;
Expand Down

0 comments on commit d09675d

Please sign in to comment.