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
112
113
114
115
116
117
|
// Copyright (C) 2012 - Scilab Enterprises
// This file is released under the 3-clause BSD license. See COPYING-BSD.
function arduinolib = startModule()
mprintf("Start Arduino\n");
defaultpath = pwd();
if isdef("arduinolib") then
warning("Arduino toolbox library is already loaded");
return;
end
// if win64() then
// warning("Arduino toolbox library is only available for scilab 32 bits");
// return;
// end
// check minimal version (xcosPal required)
// =============================================================================
if ~isdef('xcosPal') then
// and xcos features required
error(gettext('Scilab 5.3.2 or more is required.'));
end
// =============================================================================
// force to load some libraries (dependancies)
loadScicos();
// =============================================================================
etc_tlbx = get_absolute_file_path("arduino.start");
etc_tlbx = getshortpathname(etc_tlbx);
root_tlbx = strncpy( etc_tlbx, length(etc_tlbx)-length("\etc\") );
// Load functions library
// =============================================================================
mprintf("\tLoad macros\n");
pathmacros = pathconvert( root_tlbx ) + "macros" + filesep();
arduinolib = lib(pathmacros);
// Load serial dll and link
// =============================================================================
if getos() == "Windows"
mprintf("\tLoad serial dll\n");
pathdll = pathconvert( root_tlbx ) + "src" + filesep();
chdir(pathdll)
exec('loader.sce');
chdir('..')
end
// Add blocks to the Xcos palette
// =============================================================================
mprintf("\tLoad palette\n");
pal = xcosPal("Arduino");
sous_pal=["Configuration" "Digital" "Analog" "Motors"]
sous_blocks=cell(size(sous_pal));
sous_blocks(1).entries=["ARDUINO_SETUP" "TIME_SAMPLE" "ARDUINO_SCOPE"]
sous_blocks(2).entries=["DIGITAL_READ_SB" "DIGITAL_WRITE_SB" "ENCODER_SB" "INTERRUPT_SB"]
sous_blocks(3).entries=["ANALOG_READ_SB" "ANALOG_WRITE_SB" ]
sous_blocks(4).entries=["DCMOTOR_SB" "SERVO_WRITE_SB" ]
// blocks = ["ARDUINO_SETUP" "TIME_SAMPLE" "ARDUINO_ANALOG_READ" "ARDUINO_ANALOG_WRITE" "ARDUINO_DCMOTOR" ...
// "ARDUINO_DIGITAL_READ" "ARDUINO_DIGITAL_WRITE" "ARDUINO_ENCODER" ...
// "ARDUINO_SERVO_READ" "ARDUINO_SERVO_WRITE" ...
// "ARDUINO_STEPPER" "ARDUINO_WRITE" ];
for p=1:size(sous_pal,2)
local_pal = xcosPal(sous_pal(p));
blocks=sous_blocks(p).entries;
for i=1:size(blocks, "*")
h5 = ls(root_tlbx + "/images/h5/" + blocks(i) + "." + ["sod" "h5"]);
gif = ls(root_tlbx + "/images/gif/" + blocks(i) + "." + ["png" "jpg" "gif"]);
svg = ls(root_tlbx + "/images/svg/" + blocks(i) + "." + ["png" "jpg" "gif" "svg"]);
local_pal = xcosPalAddBlock(local_pal, h5(1), gif(1), svg(1));
end
if ~xcosPalAdd(local_pal,'Arduino') then
error(msprintf(gettext("%s: Unable to export %s.\n"), "arduino.start", "pal"));
end
end
// Load and add help chapter
// =============================================================================
if or(getscilabmode() == ["NW";"STD"]) then
mprintf("\tLoad help\n");
path_addchapter = pathconvert(root_tlbx+"/jar");
if ( isdir(path_addchapter) <> [] ) then
add_help_chapter("Arduino", path_addchapter, %F);
end
end
// Load demos
// =============================================================================
if or(getscilabmode() == ["NW";"STD"]) then
mprintf("\tLoad demos\n");
pathdemos = pathconvert(root_tlbx+"/demos/arduino.dem.gateway.sce", %F, %T);
add_demo("Arduino", pathdemos);
end
// Display version
fd=mopen(root_tlbx+filesep()+"VERSION");
version=mgetl(fd,-1);
mclose(fd);
mprintf("\tArduino Version: "+version);
chdir(defaultpath);
endfunction
if with_module('xcos') then
arduinolib = startModule();
clear startModule; // remove startModule on stack
end
|