diff options
author | Rafael Laboissière <rafael@debian.org> | 2024-01-01 14:23:17 -0300 |
---|---|---|
committer | Rafael Laboissière <rafael@debian.org> | 2024-01-01 14:23:17 -0300 |
commit | b31bb4aedb83517ed26f22084f9742a7a2c8b079 (patch) | |
tree | f64b489beb5da79f7f3f7cda234c0836836fd71a | |
parent | d6d7e9066885158c9534cb307d89168b620ac760 (diff) |
New upstream version 0.12.0
49 files changed, 485 insertions, 168 deletions
diff --git a/DESCRIPTION b/DESCRIPTION index 676412b..1991fc8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Name: arduino -Version: 0.11.0 -Date: 2023-07-19 +Version: 0.12.0 +Date: 2023-12-22 Author: John Donoghue <john.donoghue@ieee.org> Maintainer: John Donoghue <john.donoghue@ieee.org> Title: Octave Arduino Toolkit @@ -1,3 +1,17 @@ +Summary of important user-visible changes for arduino 0.12.0: +------------------------------------------------------------------- + + ** Minor doc changes + + ** New Board Configurations: + - Arduino Nano ESP32 + + ** Support for different communication baudrates + + ** Added additional scanForArduinos functionality + + ** expanded search for arduino binary + Summary of important user-visible changes for arduino 0.11.0: ------------------------------------------------------------------- @@ -88,6 +88,8 @@ Currently the toolkit recognizes these boards: * nano rp2040 connect +* nano esp32 + * promini * promicro diff --git a/doc/arduino.css b/doc/arduino.css index 3c116ef..ebe2bea 100644 --- a/doc/arduino.css +++ b/doc/arduino.css @@ -17,3 +17,14 @@ table.cartouche td, table.cartouche th { border: 1px solid #948473; padding: 4px 4px; } + +/* newer texinfo generation styles */ +div.example { + /* base00 ~ body text in light solarized theme */ + color: #657b83; + border-color: #657b83; } + +pre.example-preformatted { + /* base3 ~ background color in light solarized theme */ + background-color: #fdf6e3; + padding: 0.5em; } diff --git a/doc/arduino.html b/doc/arduino.html index 4d374ee..a737072 100644 --- a/doc/arduino.html +++ b/doc/arduino.html @@ -1,6 +1,6 @@ <!DOCTYPE html> <html> -<!-- Created by GNU Texinfo 7.0.2, https://www.gnu.org/software/texinfo/ --> +<!-- Created by GNU Texinfo 7.0.3, https://www.gnu.org/software/texinfo/ --> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Arduino Toolkit - a somewhat Matlab compatible arduino toolkit for GNU octave.</title> @@ -387,7 +387,7 @@ octave-forge using the following command within <abbr class="acronym">GNU</abbr> <abbr class="acronym">GNU</abbr> Octave, the package can be installed using the following command within <abbr class="acronym">GNU</abbr> Octave: </p> <div class="example"> -<pre class="example-preformatted">pkg install arduino-0.11.0.tar.gz +<pre class="example-preformatted">pkg install arduino-0.12.0.tar.gz </pre></div> </div> @@ -1657,10 +1657,12 @@ Next: <a href="#Arduino-Functions" accesskey="n" rel="next">Arduino Functions</a <h4 class="subsection">9.1.4 scanForArduinos</h4> <a class="index-entry-id" id="index-scanForArduinos"></a> <dl class="first-deftypefn"> -<dt class="deftypefn" id="index-scanForArduinos-1"><span class="category-def">: </span><span><code class="def-type"><var class="var">retval</var> =</code> <strong class="def-name">scanForArduinos</strong> <code class="def-code-arguments">(<var class="var">maxCount</var>)</code><a class="copiable-link" href='#index-scanForArduinos-1'> ¶</a></span></dt> -<dt class="deftypefnx def-cmd-deftypefn" id="index-scanForArduinos-2"><span class="category-def">: </span><span><code class="def-type"><var class="var">retval</var> =</code> <strong class="def-name">scanForArduinos</strong> <code class="def-code-arguments">(<var class="var">"debug"</var>)</code><a class="copiable-link" href='#index-scanForArduinos-2'> ¶</a></span></dt> -<dt class="deftypefnx def-cmd-deftypefn" id="index-scanForArduinos-3"><span class="category-def">: </span><span><code class="def-type"><var class="var">retval</var> =</code> <strong class="def-name">scanForArduinos</strong> <code class="def-code-arguments">(<var class="var">maxCount</var>, <var class="var">type</var>)</code><a class="copiable-link" href='#index-scanForArduinos-3'> ¶</a></span></dt> -<dd><p>Scan system for programmed arduino boards. +<dt class="deftypefn" id="index-scanForArduinos-1"><span class="category-def">: </span><span><code class="def-type"><var class="var">retval</var> =</code> <strong class="def-name">scanForArduinos</strong> <code class="def-code-arguments">()</code><a class="copiable-link" href='#index-scanForArduinos-1'> ¶</a></span></dt> +<dt class="deftypefnx def-cmd-deftypefn" id="index-scanForArduinos-2"><span class="category-def">: </span><span><code class="def-type"><var class="var">retval</var> =</code> <strong class="def-name">scanForArduinos</strong> <code class="def-code-arguments">(<var class="var">maxCount</var>)</code><a class="copiable-link" href='#index-scanForArduinos-2'> ¶</a></span></dt> +<dt class="deftypefnx def-cmd-deftypefn" id="index-scanForArduinos-3"><span class="category-def">: </span><span><code class="def-type"><var class="var">retval</var> =</code> <strong class="def-name">scanForArduinos</strong> <code class="def-code-arguments">(<var class="var">"debug"</var>)</code><a class="copiable-link" href='#index-scanForArduinos-3'> ¶</a></span></dt> +<dt class="deftypefnx def-cmd-deftypefn" id="index-scanForArduinos-4"><span class="category-def">: </span><span><code class="def-type"><var class="var">retval</var> =</code> <strong class="def-name">scanForArduinos</strong> <code class="def-code-arguments">(<var class="var">maxCount</var>, <var class="var">type</var>)</code><a class="copiable-link" href='#index-scanForArduinos-4'> ¶</a></span></dt> +<dt class="deftypefnx def-cmd-deftypefn" id="index-scanForArduinos-5"><span class="category-def">: </span><span><code class="def-type"><var class="var">retval</var> =</code> <strong class="def-name">scanForArduinos</strong> <code class="def-code-arguments">(<var class="var">propertyname</var>, <var class="var">propertvalue</var> ...)</code><a class="copiable-link" href='#index-scanForArduinos-5'> ¶</a></span></dt> +<dd><p>Scan system for programmed serial connected arduino boards. </p> <p>scanForArduinos will scan the system for programmed arduino boards and return at most <var class="var">maxCount</var> of them as a cell array @@ -1678,6 +1680,22 @@ Next: <a href="#Arduino-Functions" accesskey="n" rel="next">Arduino Functions</a scanForArduinos will display debug information as it scans all available ports for arduinos. </p> +<p><var class="var">propertyname</var>, <var class="var">propertyvalue</var> - property name/value pairs to match search with. +</p><dl class="table"> +<dt>’BaudRate’</dt> +<dd><p>Numeric BaudRate to use when trying to scan for arduinos. +</p></dd> +<dt>’MaxCount’</dt> +<dd><p>Max number of arduinos to scan for. +</p></dd> +<dt>’BoardType’</dt> +<dd><p>Boardtype to match. +</p></dd> +<dt>’Debug’</dt> +<dd><p>Logical flag for debug mode. +</p></dd> +</dl> + <h4 class="subsubheading" id="Outputs-3">Outputs</h4> <p><var class="var">retval</var> structure cell array of matching detected arduino boards. </p> @@ -1767,8 +1785,23 @@ Next: <a href="#Arduino-I2C-Functions" accesskey="n" rel="next">Arduino I2C Func for additional properties to pass to the creation of the arduino object. </p> -<p>Currently properties are ignored. -</p> +<p>Currently properties are ignored, with the exception of: +</p><dl class="table"> +<dt>debug</dt> +<dd><p>true / false flag for whether setting debug (default false) +</p></dd> +<dt>forcebuildon</dt> +<dd><p>true / false flag for whether to force show of the arduino IDE to + rebuild the installed code on the arduino (default false) +</p></dd> +<dt>baudrate (read only)</dt> +<dd><p>the communications baudrate to the board. (default 9600) +</p></dd> +<dt>libraries</dt> +<dd><p>The libraries to be enabled on the arduino board. (default uses whatever is already installed) +</p></dd> +</dl> + <p>if the arduino function is called without parameters, it will scan for the first available arduino it can find and connect to it. </p> @@ -1782,7 +1815,7 @@ Next: <a href="#Arduino-I2C-Functions" accesskey="n" rel="next">Arduino I2C Func <dd><p>name assigned to the arduino object </p></dd> <dt>debug</dt> -<dd><p>true / false flag for whether debug in turned on +<dd><p>true / false flag for whether debug is turned on </p></dd> <dt>forcebuildon</dt> <dd><p>true / false flag for whether to force show of the arduino IDE to @@ -1791,6 +1824,9 @@ Next: <a href="#Arduino-I2C-Functions" accesskey="n" rel="next">Arduino I2C Func <dt>port (read only)</dt> <dd><p>the communications port the board is connected to. </p></dd> +<dt>baudrate (read only)</dt> +<dd><p>the communications baudrate to the board. +</p></dd> <dt>board (read only)</dt> <dd><p>The name of the board type that the arduino connected to </p></dd> diff --git a/doc/arduino.pdf b/doc/arduino.pdf Binary files differindex 0400da9..bc50b9f 100644 --- a/doc/arduino.pdf +++ b/doc/arduino.pdf diff --git a/doc/arduino.qch b/doc/arduino.qch Binary files differindex 4df5b3e..d5a1d08 100644 --- a/doc/arduino.qch +++ b/doc/arduino.qch diff --git a/doc/arduino.qhc b/doc/arduino.qhc Binary files differindex 8107ce8..e62aeb9 100644 --- a/doc/arduino.qhc +++ b/doc/arduino.qhc diff --git a/doc/functions.texi b/doc/functions.texi index ae3ab04..f868a37 100644 --- a/doc/functions.texi +++ b/doc/functions.texi @@ -89,10 +89,12 @@ @c ----------------------------------------- @subsection scanForArduinos @cindex scanForArduinos -@deftypefn {} {@var{retval} =} scanForArduinos (@var{maxCount}) +@deftypefn {} {@var{retval} =} scanForArduinos () +@deftypefnx {} {@var{retval} =} scanForArduinos (@var{maxCount}) @deftypefnx {} {@var{retval} =} scanForArduinos (@var{"debug"}) @deftypefnx {} {@var{retval} =} scanForArduinos (@var{maxCount}, @var{type}) - Scan system for programmed arduino boards. +@deftypefnx {} {@var{retval} =} scanForArduinos (@var{propertyname}, @var{propertvalue} ...) + Scan system for programmed serial connected arduino boards. scanForArduinos will scan the system for programmed arduino boards and return at most @var{maxCount} of them as a cell array @@ -110,6 +112,18 @@ scanForArduinos will display debug information as it scans all available ports for arduinos. +@var{propertyname}, @var{propertyvalue} - property name/value pairs to match search with. +@table @asis +@item 'BaudRate' + Numeric BaudRate to use when trying to scan for arduinos. +@item 'MaxCount' + Max number of arduinos to scan for. +@item 'BoardType' + Boardtype to match. +@item 'Debug' + Logical flag for debug mode. +@end table + @subsubheading Outputs @var{retval} structure cell array of matching detected arduino boards. @@ -149,7 +163,18 @@ for additional properties to pass to the creation of the arduino object. - Currently properties are ignored. + Currently properties are ignored, with the exception of: +@table @asis +@item debug + true / false flag for whether setting debug (default false) +@item forcebuildon + true / false flag for whether to force show of the arduino IDE to + rebuild the installed code on the arduino (default false) +@item baudrate (read only) + the communications baudrate to the board. (default 9600) +@item libraries + The libraries to be enabled on the arduino board. (default uses whatever is already installed) +@end table if the arduino function is called without parameters, it will scan for the first available arduino it can find and connect to it. @@ -163,12 +188,14 @@ @item name name assigned to the arduino object @item debug - true / false flag for whether debug in turned on + true / false flag for whether debug is turned on @item forcebuildon true / false flag for whether to force show of the arduino IDE to reprogram the arduino @item port (read only) the communications port the board is connected to. +@item baudrate (read only) + the communications baudrate to the board. @item board (read only) The name of the board type that the arduino connected to @item libraries (read only) diff --git a/doc/version.texi b/doc/version.texi index d1654d0..743c811 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -1,4 +1,4 @@ @c autogenerated from Makefile -@set VERSION 0.11.0 +@set VERSION 0.12.0 @set PACKAGE arduino -@set DATE 2023-07-19 +@set DATE 2023-12-22 diff --git a/inst/+arduinoio/+config/config_due.m b/inst/+arduinoio/+config/config_due.m index e3cf167..34102a5 100644 --- a/inst/+arduinoio/+config/config_due.m +++ b/inst/+arduinoio/+config/config_due.m @@ -25,7 +25,7 @@ function retval = config_due (initdata) # default board info - must be provided # will be filled in on connection. retval.board = ''; - retval.board = ''; + retval.baudrate = 9600; retval.mcu = 'cortex-m3'; retval.voltref = 3.3; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_esp32_dev.m b/inst/+arduinoio/+config/config_esp32_dev.m index a6dc0eb..dda63b1 100644 --- a/inst/+arduinoio/+config/config_esp32_dev.m +++ b/inst/+arduinoio/+config/config_esp32_dev.m @@ -26,6 +26,7 @@ function retval = config_esp32_dev (initdata) # default board info - must be provided # will be filled in on connection. retval.board = ''; + retval.baudrate = 9600; retval.mcu = 'eps32'; retval.voltref = 0; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_leonardo.m b/inst/+arduinoio/+config/config_leonardo.m index e22eff7..3deaffe 100644 --- a/inst/+arduinoio/+config/config_leonardo.m +++ b/inst/+arduinoio/+config/config_leonardo.m @@ -25,6 +25,7 @@ function retval = config_leonardo (initdata) # default board info - must be provided # will be filled in on connection. retval.board = 'leonardo'; + retval.baudrate = 9600; retval.mcu = ''; retval.voltref = 0; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_lilypad.m b/inst/+arduinoio/+config/config_lilypad.m index 4ed4751..851aa4f 100644 --- a/inst/+arduinoio/+config/config_lilypad.m +++ b/inst/+arduinoio/+config/config_lilypad.m @@ -5,6 +5,7 @@ function retval = config_lilypad (initdata) # default board info - must be provided # will be filled in on connection. retval.board = ''; + retval.baudrate = 9600; retval.mcu = ''; retval.voltref = 0; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_mega2560.m b/inst/+arduinoio/+config/config_mega2560.m index caf43a0..c110d03 100644 --- a/inst/+arduinoio/+config/config_mega2560.m +++ b/inst/+arduinoio/+config/config_mega2560.m @@ -25,6 +25,7 @@ function retval = config_mega2560 (initdata) # default board info - must be provided # will be filled in on connection. retval.board = ''; + retval.baudrate = 9600; retval.mcu = ''; retval.voltref = 0; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_micro.m b/inst/+arduinoio/+config/config_micro.m index fd24cb4..8f76797 100644 --- a/inst/+arduinoio/+config/config_micro.m +++ b/inst/+arduinoio/+config/config_micro.m @@ -25,6 +25,7 @@ function retval = config_micro (initdata) # default board info - must be provided # will be filled in on connection. retval.board = 'micro'; + retval.baudrate = 9600; retval.mcu = ''; retval.voltref = 0; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_mkr1000.m b/inst/+arduinoio/+config/config_mkr1000.m index dc9a7f7..f469008 100644 --- a/inst/+arduinoio/+config/config_mkr1000.m +++ b/inst/+arduinoio/+config/config_mkr1000.m @@ -5,6 +5,7 @@ function retval = config_mkr1000 (initdata) # default board info - must be provided # will be filled in on connection. retval.board = ''; + retval.baudrate = 9600; retval.mcu = 'cortex-m0plus'; retval.voltref = 3.3; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_mkrzero.m b/inst/+arduinoio/+config/config_mkrzero.m index 5802ff0..cb44b7e 100644 --- a/inst/+arduinoio/+config/config_mkrzero.m +++ b/inst/+arduinoio/+config/config_mkrzero.m @@ -26,6 +26,7 @@ function retval = config_mkrzero (initdata) # default board info - must be provided # will be filled in on connection. retval.board = ''; + retval.baudrate = 9600; retval.mcu = 'cortex-m0plus'; retval.voltref = 3.3; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_nano.m b/inst/+arduinoio/+config/config_nano.m index 8c349bb..4e05661 100644 --- a/inst/+arduinoio/+config/config_nano.m +++ b/inst/+arduinoio/+config/config_nano.m @@ -25,6 +25,7 @@ function retval = config_nano (initdata) # default board info - must be provided # will be filled in on connection retval.board = "nano"; + retval.baudrate = 9600; retval.mcu = ''; retval.voltref = 50; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_nano_33_ble.m b/inst/+arduinoio/+config/config_nano_33_ble.m index 276defb..8e99e90 100644 --- a/inst/+arduinoio/+config/config_nano_33_ble.m +++ b/inst/+arduinoio/+config/config_nano_33_ble.m @@ -5,6 +5,7 @@ function retval = config_nano_33_ble (initdata) # default board info - must be provided # will be filled in on connection. retval.board = 'nano_33_ble'; + retval.baudrate = 9600; retval.mcu = 'nRF52840'; retval.voltref = 0; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_nano_esp32.m b/inst/+arduinoio/+config/config_nano_esp32.m new file mode 100644 index 0000000..6a5a18d --- /dev/null +++ b/inst/+arduinoio/+config/config_nano_esp32.m @@ -0,0 +1,65 @@ +## Copyright (C) 2023 John Donoghue <john.donoghue@ieee.org> +## +## This program is free software: you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program. If not, see +## <https://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {} {@var{retval} =} config_nano_esp32 (@var{initdata}) +## Private function for setting allowed modes of nano esp32 board pins +## @end deftypefn + +function retval = config_nano_esp32 (initdata) + retval = []; + # default board info - must be provided + # will be filled in on connection + retval.board = "nano_esp32"; + retval.baudrate = 9600; + retval.mcu = ''; + retval.voltref = 33; + retval.libs = {}; + retval.port = ""; + + # info expected to be provided by config. + retval.description = 'Arduino Nano ESP32 Board'; + + # pin config + retval.pins = {}; + retval.pins{end+1} = arduinoio.config.pin_info("D0", 0, { 'digital' , 'uart_rx'}); + retval.pins{end+1} = arduinoio.config.pin_info("D1", 1, { 'digital' , 'uart_tx'}); + retval.pins{end+1} = arduinoio.config.pin_info("D2", 2, { 'digital', 'interrupt' }); + retval.pins{end+1} = arduinoio.config.pin_info("D3", 3, { 'digital', 'pwm', 'interrupt' }); + retval.pins{end+1} = arduinoio.config.pin_info("D4", 4, { 'digital', 'interrupt' }); + retval.pins{end+1} = arduinoio.config.pin_info("D5", 5, { 'digital', 'pwm', 'interrupt' }); + retval.pins{end+1} = arduinoio.config.pin_info("D6", 6, { 'digital', 'pwm', 'interrupt' }); + retval.pins{end+1} = arduinoio.config.pin_info("D7", 7, { 'digital', 'interrupt' }); + retval.pins{end+1} = arduinoio.config.pin_info("D8", 8, { 'digital', 'interrupt' }); + retval.pins{end+1} = arduinoio.config.pin_info("D9", 9, { 'digital', 'pwm', 'interrupt' }); + retval.pins{end+1} = arduinoio.config.pin_info("D10", 10, { 'digital', 'pwm', 'spi0_ss', 'interrupt' }); + retval.pins{end+1} = arduinoio.config.pin_info("D11", 11, { 'digital', 'pwm', 'spi0_mosi', 'interrupt' }); + retval.pins{end+1} = arduinoio.config.pin_info("D12", 12, { 'digital', 'pwm', 'spi0_miso', 'interrupt' }); + retval.pins{end+1} = arduinoio.config.pin_info("D13", 13, { 'digital', 'pwm', 'spi0_sck', 'led', 'interrupt' }); + + retval.pins{end+1} = arduinoio.config.pin_info("D14", 14, { 'digital', 'pwm', 'led_r', 'interrupt' }); + retval.pins{end+1} = arduinoio.config.pin_info("D15", 15, { 'digital', 'pwm', 'led_g', 'interrupt' }); + retval.pins{end+1} = arduinoio.config.pin_info("D16", 16, { 'digital', 'pwm', 'led_b', 'interrupt' }); + + retval.pins{end+1} = arduinoio.config.pin_info("A0", 17, { 'analog' }); + retval.pins{end+1} = arduinoio.config.pin_info("A1", 18, { 'analog' }); + retval.pins{end+1} = arduinoio.config.pin_info("A2", 19, { 'analog' }); + retval.pins{end+1} = arduinoio.config.pin_info("A3", 20, { 'analog' }); + retval.pins{end+1} = arduinoio.config.pin_info("A4", 21, { 'digital', 'analog', 'i2c_sda' }); + retval.pins{end+1} = arduinoio.config.pin_info("A5", 22, { 'digital', 'analog', 'i2c_scl' }); + retval.pins{end+1} = arduinoio.config.pin_info("A6", 23, { 'analog' }); + retval.pins{end+1} = arduinoio.config.pin_info("A7", 24, { 'analog' }); +endfunction diff --git a/inst/+arduinoio/+config/config_nano_every.m b/inst/+arduinoio/+config/config_nano_every.m index d6ba3b9..063643b 100644 --- a/inst/+arduinoio/+config/config_nano_every.m +++ b/inst/+arduinoio/+config/config_nano_every.m @@ -24,6 +24,7 @@ function retval = config_nano_every (initdata) # default board info - must be provided # will be filled in on connection retval.board = "nano_every"; + retval.baudrate = 9600; retval.mcu = ''; retval.voltref = 50; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_nano_rp2040_connect.m b/inst/+arduinoio/+config/config_nano_rp2040_connect.m index d1ecb12..00dbe7d 100644 --- a/inst/+arduinoio/+config/config_nano_rp2040_connect.m +++ b/inst/+arduinoio/+config/config_nano_rp2040_connect.m @@ -5,6 +5,7 @@ function retval = config_nano_rp2040_connect (initdata) # default board info - must be provided # will be filled in on connection. retval.board = ''; + retval.baudrate = 9600; retval.mcu = 'cortex-m0plus'; retval.voltref = 0; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_promicro.m b/inst/+arduinoio/+config/config_promicro.m index a1773f4..019bf83 100644 --- a/inst/+arduinoio/+config/config_promicro.m +++ b/inst/+arduinoio/+config/config_promicro.m @@ -25,6 +25,7 @@ function retval = config_promicro (initdata) # default board info - must be provided # will be filled in on connection. retval.board = 'promicro'; + retval.baudrate = 9600; retval.mcu = ''; retval.voltref = 0; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_promini.m b/inst/+arduinoio/+config/config_promini.m index 8d7f2a8..298c01c 100644 --- a/inst/+arduinoio/+config/config_promini.m +++ b/inst/+arduinoio/+config/config_promini.m @@ -24,6 +24,7 @@ function retval = config_promini (initdata) # default board info - must be provided # will be filled in on connection retval.board = "promini"; + retval.baudrate = 9600; retval.mcu = ''; retval.voltref = 0; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_raspi_pico.m b/inst/+arduinoio/+config/config_raspi_pico.m index b62e29e..a60d51c 100644 --- a/inst/+arduinoio/+config/config_raspi_pico.m +++ b/inst/+arduinoio/+config/config_raspi_pico.m @@ -6,6 +6,7 @@ function retval = config_raspi_pico (initdata) # default board info - must be provided # will be filled in on connection. retval.board = ''; + retval.baudrate = 9600; retval.mcu = 'cortex-m0plus'; retval.voltref = 0; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_sparkfunsamd21.m b/inst/+arduinoio/+config/config_sparkfunsamd21.m index e596a25..bbf821d 100644 --- a/inst/+arduinoio/+config/config_sparkfunsamd21.m +++ b/inst/+arduinoio/+config/config_sparkfunsamd21.m @@ -25,7 +25,7 @@ function retval = config_sparkfunsamd21 (initdata) # default board info - must be provided # will be filled in on connection. retval.board = ''; - retval.board = ''; + retval.baudrate = 9600; retval.mcu = 'samd21'; retval.voltref = 3.3; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_uno.m b/inst/+arduinoio/+config/config_uno.m index a542ad4..52bed65 100644 --- a/inst/+arduinoio/+config/config_uno.m +++ b/inst/+arduinoio/+config/config_uno.m @@ -24,6 +24,7 @@ function retval = config_uno (initdata) # default board info - must be provided # will be filled in on connection retval.board = "uno"; + retval.baudrate = 9600; retval.mcu = ''; retval.voltref = 0; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_uno_minima_r4.m b/inst/+arduinoio/+config/config_uno_minima_r4.m index 27f11fc..d749852 100644 --- a/inst/+arduinoio/+config/config_uno_minima_r4.m +++ b/inst/+arduinoio/+config/config_uno_minima_r4.m @@ -3,6 +3,7 @@ function retval = config_uno_minima_r4 (initdata) retval = {}; retval.board = 'uno_minima_r4'; + retval.baudrate = 9600; retval.mcu = ''; retval.voltref = 0; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_uno_wifi_r2.m b/inst/+arduinoio/+config/config_uno_wifi_r2.m index 24fedc5..d53bc3b 100644 --- a/inst/+arduinoio/+config/config_uno_wifi_r2.m +++ b/inst/+arduinoio/+config/config_uno_wifi_r2.m @@ -24,6 +24,7 @@ function retval = config_uno_wifi_r2 (initdata) # default board info - must be provided # will be filled in on connection retval.board = "uno_wifi_r2"; + retval.baudrate = 9600; retval.mcu = ''; retval.voltref = 0; retval.libs = {}; diff --git a/inst/+arduinoio/+config/config_uno_wifi_r4.m b/inst/+arduinoio/+config/config_uno_wifi_r4.m index bbac523..5942cd2 100644 --- a/inst/+arduinoio/+config/config_uno_wifi_r4.m +++ b/inst/+arduinoio/+config/config_uno_wifi_r4.m @@ -24,6 +24,7 @@ function retval = config_uno_wifi_r4 (initdata) retval.board = 'uno_wifi_r4'; retval.mcu = 'Renesis RA4M1'; + retval.baudrate = 9600; retval.voltref = 0; retval.libs = {}; retval.port = ''; diff --git a/inst/+arduinoio/boardTypeString.m b/inst/+arduinoio/boardTypeString.m index b78b284..c68db53 100644 --- a/inst/+arduinoio/boardTypeString.m +++ b/inst/+arduinoio/boardTypeString.m @@ -65,6 +65,8 @@ function retval = boardTypeString (id) retval = "raspi_pico"; case 101 retval = "nano_rp2040_connect"; + case 102 + retval = "nano_esp32"; case 111 retval = "esp32_dev"; case 112 diff --git a/inst/+arduinoio/lib/LibraryBase.cpp b/inst/+arduinoio/lib/LibraryBase.cpp index c0c4df3..b4edff9 100644 --- a/inst/+arduinoio/lib/LibraryBase.cpp +++ b/inst/+arduinoio/lib/LibraryBase.cpp @@ -46,6 +46,10 @@ WiFiClient wifi_client; #endif +#ifndef ARDUINO_BAUDRATE + # define ARDUINO_BAUDRATE 9600 +#endif + // some standard(ish) error messages used throughout the addons const char ERRORMSG_INVALID_NUMBER_OF_ARGS[] PROGMEM = "Invalid number of args"; const char ERRORMSG_UNIMPLEMENTED[] PROGMEM = "Unimplemented feature"; @@ -281,7 +285,7 @@ static IPAddress make_gateway_address(const char *str) void OctaveArduinoClass::init () { - OCTAVE_COMMS_PORT.begin (9600); + OCTAVE_COMMS_PORT.begin (ARDUINO_BAUDRATE); #if defined(OCTAVE_USE_WIFI_COMMS) #ifdef ARDUINO_ARCH_ESP32 diff --git a/inst/+arduinoio/lib/LibraryBase.h b/inst/+arduinoio/lib/LibraryBase.h index 69edced..049e305 100644 --- a/inst/+arduinoio/lib/LibraryBase.h +++ b/inst/+arduinoio/lib/LibraryBase.h @@ -22,7 +22,7 @@ #include <Arduino.h> #define VERSION_MAJOR 0 -#define VERSION_MINOR 11 +#define VERSION_MINOR 12 #define VERSION_PATCH 0 #if defined(ARDUINO_SAM_DUE) diff --git a/inst/+arduinoio/lib/OctaveCoreLibrary.cpp b/inst/+arduinoio/lib/OctaveCoreLibrary.cpp index 4b12d2e..669b5eb 100644 --- a/inst/+arduinoio/lib/OctaveCoreLibrary.cpp +++ b/inst/+arduinoio/lib/OctaveCoreLibrary.cpp @@ -19,7 +19,7 @@ #include "settings.h" #include "OctaveCoreLibrary.h" -#ifdef ARDUINO_ARCH_ESP32 +#if defined(ARDUINO_ARCH_ESP32) && ! defined(ARDUINO_NANO_ESP32) // contains analogWrite #include <ESP32Servo.h> #endif @@ -97,6 +97,9 @@ #ifndef ARDUINO_ARCH_MBED #error "Expected mbed architechture" #endif +#elif defined(ARDUINO_NANO_ESP32) + #define BOARD_ID 102 + #define BOARD_VOLTAGE 33 #elif defined(ARDUINO_ESP32_DEV) #define BOARD_ID 111 #define BOARD_VOLTAGE 33 diff --git a/inst/+arduinoio/lib/OctaveServoLibrary.cpp b/inst/+arduinoio/lib/OctaveServoLibrary.cpp index 7261cca..bbb134c 100644 --- a/inst/+arduinoio/lib/OctaveServoLibrary.cpp +++ b/inst/+arduinoio/lib/OctaveServoLibrary.cpp @@ -25,7 +25,7 @@ // NOTE: if cant fint servo.h, you probally dont have the Servo library installed // go to Sketch -> Include Library -> Manage Libraries, and select 'Servo' // For ESP boards, it bwill need to be ESP32Servo -# ifdef ARDUINO_ARCH_ESP32 +# if defined(ARDUINO_ARCH_ESP32) #include <ESP32Servo.h> # else #include <Servo.h> diff --git a/inst/+arduinoio/lib/octave.ino b/inst/+arduinoio/lib/octave.ino index be449c0..a848332 100644 --- a/inst/+arduinoio/lib/octave.ino +++ b/inst/+arduinoio/lib/octave.ino @@ -1,6 +1,6 @@ /* * Octave arduino interface - * Copyright (C) 2018-2019 John Donoghue <john.donoghue@ieee.org> + * Copyright (C) 2018-2023 John Donoghue <john.donoghue@ieee.org> * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by @@ -72,7 +72,7 @@ void setup() { #if defined(ARDUINO_ARCH_AVR) // clear watchdog - //clear all flags + // clear all flags MCUSR = 0; /* Write logical one to WDCE and WDE */ diff --git a/inst/@arduino/__initArduino__.m b/inst/@arduino/__initArduino__.m index 8edc7be..65f05f7 100644 --- a/inst/@arduino/__initArduino__.m +++ b/inst/@arduino/__initArduino__.m @@ -29,13 +29,13 @@ function retval = __initArduino__ (obj, port, board) if !isempty(regexp(port, "^[0-9]+.[0-9]+.[0-9]+.[0-9]+$")) obj.connected = tcp (port, 9500, 10); else - obj.connected = serial (port, 9600, 2); + obj.connected = serialport (port, 'BaudRate', obj.BaudRate, 'Timeout', .2); endif # need wait for aduino to potentially startup pause(2); # clear any data in buffers - set(obj.connected, "timeout", 1); + set(obj.connected, "timeout", 0.1); data = fread(obj.connected,100); while length(data) >= 100 data = fread(obj.connected,100); @@ -91,6 +91,7 @@ function retval = __initArduino__ (obj, port, board) obj.config = arduinoio.getBoardConfig(boardtype); # update values that could change obj.config.port = port; + obj.config.baudrate = obj.BaudRate; obj.config.board = boardtype; obj.config.voltref = voltref; obj.config.flags = flags; diff --git a/inst/@arduino/arduino.m b/inst/@arduino/arduino.m index 1632104..b71b478 100644 --- a/inst/@arduino/arduino.m +++ b/inst/@arduino/arduino.m @@ -34,7 +34,18 @@ classdef arduino < handle ## for additional properties to pass to the creation of the ## arduino object. ## - ## Currently properties are ignored. + ## Currently properties are ignored, with the exception of: + ## @table @asis + ## @item debug + ## true / false flag for whether setting debug (default false) + ## @item forcebuildon + ## true / false flag for whether to force show of the arduino IDE to + ## rebuild the installed code on the arduino (default false) + ## @item baudrate (read only) + ## the communications baudrate to the board. (default 9600) + ## @item libraries + ## The libraries to be enabled on the arduino board. (default uses whatever is already installed) + ## @end table ## ## if the arduino function is called without parameters, it will scan ## for the first available arduino it can find and connect to it. @@ -48,12 +59,14 @@ classdef arduino < handle ## @item name ## name assigned to the arduino object ## @item debug - ## true / false flag for whether debug in turned on + ## true / false flag for whether debug is turned on ## @item forcebuildon ## true / false flag for whether to force show of the arduino IDE to ## reprogram the arduino ## @item port (read only) ## the communications port the board is connected to. + ## @item baudrate (read only) + ## the communications baudrate to the board. ## @item board (read only) ## The name of the board type that the arduino connected to ## @item libraries (read only) @@ -84,6 +97,7 @@ classdef arduino < handle AnalogReference = 5.0; Board = ""; Port = ""; + BaudRate = 9600; endproperties properties (SetAccess = private, Hidden = true) @@ -101,6 +115,8 @@ classdef arduino < handle endif this.name = "arduino"; + c = arduinoio.getBoardConfig(arduinos{1}.board); + this.BaudRate = c.baudrate; this = __initArduino__ (this, arduinos{1}.port, arduinos{1}.board); elseif (nargin == 1) arg0 = varargin{1}; @@ -129,6 +145,8 @@ classdef arduino < handle endif port = arduinos{1}.port; board = arduinos{1}.board; + c = arduinoio.getBoardConfig(arduinos{1}.board); + this.BaudRate = c.baudrate; elseif !ischar (port) error ("arduino: port must be a string"); endif @@ -148,6 +166,7 @@ classdef arduino < handle requiredlibs = {}; forcebuild = false; forcebuildon = false; + for i = 3:2:nargin propname = tolower (varargin{i}); propvalue = varargin{i+1}; @@ -174,6 +193,16 @@ classdef arduino < handle error ("arduino: expect forcebuildon to be true or false"); endif endif + if strcmp (propname,"baudrate") + if !isnumeric(propvalue) + error ("arduino: expect baudrate to be numeric"); + else + this.BaudRate = int32(propvalue); + if this.BaudRate < 1200 + error ("arduino: Invalid baudrate"); + endif + endif + endif # older option that probally should remove if strcmp (propname,"forcebuild") if islogical (propvalue) || (isnumeric(propvalue) && (propvalue == 1 || propvalue == 0)) @@ -217,7 +246,7 @@ classdef arduino < handle # free arduino resources, reprom and then reinit this = __freeArduino__(this); - if !arduinosetup ('libraries', requiredlibs); + if !arduinosetup ('libraries', requiredlibs, 'baudrate', this.BaudRate) error ("arduinosetup returned a failure, so did not reprogram") endif diff --git a/inst/@arduino/private/__recvResponse__.m b/inst/@arduino/private/__recvResponse__.m index 757a613..2670fb3 100644 --- a/inst/@arduino/private/__recvResponse__.m +++ b/inst/@arduino/private/__recvResponse__.m @@ -16,19 +16,19 @@ ## Private function ## @end deftypefn -function [dataOut, errcode] = __recvResponse__ (obj, libid, cmd, timeout) +function [dataOut, errcode] = __recvResponse__ (dev, libid, cmd, timeout, debug) dataOut = []; errcode = 0; - set(obj.connected, "timeout", timeout*10); + set(dev, "timeout", timeout); # TODO: current serial doesnt have a way to know if any data is awaiting # so try read what we need first without waiting ? # read in initial part - [tmpdataOut, tmpdataSize] = fread (obj.connected, 4); - if (obj.debug) + [tmpdataOut, tmpdataSize] = fread (dev, 4); + if (debug) printf("<< "); printf("%d ", tmpdataOut); printf("\n"); endif if tmpdataSize < 4 @@ -39,14 +39,14 @@ function [dataOut, errcode] = __recvResponse__ (obj, libid, cmd, timeout) dataOut = "Malformed packet header"; elseif (tmpdataOut(3) == 254) # got a wait for response value - length is expected to be 0 - if (obj.debug) + if (debug) printf("* wait for response\n"); endif - set(obj.connected, "timeout", -1); + set(dev, "timeout", -1); - [tmpdataOut, tmpdataSize] = fread (obj.connected, 4); - if (obj.debug) + [tmpdataOut, tmpdataSize] = fread (dev, 4); + if (debug) printf("<< "); printf("%d ", tmpdataOut); printf("\n"); endif if tmpdataSize < 4 @@ -61,8 +61,8 @@ function [dataOut, errcode] = __recvResponse__ (obj, libid, cmd, timeout) if(errcode == 0) expectlen = tmpdataOut(4); if expectlen > 0 - [dataOut, tmpdataSize] = fread (obj.connected, expectlen); - if (obj.debug) + [dataOut, tmpdataSize] = fread (dev, expectlen); + if (debug) printf("<< "); printf("%d ", dataOut); printf("\n"); endif else @@ -81,12 +81,12 @@ function [dataOut, errcode] = __recvResponse__ (obj, libid, cmd, timeout) endif elseif tmpdataOut(3) == 253 # valid but was a debug message - if obj.debug + if debug s = char(dataOut); printf("DEBUG: %s\n", s); endif - [dataOut, errcode] = __recvResponse__ (obj, libid, cmd, timeout); + [dataOut, errcode] = __recvResponse__ (dev, libid, cmd, timeout, debug); else errcode = 0; # all is good diff --git a/inst/@arduino/private/__sendCommand__.m b/inst/@arduino/private/__sendCommand__.m index 1c64264..ffe6d28 100644 --- a/inst/@arduino/private/__sendCommand__.m +++ b/inst/@arduino/private/__sendCommand__.m @@ -25,7 +25,7 @@ function [dataOut, errcode] = __sendCommand__ (obj, libid, cmd, data, timeout) endif % send command and get back reponse - if !isa(obj.connected, "octave_serial") && !isa(obj.connected, "octave_tcp") + if !isa(obj.connected, "octave_serialport") && !isa(obj.connected, "octave_tcp") error ("@arduino.__sendCommand__: not connected to a arduino"); endif @@ -53,7 +53,7 @@ function [dataOut, errcode] = __sendCommand__ (obj, libid, cmd, data, timeout) hdr = uint8([ hex2dec("A5") libid cmd numel(data)]); - set(obj.connected, "timeout", timeout*10); + set(obj.connected, "timeout", timeout); len = fwrite(obj.connected, [hdr data]); @@ -61,5 +61,5 @@ function [dataOut, errcode] = __sendCommand__ (obj, libid, cmd, data, timeout) printf(">> "); printf("%d ", [hdr data]); printf("\n"); endif - [dataOut, errcode] = __recvResponse__ (obj, libid, cmd, timeout); + [dataOut, errcode] = __recvResponse__ (obj.connected, libid, cmd, timeout, obj.debug); endfunction diff --git a/inst/PKG_ADD b/inst/PKG_ADD deleted file mode 100644 index e2407c7..0000000 --- a/inst/PKG_ADD +++ /dev/null @@ -1,24 +0,0 @@ -if exist ("isfolder") == 0 - if (isdir (fullfile (fileparts (mfilename ("fullpath")), "sensors"))) - addpath (fullfile (fileparts (mfilename ("fullpath")), "sensors")); - endif -else - if (isfolder (fullfile (fileparts (mfilename ("fullpath")), "sensors"))) - addpath (fullfile (fileparts (mfilename ("fullpath")), "sensors")); - endif -endif - -# on package load, attempt to load docs -try - pkg_dir = fileparts (fullfile (mfilename ("fullpath"))); - doc_file = fullfile (pkg_dir, "doc", "arduino.qch"); - if exist(doc_file, "file") - if exist("__event_manager_register_documentation__") - __event_manager_register_documentation__ (doc_file); - elseif exist("__event_manager_register_doc__") - __event_manager_register_doc__ (doc_file); - endif - endif -catch - # do nothing -end_try_catch diff --git a/inst/PKG_DEL b/inst/PKG_DEL deleted file mode 100644 index b7f1df1..0000000 --- a/inst/PKG_DEL +++ /dev/null @@ -1,24 +0,0 @@ -if exist ("isfolder") == 0 - if (isdir (fullfile (fileparts (mfilename ("fullpath")), "sensors"))) - rmpath (fullfile (fileparts (mfilename ("fullpath")), "sensors")); - endif -else - if (isfolder (fullfile (fileparts (mfilename ("fullpath")), "sensors"))) - rmpath (fullfile (fileparts (mfilename ("fullpath")), "sensors")); - endif -endif - -# on package load, attempt to unload docs -try - pkg_dir = fileparts (fullfile (mfilename ("fullpath"))); - doc_file = fullfile (pkg_dir, "doc", "arduino.qch"); - if exist(doc_file, "file") - if exist("__event_manager_unregister_documentation__") - __event_manager_unregister_documentation__ (doc_file); - elseif exist("__event_manager_unregister_doc__") - __event_manager_unregister_doc__ (doc_file); - endif - endif -catch - # do nothing -end_try_catch diff --git a/inst/__load_arduino__.m b/inst/__load_arduino__.m new file mode 100644 index 0000000..8598705 --- /dev/null +++ b/inst/__load_arduino__.m @@ -0,0 +1,49 @@ +## Copyright (C) 2023 John Donoghue +## +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License as +## published by the Free Software Foundation; either version 3 of the +## License, or (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, see +## <http:##www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {} {} __load_arduino__ () +## Undocumented internal function of arduino package. +## @end deftypefn + +## PKG_ADD: __load_arduino__ () + +function __load_arduino__ () + if exist ("isfolder") == 0 + if (isdir (fullfile (fileparts (mfilename ("fullpath")), "sensors"))) + addpath (fullfile (fileparts (mfilename ("fullpath")), "sensors")); + endif + else + if (isfolder (fullfile (fileparts (mfilename ("fullpath")), "sensors"))) + addpath (fullfile (fileparts (mfilename ("fullpath")), "sensors")); + endif + endif + + # on package load, attempt to load docs + try + pkg_dir = fileparts (fullfile (mfilename ("fullpath"))); + doc_file = fullfile (pkg_dir, "doc", "arduino.qch"); + if exist(doc_file, "file") + if exist("__event_manager_register_documentation__") + __event_manager_register_documentation__ (doc_file); + elseif exist("__event_manager_register_doc__") + __event_manager_register_doc__ (doc_file); + endif + endif + catch + # do nothing + end_try_catch +endfunction diff --git a/inst/__unload_arduino__.m b/inst/__unload_arduino__.m new file mode 100644 index 0000000..dad364d --- /dev/null +++ b/inst/__unload_arduino__.m @@ -0,0 +1,49 @@ +## Copyright (C) 2023 John Donoghue +## +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License as +## published by the Free Software Foundation; either version 3 of the +## License, or (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, see +## <http:##www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {} {} __unload_arduino__ () +## Undocumented internal function of arduino package. +## @end deftypefn + +## PKG_DEL: __unload_arduino__ () + +function __unload_arduino__ () + if exist ("isfolder") == 0 + if (isdir (fullfile (fileparts (mfilename ("fullpath")), "sensors"))) + rmpath (fullfile (fileparts (mfilename ("fullpath")), "sensors")); + endif + else + if (isfolder (fullfile (fileparts (mfilename ("fullpath")), "sensors"))) + rmpath (fullfile (fileparts (mfilename ("fullpath")), "sensors")); + endif + endif + + # on package unload, attempt to unload docs + try + pkg_dir = fileparts (fullfile (mfilename ("fullpath"))); + doc_file = fullfile (pkg_dir, "doc", "arduino.qch"); + if exist(doc_file, "file") + if exist("__event_manager_unregister_documentation__") + __event_manager_unregister_documentation__ (doc_file); + elseif exist("__event_manager_unregister_doc__") + __event_manager_unregister_doc__ (doc_file); + endif + endif + catch + # do nothing + end_try_catch +endfunction diff --git a/inst/arduinosetup.m b/inst/arduinosetup.m index 1e1d577..108cdaf 100644 --- a/inst/arduinosetup.m +++ b/inst/arduinosetup.m @@ -60,6 +60,8 @@ function retval = arduinosetup (varargin) libs = {}; arduinobinary = {}; debug = false; + baudrate = []; + def_baudrate = 9600; for i = 1:2:nargin propname = tolower (varargin{i}); propvalue = varargin{i+1}; @@ -74,6 +76,8 @@ function retval = arduinosetup (varargin) endif elseif strcmp (propname, "arduinobinary") arduinobinary = propvalue; + elseif strcmp (propname, "baudrate") + baudrate = int32(propvalue); elseif strcmp (propname, "debug") debug = propvalue; elseif @@ -152,6 +156,13 @@ function retval = arduinosetup (varargin) fprintf (fd, "\n"); fprintf (fd, "// override target voltage (x10) by uncommenting and providing a value\n"); fprintf (fd, "//#define BOARD_VOLTAGE 50\n"); + fprintf (fd, "\n"); + fprintf (fd, "// override baudrate by providing a value\n"); + if !isempty(baudrate) + fprintf (fd, "#define ARDUINO_BAUDRATE %d\n", baudrate); + else + fprintf (fd, "//#define ARDUINO_BAUDRATE %d\n", def_baudrate); + endif fprintf (fd, "\n"); fprintf (fd, "// builtin library support\n"); diff --git a/inst/private/__arduino_binary__.m b/inst/private/__arduino_binary__.m index 47a7cc9..e082f27 100644 --- a/inst/private/__arduino_binary__.m +++ b/inst/private/__arduino_binary__.m @@ -81,6 +81,18 @@ function arduino_binary = find_arduino_binary () arduino_binary = trypath; endif endif + if isempty(arduino_binary) + trypath = fullfile (getenv ("LOCALAPPDATA"), "Programs", "Arduino IDE", "Arduino IDE.exe"); + if exist (trypath, "file") + arduino_binary = trypath; + endif + endif + if isempty(arduino_binary) + trypath = fullfile (getenv ("PROGRAMFILES"), "Arduino IDE", "Arduino IDE.exe"); + if exist (trypath, "file") + arduino_binary = trypath; + endif + endif endif % look for arduino prefs file diff --git a/inst/scanForArduinos.m b/inst/scanForArduinos.m index 9278d8d..2a18d1d 100644 --- a/inst/scanForArduinos.m +++ b/inst/scanForArduinos.m @@ -15,12 +15,14 @@ ## <https://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {} {@var{retval} =} scanForArduinos (@var{maxCount}) +## @deftypefn {} {@var{retval} =} scanForArduinos () +## @deftypefnx {} {@var{retval} =} scanForArduinos (@var{maxCount}) ## @deftypefnx {} {@var{retval} =} scanForArduinos (@var{"debug"}) ## @deftypefnx {} {@var{retval} =} scanForArduinos (@var{maxCount}, @var{type}) -## Scan system for programmed arduino boards. +## @deftypefnx {} {@var{retval} =} scanForArduinos (@var{propertyname}, @var{propertvalue} ...) +## Scan system for programmed serial connected arduino boards. ## -## scanForArduinos will scan the system for programmed arduino boards +## scanForArduinos will scan the system for programmed arduino boards ## and return at most @var{maxCount} of them as a cell array ## in @var{retval}. ## @@ -36,6 +38,18 @@ ## scanForArduinos will display debug information as it scans ## all available ports for arduinos. ## +## @var{propertyname}, @var{propertyvalue} - property name/value pairs to match search with. +## @table @asis +## @item 'BaudRate' +## Numeric BaudRate to use when trying to scan for arduinos. +## @item 'MaxCount' +## Max number of arduinos to scan for. +## @item 'BoardType' +## Boardtype to match. +## @item 'Debug' +## Logical flag for debug mode. +## @end table +## ## @subsubheading Outputs ## @var{retval} structure cell array of matching detected arduino boards. ## @@ -50,30 +64,67 @@ ## @seealso{arduino} ## @end deftypefn -function arduinos = scanForArduinos (maxCount, typestr) +function arduinos = scanForArduinos (varargin) + + # maxCount, typestr arduinos = {}; - ARDUINO_INIT_COMMAND = 1; debug_flag = false; - if nargin > 2 - print_usage (); - elseif nargin == 1 - typestr = ""; - elseif nargin == 0 - maxCount = 0; - typestr = ""; - endif + maxCount = 0; + typestr = ""; + baudrate = []; - if ischar (maxCount) && strcmpi(maxCount, "debug") - if nargin > 1 - error ("scanForArduinos allows no additional arguments for 'debug'"); + if nargin == 1 + typestr = ""; + if ischar(varargin{1}) + if strcmp(varargin{1}, "debug") + debug_flag = 1; + else + error ("scanForArduinos: invalid argument"); + endif + elseif isnumeric(varargin{1}) + maxCount = int32(varargin{1}); + else + error ("scanForArduinos: invalid argument"); + endif + elseif nargin == 2 && isnumeric(varargin{1}) && ischar(varargin{2}) + # maxCount and boardtype + maxCount = int32(varargin{1}); + typestr = varargin{2}; + elseif nargin >= 2 + # properties + if mod (nargin, 2) != 0 + error ("scanForArduins: expected property name, value pairs"); endif - maxCount = 0; - debug_flag = true; + if !iscellstr (varargin (1:2:nargin)) + error ("scanForArduinos: expected property names to be strings"); + endif + + for i = 1:2:nargin + propname = tolower (varargin{i}); + propvalue = varargin{i+1}; + + if strcmp (propname,"debug") + if propvalue + debug_flag = 1; + else + debug_flag = 0; + endif + endif + if strcmp (propname,"boardtype") + boardstr = propvalue; + endif + if strcmp (propname,"baudrate") + baudrate = propvalue; + endif + if strcmp (propname,"maxcount") + maxCount = propvalue; + endif + endfor endif - if ! isnumeric (maxCount) + if ! isnumeric (maxCount) || maxCount < 0 error ("scanForArduinos expected maxCount to be a number"); endif if ! ischar (typestr) && !isempty (typestr) @@ -84,75 +135,55 @@ function arduinos = scanForArduinos (maxCount, typestr) typestr = ""; endif + if isempty(baudrate) + baudrate = 9600; + if !isempty(typestr) + # get default baudrate for baud + try + c = arduinoio.getBoardConfig(typestr); + baudrate = c.baudrate; + catch err + error ("scanForArduinos: unknown board type"); + end_try_catch + endif + endif + + if ! isnumeric (baudrate) || baudrate < 1200 + error ("scanForArduinos expected baudrate to be a number >= 1200"); + endif + # get list of serial ports to try - ports = instrhwinfo ('serial'); + ports = serialportlist (); for i = 1:numel (ports) try s = {}; unwind_protect - if isunix - portname = ports{i}; - if portname(1) != "/" - portname = ["/dev/" ports{i}]; - endif - elseif ispc - # use extended port name - portname = [ "\\\\.\\" ports{i}]; - else - portname = ports{i}; - endif - if debug_flag - printf("* trying comport %s\n", portname); - endif - s = serial (portname, 9600, 1); - pause(2); - - hdr = uint8 ([ hex2dec("A5") 0 ARDUINO_INIT_COMMAND 0]); - if debug_flag - printf(" >> "); printf("%02X ", hdr); printf("\n"); - endif - len = srl_write (s, hdr); - [tmpdataOut, tmpdataSize] = srl_read (s, 4); + portname = ports{i}; if debug_flag - printf(" << "); printf("%02X ", tmpdataOut); printf("\n"); + printf("* trying comport %s\n", portname); endif - - if tmpdataSize == 4 && tmpdataOut(1) == hex2dec("A5") && tmpdataOut(2) == 0 && tmpdataOut(3) == ARDUINO_INIT_COMMAND && tmpdataOut(4) >= 5 - expectlen = tmpdataOut(4); - - [dataout, datasize] = srl_read (s, expectlen); + s = arduino(portname, "", "Debug", debug_flag, "BaudRate", 9600); + if isempty (typestr) || strcmpi(s.board, typestr) + info = {}; + info.port = portname; + info.board = s.board; + arduinos{end+1} = info; + if debug_flag - printf(" << "); printf("%02X ", dataout); printf("\n"); + printf(" ** found board %s\n", info.board); endif - if datasize == expectlen - # init returns the following info - sig = (uint32 (dataout(1))*256*256) + (uint32 (dataout(2))*256) + uint32 (dataout(3)); - board = dataout(4); - voltref = double (dataout(5))/10.0; - if isempty (typestr) || strcmpi(arduinoio.boardTypeString (board), typestr) - info = {}; - info.port = portname; - info.board = arduinoio.boardTypeString (board); - arduinos{end+1} = info; - - if debug_flag - printf(" ** found board %s\n", info.board); - endif - - if numel (arduinos) == maxCount - break; - endif - endif - endif + if numel (arduinos) == maxCount + break; + endif endif - + unwind_protect_cleanup if !isempty (s) - srl_close (s); + clear s endif end_unwind_protect @@ -173,5 +204,6 @@ endfunction %! assert(!isempty(arduinos{1}.board)) %!test -%! arduinos = scanForArduinos(1, "madeuparduinoname"); -%! assert(isempty(arduinos)); +%! a = scanForArduinos("BaudRate", 115200, "BoardType", "Uno"); + +%!error <scanForArduinos: unknown board type> scanForArduinos(1, "madeuparduinoname"); diff --git a/test/make_conf.m b/test/make_conf.m index 68fa6c2..a212271 100644 --- a/test/make_conf.m +++ b/test/make_conf.m @@ -178,7 +178,7 @@ function retval = make_conf (header_file) printf(" # default board info - must be provided\n"); printf(" # will be filled in on connection.\n"); printf(" retval.board = '';\n"); - printf(" retval.board = '';\n"); + printf(" retval.baudrate = 9600;\n"); printf(" retval.mcu = '';\n"); printf(" retval.voltref = 0;\n"); printf(" retval.libs = {};\n"); |