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 <david.escalona@digi.com>
This commit is contained in:
David Escalona 2022-09-28 10:06:22 +02:00
parent 252c3544cb
commit 0e931c1826
10 changed files with 27 additions and 29 deletions

View File

@ -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):

0
connectcore-demo-example/static/images/board.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 337 B

After

Width:  |  Height:  |  Size: 337 B

View File

Before

Width:  |  Height:  |  Size: 564 KiB

After

Width:  |  Height:  |  Size: 564 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 MiB

After

Width:  |  Height:  |  Size: 1.9 MiB

View File

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 1.6 MiB

0
connectcore-demo-example/static/images/led_bubble.png Executable file → Normal file
View File

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -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;

View File

@ -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);

View File

@ -93,5 +93,10 @@ function setSelectedSection(element=null) {
}
});
}
if (isDashboardShowing()) {
window.setTimeout(function () {
adjustImageSize();
}, 300);
}
}