Jelajahi Sumber

Add new methods

jblanked 1 tahun lalu
induk
melakukan
235e92003d
2 mengubah file dengan 83 tambahan dan 6 penghapusan
  1. 35 0
      assets/FlipperHTTP/flipper_http.js
  2. 48 6
      assets/FlipperHTTP/flipper_http.py

+ 35 - 0
assets/FlipperHTTP/flipper_http.js

@@ -84,6 +84,41 @@ let fhttp = {
         this.clear_buffer(true); // Clear the buffer
         return this.includes(this.to_string(response), "[PONG]");
     },
+    // list available commands
+    list_commands: function () {
+        serial.write("[LIST]");
+        let response = this.read_data(500);
+        if (response === undefined) {
+            return "";
+        }
+        return this.to_string(response);
+    },
+    // turn on the LED
+    led_on: function () {
+        serial.write("[LED/ON]");
+    },
+    // turn off the LED
+    led_off: function () {
+        serial.write("[LED/OFF]");
+    },
+    // parse JSON data
+    parse_json: function (key, data) {
+        serial.write('[PARSE]{"key":"' + key + '","data":' + data + '}');
+        let response = this.read_data(500);
+        if (response === undefined) {
+            return "";
+        }
+        return this.to_string(response);
+    },
+    // parse JSON array
+    parse_json_array: function (key, index, data) {
+        serial.write('[PARSE/ARRAY]{"key":"' + key + '","index":' + index + ',"data":' + data + '}');
+        let response = this.read_data(500);
+        if (response === undefined) {
+            return "";
+        }
+        return this.to_string(response);
+    },
     // Get Wifi network list
     scan_wifi: function () {
         serial.write("[WIFI/SCAN]");

+ 48 - 6
assets/FlipperHTTP/flipper_http.py

@@ -113,6 +113,48 @@ def flipper_http_disconnect_wifi() -> bool:
     return False
 
 
+def flipper_http_list_commands() -> str:
+    """List all available commands"""
+    flipper_http_send_data("[LIST]")
+    data = flipper_http_read_data(500)
+    clear_buffer()
+    return data
+
+
+def flipper_http_led_on():
+    """Turn on the LED"""
+    flipper_http_send_data("[LED/ON]")
+
+
+def flipper_http_led_off():
+    """Turn off the LED"""
+    flipper_http_send_data("[LED/OFF]")
+
+
+def flipper_http_parse_json(key: str, json_data: str) -> str:
+    """Parse JSON data"""
+    flipper_http_send_data('[PARSE]{"key":"' + key + '","json":' + json_data + "}")
+    data = flipper_http_read_data(500)
+    clear_buffer()
+    return data
+
+
+def flipper_http_parse_json_array(key: str, index: int, json_data: str) -> str:
+    """Parse JSON data"""
+    flipper_http_send_data(
+        '[PARSE/ARRAY]{"key":"'
+        + key
+        + '","index":"'
+        + index
+        + '","json":'
+        + json_data
+        + "}"
+    )
+    data = flipper_http_read_data(500)
+    clear_buffer()
+    return data
+
+
 def flipper_http_scan_wifi() -> str:
     """Scan for WiFi networks"""
     flipper_http_send_data("[WIFI/SCAN]")
@@ -121,7 +163,7 @@ def flipper_http_scan_wifi() -> str:
     return data
 
 
-def flipper_http_save_wifi(ssid, password) -> bool:
+def flipper_http_save_wifi(ssid: str, password: str) -> bool:
     """Save WiFi credentials"""
     if ssid is None or password is None:
         return False
@@ -133,7 +175,7 @@ def flipper_http_save_wifi(ssid, password) -> bool:
     return "[SUCCESS]" in data
 
 
-def flipper_http_get_request(url) -> str:
+def flipper_http_get_request(url: str) -> str:
     """Send a GET request to the specified URL"""
     if url is None:
         return ""
@@ -146,7 +188,7 @@ def flipper_http_get_request(url) -> str:
     return ""
 
 
-def flipper_http_get_request_with_headers(url, headers) -> str:
+def flipper_http_get_request_with_headers(url: str, headers: str) -> str:
     """Send a GET request to the specified URL with headers"""
     if url is None:
         return ""
@@ -159,7 +201,7 @@ def flipper_http_get_request_with_headers(url, headers) -> str:
     return ""
 
 
-def flipper_http_post_request_with_headers(url, headers, data):
+def flipper_http_post_request_with_headers(url: str, headers: str, data: str):
     """Send a POST request to the specified URL with headers and data"""
     if url is None:
         return ""
@@ -180,7 +222,7 @@ def flipper_http_post_request_with_headers(url, headers, data):
     return ""
 
 
-def flipper_http_put_request_with_headers(url, headers, data):
+def flipper_http_put_request_with_headers(url: str, headers: str, data: str):
     """Send a PUT request to the specified URL with headers and data"""
     if url is None:
         return ""
@@ -201,7 +243,7 @@ def flipper_http_put_request_with_headers(url, headers, data):
     return ""
 
 
-def flipper_http_delete_request_with_headers(url, headers, data):
+def flipper_http_delete_request_with_headers(url: str, headers: str, data: str):
     """Send a DELETE request to the specified URL with headers and data"""
     if url is None:
         return ""