File: arduino_bistsetup.m

package info (click to toggle)
octave-arduino 0.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,616 kB
  • sloc: cpp: 3,221; python: 438; makefile: 152; xml: 22; sh: 1
file content (111 lines) | stat: -rw-r--r-- 3,622 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
## Copyright (C) 2019-2020 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} =} arduino_bistsetup ()
## @deftypefnx {} {@var{retval} =} arduino_bistsetup (@var{propertyname}, @var{propertyvalue})
## Install on an arduino the required core libraries to run the BIST tests
##
## As part of the setup, the arduino IDE will be opened to allow programming
## the arduino board.
##
## @subsubheading Inputs
## 
## @var{propertyname}, @var{propertyvalue} - A sequence of property name/value pairs can be given
## to set defaults while programming.
##
## Currently the following properties can be set:
## @table @asis
## @item arduinobinary
## The value should be the name/path of the arduino IDE binary for programming. If not specified,
## the function will attempt to find the binary itself.
## @item debug
## Set the debug flag when checking the arduino
## @end table
##
## @subsubheading Outputs
## @var{retval} - return 1 if everything installed ok
##
## @seealso{arduino, arduinosetup}
## @end deftypefn

function retval = arduino_bistsetup (varargin)
  retval = 0;

  if mod (nargin, 2) != 0
    error ("arduinosetup: expected property name, value pairs");
  endif
  if !iscellstr (varargin(1:2:nargin))
    error ("arduinosetup: expected property names to be strings");
  endif
  
  arduinobinary = {};
  debug = false;
  for i = 1:2:nargin
    propname = tolower (varargin{i});
    propvalue = varargin{i+1};

    if strcmp (propname, "arduinobinary")
      arduinobinary = propvalue;
    elseif strcmp (propname, "debug")
      debug = propvalue;
    elseif
      warning ("arduino_bistsetup: unknown property '%s', ignoring it", propname);
    endif
  endfor

  printf ("** Installing core libraries on arduino - please press upload in the IDE, and after completion, close the IDE\n"); 
  fflush(stdout);
  libs = { "I2C", "servo", "SPI", "ShiftRegister", "RotaryEncoder", "Ultrasonic" };
  if ! arduinosetup ('libraries', libs, varargin{:})
    error ("Failed to program the arduino");
  endif

  unwind_protect
    printf ("** Checking for any arduinos\n"); 
    fflush(stdout);
    ars = scanForArduinos();
    printf ("Found %d\n", numel(ars));

    printf ("** Checking can open an UNO arduino\n"); 
    fflush(stdout);
    ar = arduino ([], "uno", 'debug', debug);
    if ! isarduino(ar)
      error ('Couldnt load find an arduino UNO board')
    endif

    printf ("** Checking arduino version\n"); 
    fflush(stdout);
    p = pkg('list', 'arduino');
    if isempty(p)
      error ('No arduino package found');
    endif
    ver = p{1}.version;

    if ! strcmp(ver, version(ar))
      error ('Arduino version did not match %s : %s', ver, version(ar));
    endif

    printf ('Arduino has been programmed and is ready for BIST testing\n');
    printf ("run: __run_test_suite__({'%s'}, {})\n", p{1}.dir);
    fflush(stdout);

    ret = 1;
  unwind_protect_cleanup
    clear ar;
  end_unwind_protect
  
endfunction