-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,209 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
classdef devices < handle | ||
%Devices | ||
% Detailed explanation goes here | ||
|
||
properties (Constant) | ||
types = ["NIRS", "EEG"] | ||
end | ||
|
||
properties | ||
nirs struct = []; | ||
eeg struct = []; | ||
selected struct = struct([]); | ||
end | ||
|
||
methods | ||
function self = devices() | ||
self.reload(); | ||
end | ||
|
||
function reload(self) | ||
files = ls("devices/*.json"); | ||
for f = 1:size(files, 1) | ||
file = files(f, 1:end); | ||
json = jsondecode(fileread("./devices/" + file)); | ||
switch json.type | ||
case "NIRS" | ||
idx = length(self.nirs) + 1; | ||
self.nirs(idx).name = json.name; | ||
self.nirs(idx).type = json.type; | ||
self.nirs(idx).lsl = json.lsl; | ||
case "EEG" | ||
idx = length(self.eeg) + 1; | ||
self.eeg(idx).name = json.name; | ||
self.eeg(idx).type = json.type; | ||
self.eeg(idx).lsl = json.lsl; | ||
otherwise | ||
disp("Ignoring unknown device type"); | ||
end | ||
end | ||
end | ||
|
||
function r = select(self, type, name) | ||
switch type | ||
case "NIRS" | ||
for d = 1:length(self.nirs) | ||
if self.nirs(d).name == name | ||
self.selected = self.nirs(d); | ||
r = true; | ||
return | ||
end | ||
end | ||
case "EEG" | ||
for d = 1:length(self.eeg) | ||
if self.eeg(d).name == name | ||
self.selected = self.eeg(d); | ||
r = true; | ||
return | ||
end | ||
end | ||
otherwise | ||
warning("Ignoring unknown device type: " + type); | ||
end | ||
r = false; | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
classdef protocols < handle | ||
%Protocols | ||
% Detailed explanation goes here | ||
|
||
properties (Constant) | ||
end | ||
|
||
properties | ||
list struct = [] | ||
selected struct = struct([]); | ||
end | ||
|
||
methods | ||
function reload(self, device) | ||
self.list = []; | ||
self.selected = struct(); | ||
files = ls("protocols/*.m"); | ||
for f = 1:size(files, 1) | ||
file = files(f, 1:end); | ||
name = strtrim(erase(file, ".m")); | ||
fh = feval(name); | ||
req = fh.requires(); | ||
if ~self.iscompatible(req, device) | ||
continue | ||
end | ||
idx = length(self.list) + 1; | ||
self.list(idx).name = name; | ||
self.list(idx).fh = fh; | ||
self.list(idx).req = req; | ||
end | ||
end | ||
|
||
function r = iscompatible(~, req, dev) | ||
% check device type | ||
if req.devicetype ~= "ANY" && req.devicetype ~= dev.type | ||
r = false; | ||
return | ||
end | ||
% check channel requirements | ||
for idx = 1:length(req.channels) | ||
found = 0; | ||
for lslch = 1:length(dev.lsl.channels) | ||
if req.channels(idx).type == dev.lsl.channels(lslch).type && ... | ||
req.channels(idx).unit == dev.lsl.channels(lslch).unit | ||
found = found + 1; | ||
end | ||
end | ||
if found < req.channels(idx).min | ||
r = false; | ||
return | ||
end | ||
end | ||
r = true; | ||
end | ||
|
||
function r = select(self, name) | ||
for p = 1:length(self.list) | ||
if self.list(p).name == name | ||
self.selected = self.list(p); | ||
r = true; | ||
return | ||
end | ||
end | ||
r = false; | ||
end | ||
end | ||
end |
Oops, something went wrong.