aboutsummaryrefslogtreecommitdiff
path: root/src/compileAndRun/pythonSupportFiles
diff options
context:
space:
mode:
Diffstat (limited to 'src/compileAndRun/pythonSupportFiles')
-rw-r--r--src/compileAndRun/pythonSupportFiles/LuxcenaNeo/NeoBehaviour.py29
-rw-r--r--src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Strip.py6
-rw-r--r--src/compileAndRun/pythonSupportFiles/LuxcenaNeo/__init__.py10
-rw-r--r--src/compileAndRun/pythonSupportFiles/entry.py78
4 files changed, 123 insertions, 0 deletions
diff --git a/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/NeoBehaviour.py b/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/NeoBehaviour.py
new file mode 100644
index 0000000..b0238e7
--- /dev/null
+++ b/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/NeoBehaviour.py
@@ -0,0 +1,29 @@
+# This is the base-class "main" should inherit from!
+# All methods are blocking :) This means that you could potentially loose a "tick"
+# For example, if "eachSecond" is taking up the thread, and the clock goes from 11:58 to 12:02, "eachHour", will not be called.
+class NeoBehaviour:
+
+ # THIS METHOD SHOULD NOT BE OVERIDDEN! Use onStart if you want a setup-method!!!
+ # Contains basic setup
+ def __init__(self):
+ return
+
+ # This method will be run right after __init__
+ def onStart(self):
+ return
+
+ # This method is called every second (on the clock), given that the thread is open
+ def eachSecond(self):
+ return
+
+ # This method is called every mintue (on the clock), given that the thread is open
+ def eachMinute(self):
+ return
+
+ # This method is called every whole hour (on the clock), given that the thread is open
+ def eachHour(self):
+ return
+
+ # This method is called every day at noon, given that the thread is open
+ def eachDay(self):
+ return
diff --git a/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Strip.py b/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Strip.py
new file mode 100644
index 0000000..c4ac8c9
--- /dev/null
+++ b/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/Strip.py
@@ -0,0 +1,6 @@
+class Strip:
+
+ def __init__(self, segments, segmentConfiguration):
+ self.segments = segments
+ self.segmentConfiguration = segmentConfiguration
+ return
diff --git a/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/__init__.py b/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/__init__.py
new file mode 100644
index 0000000..40b8e2d
--- /dev/null
+++ b/src/compileAndRun/pythonSupportFiles/LuxcenaNeo/__init__.py
@@ -0,0 +1,10 @@
+from NeoBehaviour import *
+from Strip import *
+
+strip = None # The strip object, should be set in entry.py, and is then accessible in the script-file
+forceStop = False # When set to true, execution of the script will halt
+
+# A function that could be used to halt the script
+def stop():
+ global forceStop
+ forceStop = True
diff --git a/src/compileAndRun/pythonSupportFiles/entry.py b/src/compileAndRun/pythonSupportFiles/entry.py
new file mode 100644
index 0000000..4ba1031
--- /dev/null
+++ b/src/compileAndRun/pythonSupportFiles/entry.py
@@ -0,0 +1,78 @@
+# This is the entry-point for all Luxcena-Neo python-scripts
+# The script should be in the same folder as this, and be named "script.py"
+# In the future you could possibly have more files and stuff alongside the "script.py"-file as well
+import sys
+import json
+import importlib
+import datetime
+
+def runSync(moduleSc, sc):
+ timeNow = datetime.datetime.now()
+ lastDay = timeNow.day
+ lastHour = timeNow.hour
+ lastMinute = timeNow.minute
+ lastSecond = timeNow.second
+
+ while True:
+ timeNow = datetime.datetime.now()
+
+ if ("LuxcenaNeo" in dir(moduleSc)):
+ if moduleSc.LuxcenaNeo.forceStop: break
+ elif ("neo" in dir(moduleSc)):
+ if moduleSc.neo.forceStop == True: break
+
+ if (timeNow.second != lastSecond):
+ lastSecond = timeNow.second
+ sc.eachSecond()
+
+ if (timeNow.minute != lastMinute):
+ lastMinute = timeNow.minute
+ sc.eachMinute()
+
+ if (timeNow.hour != lastHour):
+ lastHour = timeNow.hour
+ sc.eachHour()
+
+ if (timeNow.day != lastDay):
+ lastDay = timeNow.lastDay
+ sc.eachDay()
+
+def runAsync(moduleSc, sc):
+ return
+
+def main():
+ print ("Starting script named \"{0}\"".format("test"))
+
+ root_dir = sys.argv[1]
+ config_dir = root_dir + "/config/"
+
+ print ("> Loading pixel-configuration...")
+ with open(config_dir + "strip.json", "r") as rawStripConf:
+ stripConf = json.load(rawStripConf)
+ segments = stripConf["segments"]
+ segmentConfiguration = stripConf["segmentConfiguration"]
+
+ print ("> Initializing script...")
+ moduleSc = importlib.import_module("script")
+
+ if ("LuxcenaNeo" in dir(moduleSc)):
+ moduleSc.LuxcenaNeo.strip = moduleSc.LuxcenaNeo.Strip(segments, segmentConfiguration)
+ elif ("neo" in dir(moduleSc)):
+ moduleSc.neo.strip = moduleSc.neo.Strip(segments, segmentConfiguration)
+ else:
+ raise Exception("Neither LuxcenaNeo nor neo found in script, check docs!")
+
+ sc = moduleSc.Main()
+
+ print ("> Running the script...")
+ sc.onStart()
+
+ if (("async" in dir(moduleSc)) and (moduleSc.async == True)):
+ runAsync(moduleSc, sc)
+ else:
+ runSync(moduleSc, sc)
+
+ print ("> Script exited...")
+
+if __name__ == "__main__":
+ main()