non-blocking click handle

This commit is contained in:
Devaev Maxim 2018-11-28 22:35:31 +03:00
parent 6c2d8900f5
commit fe4afd7623
2 changed files with 10 additions and 4 deletions

View File

@ -66,7 +66,13 @@ class Atx: # pylint: disable=too-many-instance-attributes
get_logger().info("Clicked reset") get_logger().info("Clicked reset")
async def __click(self, pin: int, delay: float) -> None: async def __click(self, pin: int, delay: float) -> None:
with self.__region: self.__region.enter()
asyncio.ensure_future(self.__inner_click(pin, delay))
async def __inner_click(self, pin: int, delay: float) -> None:
try:
for flag in (True, False): for flag in (True, False):
gpio.write(pin, flag) gpio.write(pin, flag)
await asyncio.sleep(delay) await asyncio.sleep(delay)
finally:
self.__region.exit()

View File

@ -8,7 +8,7 @@ function Atx() {
$("atx-hdd-led").title = "Disk Activity Led"; $("atx-hdd-led").title = "Disk Activity Led";
tools.setOnClick($("atx-power-button"), () => __clickButton("power", "Are you sure to click the power button?")); tools.setOnClick($("atx-power-button"), () => __clickButton("power", "Are you sure to click the power button?"));
tools.setOnClick($("atx-power-button-long"), () => __clickButton("power_long", "Are you sure to perform the long press of the power button?", 15000)); tools.setOnClick($("atx-power-button-long"), () => __clickButton("power_long", "Are you sure to perform the long press of the power button?"));
tools.setOnClick($("atx-reset-button"), () => __clickButton("reset", "Are you sure to reboot the server?")); tools.setOnClick($("atx-reset-button"), () => __clickButton("reset", "Are you sure to reboot the server?"));
}; };
@ -28,7 +28,7 @@ function Atx() {
$("atx-hdd-led").className = "led-gray"; $("atx-hdd-led").className = "led-gray";
}; };
var __clickButton = function(button, confirm_msg, timeout=null) { var __clickButton = function(button, confirm_msg) {
ui.confirm(confirm_msg).then(function(ok) { ui.confirm(confirm_msg).then(function(ok) {
if (ok) { if (ok) {
var http = tools.makeRequest("POST", "/kvmd/atx/click?button=" + button, function() { var http = tools.makeRequest("POST", "/kvmd/atx/click?button=" + button, function() {
@ -39,7 +39,7 @@ function Atx() {
ui.error("Click error:<br>", http.responseText); ui.error("Click error:<br>", http.responseText);
} }
} }
}, timeout); });
} }
}); });
}; };