|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | + |
| 4 | +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries |
| 5 | +# SPDX-FileCopyrightText: Copyright (c) 2021 Stefan Krüger for s-light |
| 6 | +# |
| 7 | +# SPDX-License-Identifier: Unlicense |
| 8 | + |
| 9 | +"""Simple Minimal example of CircuitPython_nonblocking_serialinput library usage.""" |
| 10 | + |
| 11 | +import time |
| 12 | +import sys |
| 13 | +import board |
| 14 | +import nonblocking_serialinput as nb_serialin |
| 15 | + |
| 16 | +########################################## |
| 17 | +# globals |
| 18 | +my_input = nb_serialin.NonBlockingSerialInput() |
| 19 | + |
| 20 | + |
| 21 | +class MyProjectMainClass(object): |
| 22 | + """This is just the Container Class for my Project.""" |
| 23 | + |
| 24 | + def __init__(self, arg): |
| 25 | + super(MyProjectMainClass, self).__init__() |
| 26 | + self.arg = arg |
| 27 | + |
| 28 | + |
| 29 | +########################################## |
| 30 | +# menu |
| 31 | + |
| 32 | + |
| 33 | +def print_help(self): |
| 34 | + """Print Help.""" |
| 35 | + profile_list = "" |
| 36 | + # for name, profile in self.profiles.items(): |
| 37 | + # profile_list += " {}\n".format(profile.title) |
| 38 | + # ^--> random order.. |
| 39 | + for name in self.profiles_names: |
| 40 | + current = "" |
| 41 | + if self.profiles[name] is self.profile_selected: |
| 42 | + current = "*" |
| 43 | + profile_list += " {: 1}{}\n".format(current, self.profiles[name].title_short) |
| 44 | + print( |
| 45 | + "you do some things:\n" |
| 46 | + "- 't': toggle print runtime ({print_runtime})\n" |
| 47 | + "- 's': set print runtime intervall ({intervall: > 7.2f})\n" |
| 48 | + "- 'pn' select next profil\n" |
| 49 | + "{profile_list}" |
| 50 | + "- 'calibrate'\n" |
| 51 | + "- 'start' reflow cycle\n" |
| 52 | + "- 'stop' reflow cycle\n" |
| 53 | + "".format( |
| 54 | + profile_list=profile_list, |
| 55 | + heater_target=self.reflowcontroller.heater_target, |
| 56 | + ), |
| 57 | + end="", |
| 58 | + ) |
| 59 | + self.print_temperature() |
| 60 | + |
| 61 | + |
| 62 | +def check_input(self): |
| 63 | + """Check Input.""" |
| 64 | + input_string = input() |
| 65 | + # sys.stdin.read(1) |
| 66 | + if "pn" in input_string: |
| 67 | + self.reflowcontroller.profile_select_next() |
| 68 | + if "pid p" in input_string: |
| 69 | + value = nb_serialin.parse_value(input_string, "pid p") |
| 70 | + if value: |
| 71 | + self.reflowcontroller.pid.P_gain = value |
| 72 | + if "h" in input_string: |
| 73 | + value = nb_serialin.parse_value(input_string, "h") |
| 74 | + if nb_serialin.is_number(value): |
| 75 | + self.reflowcontroller.heater_target = value |
| 76 | + # prepare new input |
| 77 | + self.print_help() |
| 78 | + print(">> ", end="") |
| 79 | + |
| 80 | + |
| 81 | +@staticmethod |
| 82 | +def input_parse_pixel_set(input_string): |
| 83 | + """parse pixel_set.""" |
| 84 | + # row = 0 |
| 85 | + # col = 0 |
| 86 | + # value = 0 |
| 87 | + # sep_pos = input_string.find(",") |
| 88 | + # sep_value = input_string.find(":") |
| 89 | + # try: |
| 90 | + # col = int(input_string[1:sep_pos]) |
| 91 | + # except ValueError as e: |
| 92 | + # print("Exception parsing 'col': ", e) |
| 93 | + # try: |
| 94 | + # row = int(input_string[sep_pos + 1 : sep_value]) |
| 95 | + # except ValueError as e: |
| 96 | + # print("Exception parsing 'row': ", e) |
| 97 | + # try: |
| 98 | + # value = int(input_string[sep_value + 1 :]) |
| 99 | + # except ValueError as e: |
| 100 | + # print("Exception parsing 'value': ", e) |
| 101 | + # pixel_index = 0 |
| 102 | + pass |
| 103 | + |
| 104 | + |
| 105 | +########################################## |
| 106 | +# functions |
| 107 | + |
| 108 | + |
| 109 | +def main_update(self): |
| 110 | + """Do all the things your main code want's to do....""" |
| 111 | + pass |
| 112 | + |
| 113 | + |
| 114 | +########################################## |
| 115 | +# main |
| 116 | + |
| 117 | + |
| 118 | +def main(): |
| 119 | + """Main.""" |
| 120 | + # wait some time untill the computer / terminal is ready |
| 121 | + for index in range(10): |
| 122 | + print(".", end="") |
| 123 | + time.sleep(0.5 / 10) |
| 124 | + print("") |
| 125 | + print(42 * "*") |
| 126 | + print("Python Version: " + sys.version) |
| 127 | + print("board: " + board.board_id) |
| 128 | + print(42 * "*") |
| 129 | + print("run") |
| 130 | + |
| 131 | + running = True |
| 132 | + while running: |
| 133 | + try: |
| 134 | + my_input.update() |
| 135 | + except KeyboardInterrupt as e: |
| 136 | + print("KeyboardInterrupt - Stop Program.", e) |
| 137 | + running = False |
| 138 | + else: |
| 139 | + main_update() |
| 140 | + |
| 141 | + |
| 142 | +########################################## |
| 143 | +if __name__ == "__main__": |
| 144 | + main() |
| 145 | + |
| 146 | +########################################## |
0 commit comments