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
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' );
@@ -511,15 +518,15 @@ function viewSubjectHistory(obj, ax)
511518 % collect the data for the table
512519 endpnt = sprintf(' water-requirement/%s ?start_date=2016-01-01&end_date=%s ' , obj .Subject , datestr(now , ' yyyy-mm-dd' ));
513520 wr = obj .AlyxInstance .getData(endpnt );
514- iw = wr .implant_weight ;
521+ iw = iff(isempty( wr .implant_weight ), 0 , wr . implant_weight ) ;
515522 records = catStructs(wr .records , nan );
516- expected = [records .weight_expected ];
517- expected(expected == 0 ) = nan ;
518523 % no weighings found
519524 if isempty(wr .records )
520525 obj .log(' No weight data found for subject %s ' , obj .Subject );
521526 return
522527 end
528+ expected = [records .weight_expected ];
529+ expected(expected == 0 ) = nan ;
523530 dates = cellfun(@(x )datenum(x ), {records .date });
524531
525532 % build the figure to show it
@@ -537,10 +544,12 @@ function viewSubjectHistory(obj, ax)
537544 plot(ax , dates , ((expected - iw )*0.7 )+iw , ' r' , ' LineWidth' , 2.0 );
538545 plot(ax , dates , ((expected - iw )*0.8 )+iw , ' LineWidth' , 2.0 , ' Color' , [244 , 191 , 66 ]/255 );
539546 box(ax , ' off' );
547+ % Change the plot x axis limits
540548 if numel(dates ) > 1 ; xlim(ax , [min(dates ) max(dates )]); end
541549 if nargin == 1
542550 set(ax , ' XTickLabel' , arrayfun(@(x )datestr(x , ' dd-mmm' ), get(ax , ' XTick' ), ' uni' , false ))
543551 else
552+ xticks(ax , ' auto' )
544553 ax.XTickLabel = arrayfun(@(x )datestr(x , ' dd-mmm' ), get(ax , ' XTick' ), ' uni' , false );
545554 end
546555 ylabel(ax , ' weight (g)' );
@@ -582,7 +591,7 @@ function viewSubjectHistory(obj, ax)
582591 dat = horzcat(...
583592 arrayfun(@(x )datestr(x ), dates ' , ' uni' , false ), ...
584593 weightsByDate ' , ...
585- 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 ), ...
586595 weightPctByDate ' );
587596 waterDat = (...
588597 num2cell(horzcat([records .water_given ]' , [records .hydrogel_given ]' , ...
@@ -625,6 +634,26 @@ function viewAllSubjects(obj)
625634 end
626635 end
627636
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 %.1f g' , 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+
628657 function log(obj , varargin )
629658 % Function for displaying timestamped information about
630659 % occurrences. If the LoggingDisplay property is unset, the
0 commit comments