Files
imdd_silas/Functions/Lab_helper/holdAndShowValue.m
Silas Labor Zizou 0236103b13 ecoc measurements
2025-04-13 16:29:12 +02:00

49 lines
1.7 KiB
Matlab

function holdAndShowValue()
% Create the UI figure
fig = uifigure('Name', 'Multi-Channel Power Monitor', 'Position', [100 100 600 150]);
% Create labels to display the power values for each channel in a horizontal layout
powerLabels = gobjects(4, 1);
for i = 1:4
powerLabels(i) = uilabel(fig, 'Position', [50 + (i-1)*130, 70, 120, 30], ...
'FontSize', 18, 'HorizontalAlignment', 'center');
powerLabels(i).Text = sprintf('CH %d: Fetching...', i);
end
% Create the "OK" button
okButton = uibutton(fig, 'push', 'Text', 'OK', 'Position', [250 20 100 40], ...
'ButtonPushedFcn', @(src, event) closeWindow());
% Initialize the timer
updateTimer = timer('ExecutionMode', 'fixedRate', 'Period', 0.1, ...
'TimerFcn', @(src, event) updatePowerValues());
% Start the timer
start(updateTimer);
% Function to close the window and stop the timer
function closeWindow()
stop(updateTimer);
delete(updateTimer);
delete(fig);
end
% Function to fetch and update power values for all channels
function updatePowerValues()
powerValues = fetchPowerValues(); % Replace with your data-fetching function
for i = 1:4
powerLabels(i).Text = sprintf('CH %d: %.2f dBm', i, powerValues(i));
end
end
% Wait until the figure is closed to resume execution
waitfor(fig);
end
% Example function to simulate fetching power values for four channels
function powerValues = fetchPowerValues()
% Replace this with actual code to get the power values from the power meter
[p1,p2,p3,p4] = OptAtten().readPower();
powerValues = [p1,p2,p3,p4];
end