From 0e931c1826125b6150d970e01f44771d05656d06 Mon Sep 17 00:00:00 2001 From: David Escalona Date: Wed, 28 Sep 2022 10:06:22 +0200 Subject: [PATCH] connectcore-demo-example: general fixes - Improve error messages. - Fix resizing issues with dashboard image. - Add generic message when video resolution cannot be read. - Fix change volume action and include a confirmation message. - Add confirmation message when LED state is changed. - Remove execution bit from images. Signed-off-by: David Escalona --- connectcore-demo-example/demoserver.py | 29 +++++------------- .../static/images/board.png | Bin .../static/images/ccimx6ulsbc_board.png | Bin .../static/images/ccmp133_board.png | Bin .../static/images/ccmp157_board.png | Bin .../static/images/led_bubble.png | Bin .../static/images/led_bubble_hover.png | Bin connectcore-demo-example/static/js/common.js | 10 ++++-- .../static/js/dashboard.js | 12 +++++--- connectcore-demo-example/static/js/sidebar.js | 5 +++ 10 files changed, 27 insertions(+), 29 deletions(-) mode change 100755 => 100644 connectcore-demo-example/static/images/board.png mode change 100755 => 100644 connectcore-demo-example/static/images/ccimx6ulsbc_board.png mode change 100755 => 100644 connectcore-demo-example/static/images/ccmp133_board.png mode change 100755 => 100644 connectcore-demo-example/static/images/ccmp157_board.png mode change 100755 => 100644 connectcore-demo-example/static/images/led_bubble.png mode change 100755 => 100644 connectcore-demo-example/static/images/led_bubble_hover.png diff --git a/connectcore-demo-example/demoserver.py b/connectcore-demo-example/demoserver.py index 78f1617..3413466 100755 --- a/connectcore-demo-example/demoserver.py +++ b/connectcore-demo-example/demoserver.py @@ -212,7 +212,7 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler): self.wfile.write(json.dumps({"error": error}).encode(encoding="utf_8")) return - vol, error = set_audio_volume(value) + error = set_audio_volume(value) # Send the JSON value. if error: @@ -221,7 +221,7 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler): return # Send the JSON value. - self.wfile.write(json.dumps({"value": vol}).encode(encoding="utf_8")) + self.wfile.write("{}".encode(encoding="utf_8")) elif re.search("/ajax/fs_list_directory", self.path) is not None: # Set the response headers. self._set_headers(200) @@ -652,7 +652,7 @@ def get_video_resolution(): if res == NOT_AVAILABLE: res = read_file("/sys/class/graphics/fb0/modes") if res == NOT_AVAILABLE: - return "-" + return "No video device found" line = res.splitlines()[0] if ":" in line: @@ -959,27 +959,12 @@ def set_audio_volume(value): value (Integer): Volume to set in percentage. Returns: - Tuple (Integer, String): Current volume value and error string if fails. + String: Error string if fails. """ - res = exec_cmd("amixer set Headphone %d%%" % value) + res = exec_cmd(f"amixer set 'Speaker' {value}% && amixer set 'Headphone' {value}%") if res[0] != 0: - return -1, res[1] - - tmp = res[1].split("Front Right:") - if len(tmp) < 1: - return -1, "Unable to get current volume" - - m = re.search("\[(.+?)%\]", tmp[1]) - if not m: - return -1, "Unable to get current volume" - - if len(m.groups()) < 1: - return -1, "Unable to get current volume" - - try: - return int(m.group(1)), "" - except ValueError: - return -1, "Unable to get current volume" + return res[1] + return None def read_proc_file(path): diff --git a/connectcore-demo-example/static/images/board.png b/connectcore-demo-example/static/images/board.png old mode 100755 new mode 100644 diff --git a/connectcore-demo-example/static/images/ccimx6ulsbc_board.png b/connectcore-demo-example/static/images/ccimx6ulsbc_board.png old mode 100755 new mode 100644 diff --git a/connectcore-demo-example/static/images/ccmp133_board.png b/connectcore-demo-example/static/images/ccmp133_board.png old mode 100755 new mode 100644 diff --git a/connectcore-demo-example/static/images/ccmp157_board.png b/connectcore-demo-example/static/images/ccmp157_board.png old mode 100755 new mode 100644 diff --git a/connectcore-demo-example/static/images/led_bubble.png b/connectcore-demo-example/static/images/led_bubble.png old mode 100755 new mode 100644 diff --git a/connectcore-demo-example/static/images/led_bubble_hover.png b/connectcore-demo-example/static/images/led_bubble_hover.png old mode 100755 new mode 100644 diff --git a/connectcore-demo-example/static/js/common.js b/connectcore-demo-example/static/js/common.js index d097f12..c2f0ba0 100644 --- a/connectcore-demo-example/static/js/common.js +++ b/connectcore-demo-example/static/js/common.js @@ -141,10 +141,12 @@ const CLASS_VALUE_ANIMATION = "value-animation"; const CLASS_VALUE_UPDATED = "value-updated"; const ERROR_ABORTED = "Operation aborted"; +const ERROR_BAD_REQUEST = "Bad request"; +const ERROR_FORBIDDEN = "Could not perform the selected action. Make sure you have the correct access rights."; const ERROR_URL_NOT_FOUND = "Requested URL not found"; const ERROR_SERVER_ERROR = "Internal server error"; const ERROR_TITLE = "Error"; -const ERROR_UNKNOWN_ERROR = "Unknown error"; +const ERROR_UNKNOWN_ERROR = "Unknown error. Make sure that the server is running."; const PREFIX_STREAM = "system_monitor/"; const STREAM_CPU_LOAD = PREFIX_STREAM + "cpu_load"; @@ -237,8 +239,10 @@ function processAjaxErrorResponse(response) { errorMessage = response.responseJSON[ID_ERROR]; // Show the error message (if any). if (errorMessage == null) - errorMessage = ERROR_UNKNOWN_ERROR; - } else if (response.status == 404) + errorMessage = ERROR_BAD_REQUEST; + } else if (response.status == 403) + errorMessage = ERROR_FORBIDDEN; + else if (response.status == 404) errorMessage = ERROR_URL_NOT_FOUND; else if (response.status == 500) errorMessage = ERROR_SERVER_ERROR; diff --git a/connectcore-demo-example/static/js/dashboard.js b/connectcore-demo-example/static/js/dashboard.js index 32ea784..76888f1 100644 --- a/connectcore-demo-example/static/js/dashboard.js +++ b/connectcore-demo-example/static/js/dashboard.js @@ -239,6 +239,7 @@ function processDeviceInfoResponse(response) { // Position components after some time to give time to the image to load. window.setTimeout(function () { positionComponents(); + adjustImageSize(); setInfoPanelsVisible(false); }, 500); // Read device status. @@ -979,10 +980,9 @@ function processSetAudioVolumeResponse(response) { audioSlider.setValue(volume); } else { // Save new volume value. - volume = response["value"]; - if (volume == null) - volume = audioSlider.getValue(); - audioSlider.setValue(volume); + volume = audioSlider.getValue(); + // Show confirmation. + toastr.info("Volume changed to " + volume + "%") } // Hide the loading panel of the device. showLoadingPopup(false); @@ -1052,6 +1052,10 @@ function processSetLEDResponse(response) { if (!checkErrorResponse(response, false)) { // Update the LED status. updateLEDStatus(); + if (ledStatus) + toastr.info("User LED set to ON"); + else + toastr.info("User LED set to OFF"); } // Hide the loading panel of the device. showLoadingPopup(false); diff --git a/connectcore-demo-example/static/js/sidebar.js b/connectcore-demo-example/static/js/sidebar.js index dcb7192..0c760a9 100644 --- a/connectcore-demo-example/static/js/sidebar.js +++ b/connectcore-demo-example/static/js/sidebar.js @@ -93,5 +93,10 @@ function setSelectedSection(element=null) { } }); } + if (isDashboardShowing()) { + window.setTimeout(function () { + adjustImageSize(); + }, 300); + } }