function logger(msg) {
    document.getElementById("logger").innerHTML =  msg;
}

function addPhoto(base64) {
    picLayout = document.getElementById("pic-layout");
    var li = document.createElement("li");
    var img = document.createElement("img");
    img.setAttribute("src", base64);
    li.appendChild(img);
    picLayout.appendChild(li);
}

//离开页面关闭高拍仪
function checkLeave() {
    send_command(
        "closeCamera",
        "nothing"
        );
}

//打开高拍仪、设置相对位置、窗口大小
function openCameras() {

    //重复打开，打开前先关闭
    function checkLeave() {
        send_command(
            "closeCamera",
            "nothing"
        );
    }
    checkLeave();

    logger('打开高拍仪');
    var layout={'layoutX': 50,'layoutY': 100,'layoutWidth': 690,'layoutHeight': 550};
    var jsonlayout=JSON.stringify(layout);
    send_command(
        "openCamera",
        jsonlayout,
        function (receivedData) {
            logger(receivedData);
            // logger('回调成功');
        });
}

//A3拍照
function A3takePhotos() {
    logger('A3拍照');
    send_command(
        "takePhotoA3",
        "nothing",
        function (receivedData) {
            var photoBean = JSON.parse(receivedData);
            if (photoBean.status == 100) {
                logger(photoBean);
                base64="data:image/jpeg;base64," + photoBean.imgStr;
                addPhoto(base64);
            }
        });
}
//A4拍照
function A4takePhotos() {
    logger('A4拍照');
    send_command(
        "takePhotoA4",
        "nothing",
        function (receivedData) {
            var photoBean = JSON.parse(receivedData);
            if (photoBean.status == 100) {
                logger(photoBean);
                base64="data:image/jpeg;base64," + photoBean.imgStr;
                addPhoto(base64);
            }
        });
}



//关闭相机
function closeCameras() {
    logger('关闭');

    var imgpath= [];
    var i=0;
    var lis=$('#pic-layout li img');
    lis.each(function () {
        imgpath[i]=$(this).attr('src');
        i=i+1;
    });



    // console.log(imgpath);

    function saveInfo(){
        m_info=imgpath[0];
        save_info(m_info);
    }
    saveInfo();

    send_command(
        "closeCamera",
        "nothing"
    );
    function jump() {
        window.location.href = 'sweepattachment.html';
    }
    jump();
}

openCameras();


