Implemented actuators
This commit is contained in:
		
							
								
								
									
										0
									
								
								src/actuator/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/actuator/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										24
									
								
								src/actuator/abcactuator.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/actuator/abcactuator.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
#!/usr/bin/env python3
 | 
			
		||||
from abc import ABC, abstractmethod
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
Abstract base class for Actuator
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
__author__ = "@marcsello"
 | 
			
		||||
__copyright__ = "Copyright 2020, Birbnetes Team"
 | 
			
		||||
__module_name__ = "abcactuator"
 | 
			
		||||
__version__text__ = "1"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class AbcActuator(ABC):
 | 
			
		||||
    """
 | 
			
		||||
    Abstract base class Actuator. Responsible for acting.
 | 
			
		||||
    """
 | 
			
		||||
    @abstractmethod
 | 
			
		||||
    def act(self):
 | 
			
		||||
        """
 | 
			
		||||
        Preprocess a signal.
 | 
			
		||||
        :return:
 | 
			
		||||
        """
 | 
			
		||||
        pass
 | 
			
		||||
							
								
								
									
										32
									
								
								src/actuator/loudspeaker.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								src/actuator/loudspeaker.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
#!/usr/bin/env python3
 | 
			
		||||
import random
 | 
			
		||||
import os
 | 
			
		||||
import os.path
 | 
			
		||||
from .abcactuator import AbcActuator
 | 
			
		||||
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformPlaybackDriver
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
Abstract base class for Sender
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
__author__ = "@marcsello"
 | 
			
		||||
__copyright__ = "Copyright 2020, Birbnetes Team"
 | 
			
		||||
__module_name__ = "loudspeaker"
 | 
			
		||||
__version__text__ = "1"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Loudspeaker(AbcActuator):
 | 
			
		||||
    """
 | 
			
		||||
    A class that plays back various sounds.
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    def __init__(self, sound_dir: str):
 | 
			
		||||
        BirbnetesIoTPlatformPlaybackDriver.init()
 | 
			
		||||
        self._sound_dir = sound_dir
 | 
			
		||||
 | 
			
		||||
    def act(self):
 | 
			
		||||
        choice = random.choice(os.listdir(self._sound_dir))
 | 
			
		||||
        BirbnetesIoTPlatformPlaybackDriver.play_audio(os.path.join(self._sound_dir, choice))
 | 
			
		||||
 | 
			
		||||
    def __del__(self):
 | 
			
		||||
        BirbnetesIoTPlatformPlaybackDriver.cleanup()
 | 
			
		||||
		Reference in New Issue
	
	Block a user