Added implementation of previous_selection and next_selection handlers

This commit is contained in:
BlueFox 2024-10-31 21:03:48 +00:00
parent a9dd13a1cc
commit 76cd7afa8b

View File

@ -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 <https://www.gnu.org/licenses/>.
"""
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