How much sleep do I need?
Posted: 01 Dec 2017 12:58
I am using Quicksettings to change the state of Airplane mode, LockScreen, Wifi, Bluetooth, Location, and Power Saving. Let’s assume that there are 6 Boolean variables that designate what state I want a setting to be in. For example, TurnAirplaneON. For each of the six settings, there is a variable that should show the state of that setting after it has been changed. For example, global_airplane = focus("Airplane mode on.");
The other five settings have similar logic. Now, (finally) to my question. I cannot determine how to reliably run this script in the shortest elapsed time. I have a variable at the top of the script that sets the sleep time for all the delays built into the script. If ThisDelay is set to 1000, the script runs reasonably fast, but is not always reliable; sometimes the settings do not get made. If ThisDelay is set to 3000, the script is reliable but sloooow.
1. Do I have sleep delays in the script that are not necessary?
2. Can some delays be shortened to say 1000 or 500, while others should be lengthened?
Are there any guidelines on WHEN, WHERE, and For How Long Sleep delays in a script should be?
As always, thanks for your advice.
Here is the flow…
--------------------------------
-----------------------------------------------------------------------
ThisDelay = 1000;
sleep( ThisDelay );
quickSettings();
sleep( ThisDelay );
/////////////////////////////////////
// Airplane Mode
/////////////////////////////////////
if (TurnAirplaneON)
{
click("Airplane mode off."); //This will turn AP ON
sleep(ThisDelay);
}
else
{
click("Airplane mode on."); //This will turn AP OFF
sleep(ThisDelay);
}
sleep(ThisDelay);
global_airplane = focus("Airplane mode on.");
sleep(ThisDelay);
/////////////////////////////
// BlueTooth
/////////////////////////////
if (TurnBTON)
{
click("Bluetooth off."); // This will turn BT ON. It is off. Clicking will turn on.
sleep(ThisDelay);
}
else
{
click("Bluetooth on."); // This will turn BT OFF
sleep(ThisDelay);
}
sleep(ThisDelay);
global_BT_on=(focus("Bluetooth on.") OR focus("Bluetooth connecting."));
/////////////////////////o
// WiFi
/////////////////////////
sleep(ThisDelay);
if (TurnWifiON)
{
click("Wifi off.."); // Turn WiFi ON
sleep(ThisDelay);
global_wifi_on=true;
}
else
{
if (focus("Wifi off..")==false)
{
click(292, 627);// Turns WiFi Off
sleep(ThisDelay);
}
global_wifi_on=false;
}
sleep(ThisDelay);
/////////////////////////////////////////////
//Location ON set to battery savings
////////////////////////////////////////////
click(889, 1248); // open the location window
sleep(ThisDelay);
if (TurnLocationON) //Location
{
click("OFF"); // Turn Location on
sleep(ThisDelay);
click("Battery saving");
sleep(ThisDelay);
back( );
}
else
{
click("ON"); // Turns Location Off
sleep(ThisDelay);
back( );
}
global_loc_on=focus("Battery saving");
sleep(ThisDelay);
/////////////////////////////////////////////
// Battery Saving set to Efficiency or Balanced
////////////////////////////////////////////
click(786, 627);
sleep( ThisDelay);
sleep( ThisDelay);
// open up the battery options
if (TurnPowerSavingON) //Battery power save mode
{
click("Power save");
sleep(ThisDelay);back( );
}
else
{
click("Balanced"); // Turn balanced mode on
sleep(ThisDelay);back( );
sleep(ThisDelay);
}
global_batt_saver=focus("Power save");
sleep(ThisDelay);
/////////////////////////////////////////////
//ScreenLock ON
////////////////////////////////////////////
if (TurnScreenLockON) //Screen Lock
{
//sleep( ThisDelay );
click("Lock screen off.");
sleep( ThisDelay);
}
else
{
click("Lock screen on.");
sleep( ThisDelay);
}
global_lockscreen=focus("Lock screen on.");
sleep(ThisDelay);
sleep(ThisDelay);
The other five settings have similar logic. Now, (finally) to my question. I cannot determine how to reliably run this script in the shortest elapsed time. I have a variable at the top of the script that sets the sleep time for all the delays built into the script. If ThisDelay is set to 1000, the script runs reasonably fast, but is not always reliable; sometimes the settings do not get made. If ThisDelay is set to 3000, the script is reliable but sloooow.
1. Do I have sleep delays in the script that are not necessary?
2. Can some delays be shortened to say 1000 or 500, while others should be lengthened?
Are there any guidelines on WHEN, WHERE, and For How Long Sleep delays in a script should be?
As always, thanks for your advice.
Here is the flow…
--------------------------------
-----------------------------------------------------------------------
ThisDelay = 1000;
sleep( ThisDelay );
quickSettings();
sleep( ThisDelay );
/////////////////////////////////////
// Airplane Mode
/////////////////////////////////////
if (TurnAirplaneON)
{
click("Airplane mode off."); //This will turn AP ON
sleep(ThisDelay);
}
else
{
click("Airplane mode on."); //This will turn AP OFF
sleep(ThisDelay);
}
sleep(ThisDelay);
global_airplane = focus("Airplane mode on.");
sleep(ThisDelay);
/////////////////////////////
// BlueTooth
/////////////////////////////
if (TurnBTON)
{
click("Bluetooth off."); // This will turn BT ON. It is off. Clicking will turn on.
sleep(ThisDelay);
}
else
{
click("Bluetooth on."); // This will turn BT OFF
sleep(ThisDelay);
}
sleep(ThisDelay);
global_BT_on=(focus("Bluetooth on.") OR focus("Bluetooth connecting."));
/////////////////////////o
// WiFi
/////////////////////////
sleep(ThisDelay);
if (TurnWifiON)
{
click("Wifi off.."); // Turn WiFi ON
sleep(ThisDelay);
global_wifi_on=true;
}
else
{
if (focus("Wifi off..")==false)
{
click(292, 627);// Turns WiFi Off
sleep(ThisDelay);
}
global_wifi_on=false;
}
sleep(ThisDelay);
/////////////////////////////////////////////
//Location ON set to battery savings
////////////////////////////////////////////
click(889, 1248); // open the location window
sleep(ThisDelay);
if (TurnLocationON) //Location
{
click("OFF"); // Turn Location on
sleep(ThisDelay);
click("Battery saving");
sleep(ThisDelay);
back( );
}
else
{
click("ON"); // Turns Location Off
sleep(ThisDelay);
back( );
}
global_loc_on=focus("Battery saving");
sleep(ThisDelay);
/////////////////////////////////////////////
// Battery Saving set to Efficiency or Balanced
////////////////////////////////////////////
click(786, 627);
sleep( ThisDelay);
sleep( ThisDelay);
// open up the battery options
if (TurnPowerSavingON) //Battery power save mode
{
click("Power save");
sleep(ThisDelay);back( );
}
else
{
click("Balanced"); // Turn balanced mode on
sleep(ThisDelay);back( );
sleep(ThisDelay);
}
global_batt_saver=focus("Power save");
sleep(ThisDelay);
/////////////////////////////////////////////
//ScreenLock ON
////////////////////////////////////////////
if (TurnScreenLockON) //Screen Lock
{
//sleep( ThisDelay );
click("Lock screen off.");
sleep( ThisDelay);
}
else
{
click("Lock screen on.");
sleep( ThisDelay);
}
global_lockscreen=focus("Lock screen on.");
sleep(ThisDelay);
sleep(ThisDelay);