├── requirements.txt ├── recording_examples ├── get_device_index.py ├── record.py └── record_one_channel.py ├── README.md ├── online_service_demos ├── alexa.py └── google_assistant.py ├── interfaces ├── alexa_led_pattern.py ├── pixels.py ├── google_home_led_pattern.py └── apa102.py ├── .gitignore └── LICENSE /requirements.txt: -------------------------------------------------------------------------------- 1 | spidev 2 | gpiozero 3 | pyaudio -------------------------------------------------------------------------------- /recording_examples/get_device_index.py: -------------------------------------------------------------------------------- 1 | import pyaudio 2 | 3 | p = pyaudio.PyAudio() 4 | info = p.get_host_api_info_by_index(0) 5 | numdevices = info.get('deviceCount') 6 | 7 | for i in range(0, numdevices): 8 | if (p.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0: 9 | print("Input Device id ", i, " - ", p.get_device_info_by_host_api_device_index(0, i).get('name')) 10 | else: 11 | print("Output Device id ", i, " - ", p.get_device_info_by_host_api_device_index(0, i).get('name')) 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 4MICs HAT for Raspberry Pi 2 | ======================== 3 | 4 | ## Introduction 5 | 6 | This repository fork from [mic_hat](https://github.com/respeaker/mic_hat) and is made to be suitable for 4Mics Pi HAT. 7 | 8 | ## Requirements 9 | + [spidev](https://pypi.python.org/pypi/spidev) 10 | + [google-assistant-library](https://github.com/googlesamples/assistant-sdk-python/tree/master/google-assistant-sdk/googlesamples/assistant/library) 11 | + [gpiozero](http://gpiozero.readthedocs.io/) 12 | 13 | ## Setup 14 | 1. Setup [google-assistant-library](https://github.com/googlesamples/assistant-sdk-python/tree/master/google-assistant-sdk/googlesamples/assistant/library) 15 | 2. Use `raspi-config` to enable SPI. 16 | 3. Install `spidev` and `gpiozero` (`pip install spidev gpiozero`) 17 | 4. Run `python google_assistant.py` 18 | -------------------------------------------------------------------------------- /recording_examples/record.py: -------------------------------------------------------------------------------- 1 | import pyaudio 2 | import wave 3 | 4 | RESPEAKER_RATE = 16000 5 | RESPEAKER_CHANNELS = 2 6 | RESPEAKER_WIDTH = 2 7 | # run getDeviceInfo.py to get index 8 | RESPEAKER_INDEX = 1 # refer to input device id 9 | CHUNK = 1024 10 | RECORD_SECONDS = 5 11 | WAVE_OUTPUT_FILENAME = "output.wav" 12 | 13 | p = pyaudio.PyAudio() 14 | 15 | stream = p.open( 16 | rate=RESPEAKER_RATE, 17 | format=p.get_format_from_width(RESPEAKER_WIDTH), 18 | channels=RESPEAKER_CHANNELS, 19 | input=True, 20 | input_device_index=RESPEAKER_INDEX,) 21 | 22 | print("* recording") 23 | 24 | frames = [] 25 | 26 | for i in range(0, int(RESPEAKER_RATE / CHUNK * RECORD_SECONDS)): 27 | data = stream.read(CHUNK) 28 | frames.append(data) 29 | 30 | print("* done recording") 31 | 32 | stream.stop_stream() 33 | stream.close() 34 | p.terminate() 35 | 36 | wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb') 37 | wf.setnchannels(RESPEAKER_CHANNELS) 38 | wf.setsampwidth(p.get_sample_size(p.get_format_from_width(RESPEAKER_WIDTH))) 39 | wf.setframerate(RESPEAKER_RATE) 40 | wf.writeframes(b''.join(frames)) 41 | wf.close() 42 | -------------------------------------------------------------------------------- /online_service_demos/alexa.py: -------------------------------------------------------------------------------- 1 | """ 2 | Hands-free Voice Assistant with Snowboy and Alexa Voice Service. The wake-up keyword is "alexa" 3 | 4 | Requirement: 5 | pip install avs 6 | pip install voice-engine 7 | """ 8 | 9 | 10 | import time 11 | import logging 12 | from voice_engine.source import Source 13 | from voice_engine.kws import KWS 14 | from avs.alexa import Alexa 15 | from pixels import pixels 16 | 17 | 18 | def main(): 19 | logging.basicConfig(level=logging.DEBUG) 20 | 21 | src = Source(rate=16000, frames_size=320) 22 | kws = KWS(model='alexa', sensitivity=0.8) 23 | alexa = Alexa() 24 | 25 | 26 | alexa.state_listener.on_listening = pixels.listen 27 | alexa.state_listener.on_thinking = pixels.think 28 | alexa.state_listener.on_speaking = pixels.speak 29 | alexa.state_listener.on_finished = pixels.off 30 | 31 | 32 | src.link(kws) 33 | kws.link(alexa) 34 | 35 | def on_detected(keyword): 36 | logging.info('detected {}'.format(keyword)) 37 | alexa.listen() 38 | 39 | kws.set_callback(on_detected) 40 | 41 | src.recursive_start() 42 | 43 | while True: 44 | try: 45 | time.sleep(1) 46 | except KeyboardInterrupt: 47 | break 48 | 49 | src.recursive_stop() 50 | 51 | 52 | if __name__ == '__main__': 53 | main() 54 | -------------------------------------------------------------------------------- /recording_examples/record_one_channel.py: -------------------------------------------------------------------------------- 1 | import pyaudio 2 | import wave 3 | import numpy as np 4 | 5 | RESPEAKER_RATE = 16000 6 | RESPEAKER_CHANNELS = 2 7 | RESPEAKER_WIDTH = 2 8 | # run getDeviceInfo.py to get index 9 | RESPEAKER_INDEX = 1 # refer to input device id 10 | CHUNK = 1024 11 | RECORD_SECONDS = 3 12 | WAVE_OUTPUT_FILENAME = "output_one_channel.wav" 13 | 14 | p = pyaudio.PyAudio() 15 | 16 | stream = p.open( 17 | rate=RESPEAKER_RATE, 18 | format=p.get_format_from_width(RESPEAKER_WIDTH), 19 | channels=RESPEAKER_CHANNELS, 20 | input=True, 21 | input_device_index=RESPEAKER_INDEX,) 22 | 23 | print("* recording") 24 | 25 | frames = [] 26 | 27 | for i in range(0, int(RESPEAKER_RATE / CHUNK * RECORD_SECONDS)): 28 | data = stream.read(CHUNK) 29 | # extract channel 0 data from 2 channels, if you want to extract channel 1, please change to [1::2] 30 | a = np.fromstring(data,dtype=np.int16)[0::2] 31 | frames.append(a.tostring()) 32 | 33 | print("* done recording") 34 | 35 | stream.stop_stream() 36 | stream.close() 37 | p.terminate() 38 | 39 | wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb') 40 | wf.setnchannels(1) 41 | wf.setsampwidth(p.get_sample_size(p.get_format_from_width(RESPEAKER_WIDTH))) 42 | wf.setframerate(RESPEAKER_RATE) 43 | wf.writeframes(b''.join(frames)) 44 | wf.close() 45 | 46 | -------------------------------------------------------------------------------- /interfaces/alexa_led_pattern.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright (C) 2017 Seeed Technology Limited 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import time 18 | 19 | class AlexaLedPattern(object): 20 | def __init__(self, show=None, number=12): 21 | self.pixels_number = number 22 | self.pixels = [0] * 4 * number 23 | 24 | if not show or not callable(show): 25 | def dummy(data): 26 | pass 27 | show = dummy 28 | 29 | self.show = show 30 | self.stop = False 31 | 32 | def wakeup(self, direction=0): 33 | position = int((direction + 15) / (360 / self.pixels_number)) % self.pixels_number 34 | 35 | pixels = [0, 0, 0, 24] * self.pixels_number 36 | pixels[position * 4 + 2] = 48 37 | 38 | self.show(pixels) 39 | 40 | def listen(self): 41 | pixels = [0, 0, 0, 24] * self.pixels_number 42 | 43 | self.show(pixels) 44 | 45 | def think(self): 46 | pixels = [0, 0, 12, 12, 0, 0, 0, 24] * self.pixels_number 47 | 48 | while not self.stop: 49 | self.show(pixels) 50 | time.sleep(0.2) 51 | pixels = pixels[-4:] + pixels[:-4] 52 | 53 | def speak(self): 54 | step = 1 55 | position = 12 56 | while not self.stop: 57 | pixels = [0, 0, position, 24 - position] * self.pixels_number 58 | self.show(pixels) 59 | time.sleep(0.01) 60 | if position <= 0: 61 | step = 1 62 | time.sleep(0.4) 63 | elif position >= 12: 64 | step = -1 65 | time.sleep(0.4) 66 | 67 | position += step 68 | 69 | def off(self): 70 | self.show([0] * 4 * 12) 71 | -------------------------------------------------------------------------------- /interfaces/pixels.py: -------------------------------------------------------------------------------- 1 | 2 | import apa102 3 | import time 4 | import threading 5 | from gpiozero import LED 6 | try: 7 | import queue as Queue 8 | except ImportError: 9 | import Queue as Queue 10 | 11 | from alexa_led_pattern import AlexaLedPattern 12 | 13 | #install numpy to use GoogleHomeLedPattern 14 | #from google_home_led_pattern import GoogleHomeLedPattern 15 | 16 | class Pixels: 17 | PIXELS_N = 12 18 | 19 | def __init__(self, pattern=AlexaLedPattern): 20 | self.pattern = pattern(show=self.show) 21 | 22 | self.dev = apa102.APA102(num_led=self.PIXELS_N) 23 | 24 | self.power = LED(5) 25 | self.power.on() 26 | 27 | self.queue = Queue.Queue() 28 | self.thread = threading.Thread(target=self._run) 29 | self.thread.daemon = True 30 | self.thread.start() 31 | 32 | self.last_direction = None 33 | 34 | def wakeup(self, direction=0): 35 | self.last_direction = direction 36 | def f(): 37 | self.pattern.wakeup(direction) 38 | 39 | self.put(f) 40 | 41 | def listen(self): 42 | if self.last_direction: 43 | def f(): 44 | self.pattern.wakeup(self.last_direction) 45 | self.put(f) 46 | else: 47 | self.put(self.pattern.listen) 48 | 49 | def think(self): 50 | self.put(self.pattern.think) 51 | 52 | def speak(self): 53 | self.put(self.pattern.speak) 54 | 55 | def off(self): 56 | self.put(self.pattern.off) 57 | 58 | def put(self, func): 59 | self.pattern.stop = True 60 | self.queue.put(func) 61 | 62 | def _run(self): 63 | while True: 64 | func = self.queue.get() 65 | self.pattern.stop = False 66 | func() 67 | 68 | def show(self, data): 69 | for i in range(self.PIXELS_N): 70 | self.dev.set_pixel(i, int(data[4*i + 1]), int(data[4*i + 2]), int(data[4*i + 3])) 71 | 72 | self.dev.show() 73 | 74 | 75 | pixels = Pixels() 76 | 77 | 78 | if __name__ == '__main__': 79 | while True: 80 | 81 | try: 82 | pixels.wakeup() 83 | time.sleep(3) 84 | pixels.think() 85 | time.sleep(3) 86 | pixels.speak() 87 | time.sleep(6) 88 | pixels.off() 89 | time.sleep(3) 90 | except KeyboardInterrupt: 91 | break 92 | 93 | 94 | pixels.off() 95 | time.sleep(1) 96 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 98 | __pypackages__/ 99 | 100 | # Celery stuff 101 | celerybeat-schedule 102 | celerybeat.pid 103 | 104 | # SageMath parsed files 105 | *.sage.py 106 | 107 | # Environments 108 | .env 109 | .venv 110 | env/ 111 | venv/ 112 | ENV/ 113 | env.bak/ 114 | venv.bak/ 115 | 116 | # Spyder project settings 117 | .spyderproject 118 | .spyproject 119 | 120 | # Rope project settings 121 | .ropeproject 122 | 123 | # mkdocs documentation 124 | /site 125 | 126 | # mypy 127 | .mypy_cache/ 128 | .dmypy.json 129 | dmypy.json 130 | 131 | # Pyre type checker 132 | .pyre/ 133 | 134 | # pytype static type analyzer 135 | .pytype/ 136 | 137 | # Cython debug symbols 138 | cython_debug/ 139 | 140 | -------------------------------------------------------------------------------- /interfaces/google_home_led_pattern.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Copyright (C) 2017 Seeed Technology Limited 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | 18 | import numpy 19 | import time 20 | try: 21 | import queue as Queue 22 | except ImportError: 23 | import Queue as Queue 24 | 25 | 26 | class GoogleHomeLedPattern(object): 27 | def __init__(self, show=None): 28 | self.basis = numpy.array([0] * 4 * 12) 29 | self.basis[0 * 4 + 1] = 2 30 | self.basis[3 * 4 + 1] = 1 31 | self.basis[3 * 4 + 2] = 1 32 | self.basis[6 * 4 + 2] = 2 33 | self.basis[9 * 4 + 3] = 2 34 | 35 | self.pixels = self.basis * 24 36 | 37 | if not show or not callable(show): 38 | def dummy(data): 39 | pass 40 | show = dummy 41 | 42 | self.show = show 43 | self.stop = False 44 | 45 | def wakeup(self, direction=0): 46 | position = int((direction + 15) / 30) % 12 47 | 48 | basis = numpy.roll(self.basis, position * 4) 49 | for i in range(1, 25): 50 | pixels = basis * i 51 | self.show(pixels) 52 | time.sleep(0.005) 53 | 54 | pixels = numpy.roll(pixels, 4) 55 | self.show(pixels) 56 | time.sleep(0.1) 57 | 58 | for i in range(2): 59 | new_pixels = numpy.roll(pixels, 4) 60 | self.show(new_pixels * 0.5 + pixels) 61 | pixels = new_pixels 62 | time.sleep(0.1) 63 | 64 | self.show(pixels) 65 | self.pixels = pixels 66 | 67 | def listen(self): 68 | pixels = self.pixels 69 | for i in range(1, 25): 70 | self.show(pixels * i / 24) 71 | time.sleep(0.01) 72 | 73 | def think(self): 74 | pixels = self.pixels 75 | 76 | while not self.stop: 77 | pixels = numpy.roll(pixels, 4) 78 | self.show(pixels) 79 | time.sleep(0.2) 80 | 81 | t = 0.1 82 | for i in range(0, 5): 83 | pixels = numpy.roll(pixels, 4) 84 | self.show(pixels * (4 - i) / 4) 85 | time.sleep(t) 86 | t /= 2 87 | 88 | self.pixels = pixels 89 | 90 | def speak(self): 91 | pixels = self.pixels 92 | step = 1 93 | brightness = 5 94 | while not self.stop: 95 | self.show(pixels * brightness / 24) 96 | time.sleep(0.02) 97 | 98 | if brightness <= 5: 99 | step = 1 100 | time.sleep(0.4) 101 | elif brightness >= 24: 102 | step = -1 103 | time.sleep(0.4) 104 | 105 | brightness += step 106 | 107 | def off(self): 108 | self.show([0] * 4 * 12) 109 | 110 | 111 | -------------------------------------------------------------------------------- /online_service_demos/google_assistant.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # The code is based on google-assistant-sdk's hotword.py 4 | # LED light is added to notify its status. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | 18 | 19 | from __future__ import print_function 20 | 21 | import argparse 22 | import os.path 23 | import json 24 | 25 | import google.auth.transport.requests 26 | import google.oauth2.credentials 27 | 28 | from google.assistant.library import Assistant 29 | from google.assistant.library.event import EventType 30 | from google.assistant.library.file_helpers import existing_file 31 | 32 | from pixels import pixels 33 | 34 | 35 | DEVICE_API_URL = 'https://embeddedassistant.googleapis.com/v1alpha2' 36 | 37 | 38 | def process_device_actions(event, device_id): 39 | if 'inputs' in event.args: 40 | for i in event.args['inputs']: 41 | if i['intent'] == 'action.devices.EXECUTE': 42 | for c in i['payload']['commands']: 43 | for device in c['devices']: 44 | if device['id'] == device_id: 45 | if 'execution' in c: 46 | for e in c['execution']: 47 | if 'params' in e: 48 | yield e['command'], e['params'] 49 | else: 50 | yield e['command'], None 51 | 52 | 53 | def process_event(event, device_id): 54 | """Pretty prints events. 55 | 56 | Prints all events that occur with two spaces between each new 57 | conversation and a single space between turns of a conversation. 58 | 59 | Args: 60 | event(event.Event): The current event to process. 61 | device_id(str): The device ID of the new instance. 62 | """ 63 | if event.type == EventType.ON_CONVERSATION_TURN_STARTED: 64 | print() 65 | pixels.wakeup() 66 | 67 | print(event) 68 | 69 | if event.type == EventType.ON_END_OF_UTTERANCE: 70 | pixels.think() 71 | 72 | if event.type == EventType.ON_RESPONDING_STARTED: 73 | pixels.speak() 74 | 75 | if event.type == EventType.ON_CONVERSATION_TURN_FINISHED: 76 | if event.args and event.args['with_follow_on_turn']: 77 | pixels.listen() 78 | else: 79 | pixels.off() 80 | print() 81 | 82 | if event.type == EventType.ON_DEVICE_ACTION: 83 | for command, params in process_device_actions(event, device_id): 84 | print('Do command', command, 'with params', str(params)) 85 | 86 | 87 | def register_device(project_id, credentials, device_model_id, device_id): 88 | """Register the device if needed. 89 | 90 | Registers a new assistant device if an instance with the given id 91 | does not already exists for this model. 92 | 93 | Args: 94 | project_id(str): The project ID used to register device instance. 95 | credentials(google.oauth2.credentials.Credentials): The Google 96 | OAuth2 credentials of the user to associate the device 97 | instance with. 98 | device_model_id(str): The registered device model ID. 99 | device_id(str): The device ID of the new instance. 100 | """ 101 | base_url = '/'.join([DEVICE_API_URL, 'projects', project_id, 'devices']) 102 | device_url = '/'.join([base_url, device_id]) 103 | session = google.auth.transport.requests.AuthorizedSession(credentials) 104 | r = session.get(device_url) 105 | print(device_url, r.status_code) 106 | if r.status_code == 404: 107 | print('Registering....') 108 | r = session.post(base_url, data=json.dumps({ 109 | 'id': device_id, 110 | 'model_id': device_model_id, 111 | 'client_type': 'SDK_LIBRARY' 112 | })) 113 | if r.status_code != 200: 114 | raise Exception('failed to register device: ' + r.text) 115 | print('\rDevice registered.') 116 | 117 | 118 | def main(): 119 | parser = argparse.ArgumentParser( 120 | formatter_class=argparse.RawTextHelpFormatter) 121 | parser.add_argument('--credentials', type=existing_file, 122 | metavar='OAUTH2_CREDENTIALS_FILE', 123 | default=os.path.join( 124 | os.path.expanduser('~/.config'), 125 | 'google-oauthlib-tool', 126 | 'credentials.json' 127 | ), 128 | help='Path to store and read OAuth2 credentials') 129 | parser.add_argument('--device_model_id', type=str, 130 | metavar='DEVICE_MODEL_ID', required=True, 131 | help='The device model ID registered with Google') 132 | parser.add_argument( 133 | '--project_id', 134 | type=str, 135 | metavar='PROJECT_ID', 136 | required=False, 137 | help='The project ID used to register device instances.') 138 | parser.add_argument( 139 | '-v', 140 | '--version', 141 | action='version', 142 | version='%(prog)s ' + 143 | Assistant.__version_str__()) 144 | 145 | args = parser.parse_args() 146 | with open(args.credentials, 'r') as f: 147 | credentials = google.oauth2.credentials.Credentials(token=None, 148 | **json.load(f)) 149 | 150 | with Assistant(credentials, args.device_model_id) as assistant: 151 | events = assistant.start() 152 | 153 | print('device_model_id:', args.device_model_id + '\n' + 154 | 'device_id:', assistant.device_id + '\n') 155 | 156 | if args.project_id: 157 | register_device(args.project_id, credentials, 158 | args.device_model_id, assistant.device_id) 159 | 160 | for event in events: 161 | process_event(event, assistant.device_id) 162 | 163 | 164 | if __name__ == '__main__': 165 | main() 166 | -------------------------------------------------------------------------------- /interfaces/apa102.py: -------------------------------------------------------------------------------- 1 | """ 2 | from https://github.com/tinue/APA102_Pi 3 | This is the main driver module for APA102 LEDs 4 | """ 5 | import spidev 6 | from math import ceil 7 | 8 | RGB_MAP = { 'rgb': [3, 2, 1], 'rbg': [3, 1, 2], 'grb': [2, 3, 1], 9 | 'gbr': [2, 1, 3], 'brg': [1, 3, 2], 'bgr': [1, 2, 3] } 10 | 11 | class APA102: 12 | """ 13 | Driver for APA102 LEDS (aka "DotStar"). 14 | 15 | (c) Martin Erzberger 2016-2017 16 | 17 | My very first Python code, so I am sure there is a lot to be optimized ;) 18 | 19 | Public methods are: 20 | - set_pixel 21 | - set_pixel_rgb 22 | - show 23 | - clear_strip 24 | - cleanup 25 | 26 | Helper methods for color manipulation are: 27 | - combine_color 28 | - wheel 29 | 30 | The rest of the methods are used internally and should not be used by the 31 | user of the library. 32 | 33 | Very brief overview of APA102: An APA102 LED is addressed with SPI. The bits 34 | are shifted in one by one, starting with the least significant bit. 35 | 36 | An LED usually just forwards everything that is sent to its data-in to 37 | data-out. While doing this, it remembers its own color and keeps glowing 38 | with that color as long as there is power. 39 | 40 | An LED can be switched to not forward the data, but instead use the data 41 | to change it's own color. This is done by sending (at least) 32 bits of 42 | zeroes to data-in. The LED then accepts the next correct 32 bit LED 43 | frame (with color information) as its new color setting. 44 | 45 | After having received the 32 bit color frame, the LED changes color, 46 | and then resumes to just copying data-in to data-out. 47 | 48 | The really clever bit is this: While receiving the 32 bit LED frame, 49 | the LED sends zeroes on its data-out line. Because a color frame is 50 | 32 bits, the LED sends 32 bits of zeroes to the next LED. 51 | As we have seen above, this means that the next LED is now ready 52 | to accept a color frame and update its color. 53 | 54 | So that's really the entire protocol: 55 | - Start by sending 32 bits of zeroes. This prepares LED 1 to update 56 | its color. 57 | - Send color information one by one, starting with the color for LED 1, 58 | then LED 2 etc. 59 | - Finish off by cycling the clock line a few times to get all data 60 | to the very last LED on the strip 61 | 62 | The last step is necessary, because each LED delays forwarding the data 63 | a bit. Imagine ten people in a row. When you yell the last color 64 | information, i.e. the one for person ten, to the first person in 65 | the line, then you are not finished yet. Person one has to turn around 66 | and yell it to person 2, and so on. So it takes ten additional "dummy" 67 | cycles until person ten knows the color. When you look closer, 68 | you will see that not even person 9 knows its own color yet. This 69 | information is still with person 2. Essentially the driver sends additional 70 | zeroes to LED 1 as long as it takes for the last color frame to make it 71 | down the line to the last LED. 72 | """ 73 | # Constants 74 | MAX_BRIGHTNESS = 31 # Safeguard: Set to a value appropriate for your setup 75 | LED_START = 0b11100000 # Three "1" bits, followed by 5 brightness bits 76 | 77 | def __init__(self, num_led, global_brightness=MAX_BRIGHTNESS, 78 | order='rgb', bus=0, device=1, max_speed_hz=8000000): 79 | self.num_led = num_led # The number of LEDs in the Strip 80 | order = order.lower() 81 | self.rgb = RGB_MAP.get(order, RGB_MAP['rgb']) 82 | # Limit the brightness to the maximum if it's set higher 83 | if global_brightness > self.MAX_BRIGHTNESS: 84 | self.global_brightness = self.MAX_BRIGHTNESS 85 | else: 86 | self.global_brightness = global_brightness 87 | 88 | self.leds = [self.LED_START,0,0,0] * self.num_led # Pixel buffer 89 | self.spi = spidev.SpiDev() # Init the SPI device 90 | self.spi.open(bus, device) # Open SPI port 0, slave device (CS) 1 91 | # Up the speed a bit, so that the LEDs are painted faster 92 | if max_speed_hz: 93 | self.spi.max_speed_hz = max_speed_hz 94 | 95 | def clock_start_frame(self): 96 | """Sends a start frame to the LED strip. 97 | 98 | This method clocks out a start frame, telling the receiving LED 99 | that it must update its own color now. 100 | """ 101 | self.spi.xfer2([0] * 4) # Start frame, 32 zero bits 102 | 103 | 104 | def clock_end_frame(self): 105 | """Sends an end frame to the LED strip. 106 | 107 | As explained above, dummy data must be sent after the last real colour 108 | information so that all of the data can reach its destination down the line. 109 | The delay is not as bad as with the human example above. 110 | It is only 1/2 bit per LED. This is because the SPI clock line 111 | needs to be inverted. 112 | 113 | Say a bit is ready on the SPI data line. The sender communicates 114 | this by toggling the clock line. The bit is read by the LED 115 | and immediately forwarded to the output data line. When the clock goes 116 | down again on the input side, the LED will toggle the clock up 117 | on the output to tell the next LED that the bit is ready. 118 | 119 | After one LED the clock is inverted, and after two LEDs it is in sync 120 | again, but one cycle behind. Therefore, for every two LEDs, one bit 121 | of delay gets accumulated. For 300 LEDs, 150 additional bits must be fed to 122 | the input of LED one so that the data can reach the last LED. 123 | 124 | Ultimately, we need to send additional numLEDs/2 arbitrary data bits, 125 | in order to trigger numLEDs/2 additional clock changes. This driver 126 | sends zeroes, which has the benefit of getting LED one partially or 127 | fully ready for the next update to the strip. An optimized version 128 | of the driver could omit the "clockStartFrame" method if enough zeroes have 129 | been sent as part of "clockEndFrame". 130 | """ 131 | # Round up num_led/2 bits (or num_led/16 bytes) 132 | for _ in range((self.num_led + 15) // 16): 133 | self.spi.xfer2([0x00]) 134 | 135 | 136 | def clear_strip(self): 137 | """ Turns off the strip and shows the result right away.""" 138 | 139 | for led in range(self.num_led): 140 | self.set_pixel(led, 0, 0, 0) 141 | self.show() 142 | 143 | 144 | def set_pixel(self, led_num, red, green, blue, bright_percent=100): 145 | """Sets the color of one pixel in the LED stripe. 146 | 147 | The changed pixel is not shown yet on the Stripe, it is only 148 | written to the pixel buffer. Colors are passed individually. 149 | If brightness is not set the global brightness setting is used. 150 | """ 151 | if led_num < 0: 152 | return # Pixel is invisible, so ignore 153 | if led_num >= self.num_led: 154 | return # again, invisible 155 | 156 | # Calculate pixel brightness as a percentage of the 157 | # defined global_brightness. Round up to nearest integer 158 | # as we expect some brightness unless set to 0 159 | brightness = ceil(bright_percent*self.global_brightness/100.0) 160 | brightness = int(brightness) 161 | 162 | # LED startframe is three "1" bits, followed by 5 brightness bits 163 | ledstart = (brightness & 0b00011111) | self.LED_START 164 | 165 | start_index = 4 * led_num 166 | self.leds[start_index] = ledstart 167 | self.leds[start_index + self.rgb[0]] = red 168 | self.leds[start_index + self.rgb[1]] = green 169 | self.leds[start_index + self.rgb[2]] = blue 170 | 171 | 172 | def set_pixel_rgb(self, led_num, rgb_color, bright_percent=100): 173 | """Sets the color of one pixel in the LED stripe. 174 | 175 | The changed pixel is not shown yet on the Stripe, it is only 176 | written to the pixel buffer. 177 | Colors are passed combined (3 bytes concatenated) 178 | If brightness is not set the global brightness setting is used. 179 | """ 180 | self.set_pixel(led_num, (rgb_color & 0xFF0000) >> 16, 181 | (rgb_color & 0x00FF00) >> 8, rgb_color & 0x0000FF, 182 | bright_percent) 183 | 184 | 185 | def rotate(self, positions=1): 186 | """ Rotate the LEDs by the specified number of positions. 187 | 188 | Treating the internal LED array as a circular buffer, rotate it by 189 | the specified number of positions. The number could be negative, 190 | which means rotating in the opposite direction. 191 | """ 192 | cutoff = 4 * (positions % self.num_led) 193 | self.leds = self.leds[cutoff:] + self.leds[:cutoff] 194 | 195 | 196 | def show(self): 197 | """Sends the content of the pixel buffer to the strip. 198 | 199 | Todo: More than 1024 LEDs requires more than one xfer operation. 200 | """ 201 | self.clock_start_frame() 202 | # xfer2 kills the list, unfortunately. So it must be copied first 203 | # SPI takes up to 4096 Integers. So we are fine for up to 1024 LEDs. 204 | self.spi.xfer2(list(self.leds)) 205 | self.clock_end_frame() 206 | 207 | 208 | def cleanup(self): 209 | """Release the SPI device; Call this method at the end""" 210 | 211 | self.spi.close() # Close SPI port 212 | 213 | @staticmethod 214 | def combine_color(red, green, blue): 215 | """Make one 3*8 byte color value.""" 216 | 217 | return (red << 16) + (green << 8) + blue 218 | 219 | 220 | def wheel(self, wheel_pos): 221 | """Get a color from a color wheel; Green -> Red -> Blue -> Green""" 222 | 223 | if wheel_pos > 255: 224 | wheel_pos = 255 # Safeguard 225 | if wheel_pos < 85: # Green -> Red 226 | return self.combine_color(wheel_pos * 3, 255 - wheel_pos * 3, 0) 227 | if wheel_pos < 170: # Red -> Blue 228 | wheel_pos -= 85 229 | return self.combine_color(255 - wheel_pos * 3, 0, wheel_pos * 3) 230 | # Blue -> Green 231 | wheel_pos -= 170 232 | return self.combine_color(0, wheel_pos * 3, 255 - wheel_pos * 3) 233 | 234 | 235 | def dump_array(self): 236 | """For debug purposes: Dump the LED array onto the console.""" 237 | 238 | print(self.leds) 239 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | --------------------------------------------------------------------------------