From e78c40d08e324b98f62c88c055b5194ce2a7f4f2 Mon Sep 17 00:00:00 2001 From: pommicket Date: Tue, 25 Feb 2025 17:16:26 -0500 Subject: save & restore settings --- camera.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'camera.c') diff --git a/camera.c b/camera.c index b344ca2..dcee6f3 100644 --- a/camera.c +++ b/camera.c @@ -1077,6 +1077,21 @@ void hash_to_str(Hash h, char str[HASH_STR_SIZE]) { } } +bool hash_from_str(Hash *hash, const char *str) { + if (strlen(str) != 2 * HASH_SIZE) { + return false; + } + for (int i = 0; i < HASH_SIZE; i++) { + char n[3] = {str[2 * i], str[2 * i + 1], 0}, *endp = NULL; + long byte = strtol(n, &endp, 16); + if (byte < 0 || byte >= 256) { + return false; + } + hash->hash[i] = (uint8_t)byte; + } + return true; +} + void camera_hash_str(Camera *camera, char str[HASH_STR_SIZE]) { hash_to_str(camera->hash, str); } -- cgit v1.2.3