Skip to content

Commit 6ebf03f

Browse files
committed
AlyxPanel weight button can now records current scales reading
1 parent 364633f commit 6ebf03f

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

+eui/AlyxPanel.m

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@
4343
NewExpSubject % Drop-down menu subject list
4444
LoginText % Text displaying whether/which user is logged in
4545
LoginButton % Button to log in to Alyx
46+
WeightButton % Button to submit weight to Alyx
4647
WaterEntry % Text box for entering the amout of water to give
4748
IsHydrogel % UI checkbox indicating whether to water to be given is in gel form
4849
WaterRequiredText % Handle to text UI element displaying the water required
4950
WaterRemainingText % Handle to text UI element displaying the water remaining
5051
LoginTimer % Timer to keep track of how long the user has been logged in, when this expires the user is automatically logged out
52+
WeightTimer % Timer to reset weight button text when scale no longer gives new readings
5153
WaterRemaining % Holds the current water required for the selected subject
5254
end
5355

@@ -134,7 +136,7 @@
134136
'Enable', 'off',...
135137
'Callback', @(~,~)obj.viewAllSubjects);
136138
% Button to open a dialog for manually submitting a mouse weight
137-
uicontrol('Parent', waterbox,...
139+
obj.WeightButton = uicontrol('Parent', waterbox,...
138140
'Style', 'pushbutton', ...
139141
'String', 'Manual weighing', ...
140142
'Enable', 'off',...
@@ -206,6 +208,11 @@ function delete(obj)
206208
delete(obj.LoginTimer) % ... delete it...
207209
obj.LoginTimer = []; % ... and remove it
208210
end
211+
if ~isempty(obj.WeightTimer) % If there is a timer object
212+
stop(obj.WeightTimer) % Stop the timer...
213+
delete(obj.WeightTimer) % ... delete it...
214+
obj.WeightTimer = []; % ... and remove it
215+
end
209216
end
210217

211218
function login(obj)
@@ -225,7 +232,7 @@ function login(obj)
225232
% minutes of 'inactivity' (defined as not calling
226233
% dispWaterReq)
227234
obj.LoginTimer = timer('StartDelay', 30*60, 'TimerFcn',...
228-
@(~,~)obj.login, 'BusyMode', 'queue');
235+
@(~,~)obj.login, 'BusyMode', 'queue', 'Name', 'Login Timer');
229236
start(obj.LoginTimer)
230237
% Enable all buttons
231238
set(findall(obj.RootContainer, '-property', 'Enable'), 'Enable', 'on');
@@ -584,7 +591,7 @@ function viewSubjectHistory(obj, ax)
584591
dat = horzcat(...
585592
arrayfun(@(x)datestr(x), dates', 'uni', false), ...
586593
weightsByDate', ...
587-
arrayfun(@(x)sprintf('%.1f', 0.8*(x-iw)), [records.weight_expected]', 'uni', false), ...
594+
arrayfun(@(x)sprintf('%.1f', 0.8*(x-iw)+iw), [records.weight_expected]', 'uni', false), ...
588595
weightPctByDate');
589596
waterDat = (...
590597
num2cell(horzcat([records.water_given]', [records.hydrogel_given]', ...
@@ -627,6 +634,26 @@ function viewAllSubjects(obj)
627634
end
628635
end
629636

637+
function updateWeightButton(obj, src, ~)
638+
% Function for changing the text on the weight button to reflect the
639+
% current weight value obtained by the scale. This function must be
640+
% a callback for the hw.WeighingScale NewReading event. If a new
641+
% reading isn't read for 10 sec the manual weighing option is made
642+
% available instead.
643+
%
644+
% Example:
645+
% aiPanel = eui.AlyxPanel;
646+
% lh = event.listener(obj.WeighingScale, 'NewReading',...
647+
% @(src,evt)aiPanel.updateWeightButton(src,evt));
648+
%
649+
% See also hw.WeighingScale, eui.MControl
650+
set(obj.WeightButton, 'String', sprintf('Record %.1fg', src.readGrams), 'Callback', @(~,~)obj.recordWeight(src.readGrams))
651+
obj.WeightTimer = timer('Name', 'Last Weight',...
652+
'TimerFcn', @(~,~)set(obj.WeightButton, 'String', 'Manual weighing', 'Callback', @(~,~)obj.recordWeight),...
653+
'StopFcn', @(src,~)delete(src), 'StartDelay', 10);
654+
start(obj.WeightTimer)
655+
end
656+
630657
function log(obj, varargin)
631658
% Function for displaying timestamped information about
632659
% occurrences. If the LoggingDisplay property is unset, the

+eui/MControl.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@
9090
if isfield(rig, 'scale') && ~isempty(rig.scale)
9191
obj.WeighingScale = fieldOrDefault(rig, 'scale');
9292
init(obj.WeighingScale);
93+
% Add listners for new reading, both for the log tab and also for
94+
% the weigh button in the Alyx Panel.
9395
obj.Listeners = [obj.Listeners,...
94-
{event.listener(obj.WeighingScale, 'NewReading', @obj.newScalesReading)}];
96+
{event.listener(obj.WeighingScale, 'NewReading', @obj.newScalesReading)}...
97+
{event.listener(obj.WeighingScale, 'NewReading', @(src,evt)obj.AlyxPanel.updateWeightButton(src,evt))}];
9598
end
9699
catch
97100
obj.log('Warning: could not connect to weighing scales');

0 commit comments

Comments
 (0)