parent
b15686f264
commit
3d04af8427
@ -1,77 +1,42 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import shepherd.config
|
import shepherd.config as shconf
|
||||||
import shepherd.module
|
import shepherd.plugin
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from gpiozero import OutputDevice, Device
|
|
||||||
from gpiozero.pins.pigpio import PiGPIOFactory
|
|
||||||
|
|
||||||
from shepherd.modules.betterservo import BetterServo
|
class AphidtrapModule(shepherd.plugin.Plugin):
|
||||||
|
@staticmethod
|
||||||
|
def define_config(confdef):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def __init__(self, pluginInterface, config):
|
||||||
|
super().__init__(pluginInterface, config)
|
||||||
|
|
||||||
Device.pin_factory = PiGPIOFactory()
|
self.config = config
|
||||||
|
self.interface = pluginInterface
|
||||||
|
self.plugins = pluginInterface.other_plugins
|
||||||
APHIDTRAP_LED_PIN = 5 #Out2
|
self.hooks = pluginInterface.hooks
|
||||||
|
|
||||||
|
|
||||||
class AphidtrapConfDef(shepherd.config.ConfDefinition):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
|
|
||||||
class AphidtrapModule(shepherd.module.SimpleModule):
|
|
||||||
conf_def = AphidtrapConfDef()
|
|
||||||
|
|
||||||
def setup(self):
|
|
||||||
|
|
||||||
print("Aphidtrap config:")
|
print("Aphidtrap config:")
|
||||||
print(self.config)
|
print(self.config)
|
||||||
|
|
||||||
self.led_power = OutputDevice(APHIDTRAP_LED_PIN,
|
self.interface.attach_hook("picam", "pre_cam", self.led_on)
|
||||||
active_high=True,
|
self.interface.attach_hook("picam", "post_cam", self.led_off)
|
||||||
initial_value=False)
|
|
||||||
|
|
||||||
def setup_other_modules(self):
|
self.interface.register_function(self.test)
|
||||||
self.modules.picam.hook_pre_cam.attach(self.led_on)
|
|
||||||
self.modules.picam.hook_post_cam.attach(self.led_off)
|
|
||||||
|
|
||||||
def led_on(self):
|
def led_on(self):
|
||||||
self.led_power.on()
|
self.plugins["scout"].set_out2(True)
|
||||||
|
|
||||||
def led_off(self):
|
def led_off(self):
|
||||||
self.led_power.off()
|
self.plugins["scout"].set_out2(False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
|
||||||
argparser = argparse.ArgumentParser(
|
|
||||||
description='Module for aphidtrap control functions. Run for testing')
|
|
||||||
argparser.add_argument("configfile", nargs='?', metavar="configfile",
|
|
||||||
help="Path to configfile", default="conf.toml")
|
|
||||||
|
|
||||||
|
|
||||||
args = argparser.parse_args()
|
|
||||||
confman = shepherd.config.ConfigManager()
|
|
||||||
|
|
||||||
srcdict = {"aphidtrap": {}}
|
|
||||||
|
|
||||||
if os.path.isfile(args.configfile):
|
|
||||||
confman.load(args.configfile)
|
|
||||||
else:
|
|
||||||
confman.load(srcdict)
|
|
||||||
|
|
||||||
aphidtrap_mod = AphidtrapModule(confman.get_config("aphidtrap", AphidtrapConfDef()),
|
|
||||||
shepherd.module.Interface(None))
|
|
||||||
|
|
||||||
aphidtrap_mod.led_on()
|
|
||||||
time.sleep(2)
|
|
||||||
aphidtrap_mod.led_off()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def test(self):
|
||||||
main(sys.argv[1:])
|
self.led_on()
|
||||||
|
time.sleep(2)
|
||||||
|
self.led_off()
|
||||||
Loading…
Reference in new issue