2022-10-14 16:11:01 +00:00
|
|
|
|
|
|
|
# This is a simple Tkinter program, running a main loop and reacting on keys
|
|
|
|
#
|
|
|
|
# Tested on Windows10 with python 3.9
|
|
|
|
#
|
|
|
|
# https://groups.google.com/g/comp.lang.python/c/dldnjWRX3lE/m/cL69gG3fCAAJ
|
|
|
|
|
|
|
|
#------------------------------------------------------------
|
|
|
|
import tkinter as tk
|
|
|
|
import time
|
|
|
|
import pyPlcWorker
|
2022-11-07 08:21:25 +00:00
|
|
|
from pyPlcModes import *
|
|
|
|
import sys # for argv
|
2023-04-15 18:35:51 +00:00
|
|
|
from configmodule import getConfigValue, getConfigValueBool
|
2023-05-13 22:22:26 +00:00
|
|
|
from mytestsuite import *
|
2022-10-14 16:11:01 +00:00
|
|
|
|
2023-04-11 20:09:26 +00:00
|
|
|
startTime_ms = round(time.time()*1000)
|
|
|
|
|
2022-10-14 16:11:01 +00:00
|
|
|
def storekeyname(event):
|
|
|
|
global nKeystrokes
|
|
|
|
global lastKey
|
|
|
|
nKeystrokes+=1
|
|
|
|
lastKey = event.keysym
|
|
|
|
worker.handleUserAction(lastKey)
|
|
|
|
return 'break' # swallow the event
|
|
|
|
|
|
|
|
def inkey():
|
|
|
|
global lastKey
|
|
|
|
return lastKey
|
|
|
|
lastKey = ''
|
|
|
|
|
|
|
|
def cbAddToTrace(s):
|
2023-04-11 20:09:26 +00:00
|
|
|
currentTime_ms = round(time.time()*1000)
|
|
|
|
dT_ms = currentTime_ms - startTime_ms
|
|
|
|
print("[" + str(dT_ms) + "ms] " + s)
|
2022-10-14 16:11:01 +00:00
|
|
|
|
2022-10-19 16:52:43 +00:00
|
|
|
def cbShowStatus(s, selection=""):
|
|
|
|
#print(s)
|
|
|
|
if (selection == "mode"):
|
|
|
|
lblMode['text']=s
|
|
|
|
s=""
|
|
|
|
if (selection == "pevmac"):
|
2022-10-24 21:19:45 +00:00
|
|
|
lblPevMac['text']="PEV MAC " + s
|
2022-10-19 16:52:43 +00:00
|
|
|
s=""
|
2022-12-19 13:48:23 +00:00
|
|
|
if (selection == "uInlet"):
|
|
|
|
lblUInlet['text']= "UInlet " + s + "V"
|
|
|
|
s=""
|
2023-04-05 19:01:43 +00:00
|
|
|
if (selection == "EVSEPresentVoltage"):
|
|
|
|
lblEVSEPresentVoltage['text']= "EVSEPresentVoltage " + s + "V"
|
|
|
|
s=""
|
2022-12-19 17:09:39 +00:00
|
|
|
if (selection == "pevState"):
|
|
|
|
lblState['text']= s
|
|
|
|
s=""
|
|
|
|
if (selection == "evseState"):
|
|
|
|
lblState['text']= s
|
|
|
|
s=""
|
|
|
|
if (selection == "soc"):
|
|
|
|
lblSoc['text']= "SOC " + s + "%"
|
|
|
|
s=""
|
2022-10-19 16:52:43 +00:00
|
|
|
if (len(s)>0):
|
|
|
|
lblStatus['text']=s
|
2022-10-14 16:11:01 +00:00
|
|
|
root.update()
|
|
|
|
|
2022-11-07 08:21:25 +00:00
|
|
|
myMode = C_LISTEN_MODE
|
2023-04-15 18:35:51 +00:00
|
|
|
if (getConfigValue("mode")=="PevMode"):
|
|
|
|
myMode = C_PEV_MODE
|
|
|
|
if (getConfigValue("mode")=="EvseMode"):
|
|
|
|
myMode = C_EVSE_MODE
|
2023-04-19 07:05:21 +00:00
|
|
|
# The command line arguments overwrite the config file setting for PevMode/EvseMode.
|
2022-11-07 08:21:25 +00:00
|
|
|
if (len(sys.argv) > 1):
|
|
|
|
if (sys.argv[1] == "P"):
|
|
|
|
myMode = C_PEV_MODE
|
|
|
|
else:
|
|
|
|
if (sys.argv[1] == "E"):
|
|
|
|
myMode = C_EVSE_MODE
|
|
|
|
|
2023-04-19 07:05:21 +00:00
|
|
|
# The simulation mode can be set by command line in addition in both, PevMode and EvseMode.
|
2022-11-16 18:33:37 +00:00
|
|
|
isSimulationMode=0
|
|
|
|
if (len(sys.argv) > 2):
|
|
|
|
if (sys.argv[2] == "S"):
|
|
|
|
isSimulationMode=1
|
|
|
|
|
2022-11-07 08:21:25 +00:00
|
|
|
if (myMode == C_LISTEN_MODE):
|
|
|
|
print("starting in LISTEN_MODE")
|
|
|
|
if (myMode == C_PEV_MODE):
|
2023-04-19 07:05:21 +00:00
|
|
|
if (isSimulationMode!=0):
|
|
|
|
print("starting in PevMode, simulated environment")
|
|
|
|
else:
|
|
|
|
print("starting in PevMode")
|
2022-11-07 08:21:25 +00:00
|
|
|
if (myMode == C_EVSE_MODE):
|
2023-04-19 07:05:21 +00:00
|
|
|
if (isSimulationMode!=0):
|
|
|
|
print("starting in EvseMode, simulated environment")
|
|
|
|
else:
|
|
|
|
print("starting in EvseMode")
|
2022-11-07 08:21:25 +00:00
|
|
|
|
2022-10-14 16:11:01 +00:00
|
|
|
root = tk.Tk()
|
2023-04-05 19:01:43 +00:00
|
|
|
root.geometry("400x350")
|
2022-10-14 16:11:01 +00:00
|
|
|
lastKey = ''
|
2022-10-24 21:19:45 +00:00
|
|
|
lblHelp = tk.Label(root, justify= "left")
|
2022-12-19 17:09:39 +00:00
|
|
|
lblHelp['text']="x=exit \nS=GET_SW \nP=PEV mode \nE=EVSE mode \nL=Listen mode \ns=SET_KEY \nG=GET_KEY (try twice) \nt=SET_KEY modified \n space=stop charging"
|
2022-10-14 16:11:01 +00:00
|
|
|
lblHelp.pack()
|
|
|
|
lblStatus = tk.Label(root, text="(Status)")
|
|
|
|
lblStatus.pack()
|
2022-10-19 16:52:43 +00:00
|
|
|
lblPevMac = tk.Label(root, text="(pev mac)")
|
|
|
|
lblPevMac.pack()
|
2022-12-19 17:09:39 +00:00
|
|
|
lblState = tk.Label(root, text="(state)")
|
|
|
|
lblState.config(font=('Helvetica bold', 20))
|
|
|
|
lblState.pack()
|
|
|
|
lblSoc = tk.Label(root, text="(soc)")
|
|
|
|
lblSoc.pack()
|
2022-12-19 13:48:23 +00:00
|
|
|
lblUInlet = tk.Label(root, text="(U Inlet)")
|
|
|
|
lblUInlet.config(font=('Helvetica bold', 26))
|
|
|
|
lblUInlet.pack()
|
2023-04-05 19:01:43 +00:00
|
|
|
lblEVSEPresentVoltage = tk.Label(root, text="(EVSEPresentVoltage)")
|
|
|
|
lblEVSEPresentVoltage.config(font=('Helvetica bold', 16))
|
|
|
|
lblEVSEPresentVoltage.pack()
|
2023-05-13 22:22:26 +00:00
|
|
|
|
|
|
|
if (myMode == C_EVSE_MODE):
|
|
|
|
lblTestcase = tk.Label(root, text="(test case)")
|
|
|
|
lblTestcase.pack()
|
|
|
|
|
2022-10-19 16:52:43 +00:00
|
|
|
lblMode = tk.Label(root, text="(mode)")
|
|
|
|
lblMode.pack()
|
|
|
|
|
2023-03-18 18:14:23 +00:00
|
|
|
if (myMode != C_PEV_MODE):
|
|
|
|
lblUInlet['text']= ""
|
|
|
|
|
2022-12-19 17:09:39 +00:00
|
|
|
nKeystrokes=0
|
2022-10-14 16:11:01 +00:00
|
|
|
# Bind the keyboard handler to all relevant elements:
|
|
|
|
root.bind('<Key>', storekeyname)
|
|
|
|
cbShowStatus("initialized")
|
|
|
|
root.update()
|
2022-11-16 18:33:37 +00:00
|
|
|
worker=pyPlcWorker.pyPlcWorker(cbAddToTrace, cbShowStatus, myMode, isSimulationMode)
|
2022-10-14 16:11:01 +00:00
|
|
|
|
|
|
|
nMainloops=0
|
|
|
|
while lastKey!="x":
|
2022-11-17 09:07:42 +00:00
|
|
|
time.sleep(.03) # 'do some calculation'
|
2022-10-14 16:11:01 +00:00
|
|
|
nMainloops+=1
|
|
|
|
# print(str(nMainloops) + " " + str(nKeystrokes)) # show something in the console window
|
|
|
|
root.update()
|
|
|
|
worker.mainfunction()
|
2023-05-13 22:22:26 +00:00
|
|
|
if (myMode == C_EVSE_MODE):
|
|
|
|
lblTestcase['text']= "Testcase " + str(testsuite_getTcNumber())
|
|
|
|
|
2022-12-09 11:06:10 +00:00
|
|
|
del(worker)
|
2022-10-14 16:11:01 +00:00
|
|
|
|
|
|
|
#---------------------------------------------------------------
|