Skip to content

Commit

Permalink
Merge pull request #33 from nikhiljohn10/master
Browse files Browse the repository at this point in the history
v1.2.1
  • Loading branch information
nikhiljohn10 committed Aug 26, 2020
2 parents 5cac25d + 83792d7 commit bfdb7af
Show file tree
Hide file tree
Showing 233 changed files with 31,967 additions and 2,348 deletions.
102 changes: 63 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
SRCDIR := ./piclap
DOCSDIR := ./docs
DOCSRCDIR := $(DOCSDIR)/source
PROJECT := $(shell cat $(SRCDIR)/__init__.py | grep __project__ | sed -e 's/^.* = '\"'//' -e 's/'\"'//')
AUTHOR := $(shell cat $(SRCDIR)/__init__.py | grep __author__ | sed -e 's/^.* = '\"'//' -e 's/'\"'//')
VERSION := $(shell cat $(SRCDIR)/__init__.py | grep __version__ | sed -e 's/^.* = '\"'//' -e 's/'\"'//')
RELEASE := $(shell cat $(SRCDIR)/__init__.py | grep __release__ | sed -e 's/^.* = '\"'//' -e 's/'\"'//')
DOMAIN := $(PROJECT).nikz.in
DOCTHEME := classic
PROJECT := pi-clap
AUTHOR := Nikhil John
SRCDIR := ./piclap
DOCSDIR := ./docs
DOCSRCDIR := $(DOCSDIR)/source
DOMAIN := $(PROJECT).nikz.in
DOCTHEME := sphinx_rtd_theme
RELEASE := $(shell cat $(SRCDIR)/__init__.py | grep __version__ | sed -e 's/^.* = '\''//' -e 's/'\''//')
VERSION := $(shell echo $(RELEASE) | sed -e 's/^\([0-9]*\.[0-9]*\).*$$/\1/')

help: version
@echo "Please use 'make <target>' where <target> is one of"
@echo " version to display package version"
@echo " setup to install development dependencies"
@echo " run to run example app"
@echo " clean to clean the build and execution temp files and directories"
@echo " build to build PyPi package"
@echo " publish to upload python package to PyPi server"
@echo " test-publish to upload python package to TestPyPi server"
@echo " docs-clean to clean the documentation directory"
@echo " docs-build to make documentation source directory"
@echo " docs-html to make standalone HTML documentation files for Github Pages"
@echo " docs-auto to execute 'make docs-build' and 'make docs-html' together"

version:
@echo "\n\t#################################"
@echo "\t#\t\t\t\t#"
@echo "\t#\t $(PROJECT) v$(RELEASE)\t#"
@echo "\t#\t\t\t\t#"
@echo "\t#################################\n"

setup:
@pip3 install -Ur requirements.txt

test: setup
@python3 ./tests/test_settings.py
@pytest

run: setup
@python3 ./example/app.py

clean-build:
@rm -rf build/
Expand All @@ -23,56 +47,56 @@ clean: clean-build
@find . -name '*.pyc' -exec rm -f {} +
@find . -name '*.pyo' -exec rm -f {} +
@find . -name '*~' -exec rm -f {} +
@find . -name '.DS_Store' -exec rm -f {} +
@find . -name 'Thumbs.db' -exec rm -f {} +
@find . -name '__pycache__' -exec rm -rf {} +
@find . -name '.DS_Store' -exec rm -rf {} +
@find . -name 'Thumbs.db' -exec rm -rf {} +
@find . -name '.pytest_cache' -exec rm -rf {} +

build: clean test
@pip3 install twine
@python3 setup.py sdist bdist_wheel

publish: build
@twine upload dist/*
@make clean

test-publish: build
@twine upload --repository testpypi dist/*
@make clean

install: clean setup
@pip3 install pi-clap==$(RELEASE)

test-install: clean setup
@pip3 install --index-url https://test.pypi.org/simple/ pi-clap==$(RELEASE)

rmd:
@rm -rf $(DOCSDIR)
uninstall:
@pip uninstall pi-clap

docs: rmd
@echo "\nCompiling docs for $(PROJECT) v$(RELEASE)\n"
@sphinx-apidoc -f -F -e -a -M -l -d 5 -H '$(PROJECT)' -A '$(AUTHOR)' -V '$(VERSION)' -R '$(RELEASE)' -o $(DOCSRCDIR) $(SRCDIR)
@sed -i "" -e 's/path\.insert\(.*\)$$/path.append\('\''..\/..'\''\)/' -e "s/alabaster/$(DOCTHEME)/" $(DOCSRCDIR)/conf.py
docs-clean:
@rm -rf $(DOCSDIR)/_* $(DOCSDIR)/*.* $(DOCSDIR)/.buildinfo $(DOCSRCDIR)/_build/html $(DOCSRCDIR)/_build/doctrees

html:
docs-build: version
@echo "Compiling package documentation"
@sphinx-apidoc -f -F -e -a -l -d 5 -H '$(PROJECT)' -A '$(AUTHOR)' -V '$(VERSION)' -R '$(RELEASE)' -o $(DOCSRCDIR) $(SRCDIR)
@sed -i '' -e 's/path\.insert\(.*\)$$/path.append\('\''..\/..'\''\)/' -e "s/alabaster/$(DOCTHEME)/" $(DOCSRCDIR)/conf.py

docs-html: docs-clean
@cd $(DOCSRCDIR) && make html
@echo "Moving HTML files to docs directory"
@echo 'Moving HTML files to docs directory'
@cp -af $(DOCSRCDIR)/_build/html/. $(DOCSDIR)
@echo "Removing source"
@rm -rf $(DOCSRCDIR)
@echo "Configuring docs for Github pages"
@echo 'Configuring docs for Github pages'
@echo '$(DOMAIN)' > $(DOCSDIR)/CNAME
@echo "Documentation successfully created."
@echo 'Documentation successfully created.'
@touch $(DOCSDIR)/.nojekyll

html-docs:
@make docs
@make html

run: setup
@python3 ./example/app.py
docs-auto: docs-build docs-html

.PHONY:
setup
help
test
clean-build
version
setup
clean
build
publish
test-publish
rmd
docs
html
html-docs
run
install
63 changes: 47 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A python package for clap detection

**Platforms Supported:** *Raspberry Pi, Linux, MacOS*

### H/w Requirements
### Hardware Requirements

* Raspberry Pi
* Microphone [5]
Expand All @@ -36,14 +36,14 @@ A python package for clap detection
### Setting up Raspberry Pi

1. [Download Raspbian OS](http://www.raspberrypi.org/downloads/)
2. [Install Raspbian OS in RPi](http://www.raspberrypi.org/documentation/installation/installing-images/)
2. Install Raspbian OS in RPi [4]
3. Plugin the USB input audio device(Audio Card or Microphone)
4. Configure OS after OS bootup [6] `sudo raspi-config`
5. Update OS `sudo apt-get update && sudo apt-get upgrade -y`
6. Reboot `sudo reboot` (This should enable the audio driver for the device connected)
7. Install pip & portaudio module `sudo apt-get install -y python3-pip portaudio19-dev`
8. Install pi-clap pip module `pip3 install pi-clap`
9. Connect the output line to BCM #24 & #13 Pin on RPi.
9. Connect the output line to BCM #4 & #6 Pin on Raspberry Pi.

( Try 2 claps to activate the output line for 1 sec and 3 claps to toggle ON/OFF state of given PIN. Note: Use 4 claps to exit from the system )

Expand Down Expand Up @@ -87,19 +87,30 @@ pip3 install pyaudio munch || pip3 install --global-option='build_ext' --global-
```
# Example code for using the package
from piclap.listener import Listener
from piclap.settings import Settings
from piclap import Listener, Settings
def main():
config = Settings() # Optional
config.chunk_size = 512 # Reduce as power of 2 if pyaudio overflow
config.interval = 1 # Adjust interval between claps
config.customPin = 13 # Custom config variable
listener = Listener(config) # 'config' argument is optional
listener.start()
if __name__ == '__main__':
main()
class Config(Settings):
'''This is an user defined derived class with `piclap.Settings` as base class'''
def __init__(self):
'''Defines new and override existing properties here'''
super().__init__()
self.chunk_size = 512 # Reduce as power of 2 if pyaudio overflow
self.interval = 1.0 # Adjust interval between claps
self.method.value = 300 # Threshold value adjustment
def on2Claps(self):
'''Custom action for 2 claps'''
self.controller.flashLight(pin=4)
def on3Claps(self):
'''Custom action for 3 claps'''
self.controller.toggleLight(pin=6)
config = Config()
listener = Listener(config)
listener.start()
```

Expand All @@ -114,12 +125,32 @@ pip3 install pi-clap
```
git clone https://github.com/nikhiljohn10/pi-clap
cd pi-clap
python3 tests/app.py
python3 ./example/app.py
```

### License

[MIT](https://github.com/nikhiljohn10/pi-clap/blob/master/LICENSE)
**[MIT License](https://github.com/nikhiljohn10/pi-clap/blob/master/LICENSE)**

Copyright (c) 2020 Nikhil John

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

### References

Expand Down
2 changes: 1 addition & 1 deletion docs/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 0b439e30450ee9ffe205edb13efc4135
config: 19ef8bce55a55439ac947821f766704a
tags: 645f666f9bcd5a90fca523b33c5a78b7

0 comments on commit bfdb7af

Please sign in to comment.