--restore and --wait are now always active

This commit is contained in:
Shy 2017-04-18 18:51:30 +02:00
parent 83dd8fca51
commit 5faa7da585

View file

@ -17,10 +17,11 @@
# You should have received a copy of the GNU General Public License along with # You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>. # this program. If not, see <http://www.gnu.org/licenses/>.
def kitchentext(delay=200, skip_if_off=False, poweron=False, restore=False, def kitchentext(delay=200, skip_if_off=False, poweron=False, verbose=False,
wait=False, verbose=False, debug=False): debug=False):
import sys, signal import sys, signal
from time import sleep
from c4ctrl import C4Interface, Kitchenlight from c4ctrl import C4Interface, Kitchenlight
charwidth = { # Width of characters. charwidth = { # Width of characters.
@ -45,11 +46,7 @@ def kitchentext(delay=200, skip_if_off=False, poweron=False, restore=False,
C4Interface.debug = debug C4Interface.debug = debug
kl = Kitchenlight(autopower=poweron) kl = Kitchenlight(autopower=poweron)
# Enforce wait=True if restore=True
wait = wait or restore
# Store previous state. # Store previous state.
if restore or skip_if_off:
c4 = C4Interface() c4 = C4Interface()
saved_state = c4.pull([kl.topic, kl.powertopic]) saved_state = c4.pull([kl.topic, kl.powertopic])
@ -95,8 +92,6 @@ def kitchentext(delay=200, skip_if_off=False, poweron=False, restore=False,
try: # We might well get interrupted while waiting. try: # We might well get interrupted while waiting.
kl.text(text, delay) kl.text(text, delay)
if wait:
from time import sleep
# How long shall we wait? Kitchenlight has 30 columns, each # How long shall we wait? Kitchenlight has 30 columns, each
# char uses 2-5 columns followed by an empty one. The # char uses 2-5 columns followed by an empty one. The
# traversal of one column takes 30 * <delay> ms. # traversal of one column takes 30 * <delay> ms.
@ -124,7 +119,6 @@ def kitchentext(delay=200, skip_if_off=False, poweron=False, restore=False,
finally: finally:
# Always restore privious state if "restore" is set. # Always restore privious state if "restore" is set.
if restore:
re = [] re = []
for top in saved_state: re.append((top.topic, top.payload)) for top in saved_state: re.append((top.topic, top.payload))
c4.push(re) c4.push(re)
@ -155,16 +149,9 @@ if __name__ == "__main__":
parser.add_argument( parser.add_argument(
"-p", "--power-on", action="store_true", default=False, "-p", "--power-on", action="store_true", default=False,
help="turn on Kitchenlight if it is powered off") help="turn on Kitchenlight if it is powered off")
parser.add_argument(
"-r", "--restore", action="store_true", default=False,
help="restore the Kitchenlight to its prior state after the text has \
been displayed (implies --wait)")
parser.add_argument( parser.add_argument(
"-v", "--verbose", action="store_true", "-v", "--verbose", action="store_true",
help="be more verbose") help="be more verbose")
parser.add_argument(
"-w", "--wait", action="store_true", default=False,
help="wait until the text has been displayed")
args = parser.parse_args() args = parser.parse_args()
if args.fork or args.F: if args.fork or args.F:
@ -188,8 +175,6 @@ if __name__ == "__main__":
kitchentext(delay=args.delay, kitchentext(delay=args.delay,
skip_if_off=args.skip_if_off, skip_if_off=args.skip_if_off,
poweron=args.power_on, poweron=args.power_on,
restore=args.restore,
wait=args.wait,
verbose=args.verbose, verbose=args.verbose,
debug=args.debug) debug=args.debug)