<commit_before><commit_msg>An actuator which will toggle or set a configured GPIO pin upon receipt of a message<commit_after>"""
 Script  rpiGPIOActuator.py
 Author: <NAME>
 Date:   April 19, 2016
 Purpose: Changes the state of the configured pin on command
"""

import sys
import RPi.GPIO as GPIO

class rpiGPIOActuator:
    """Represents an actuator connected to a GPIO pin"""

    def __init__(self, pin, destination, connection, toggle, logger):
        """Sets the output and changes its state when it receives a command"""

        self.logger = logger
        self.logger.info('----------Configuring rpiGPIOActuator: pin {0} on destination {1} with toggle {2}'.format(pin, destination, toggle))
        
        GPIO.setmode(GPIO.BCM) # uses BCM numbering, not Board numbering
        GPIO.setup(pin, GPIO.OUT)
        GPIO.output(pin, GPIO.HIGH)

        self.destination = destination
        self.connection = connection
        self.toggle = toggle

        self.connection.register(self.destination, self.on_message)

    def on_message(self, client, userdata, msg):
        """Process a message"""
        self.logger.info('Received command on {0}: {1} Toggle = {2}'.format(self.destination, msg.payload, self.toggle))
        if self.toggle == True:
            GPIO.output(pin, GPIO.HIGH)
            time.sleep(.5)
            GPIO.output(pin, GPIO.LOW)
        else:
            out = GPIO.LOW if msg.payload == "ON" else GPIO.HIGH

{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.008971704623878536, 'mean_word_length': 2.756476683937824, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5856879', 'n_tokens_mistral': 420, 'n_tokens_neox': 404, 'n_words': 135}