File tree 1 file changed +24
-1
lines changed
1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change 25
25
endfor
26
26
elseif isunix() && !ispc()
27
27
list = port_sort(ports , @unix_port_compare );
28
+ elseif !isunix() && ispc()
29
+ list = port_sort(ports , @win32_port_compare );
28
30
else
29
31
list = ports ;
30
32
endif
67
69
endif
68
70
endfunction
69
71
72
+ function res = win32_port_compare(s1 , s2 )
73
+ # we want to priortise comports - assuming
74
+ # that comports more likely to arduinos
75
+ # will be towards end of the list
76
+
77
+ s1_p = strncmp(s1 , " COM" , 3 );
78
+ s2_p = strncmp(s2 , " COM" , 3 );
79
+ if s1_p && s2_p
80
+ # sort numerically
81
+ s1_p = sscanf(s1 , " COM%d" );
82
+ s2_p = sscanf(s2 , " COM%d" );
83
+ # reverse order
84
+ res = s2_p - s1_p ;
85
+ else
86
+ res = c_strcmp(s2 , s1 );
87
+ endif
88
+ endfunction
89
+
70
90
function slist = port_sort(ulist , sort_method= @c_strcmp )
71
91
# crappy bubble sort for now
72
92
sorted = false ;
73
- while sorted == false
93
+ max_try = length(ulist ) * length(ulist );
94
+ while sorted == false && max_try > 0
74
95
sorted = true ;
75
96
for idx= 1 : length(ulist )-1
76
97
cmp = sort_method(ulist{idx }, ulist{idx + 1 });
82
103
ulist{idx + 1 } = t ;
83
104
sorted = false ;
84
105
endif
106
+ # fail safe in case we get given some function that means we can never sort
107
+ max_try = max_try - 1 ;
85
108
endfor
86
109
endwhile
87
110
slist = ulist ;
You can’t perform that action at this time.
0 commit comments