delete(timerfind)
clc
clear
close all
global Batterytimer f
f=figure;
set(f,'Position',[1121 474 230 65],'MenuBar', 'none','ToolBar', 'none','color',[1 1 1],'Name',' ','NumberTitle','off');
text(0,0.5,'Cortana for battery is running');
text(-0.15,0,'Close this window to stop the program');
set(gca, 'visible','off')
NET.addAssembly('System.Windows.Forms');
Batterytimer=timer;
Batterytimer.executionmode='fixedrate';
Batterytimer.TimerFcn = @(~,~)batteryfun;
start(Batterytimer)
function batteryfun
global percentage battery Batterytimer Time_Remaining
percentage = double(System.Windows.Forms.SystemInformation.PowerStatus.BatteryLifePercent*100);
battery = ['The battery is now' ' ' char(string(percentage)) '%'];
Charging_Status = string(System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus);
Time_Remaining = double(System.Windows.Forms.SystemInformation.PowerStatus.BatteryLifeRemaining);
Hours = uint8(Time_Remaining/60/60);
Minutes = uint8((Time_Remaining/60/60-floor(Time_Remaining/60/60))*60);
% Minutes = char(string(round((Hours-floor(Hours))*60)));
% Hours = char(string(round(Time_Remaining/60/60)));
if Charging_Status=='Online'
stop(Batterytimer)
onlinefun()
end
if Charging_Status=='Offline'
stop(Batterytimer)
offlinefun()
end
end
function onlinefun
global Batterytimer f
temp=timer;
temp.executionmode='fixedrate';
temp.TimerFcn = @(~,~)checkstatus;
start(temp)
function checkstatus
percentage = double(System.Windows.Forms.SystemInformation.PowerStatus.BatteryLifePercent*100);
checkstatus=string(System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus);
if checkstatus=='Online' && percentage >=98
tts('hmm. I am so full now. You might consider Stop feeding me anyfurther.','Microsoft Eva Mobile - English (United States)',0)
plugged()
stop(temp);delete(temp)
return
end
if checkstatus=='Offline'
tts('Fine then. I will remind you when I am hungry.','Microsoft Eva Mobile - English (United States)',0)
stop(temp);delete(temp)
start(Batterytimer)
return
end
if ~ishghandle(f)
stop(temp);delete(temp)
stop(Batterytimer);delete(Batterytimer)
end
end
end
function offlinefun
global Batterytimer f
temp=timer;
temp.executionmode='fixedrate';
temp.TimerFcn = @(~,~)checkstatus;
start(temp)
function checkstatus
checkstatus=string(System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus);
percentage = double(System.Windows.Forms.SystemInformation.PowerStatus.BatteryLifePercent*100);
battery = ['The battery is now' ' ' char(string(percentage)) '%'];
if checkstatus=='Offline' && percentage <= 14
tts(['Hey' ' ' getenv('username')])
tts(battery,'Microsoft Eva Mobile - English (United States)',0)
tts('Plug in the charger.','Microsoft Eva Mobile - English (United States)',0)
tts('But if you want to work more, I can spare you a few minutes I guess!','Microsoft Eva Mobile - English (United States)',0)
lowbattery()
stop(temp);delete(temp)
return
end
if checkstatus=='Online' && percentage > 14 && percentage <= 40
tts('Haha. I was about to get hungry anyways.','Microsoft Eva Mobile - English (United States)',-1)
stop(temp);delete(temp)
start(Batterytimer)
return
end
if checkstatus=='Online' && percentage > 40 && percentage <= 75
tts('Yay!','Microsoft Eva Mobile - English (United States)',-3)
tts('Snacks Time','Microsoft Eva Mobile - English (United States)',0)
stop(temp);delete(temp)
start(Batterytimer)
return
end
if checkstatus=='Online' && percentage > 75
tts(['Oh! I am' ' ' char(string(percentage)) '%Full'],'Microsoft Eva Mobile - English (United States)',0)
tts('Do you think I should eat more?','Microsoft Eva Mobile - English (United States)',0)
stop(temp);delete(temp)
start(Batterytimer)
return
end
if ~ishghandle(f)
stop(temp);delete(temp)
stop(Batterytimer);delete(Batterytimer)
end
end
end
function plugged
global Batterytimer
temp=timer;
temp.executionmode='fixedrate';
temp.TimerFcn = @(~,~)checkstatus;
start(temp)
function checkstatus
checkstatus=string(System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus);
if checkstatus=='Offline'
tts('Well Thank you for making me full. But I will always ask for more later. Hehe','Microsoft Eva Mobile - English (United States)',0)
stop(temp);delete(temp)
start(Batterytimer)
return
end
end
end
function lowbattery
global Batterytimer
temp=timer;
temp.executionmode='fixedrate';
temp.TimerFcn = @(~,~)checkstatus;
start(temp)
function checkstatus
checkstatus = string(System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus);
% percentage = double(System.Windows.Forms.SystemInformation.PowerStatus.BatteryLifePercent*100);
percentage = 5;
if checkstatus == 'Offline' && percentage <= 5
tts('Hey dude','Microsoft Eva Mobile - English (United States)',0)
tts('Its time to Plug in the charger. Hurryup before I hibernate','Microsoft Eva Mobile - English (United States)',0)
criticalbattery()
stop(temp);delete(temp)
return
end
if checkstatus == 'Online'
tts('aahhhhh. Thank you very much. Now see my lightning fast performance!','Microsoft Eva Mobile - English (United States)',0)
stop(temp);delete(temp)
start(Batterytimer)
return
end
end
end
function criticalbattery
global Batterytimer
temp=timer;
temp.executionmode='fixedrate';
temp.TimerFcn = @(~,~)checkstatus;
start(temp)
function checkstatus
checkstatus=string(System.Windows.Forms.SystemInformation.PowerStatus.PowerLineStatus);
if checkstatus=='Online'
tts('The doctor said you saved me on time. Thank you very much!','Microsoft Eva Mobile - English (United States)',0)
stop(temp);delete(temp)
start(Batterytimer)
return
end
end
end