From b532c5b5aa7f3b30e537de187e6d160046d6dc88 Mon Sep 17 00:00:00 2001 From: sailoog Date: Sun, 24 Apr 2022 20:28:59 +0200 Subject: [PATCH] add actions --- openplotterMaiana/actions.py | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 openplotterMaiana/actions.py diff --git a/openplotterMaiana/actions.py b/openplotterMaiana/actions.py new file mode 100644 index 0000000..073430e --- /dev/null +++ b/openplotterMaiana/actions.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +# This file is part of OpenPlotter. +# Copyright (C) 2022 by Sailoog +# +# Openplotter is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# any later version. +# Openplotter is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Openplotter. If not, see . + +import os, subprocess, serial +from openplotterSettings import language + +class Actions: + def __init__(self,conf,currentLanguage): + self.conf = conf + currentdir = os.path.dirname(os.path.abspath(__file__)) + language.Language(currentdir,'openplotter-maiana',currentLanguage) + if self.conf.get('GENERAL', 'debug') == 'yes': self.debug = True + else: self.debug = False + self.available = [] + self.available.append({'ID':'txOn','name':_('Turn MAIANA TX on'),"module": "openplotterMaiana",'data':False,'default':'','help':''}) + self.available.append({'ID':'txOff','name':_('Turn MAIANA TX off'),"module": "openplotterMaiana",'data':False,'default':'','help':''}) + + def run(self,action,data): + try: + device = self.conf.get('MAIANA', 'device') + ser = serial.Serial(device, 38400) + if action == 'txOn': ser.write('tx on\r\n'.encode("utf-8")) + elif action == 'txOff': ser.write('tx off\r\n'.encode("utf-8")) + except Exception as e: + if self.debug: print('Error processing openplotter-maiana actions: '+str(e))