Prechádzať zdrojové kódy

touchscreen calibration and server switch functionality to diu_minder

clementinecomputing 5 rokov pred
rodič
commit
ad5783d913
1 zmenil súbory, kde vykonal 56 pridanie a 0 odobranie
  1. 56 0
      busunit/DIUv2/diu_main.c

+ 56 - 0
busunit/DIUv2/diu_main.c

@@ -1042,6 +1042,54 @@ static void ui_handle_interfaceupdown(struct mg_connection *nc, struct http_mess
       (unsigned long)strlen(msg_success), msg_success);
 }
 
+// bring network interface up/down
+//
+static void ui_handle_calibration(struct mg_connection *nc, struct http_message *hm) {
+  int ret;
+
+  char msg_fail[] = "fail calibration";
+  char msg_success[] = "ok calibration";
+
+  // Assuming we're running as root for now.
+  //
+  ret = system("/usr/bin/ts_calibrate &");
+
+  if (ret!=0) {
+    mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%s",
+        (unsigned long)strlen(msg_fail), msg_fail);
+    return;
+  }
+
+  mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%s",
+      (unsigned long)strlen(msg_success), msg_success);
+}
+
+// bring network interface up/down
+//
+static void ui_handle_switchserver(struct mg_connection *nc, struct http_message *hm) {
+  int ret;
+
+  char s_server[_SLEN];
+
+  char msg_fail[] = "fail switchserver";
+  char msg_success[] = "ok switchserver";
+
+  ret = mg_get_http_var(&(hm->body), "server", s_server, _SLEN);
+  if (ret<=0) { mg_http_send_error(nc, 404, NULL); return; }
+
+  //TODO: switch server code (call shell script)...
+  //
+
+  if (ret!=0) {
+    mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%s",
+        (unsigned long)strlen(msg_fail), msg_fail);
+    return;
+  }
+
+  mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%s",
+      (unsigned long)strlen(msg_success), msg_success);
+}
+
 
 // get network interface information
 //
@@ -1193,6 +1241,14 @@ static void api_handle_req(struct mg_connection *nc, struct http_message *hm) {
     ui_handle_eqnum(nc, hm);
   }
 
+  else if (strncmp(s_action, "calibration", strlen("calibration")+1)==0) {
+    ui_handle_calibration(nc, hm);
+  }
+
+  else if (strncmp(s_action, "switchserver", strlen("switchserver")+1)==0) {
+    ui_handle_switchserver(nc, hm);
+  }
+
   else {
     mg_http_send_error(nc, 404, NULL);
   }