diff --git a/.gitignore b/.gitignore index 41c99f79f..1855ea7a8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ build/ # Object files *.o *.lib +*.so.* *.so *.lo *.la @@ -20,3 +21,16 @@ package.json binding.gyp READMEFIRST npm-debug.log + +# lua files +src/lua/mraaLUA_wrap.cxx + +# CMake +CMakeFiles +CMakeCache.txt +cmake_install.cmake +CTestTestfile.cmake +Makefile + +# Gen files +arch.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b3910bb3..7b15e1283 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,7 @@ option (BUILDSWIG "Build swig modules." ON) option (BUILDSWIGPYTHON "Build swig python modules." ON) option (BUILDSWIGNODE "Build swig node modules." ON) option (BUILDSWIGJAVA "Build Java API." OFF) +option (BUILDSWIGLUA "Build Lua API." OFF) option (USBPLAT "Detection USB platform." OFF) option (FIRMATA "Add Firmata support to mraa." OFF) option (ONEWIRE "Add Onewire support to mraa." ON) @@ -87,6 +88,7 @@ if (NOT BUILDSWIG) set (BUILDSWIGPYTHON OFF) set (BUILDSWIGNODE OFF) set (BUILDSWIGJAVA OFF) + set (BUILDSWIGLUA OFF) endif() if (NOT BUILDARCH) diff --git a/examples/lua/aio.lua b/examples/lua/aio.lua new file mode 100644 index 000000000..1fa71d5ab --- /dev/null +++ b/examples/lua/aio.lua @@ -0,0 +1,31 @@ +#!/usr/bin/env lua + +-- Author: Vasiliy Soshnikov +-- Copyright (c) 2016 Intel Corporation. +-- +-- 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 +-- NONINFRINGEMENT. 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. + +mraa = require('mraa') + +print (mraa.getVersion()) + +x = mraa.Aio(0) +print (x:read()) +print ("%.5f" % x:readFloat()) diff --git a/examples/lua/blink-io8.lua b/examples/lua/blink-io8.lua new file mode 100644 index 000000000..8852cb4b4 --- /dev/null +++ b/examples/lua/blink-io8.lua @@ -0,0 +1,42 @@ +#!/usr/bin/env lua + +-- Author: Vasiliy Soshnikov +-- Copyright (c) 2016 Intel Corporation. +-- +-- 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 +-- NONINFRINGEMENT. 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. + +mraa = require('mraa') +os = require('os') + +x = mraa.Gpio(8) +x:dir(mraa.DIR_OUT) + +local function my_sleep(sec) + os.execute('sleep ' .. tonumber(sec)) +end + +while true do + -- On + x:write(1) + my_sleep(0.2) + -- off + x:write(0) + my_sleep(0.2) +end diff --git a/examples/lua/cycle-pwm3.lua b/examples/lua/cycle-pwm3.lua new file mode 100644 index 000000000..492eb8c20 --- /dev/null +++ b/examples/lua/cycle-pwm3.lua @@ -0,0 +1,44 @@ +#!/usr/bin/env lua + +-- Author: Vasiliy Soshnikov +-- Copyright (c) 2016 Intel Corporation. +-- +-- 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 +-- NONINFRINGEMENT. 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. + +mraa = require('mraa') +os = require('os') + +local function my_sleep(sec) + os.execute('sleep ' .. tonumber(sec)) +end + +x = mraa.Pwm(3) +x:period_us(700) +x:enable(true) +value = 0.0 + +while true do + x:write(value) + my_sleep(0.05) + value = value + 0.01 + if value >= 1 then + value = 0.0 + end +end diff --git a/examples/lua/firmata.lua b/examples/lua/firmata.lua new file mode 100644 index 000000000..3ea4f5014 --- /dev/null +++ b/examples/lua/firmata.lua @@ -0,0 +1,29 @@ +#!/usr/bin/env lua + +-- Author: Soshnikov Vasiliy +-- Copyright (c) 2016 Intel Corporation. +-- +-- 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 +-- NONINFRINGEMENT. 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. + +mraa = require('mraa') + +print (mraa.getVersion()) + +mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0"); diff --git a/examples/lua/hello_gpio.lua b/examples/lua/hello_gpio.lua new file mode 100644 index 000000000..114591ab1 --- /dev/null +++ b/examples/lua/hello_gpio.lua @@ -0,0 +1,30 @@ +#!/usr/bin/env lua + +-- Author: Vasiliy Soshnikov +-- Copyright (c) 2016 Intel Corporation. +-- +-- 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 +-- NONINFRINGEMENT. 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. + +mraa = require('mraa') + +print (mraa.getVersion()) +x = mraa.Gpio(13) +x:dir(mraa.DIR_OUT) +x:write(1) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 675d897e3..db400c5d0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -204,6 +204,9 @@ if (BUILDSWIG) message (SEND_ERROR "SWIG is ${SWIG_VERSION}. Please upgrade to 3.0.5+ to build nodejs addon") endif () endif () + if (BUILDSWIGLUA) + add_subdirectory (lua) + endif() endif () endif () diff --git a/src/lua/CMakeLists.txt b/src/lua/CMakeLists.txt new file mode 100644 index 000000000..e172e8e1a --- /dev/null +++ b/src/lua/CMakeLists.txt @@ -0,0 +1,50 @@ +find_package (Lua REQUIRED) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/.. + ${LUA_INCLUDE_DIR} +) + +set_source_files_properties (mraa.i PROPERTIES CPLUSPLUS ON) +set_source_files_properties (mraa.i PROPERTIES SWIG_FLAGS "-I${CMAKE_BINARY_DIR}/src") +swig_add_module (lua-mraa lua mraa.i) +swig_link_libraries (lua-mraa mraa ${LUA_LIBRARIES}) + +if (DOXYGEN_FOUND) + foreach (_file ${DOCCLASSES}) + add_dependencies (${SWIG_MODULE_lua-mraa_REAL_NAME} ${_file}class_doc_i) + endforeach () + add_dependencies (${SWIG_MODULE_lua-mraa_REAL_NAME} common_hpp_doc_i) + + add_custom_target (pydoc + pydoc -w ${CMAKE_CURRENT_BINARY_DIR}/mraa.py ${CMAKE_CURRENT_BINARY_DIR}/ + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Generating API documentation with pydoc" VERBATIM + ) +endif () + +set_target_properties (${SWIG_MODULE_lua-mraa_REAL_NAME} PROPERTIES + OUTPUT_NAME mraa + COMPILE_FLAGS "${CMAKE_C_FLAGS} -DSWIG=${SWIG_FOUND}" +) + +execute_process ( + COMMAND lua -e + "string.gsub(package.path, '[^;]+', function(e) + if e:find('/usr/local') == 1 then + p = e:gsub('(?.lua)', '') + io.write(p) + os.exit(0) + end + end) + os.exit(1) + " + OUTPUT_VARIABLE LUA_SITE_DIR +) + +install (FILES ${CMAKE_CURRENT_BINARY_DIR}/mraa.so + DESTINATION ${LUA_SITE_DIR}) + +message(STATUS "Lua site dir: ${LUA_SITE_DIR}") + +add_subdirectory (docs) diff --git a/src/lua/docs/CMakeLists.txt b/src/lua/docs/CMakeLists.txt new file mode 100644 index 000000000..6fb2c5749 --- /dev/null +++ b/src/lua/docs/CMakeLists.txt @@ -0,0 +1,41 @@ +if (DOXYGEN_FOUND) + find_package (Sphinx) + if (SPHINX_FOUND) + if (NOT DEFINED SPHINX_THEME) + set (SPHINX_THEME default) + endif () + + if (NOT DEFINED SPHINX_THEME_DIR) + set (SPHINX_THEME_DIR) + endif () + + # configured documentation tools and intermediate build results + set (BINARY_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}") + + # Sphinx cache with pickled ReST documents + set (SPHINX_CACHE_DIR "${CMAKE_CURRENT_BINARY_DIR}/doctrees") + + # HTML output directory + set (SPHINX_HTML_DIR "${CMAKE_CURRENT_BINARY_DIR}/html") + + # doc .rst locations + set (SPHINX_DOC_LOATION "${CMAKE_CURRENT_SOURCE_DIR}") + + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/conf.py.in" + "${BINARY_BUILD_DIR}/conf.py" + @ONLY + ) + + add_custom_target(sphinx ALL + ${SPHINX_EXECUTABLE} -b html + -c "${BINARY_BUILD_DIR}" + -d "${SPHINX_CACHE_DIR}" + "${SPHINX_DOC_LOATION}" + "${SPHINX_HTML_DIR}" + COMMENT "Building HTML documentation with Sphinx" + ) + + add_dependencies (sphinx ${SWIG_MODULE_lua-mraa_REAL_NAME}) + endif () +endif () diff --git a/src/lua/docs/conf.py.in b/src/lua/docs/conf.py.in new file mode 100644 index 000000000..552a54e14 --- /dev/null +++ b/src/lua/docs/conf.py.in @@ -0,0 +1,332 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# . documentation build configuration file, created by +# sphinx-quickstart on Thu May 1 18:34:23 2014. +# +# 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. + +import sys +import os + +# 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. +sys.path.insert(0, "@CMAKE_BINARY_DIR@/src/lua") + +# -- General configuration ------------------------------------------------ + +# 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.viewcode', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = 'mraa' +copyright = '2016, Intel Corporation' + +# 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 = '@mraa_VERSION_STRING@' +# The full version, including alpha/beta/rc tags. +release = '@VERSION@' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build', '**/.git', '**/CMakeFiles/**', '**/CMakeLists.txt'] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = 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_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 themes here, relative to this directory. +html_theme_path = ['@SPHINX_THEME_DIR@'] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# 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'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'mraadoc' + + +# -- 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': '', +} + +# 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 = [ + ('index', 'sphinx.tex', '. Documentation', + 'Author', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'sphinx', '. Documentation', + ['Author'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- 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 = [ + ('index', 'sphinx', '. Documentation', + 'Author', 'sphinx', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False + + +# -- Options for Epub output ---------------------------------------------- + +# Bibliographic Dublin Core info. +epub_title = '.' +epub_author = 'Author' +epub_publisher = 'Author' +epub_copyright = '2014, Author' + +# The basename for the epub file. It defaults to the project name. +#epub_basename = '.' + +# The HTML theme for the epub output. Since the default themes are not optimized +# for small screen space, using the same theme for HTML and epub output is +# usually not wise. This defaults to 'epub', a theme designed to save visual +# space. +#epub_theme = 'epub' + +# The language of the text. It defaults to the language option +# or en if the language is not set. +#epub_language = '' + +# The scheme of the identifier. Typical schemes are ISBN or URL. +#epub_scheme = '' + +# The unique identifier of the text. This can be a ISBN number +# or the project homepage. +#epub_identifier = '' + +# A unique identification for the text. +#epub_uid = '' + +# A tuple containing the cover image and cover page html template filenames. +#epub_cover = () + +# A sequence of (type, uri, title) tuples for the guide element of content.opf. +#epub_guide = () + +# HTML files that should be inserted before the pages created by sphinx. +# The format is a list of tuples containing the path and title. +#epub_pre_files = [] + +# HTML files shat should be inserted after the pages created by sphinx. +# The format is a list of tuples containing the path and title. +#epub_post_files = [] + +# A list of files that should not be packed into the epub file. +epub_exclude_files = ['search.html'] + +# The depth of the table of contents in toc.ncx. +#epub_tocdepth = 3 + +# Allow duplicate toc entries. +#epub_tocdup = True + +# Choose between 'default' and 'includehidden'. +#epub_tocscope = 'default' + +# Fix unsupported image types using the PIL. +#epub_fix_images = False + +# Scale large images. +#epub_max_image_width = 0 + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#epub_show_urls = 'inline' + +# If false, no index is generated. +#epub_use_index = True diff --git a/src/lua/docs/example.rst b/src/lua/docs/example.rst new file mode 100644 index 000000000..edd2c177e --- /dev/null +++ b/src/lua/docs/example.rst @@ -0,0 +1,41 @@ +####### +Example +####### +Here are some examples of how to use mraa, common convention is to +require('mraa'). As a general rule the API is very similar to the C++ API so +there are only basic examples to show quick usage. The mraa module can be +built with lua 5.1+, luajit 5.1+, Tarantool. + +Hello GPIO +========== + +Here is the simplest Gpio program in mraa. + +.. literalinclude:: ../../../examples/lua/hello_gpio.lua + + :prepend: require('mraa') + :start-after: require('mraa') + +Aio +=== + +The ADC is typically provided on a dedicated or shared SPI bus, this is +abstracted by the Linux kernel as spidev and abstracted again by mraa. It is +fairly simple in use. + +.. literalinclude:: ../../../examples/lua/aio.lua + + :prepend: require('mraa') + :start-after: require('mraa') + +Pwm +=== + +The PWM module is rather simple, note that different hardware support PWM +generation is various different ways so results may vary. + +.. literalinclude:: ../../../examples/lua/cycle-pwm3.lua + + :prepend: require('mraa') + :start-after: require('mraa') + diff --git a/src/lua/docs/index.rst b/src/lua/docs/index.rst new file mode 100644 index 000000000..bb0ad9273 --- /dev/null +++ b/src/lua/docs/index.rst @@ -0,0 +1,57 @@ +.. . documentation master file, created by + sphinx-quickstart on Thu May 1 18:34:23 2014. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to mraa's documentation! +================================ + +.. include:: ../../../docs/index.md + :start-after: ============== + :end-before: ## API + +.. toctree:: + :maxdepth: 2 + + mraa + example + +Supported Platforms +=================== + + * `Galileo Gen 1 - Rev D <../galileorevd.html>`_ + * `Galileo Gen 2 - Rev H <../galileorevh.html>`_ + * `Intel Edison <../edison.html>`_ + * `Intel(R) NUC DE3815tykhe <../de3815.html>`_ + * `Intel(R) Minnowboard Max <../minnowmax.html>`_ + * `Raspberry Pi <../rasppi.html>`_ + * `Banana Pi/Pro <../bananapi.html>`_ + * `Beaglebone Black <../beaglebone.html>`_ + * `Intel NUC NUC5i5MYBE <../nuc5.html>`_ + * `UP <../up.html>`_ + * `FTDI FT4222H <../ft4222.html>`_ + +Compiling & Debugging libmraa +============================= + +Libmraa is a C library and SWIG is used to generate bindings therefore to +debug, you very quickly need to use the same methods as you would for debugging +a C library. Generally attaching gdb to lua works well, build mraa with +debug symbols and set breakpoints either in the SWIG _wrap functions, the C++ +method/functions or the underlying C function. More info can be found on the +C/C++ documentation: + * `Debugging <../debugging.html>`_ + * `Building from source <../building.html>`_ + +API Changelog +============= +.. include:: ../../../docs/index.md + :start-after: API Changelog + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` + diff --git a/src/lua/docs/mraa.rst b/src/lua/docs/mraa.rst new file mode 100644 index 000000000..04e7c1e48 --- /dev/null +++ b/src/lua/docs/mraa.rst @@ -0,0 +1,52 @@ +### +API +### + +Aio +=== +.. autoclass:: mraa.Aio + :members: + :undoc-members: + :show-inheritance: + +I2c +=== +.. autoclass:: mraa.I2c + :members: + :undoc-members: + :show-inheritance: + +Gpio +==== +.. autoclass:: mraa.Gpio + :members: + :undoc-members: + :show-inheritance: + +Pwm +=== +.. autoclass:: mraa.Pwm + :members: + :undoc-members: + :show-inheritance: + +Spi +=== +.. autoclass:: mraa.Spi + :members: + :undoc-members: + :show-inheritance: + +Uart +==== +.. autoclass:: mraa.Uart + :members: + :undoc-members: + :show-inheritance: + +Common +====== + +.. automodule:: mraa + :members: + :exclude-members: Gpio, Aio, Uart, Spi, I2c, Pwm, uint8Array, uint8Array_frompointer diff --git a/src/lua/mraa.i b/src/lua/mraa.i new file mode 100644 index 000000000..ea265ac98 --- /dev/null +++ b/src/lua/mraa.i @@ -0,0 +1,18 @@ +%module(docstring="Lua interface to libmraa") mraa + +%inline %{ + #include +%} + +%include typemaps.i +%include carrays.i + +%array_class(uint8_t, uint8Array); + +%include ../mraa.i + +%init %{ + //Adding mraa_init() to the module initialisation process + if (mraa_init() != MRAA_SUCCESS) + fprintf(stderr, "Lua Runtime Error: mraa_init() failed.\n"); +%}