_ENCRYPT_=0    --LUA脚本加密

--数据类型定义
VT_LW = 1    --变量地址
VT_RW = 2    --FLASH存储

page = {
    single   = 1,
    multiple = 2,
    stacked  = 3,
}

baseGraphCmd = {
    opint      = 0x0001,
    Connection = 0x0002,
    rect       = 0x0003,
    PIC        = 0x0006,
    ICON       = 0x0007,
    rectFill   = 0x0004,
    circle     = 0x0005,
    fill       = 0x0008,
    Spectrum   = 0x0009,
    line       = 0x000A,
    rectFillOr = 0x000D
}


function on_init()
end

function on_run(screen)
end

function on_update(slave,vtype,addr)

    if vtype == VT_LW
    then
        if addr == 0xF000
        then
            local key = get_uint16(vtype, addr)
            local num = get_screen()
            set_array(VT_LW, 0x2000, {0XFFFF, 0XFFFF,  0XFFFF, 0XFFFF, 0XFFFF, 0XFFFF})
            set_array(VT_LW, 0x3000, {0XFFFF, 0XFFFF,  0XFFFF, 0XFFFF, 0XFFFF, 0XFFFF})

            if key == 0 -- 白色填充
            then
                local data = {baseGraphCmd.rectFill, 0x0001, 0x00C5, 0x0045,
                                                              (0x00C5 + 536), (0x0045 + 327), 0xFFFF, 0xFF00}
                set_array(VT_LW, 0x4000, data)

            elseif key == 1 -- 点
            then
                local data = {baseGraphCmd.opint, 0x0003, 0x01F4, 0x00F0, 0xF800, 0x01F5, 0x00F1, 0xF800, 0x01F6, 0x00F3, 0xF800, 0xFF00}
                set_array(VT_LW, (page.single == num) and 0x2000 or 0x4000, data)

            elseif key == 2 -- 端点连线
            then
                local data = {baseGraphCmd.Connection, 0x0003, 0xFC00, 0x012C, 0x012C,
                                                                       0x01F4, 0x012C,
                                                                       0x01F4, 0x0064,
                                                                       0x02BC, 0X0064, 0xFF00}
                                                                 
                set_array(VT_LW, (page.single == num) and 0x2000 or 0x4000, data)

            elseif key == 3 -- 矩形
            then
                local data = {baseGraphCmd.rect, 0x0002, 0x011E, (0x012C-130),
                                                         0x01AA, (0x018C-130), 0x471A,
                                                         0x0258, 0x0064,
                                                         0x02BC, 0x12C, 0x2C4A, 0xFF00}
                set_array(VT_LW, (page.single == num) and 0x2000 or 0x4000, data)

            elseif key == 4 -- 填充矩形
            then
                local data = {baseGraphCmd.rectFill, 0x0002, 0x011E, (0x012C-130),
                                                             0x01AA, (0x018C-130), 0x0000,
                                                             0x0258, 0x0064,
                                                             0x02BC, 0x12C, 0xA0FF, 0xFF00}
                set_array(VT_LW, (page.single == num) and 0x2000 or 0x4000, data)

            elseif key == 5 -- 圆形
            then
                local data = {}
                data = {baseGraphCmd.circle, 0x0001, 0x01F4, 0x00FA, 0x0096, 0xfea0, 0xFF00}
                set_array(VT_LW, (page.single == num) and 0x2000 or 0x4000, data)

            elseif key == 6 -- 频谱（垂直线段）
            then

                local data = {baseGraphCmd.Spectrum, 0x0005, 0xF800, 0x0168, 0x0064, 0x0064,
                                                             0xF800, 0x0190, 0x0064, 0x0096,
                                                             0xF800, 0x01C2, 0x0064, 0x00C8,
                                                             0xF800, 0x01F4, 0x0064, 0x00FA,
                                                             0xF800, 0x0226, 0x0064, 0x012C, 0xFF00}
                set_array(VT_LW, (page.single == num) and 0x2000 or 0x4000, data)

            elseif key == 7 -- 图片填充
            then
                local data = {baseGraphCmd.ICON , 0x0001 , 0x0000 , 0x0021 , 0x0027 , 0x00A3 , 0x0040 , 0x0168 , 0x0168 , 0xFF00}
                set_array(VT_LW, (page.single == num) and 0x2000 or 0x4000, data)

            elseif key == 8 --封闭填充
            then
                local data = {baseGraphCmd.Connection, 0x0004, 0xF000, 424, 160,365, 294,505, 361,517, 293, 424, 159, 0xFF00}
                set_array(VT_LW, 0x2000, data)

                local data = {baseGraphCmd.fill, 0x0001,400, 250, 0xF800, 0xFF00}
                set_array(VT_LW, 0x1001, data)

            elseif key == 9 -- 线段
            then
                local data = {baseGraphCmd.line, 0x0004, 0x7412, 0x0168, (0x0168-130), 0x0190, (0x0168-130),
                                                         0xF800, 0x0168, (0x0190-130), 0x01C2, (0x0190-130),
                                                         0x7412, 0x0168, (0x01C2-130), 0x01F4, (0x01C2-130),
                                                         0xF800, 0x0168, (0x01F4-130), 0x0226, (0x01F4-130), 0xFF00}
                set_array(VT_LW, (page.single == num) and 0x2000 or 0x4000, data)

            elseif key == 10 -- 反色矩形
            then
                local data = {baseGraphCmd.rectFillOr, 0x0001, 0x0168, (0x0168-130), 0x0190, (0x0190-130), 0x49f1, 0xFF00}
                set_array(VT_LW, (page.single == num) and 0x2000 or 0x4000, data)

            elseif key == 11 -- 综合指令1
            then
                local data = {baseGraphCmd.Connection, 0x0003, 0xFFFF, 0x012C, 0x012C, 0x01F4, 0x012C, 0x01F4, 0x0064, 0x02BC, 0X0064,
                              baseGraphCmd.rect, 0x0002, 0x011E, (0x012C-130), 0x01AA, (0x018C-130), 0x471A, 0x0258, 0x0064, 0x02BC, 0x12C, 0x2C4A,
                              baseGraphCmd.circle, 0x0001, 0x01F4, 0x00FA, 0x0096, 0xfea0,
                                0xFF00}
                set_array(VT_LW, 0x3000, data)
 
            elseif key == 12 -- 综合指令2
            then
                local data = {baseGraphCmd.Connection, 0x0003, 0xFFFF, 0x012C, 0x0064, 0x01F4, 0X0064, 0x01F4, 0x012C, 0x02BC, 0x012C,
                              baseGraphCmd.rectFill, 0x0002, 0x011E, (0x012C-130), 0x01AA, (0x018C-130), 0x0000, 0x0258, 0x0064, 0x02BC, 0x12C, 0xFFFF,
                              baseGraphCmd.circle, 0x0001, 0x01F4, 0x0160, 0x0055, 0xfea0,
                              0xFF00}
                set_array(VT_LW, 0x3000, data)

            elseif key == 13 -- 综合指令3
            then
                local data = {baseGraphCmd.Spectrum, 0x0005, 0xF800, 0x0168, 0x0064, 0x0064, 0xF800, 0x0190, 0x0064, 0x0096, 0xF800, 0x01C2, 0x0064, 0x00C8, 0xF800, 0x01F4, 0x0064, 0x00FA, 0xF800, 0x0226, 0x0064, 0x012C,
                              baseGraphCmd.circle, 0x0001, 0x0160, 0x00F0, 0x0075, 0xABCD,
                              baseGraphCmd.rectFill, 0x0002, 0x011E, (0x012C-130), 0x01AA, (0x018C-130), 0x0000, 0x0258, 0x0064, 0x02BC, 0x12C, 0xFFFF,
                              0xFF00}
                set_array(VT_LW, 0x3000, data)
            end
        end
    end
end

function on_draw(screen_id,control_id)
end

