|
| 1 | +Rotary |
| 2 | +====== |
| 3 | + |
| 4 | +.. include:: ../refs/hardware.rotary.ref |
| 5 | + |
| 6 | + |
| 7 | +Rotary is used to control the rotary encoder integrated inside the host. Below |
| 8 | +is the detailed Rotary support for the host: |
| 9 | + |
| 10 | +.. table:: |
| 11 | + :widths: auto |
| 12 | + :align: center |
| 13 | + |
| 14 | + +-----------------+--------+ |
| 15 | + | Controller | Rotary | |
| 16 | + +=================+========+ |
| 17 | + | Dial | |S| | |
| 18 | + +-----------------+--------+ |
| 19 | + | DinMeter | |S| | |
| 20 | + +-----------------+--------+ |
| 21 | + |
| 22 | +.. |S| unicode:: U+2714 |
| 23 | + |
| 24 | + |
| 25 | +Micropython Example:: |
| 26 | + |
| 27 | + import os, sys, io |
| 28 | + import M5 |
| 29 | + from M5 import * |
| 30 | + from hardware import * |
| 31 | + |
| 32 | + label0 = None |
| 33 | + rotary = None |
| 34 | + |
| 35 | + def btnA_wasClicked_event(state): |
| 36 | + global label0, rotary |
| 37 | + rotary.reset_rotary_value() |
| 38 | + label0.setText(str(rotary.get_rotary_value())) |
| 39 | + |
| 40 | + def setup(): |
| 41 | + global label0, rotary |
| 42 | + |
| 43 | + M5.begin() |
| 44 | + Widgets.fillScreen(0x222222) |
| 45 | + label0 = Widgets.Label("0", 96, 80, 1.0, 0xffa000, 0x222222, Widgets.FONTS.DejaVu72) |
| 46 | + |
| 47 | + BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btnA_wasClicked_event) |
| 48 | + |
| 49 | + rotary = Rotary() |
| 50 | + |
| 51 | + def loop(): |
| 52 | + global label0, rotary |
| 53 | + M5.update() |
| 54 | + if rotary.get_rotary_status(): |
| 55 | + label0.setText(str(rotary.get_rotary_value())) |
| 56 | + |
| 57 | + if __name__ == '__main__': |
| 58 | + try: |
| 59 | + setup() |
| 60 | + while True: |
| 61 | + loop() |
| 62 | + except (Exception, KeyboardInterrupt) as e: |
| 63 | + try: |
| 64 | + from utility import print_error_msg |
| 65 | + print_error_msg(e) |
| 66 | + except ImportError: |
| 67 | + print("please update to latest firmware") |
| 68 | + |
| 69 | + |
| 70 | +UIFLOW2 Example: |
| 71 | + |
| 72 | + |example.svg| |
| 73 | + |
| 74 | + |
| 75 | +class Rotary |
| 76 | +------------ |
| 77 | + |
| 78 | +Constructors |
| 79 | +------------ |
| 80 | + |
| 81 | +.. class:: Rotary() |
| 82 | + |
| 83 | + Creates a Rotary object. |
| 84 | + |
| 85 | + UIFLOW2: |
| 86 | + |
| 87 | + |init.svg| |
| 88 | + |
| 89 | +Methods |
| 90 | +------- |
| 91 | + |
| 92 | +.. method:: Rotary.get_rotary_status() -> bool |
| 93 | + |
| 94 | + Gets the rotation status of the Rotary object. |
| 95 | + |
| 96 | + UIFLOW2: |
| 97 | + |
| 98 | + |get_rotary_status.svg| |
| 99 | + |
| 100 | + |
| 101 | +.. method:: Rotary.get_rotary_value() -> int |
| 102 | + |
| 103 | + .. note:: Cannot be used simultaneously with :meth:`Rotary.get_rotary_increments()`. |
| 104 | + |
| 105 | + Gets the rotation value of the Rotary object. |
| 106 | + |
| 107 | + UIFLOW2: |
| 108 | + |
| 109 | + |get_rotary_value.svg| |
| 110 | + |
| 111 | + |
| 112 | +.. method:: Rotary.get_rotary_increments() -> int |
| 113 | + |
| 114 | + .. note:: Cannot be used simultaneously with :meth:`Rotary.get_rotary_increments()`. |
| 115 | + |
| 116 | + Gets the rotation value of the Rotary object. |
| 117 | + |
| 118 | + UIFLOW2: |
| 119 | + |
| 120 | + |get_rotary_increments.svg| |
| 121 | + |
| 122 | + |
| 123 | +.. method:: Rotary.reset_rotary_value() -> None |
| 124 | + |
| 125 | + Resets the rotation value of the Rotary object. |
| 126 | + |
| 127 | + UIFLOW2: |
| 128 | + |
| 129 | + |reset_rotary_value.svg| |
| 130 | + |
| 131 | + |
| 132 | +.. method:: Rotary.set_rotary_value() -> None |
| 133 | + |
| 134 | + Sets the rotation value of the Rotary object. |
| 135 | + |
| 136 | + UIFLOW2: |
| 137 | + |
| 138 | + |set_rotary_value.svg| |
0 commit comments