diff --git a/__init__.py b/__init__.py index 078fe96..5b26d34 100644 --- a/__init__.py +++ b/__init__.py @@ -9,6 +9,7 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY You should have received a copy of the GNU General Public License along with this program. If not, see . """ + class lcdMenu: # lcd: I2C_LCD - an object of the I2C_LCD class (https://git.privacynerd.de/BlueFox/micropython-libraries/src/branch/main/PCF8574T) # buttons: dict - a dictionary with machine.Pin objects as items with following keys @@ -49,10 +50,29 @@ class lcdMenu: pass + def previous_selection(self): + self.current_selection -= 1 + if self.current_selection < 0: # after the last element: + if self.cycle: # if cycling is enabled, set it to the index of the last element + self.current_selection = len(self.menu_items)-1 + else: # else, go to first element + self.current_selection = 0 + + + def next_selection(self): + self.current_selection += 1 + if self.current_selection >= len(self.menu_items): # after the last element: + if self.cycle: # if cycling is enabled, go to first element + self.current_selection = 0 + else: # else, set it to the index of the last element + self.current_selection = len(self.menu_items)-1 + + def execute_selection(self): self.menu_items[self.current_selection][1]() def run(self): # TODO: add btn handlers and the actual process + pass