|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | + |
| 4 | +# SPDX-FileCopyrightText: Copyright (c) 2021 Stefan Krüger s-light |
| 5 | +# |
| 6 | +# SPDX-License-Identifier: Unlicense |
| 7 | + |
| 8 | +"""Development things,""" |
| 9 | + |
| 10 | +import time |
| 11 | +import board |
| 12 | +import digitalio |
| 13 | +import nonblocking_serialinput as nb_serialin |
| 14 | + |
| 15 | +########################################## |
| 16 | +# globals |
| 17 | +led = digitalio.DigitalInOut(board.LED) |
| 18 | +led.direction = digitalio.Direction.OUTPUT |
| 19 | + |
| 20 | +########################################## |
| 21 | +# menu |
| 22 | + |
| 23 | +my_input = nb_serialin.NonBlockingSerialInput() |
| 24 | + |
| 25 | +########################################## |
| 26 | +# main |
| 27 | + |
| 28 | + |
| 29 | +def main(): |
| 30 | + """Main.""" |
| 31 | + # wait for serial terminal to get ready.. |
| 32 | + time.sleep(1) |
| 33 | + print("") |
| 34 | + print("nonblocking_serialinput_simpletest.py") |
| 35 | + print(42 * "*") |
| 36 | + |
| 37 | + runtime_print_next = time.monotonic() |
| 38 | + runtime_print_intervall = 1.0 |
| 39 | + running = True |
| 40 | + while running: |
| 41 | + # input handling |
| 42 | + my_input.update() |
| 43 | + input_string = my_input.input() |
| 44 | + if input_string is not None: |
| 45 | + # print("input_string: {}".format(repr(input_string))) |
| 46 | + # we have at least a empty string. |
| 47 | + if "exit" in input_string: |
| 48 | + print("Stop Program running.") |
| 49 | + running = False |
| 50 | + elif "hello" in input_string: |
| 51 | + print("World :-)") |
| 52 | + else: |
| 53 | + print("type 'exit' to stop the program.") |
| 54 | + # live sign |
| 55 | + if runtime_print_next < time.monotonic(): |
| 56 | + runtime_print_next = time.monotonic() + runtime_print_intervall |
| 57 | + print("{: > 7.2f}s".format(time.monotonic())) |
| 58 | + led.value = not led.value |
| 59 | + |
| 60 | + |
| 61 | +########################################## |
| 62 | +if __name__ == "__main__": |
| 63 | + main() |
| 64 | + |
| 65 | +########################################## |
0 commit comments