Skip to content
This repository was archived by the owner on Sep 16, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MAINTAINER Clifton Barnes <[email protected]>

RUN apt-get update
RUN apt-get install -y python python-dev python-pip python-smbus nginx build-essential git libssl-dev
RUN pip install flask flask-socketio gevent uwsgi
RUN pip install flask flask-socketio gevent uwsgi Sphinx==1.4.8 sphinx_rtd_theme

EXPOSE 80

Expand Down
2 changes: 1 addition & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if [ ! -e ${ADAFRUIT_DIR} ]; then
fi

apt-get install -y python python-dev python-pip python-smbus nginx build-essential git libssl-dev
pip install flask flask-socketio gevent uwsgi
pip install flask flask-socketio gevent uwsgi Sphinx==1.4.8 sphinx_rtd_theme

pushd ${ADAFRUIT_DIR} > /dev/null
python setup.py install
Expand Down
66 changes: 65 additions & 1 deletion www/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
# Let SocketIO choose the best async mode
async_mode = 'gevent_uwsgi'
app = Flask(__name__)
socketio = SocketIO(app, async_mode=async_mode)
try:
socketio = SocketIO(app, async_mode=async_mode)
except:
# Needed for sphinx documentation
socketio = SocketIO(app)
thread = None

pwm = pwmLib.get_platform_pwm(pwmtype="softpwm")
Expand All @@ -19,6 +23,19 @@
binary_sensors = []

class BinarySensor:
"""
The binary sensor object contains all of the important information for each
binary sensor

:param name:
The human readable name of the sensor
:param pin:
The hardware pin connected to the sensor
:param rising_event:
The event name associated with a signal changing from low to high
:param falling_event:
The event name associated with a signal changing from high to low
"""
def __init__(self, name, pin, rising_event, falling_event):
self.name = name
self.pin = pin
Expand All @@ -27,6 +44,9 @@ def __init__(self, name, pin, rising_event, falling_event):
self.old_val = False

def sensors_thread():
"""
Scans each binary sensor and sends events based on changes
"""
while True:
global binary_sensors
socketio.sleep(0.2)
Expand Down Expand Up @@ -58,6 +78,11 @@ def test_message(message):

@app.route('/api/v1/blockdiagrams', methods=['GET'])
def get_block_diagrams():
"""
API: /blockdiagrams [GET]

Replies with a JSON formatted list of the block diagrams
"""
names = []
for f in listdir('saved-bds'):
if isfile(join('saved-bds', f)) and f.endswith('.xml'):
Expand All @@ -66,6 +91,11 @@ def get_block_diagrams():

@app.route('/api/v1/blockdiagrams', methods=['POST'])
def save_block_diagram():
"""
API: /blockdiagrams [POST]

Saves the posted block diagram
"""
designName = request.form['designName'].replace(' ', '_').replace('.', '_')
bdString = request.form['bdString']
root = xml.etree.ElementTree.Element("root")
Expand All @@ -79,6 +109,12 @@ def save_block_diagram():

@app.route('/api/v1/blockdiagrams/<string:id>', methods=['GET'])
def get_block_diagram(id):
"""
API: /blockdiagrams/<id> [GET]

Replies with an XML formatted description of the block diagram specified by
`id`
"""
id = id.replace(' ', '_').replace('.', '_')
bd = [f for f in listdir('saved-bds') if isfile(join('saved-bds', f)) and id in f]
with open(join('saved-bds',bd[0]), 'r') as content_file:
Expand All @@ -87,13 +123,23 @@ def get_block_diagram(id):

@app.route('/api/v1/download/<string:id>', methods = ['GET'])
def download_block_diagram(id):
"""
API: /download/<id> [GET]

Starts a download of the block diagram specified by `id`
"""
if isfile(join('saved-bds', id)):
return send_from_directory('saved-bds', id, mimetype='text/xml', as_attachment=True)
else:
return ('', 404)

@app.route('/api/v1/upload', methods = ['POST'])
def upload_block_diagram():
"""
API: /upload [POST]

Adds the posted block diagram
"""
if 'fileToUpload' not in request.files:
return ('', 400)
file = request.files['fileToUpload']
Expand All @@ -116,10 +162,22 @@ def upload_block_diagram():

@app.route('/api/v1/sendcommand', methods = ['POST'])
def send_command():
"""
API: /sendcommand [POST]

Executes the posted command

**Available Commands:**::
START_MOTOR
STOP_MOTOR
"""
run_command(request.form)
return jsonify(request.form)

def init_rover_service():
"""
Initializes hardware pins and motor speeds
"""
# set up IR sensor gpio
gpio.setup("XIO-P2", gpioLib.IN)
gpio.setup("XIO-P4", gpioLib.IN)
Expand Down Expand Up @@ -159,6 +217,12 @@ def set_speed(self, pin, speed):
self.started_motors.append(pin)

def run_command(decoded):
"""
Runs the command specified by `decoded`

:param decoded:
The command to run
"""
print decoded['command']
global motor_manager
if decoded['command'] == 'START_MOTOR':
Expand Down
2 changes: 2 additions & 0 deletions www/docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_build
_autosummary
20 changes: 20 additions & 0 deletions www/docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = Rovercode
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
7 changes: 7 additions & 0 deletions www/docs/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
API
====================================================================

.. autosummary::
:toctree: _autosummary

app
163 changes: 163 additions & 0 deletions www/docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# -*- coding: utf-8 -*-
#
# Rovercode documentation build configuration file, created by
# sphinx-quickstart on Mon Dec 26 16:06:49 2016.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))

# -- General configuration ------------------------------------------------
autoclass_content = "both" # include both class docstring and __init__
autodoc_default_flags = [
# Make sure that any autodoc declarations show the right members
"members",
"inherited-members",
"private-members",
"show-inheritance",
]
autosummary_generate = True
# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = u'Rovercode'
copyright = u'2016, Brady L. Hurlburt and other rovercode.org contributers'
author = u'Brady L. Hurlburt and other rovercode.org contributers'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u'0.2.0'
# The full version, including alpha/beta/rc tags.
release = u'0.2.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False


# -- Options for HTML output ----------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'Rovercodedoc'


# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'Rovercode.tex', u'Rovercode Documentation',
u'Brady L. Hurlburt and other rovercode.org contributers', 'manual'),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'rovercode', u'Rovercode Documentation',
[author], 1)
]


# -- Options for Texinfo output -------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'Rovercode', u'Rovercode Documentation',
author, 'Rovercode', 'One line description of project.',
'Miscellaneous'),
]
20 changes: 20 additions & 0 deletions www/docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. Rovercode documentation master file, created by
sphinx-quickstart on Mon Dec 26 16:06:49 2016.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to Rovercode's documentation!
=====================================

.. toctree::
:maxdepth: 2
:caption: Contents:

api

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`