_ENCRYPT_=0    --LUA脚本加密

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

__page = {

    _hisgraph1 = 1,
    _hisgraph2 = 2,
}

function on_init()
    set_run_cycle(1000)
    set_uint16(VT_LW, 0x1008, 100)
    set_uint16(VT_LW, 0xA000, 0)
    set_uint16(VT_LW, 0xA001, 100)
end

function on_run(screen)

    if screen == __page._hisgraph1
    then
        for addr = 0x1010, 0x1012
        do
            local rn1  = tonumber(math.random(0, 50))
            local rn2  = tonumber(math.random(0, 50))
            local data = (rn1*rn2)%100

            --print('0x'..string.format('%04X', addr)..' = '..data)
            set_uint16(VT_LW, addr, data)
        end

    elseif screen == __page._hisgraph2
    then
        local paramTb = {}
        for addr = 1, 100
        do
            paramTb[addr] = tonumber(math.random(0, 100))
        end
        set_array(VT_LW, 0x4000, paramTb)
    end

end

function on_update(slave,vtype,addr)
    if vtype == VT_LW
    then
        if addr == 0xA000
        then
            local _min = get_uint16(VT_LW, 0xA000)
            wgt_set_param(__page._hisgraph1, 100, 0x31, _min)
        elseif addr == 0xA001
        then
            local _max = get_uint16(VT_LW, 0xA001)
            wgt_set_param(__page._hisgraph1, 100, 0x32, _max)
            
        end
    end
end

function on_draw(screen_id,control_id)
end

