Skip to content
Snippets Groups Projects

Add w1f1 app & replace wifi in settings menu

Merged ave requested to merge ave/flow3r-firmware:add-wifi-app into main
5 unresolved threads
2 files
+ 115
90
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -33,7 +33,9 @@ class TextInputModel(Model):
LEFT = -1
RIGHT = 1
def __init__(self, input_left: str = '', input_right: str = '', input_candidate: str = '') -> None:
def __init__(
self, input_left: str = "", input_right: str = "", input_candidate: str = ""
) -> None:
super().__init__()
self._input_left = input_left
@@ -74,7 +76,7 @@ class TextInputModel(Model):
Adds an input character at the current cursor position.
"""
self._input_left += char
self.input_candidate = ''
self.input_candidate = ""
def delete_input_character(self) -> None:
"""
@@ -82,10 +84,10 @@ class TextInputModel(Model):
If an input candidate is pending, it will be removed instead.
"""
if self.input_candidate == '':
if self.input_candidate == "":
self._input_left = self._input_left[:-1]
self.input_candidate = ''
self.input_candidate = ""
def commit_input(self) -> None:
"""
@@ -99,7 +101,9 @@ class TextInputFieldView(Responder):
Displays the current text input and cursor of a keyboard.
"""
def __init__(self, model: TextInputModel, cursor_blink_duration_ms: float = 500) -> None:
def __init__(
self, model: TextInputModel, cursor_blink_duration_ms: float = 500
) -> None:
super().__init__()
self._model = model
@@ -130,15 +134,23 @@ class TextInputFieldView(Responder):
ctx.gray(0.2).rectangle(
-1.0 - cursor_offset - input_candidate_width - left_input_width,
ctx.font_size / 2.4,
left_input_width + input_candidate_width + right_input_width + 2 * cursor_offset + 2 * 1.0,
2
left_input_width
+ input_candidate_width
+ right_input_width
+ 2 * cursor_offset
+ 2 * 1.0,
2,
).fill()
ctx.text_align = ctx.END
ctx.gray(1.0).move_to(-cursor_offset - input_candidate_width, 0).text(self._model.input_left)
ctx.gray(1.0).move_to(-cursor_offset - input_candidate_width, 0).text(
self._model.input_left
)
ctx.text_align = ctx.END
ctx.rgb(0.0, 0.2, 1.0).move_to(-cursor_offset, 0).text(self._model.input_candidate)
ctx.rgb(0.0, 0.2, 1.0).move_to(-cursor_offset, 0).text(
self._model.input_candidate
)
ctx.text_align = ctx.START
ctx.gray(1.0).move_to(cursor_offset, 0).text(self._model.input_right)
@@ -154,7 +166,9 @@ class TextInputFieldView(Responder):
ctx.close_path()
def think(self, ins: InputState, delta_ms: int) -> None:
self._cursor_timer_ms = (self._cursor_timer_ms + delta_ms) % (2 * self._cursor_blink_duration_ms)
self._cursor_timer_ms = (self._cursor_timer_ms + delta_ms) % (
2 * self._cursor_blink_duration_ms
)
class InputControlsModel(Model):
@@ -169,10 +183,10 @@ class InputControlsModel(Model):
"""
def __init__(
self,
input_groups: list[list[str]],
control_groups: list[list[str]],
active_input_group: int = 0,
self,
input_groups: list[list[str]],
control_groups: list[list[str]],
active_input_group: int = 0,
) -> None:
super().__init__()
@@ -249,7 +263,7 @@ class InputControlsView(Responder):
ctx.font_size = 18.0
ctx.gray(0.6)
ctx.font = 'Material Icons'
ctx.font = "Material Icons"
angle_offset = tau / 5.0 / 10
angle = (group + 0.5) * tau / 5.0 - angle_offset * (len(controls) - 1) / 2.0
@@ -318,65 +332,68 @@ class KeyboardView(BaseView):
self._text_input_model = model
self._text_input_view = TextInputFieldView(self._text_input_model)
self._input_controls_model = InputControlsModel([
[
'fghij',
'klmno',
'uvwxyz',
'pqrst',
'abcde',
],
[
'FGHIJ',
'KLMNO',
'UVWXYZ',
'PQRST',
'ABCDE',
],
[
'34',
'56',
'90',
'78',
'12',
],
[
'.,!?:;',
'\'"@#~',
'%$&<>\\',
'+-*/=',
'()[]{}',
],
], [
[
'\ue9ef', # Special characters
'\ue14a', # Backspace
'\ue256', # Space
'\ue5ce', # Shift
'\ue400', # Num
],
[
'\ue9ef', # Special characters
'\ue14a', # Backspace
'\ue256', # Space
'\ue5cf', # Shift active
'\ue400', # Num
],
self._input_controls_model = InputControlsModel(
[
'\ue9ef', # Special characters
'\ue14a', # Backspace
'\ue256', # Space
'\ue264', # Text
'',
[
"fghij",
"klmno",
"uvwxyz",
"pqrst",
"abcde",
],
[
"FGHIJ",
"KLMNO",
"UVWXYZ",
"PQRST",
"ABCDE",
],
[
"34",
"56",
"90",
"78",
"12",
],
[
".,!?:;",
"'\"@#~",
"%$&<>\\",
"+-*/=",
"()[]{}",
],
],
[
'',
'\ue14a', # Backspace
'\ue256', # Space
'\ue264', # Text
'\ue400', # Num
[
"\ue9ef", # Special characters
"\ue14a", # Backspace
"\ue256", # Space
"\ue5ce", # Shift
"\ue400", # Num
],
[
"\ue9ef", # Special characters
"\ue14a", # Backspace
"\ue256", # Space
"\ue5cf", # Shift active
"\ue400", # Num
],
[
"\ue9ef", # Special characters
"\ue14a", # Backspace
"\ue256", # Space
"\ue264", # Text
"",
],
[
"",
"\ue14a", # Backspace
"\ue256", # Space
"\ue264", # Text
"\ue400", # Num
],
],
])
)
self._input_controls_view = InputControlsView(self._input_controls_model)
def on_enter(self, vm: Optional[ViewManager]) -> None:
@@ -400,7 +417,7 @@ class KeyboardView(BaseView):
self._time_since_last_input_group_press = 0
self._last_input_group_press = -1
self._last_input_group_character = -1
self._text_input_model.input_candidate = ''
self._text_input_model.input_candidate = ""
def add_input_character(self, char: str) -> None:
self._text_input_model.commit_input()
@@ -434,20 +451,23 @@ class KeyboardView(BaseView):
self._text_input_model.move_cursor(TextInputModel.CursorDirection.RIGHT)
def handle_control_inputs(self) -> None:
if self.input.captouch.petals[self.ControlPetal.SPECIAL_CHARACTERS].whole.pressed:
if self.input.captouch.petals[
self.ControlPetal.SPECIAL_CHARACTERS
].whole.pressed:
self.select_input_group(self.InputControlGroup.SPECIAL_CHARACTERS)
if self.input.captouch.petals[self.ControlPetal.BACKSPACE].whole.pressed:
self.delete_input_character()
if self.input.captouch.petals[self.ControlPetal.SPACE].whole.pressed:
self.add_input_character(' ')
self.add_input_character(" ")
if self.input.captouch.petals[self.ControlPetal.CAPSLOCK].whole.pressed:
self.select_input_group(
self.InputControlGroup.UPPERCASE_LETTERS \
if self._input_controls_model.active_input_control_group == self.InputControlGroup.LOWERCASE_LETTERS \
else self.InputControlGroup.LOWERCASE_LETTERS
self.InputControlGroup.UPPERCASE_LETTERS
if self._input_controls_model.active_input_control_group
== self.InputControlGroup.LOWERCASE_LETTERS
else self.InputControlGroup.LOWERCASE_LETTERS
)
if self.input.captouch.petals[self.ControlPetal.NUMLOCK].whole.pressed:
@@ -456,22 +476,32 @@ class KeyboardView(BaseView):
def handle_input_groups(self, delta_ms: int) -> bool:
for i in range(0, 5):
if self.input.captouch.petals[i * 2].whole.pressed:
if self._last_input_group_press >= 0 and self._last_input_group_press != i:
if (
self._last_input_group_press >= 0
and self._last_input_group_press != i
):
self.commit_input()
self._last_input_group_press = i
self._last_input_group_character = \
(self._last_input_group_character + 1) % len(self._input_controls_model.active_input_groups)
self._last_input_group_character = (
self._last_input_group_character + 1
) % len(self._input_controls_model.active_input_groups)
self._time_since_last_input_group_press = 0
self._text_input_model.input_candidate = \
self._input_controls_model.active_input_groups[i][self._last_input_group_character]
self._text_input_model.input_candidate = (
self._input_controls_model.active_input_groups[i][
self._last_input_group_character
]
)
return
self._time_since_last_input_group_press += delta_ms
if self._last_input_group_press >= 0 and self._time_since_last_input_group_press > self._input_group_timeout:
if (
self._last_input_group_press >= 0
and self._time_since_last_input_group_press > self._input_group_timeout
):
self.commit_input()
def think(self, ins: InputState, delta_ms: int) -> None:
@@ -488,7 +518,7 @@ class KeyboardDemoApp(Application):
def __init__(self, app_ctx: ApplicationContext) -> None:
super().__init__(app_ctx)
self._model = TextInputModel('Hello world!')
self._model = TextInputModel("Hello world!")
def draw(self, ctx: Context) -> None:
ctx.gray(0).rectangle(-120, -120, 240, 240).fill()
@@ -515,5 +545,5 @@ class KeyboardDemoApp(Application):
self.vm.push(KeyboardView(self._model))
if __name__ == '__main__':
if __name__ == "__main__":
st3m.run.run_view(KeyboardDemoApp(ApplicationContext()))
Loading