summaryrefslogtreecommitdiff
path: root/2.3-1/macros/Scilab-Arduino/InsertSetupInList.sci
blob: b73910f28fe0eded4330fe9ddfc3bd1df84fb557 (plain)
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
function InsertSetupInList(FunName,InArg,NInArg,SetupListFile,FunType)

    load(SetupListFile,'SetupList');

    //Check first if current input function already exists in the list
    nelements = size(SetupList);

    found=%F;
    if(FunType=='Setup')
        for i=1:nelements
            if(SetupList(i)(1) == FunName)
                for j=1:NInArg
                    if(SetupList(i)(j+1) ~= InArg(j).Name)
                        found = %F
                        break;
                    else
                        found = %T;
                    end
                end
            end
            if (found == %T) 
                break;			//One match found. No need to check further.
            end
        end

        if(found == %F)
            temp = list(FunName);
            for i=1:NInArg
                temp($+1) = InArg(i).Name;
            end
        end
        SetupList($+1) = temp;
    elseif((FunType=='Init')&((FunName=='cmd_digital_out')|(FunName=='cmd_analog_out')|(FunName=='cmd_digital_in')))
        for i=1:nelements
            if(SetupList(i)(1) == "pinMode")
                if(SetupList(i)(2) == InArg(2).Name)
                    found = %T
                    break;
                else
                    found = %F;
                end
            else

                found = %F;

            end

        end

        if(found == %F)
            temp = list('pinMode');
            temp($+1) = InArg(2).Name;
            if ((FunName=='cmd_digital_out')|(FunName=='cmd_analog_out'))
                temp($+1) = 'OUTPUT';
            elseif ((FunName == 'cmd_digital_in') | (FunName=='cmd_analog_in'))
                temp($+1) = 'INPUT';
            end	
            SetupList($+1) = temp;

        end


    end
    save(SetupListFile,'SetupList');

endfunction