ui_utils – use the buttons and LEDs on your CB2 as a primitive UI

With no screen and no keypad, we have to make do with the buttons and LEDs.

The ui_utils module gives you the ability to enter data at program run-time. This can reduce the number of times you have to edit and re-download your program. This is especially handy if you are running your CodeBot untethered.

ui_utils.UI_BUTTON_NONE

value used to represent NO BUTTON is pressed

Type

int

ui_utils.UI_BUTTON_0

value used to represent BTN-0 is pressed

Type

int

ui_utils.UI_BUTTON_1

value used to represent BTN-1 is pressed

Type

int

ui_utils.UI_BUTTON_BOTH

value used to represent BOTH buttons are pressed

Type

int

Treating “both buttons are pressed” as a special case gives us a virtual 3rd button.

ui_utils.get_button()[source]

Returns which button is currently pressed, as one of the UI_BUTTON_xxx codes.

ui_utils.tweak_parameter(initial_value)[source]

Allows a value to be adjusted, or kept as-is:

Press BTN-1 to raise the value.

Press BTN-0 to lower the value.

Press BOTH buttons at the same time to lock-in your choice.

Flashes the final value on the LEDs so you can tell what you entered.

Parameters

initial_value (int) – the value to start at.

ui_utils.wait_for_button(requested_ui_button)[source]

Wait until the specified button is pressed.

Parameters

requested_ui_button (int) – the UI_BUTTON_XXX combination to wait for

Download Source