parent
b15686f264
commit
3d04af8427
@ -1,77 +1,42 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import shepherd.config
|
||||
import shepherd.module
|
||||
import shepherd.config as shconf
|
||||
import shepherd.plugin
|
||||
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
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()
|
||||
|
||||
|
||||
APHIDTRAP_LED_PIN = 5 #Out2
|
||||
|
||||
|
||||
class AphidtrapConfDef(shepherd.config.ConfDefinition):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
|
||||
class AphidtrapModule(shepherd.module.SimpleModule):
|
||||
conf_def = AphidtrapConfDef()
|
||||
|
||||
def setup(self):
|
||||
self.config = config
|
||||
self.interface = pluginInterface
|
||||
self.plugins = pluginInterface.other_plugins
|
||||
self.hooks = pluginInterface.hooks
|
||||
|
||||
print("Aphidtrap config:")
|
||||
print(self.config)
|
||||
|
||||
self.led_power = OutputDevice(APHIDTRAP_LED_PIN,
|
||||
active_high=True,
|
||||
initial_value=False)
|
||||
self.interface.attach_hook("picam", "pre_cam", self.led_on)
|
||||
self.interface.attach_hook("picam", "post_cam", self.led_off)
|
||||
|
||||
def setup_other_modules(self):
|
||||
self.modules.picam.hook_pre_cam.attach(self.led_on)
|
||||
self.modules.picam.hook_post_cam.attach(self.led_off)
|
||||
self.interface.register_function(self.test)
|
||||
|
||||
def led_on(self):
|
||||
self.led_power.on()
|
||||
self.plugins["scout"].set_out2(True)
|
||||
|
||||
def led_off(self):
|
||||
self.led_power.off()
|
||||
|
||||
|
||||
|
||||
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()
|
||||
|
||||
self.plugins["scout"].set_out2(False)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
def test(self):
|
||||
self.led_on()
|
||||
time.sleep(2)
|
||||
self.led_off()
|
||||
Loading…
Reference in new issue