Commit 05d83bba authored by Martin Cífka's avatar Martin Cífka
Browse files

added poweroff, turn wifi off...

parent e7fca3d5
Loading
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ INVALID_MSGID? = -23

/* POWER */
int AMBA_MSGID_SET_AUTO_SHUTDOWN_TIME = 6151; 
    // param minutes
int AMBA_MSGID_WAKEUP_CAMERA = 6154;
int AMBA_MSGID_CLOSE_CAMERA = 6155;

+14 −5
Original line number Diff line number Diff line
@@ -11,16 +11,25 @@
    
    
    <body>
        <div id="notification-wrapper"><div id="notification" style="display: none;"></div></div>
        <div class="box center">
            <h1>Mi Camera Photo</h1>
            <p>This is simple WebSocket form.</p>
            <button id="buttonConnect" class="button" onclick="buttonConnect_onClick()">Connect</button>
            <form id="ws-form" onsubmit="wsFormSubmit(); return false;">
                <input id="ws-form-data" type="text" placeholder="Data to send" disabled="">
                <input id="ws-form-submit" class="button" type="submit" value="Send" disabled="">
            
            <span class="block">
                <input type="button" id="buttonConnect"  onclick="buttonConnectClick()" value="Connect">
                <input type="button" id="buttonTurnOffApp" onclick="turnOffAppClick()" value="Turn off app" disabled="">
                <input type="button" id="buttonPowerOff" onclick="powerOffClick()" value="Power off" disabled="">
            </span>
            
            <input type="checkbox" name="wifiOff" id="checkboxWifiOff" disabled="">
            <label for="wifiOff" id="label-WifiOff">Turn off Wifi when disconnecting</label>
            
            <form id="wsForm" onsubmit="wsFormSubmit(); return false;">
                <input id="wsForm-data" type="text" placeholder="Data to send" disabled="">
                <input id="wsForm-submit" type="submit" value="Send" disabled="">
            </form>
        </div>
        <div id="notification-wrapper"><div id="notification" style="display: none;"></div></div>
    </body>

    
+37 −11
Original line number Diff line number Diff line
var ws;
var notifying = false;
var connected = false;
var host = "192.168.42.1";

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
@@ -19,18 +20,19 @@ function waitFor(conditionFunction) {



function connect()
function wsConnect()
{
    if (!("WebSocket" in window))
    {
        notify("Sorry, WebSockets not supported by your browser!", true)
        return;
    }
    ws = new WebSocket("ws://192.168.42.1:80");
    ws = new WebSocket("ws://"+host+":80");
    ws.onopen = function(e)
    {
        notify("Connected, waiting for confirmation", false, 1000);
        connected = true;
        
    };

    ws.onmessage = function(event)
@@ -42,7 +44,6 @@ function connect()
        try
        {
            var json = JSON.parse(event.data);
            notify(`[message] JSON data received from server: ${event.data}`, false);
            switch(json["cmd"])
            {
                case "CONNECT":
@@ -98,6 +99,7 @@ function connect()

        enableForm(false);
        connected = false;
        
    };

    ws.onerror = function(error){};
@@ -105,43 +107,66 @@ function connect()

function enableForm(enable)
{
    var elements = document.getElementById("ws-form").elements;
    var elements = document.getElementById("wsForm").elements;
        for (var i = 0, len = elements.length; i < len; ++i)
        {
            elements[i].disabled = !enable;
        }
        
        document.getElementById("checkboxWifiOff").disabled = !enable;
        document.getElementById("buttonTurnOffApp").disabled = !enable;
        document.getElementById("buttonPowerOff").disabled = !enable;
        
        if (enable)
            document.getElementById("buttonConnect").innerHTML = "Disconnect";
            document.getElementById("buttonConnect").value = "Disconnect";
        else
            document.getElementById("buttonConnect").innerHTML = "Connect";
            document.getElementById("buttonConnect").value = "Connect";
}

function disconnect()
function wsDisconnect()
{
    if (document.getElementById("checkboxWifiOff").checked)
        ws.send('{"cmd":"WIFI_OFF"}');
    document.getElementById("checkboxWifiOff").disabled = true;
    
    ws.close(1000, "disconnected by user");
    connected = false;
}


function buttonConnect_onClick()
function buttonConnectClick()
{
    if (ws != undefined && ws.readyState === WebSocket.OPEN)
        disconnect();
        wsDisconnect();
    else
    {
        document.getElementById("buttonConnect").disabled = true;
        connect();
        wsConnect();
    }
}

function wsFormSubmit()
{
    var input = document.getElementById('ws-form-data')
    var input = document.getElementById('wsForm-data')
    ws.send(input.value);
    input.value = "";
}

function turnOffAppClick()
{
    if (document.getElementById("checkboxWifiOff").checked)
        ws.send('{"cmd":"WIFI_OFF"}');
    ws.send('{"cmd":"APP_OFF"}');
    wsDisconnect();
}

function powerOffClick()
{
    ws.send('{"cmd":"POWER_OFF"}');
    wsDisconnect();
}


async function notify(text, error = false, time = 1500)
{
    if (error)
@@ -166,3 +191,4 @@ async function notify(text, error = false, time = 1500)
        })
    });
}
+61 −29
Original line number Diff line number Diff line
@@ -4,32 +4,9 @@ body
    background-color: #fffae0;
}

.button
.block
{
    background-color: #fff6cb;
    border: none;
    color: #313b42;
    padding: 7px 14px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 14px;
    margin: 4px 2px;
    cursor: pointer;
    border-radius: 3px;
}
.button:disabled {
    filter: brightness(0.8)contrast(0.3);
}

input
{
    border-radius: 3px;
}

input[type=text]
{
    padding: 7px;
    display: block;
}

.box
@@ -38,16 +15,17 @@ input[type=text]
    padding: 15px 30px 35px 30px;
    margin: auto;
    border-radius: 10px;
    min-width: 250px;
    min-width: 350px;
}

.center {
.center
{
  margin: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  -ms-transform: translate(-50%, -65%);
  transform: translate(-50%, -65%);
  -ms-transform: translate(-50%, -60%);
  transform: translate(-50%, -60%);
}

#notification-wrapper
@@ -70,3 +48,57 @@ input[type=text]
    background-color: #3a1b1b;    
    display: inline-block;
}


/********** INPUT **********/
button,
input[type="button"],
input[type="submit"]
{
    background-color: #fff6cb;
    border: none;
    color: #313b42;
    padding: 7px 14px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 14px;
    margin: 4px 2px;
    cursor: pointer;
    border-radius: 3px;
}

button:disabled,
input[type="button"]:disabled,
input[type="submit"]:disabled,
input[type="checkbox" i]:disabled+label
{
    filter: brightness(0.8)contrast(0.3);
}

#buttonConnect,#wsForm-turnOffApp
{
    width: 105px;
}

input
{
    border-radius: 3px;
}

input[type=text]
{
    padding: 7px;
}

input[type="checkbox"] {
    width: 20px;
    height: 20px;
    position: relative;
    margin: 7px 5px;
}
label
{
    position: relative;
    top: -5px;
}
 No newline at end of file
+5 −0
Original line number Diff line number Diff line
@@ -13,6 +13,9 @@ public:
        GetToken = 257,
        DropToken = 258,
        
        WifiStart = 1541,
        WifiStop = 1540,
        
        ShootNormal = 4864,
        ShootBracketing = 5029,
        
@@ -20,6 +23,7 @@ public:
        GetSetISO = 5172,
        GetSetBracketingBuiltIn = 4918,
        GetSetMode = 4611, //button press
        GetSetPhotoWB = 5168,//TODO
        
        ImgCaptured = 8193,
        
@@ -29,6 +33,7 @@ public:
        QuerySessionHolder = 1793,
        
        PowerOff = 6155,
        GetSetAutoPowerOff = 6151 //TODO
        
    };
    
Loading