--L Shems: Multiple widget instances will al use these variables. Better to embed them in the widget! --local frecuency = 500; --local signal = 0; --local pause = 0; --local duration = 0; local options = { { "Option1", SOURCE, (getFieldInfo("RSSI") or {id=99}).id }, { "Option2", VALUE, 35 }, { "Option3", COLOR, RED } } local function create(zone, options) -- remove RSSIThreshold and move to options local data = { zone=zone, options=options, rssiThresHold = 35, packetLost=0, local data = { zone=zone, options=options, packetLost=0, frecuency = 500, signal = 0, pause = 0, duration = 0, } return data end local function map_range(val, low1, high1, low2, high2) return low2 + (high2 - low2) * (val - low1) / (high1-low1) end local function update(data, options) data.options = options end local function background(data) end local function refresh(data) local TC = TEXT_COLOR --Store current color as setcolor will change it for ALL widgets --data.rssiThresHold get this value from gVAR9 to use as our mini threshold --data.rssiThresHold = getValue("gvar9") -- get the rssi value --L Shems: changed to data element: signal = getValue("RSSI") data.signal = getValue(data.options.Option1) -- count packet lost if data.signal == 0 then data.packetLost = data.packetLost+1 end -- ensure that value is in range --L Shems: use the option in data if data.signal < data.options.Option2 then data.signal = data.options.Option2 elseif data.signal > 100 then data.signal = 100 end -- map to frecuency data.frecuency = map_range(data.signal,data.options.Option2 ,100,1500,150) -- map to pause data.pause = map_range(data.signal,data.options.Option2 ,100,200,1000) -- map to duration data.duration = map_range(data.signal,data.options.Option2 ,100,100,500) -- play tone playTone(data.frecuency,100,data.pause, PLAY_BACKGROUND) -- draw to screen rssi data lcd.setColor(TEXT_COLOR,data.options.Option3) --L Shems assign options color lcd.drawText(data.zone.x, data.zone.y + 8, "param.", LEFT + MIDSIZE + TEXT_COLOR); lcd.drawNumber(data.zone.x + 150, data.zone.y, getValue(data.options.Option1), LEFT + DBLSIZE + TEXT_COLOR); -- draw to screen packet lost lcd.drawText(data.zone.x, data.zone.y + 40, "Logs down", LEFT + MIDSIZE + TEXT_COLOR); lcd.drawNumber(data.zone.x + 140, data.zone.y + 32,data.packetLost, LEFT + DBLSIZE + TEXT_COLOR); -- draw to screen rssi user settings lcd.drawText(data.zone.x, data.zone.y + 100, "user settings", LEFT + SMLSIZE + TEXT_COLOR); lcd.drawText(data.zone.x, data.zone.y + 110, "par. min", LEFT + MIDSIZE + TEXT_COLOR); lcd.drawNumber(data.zone.x + 100, data.zone.y + 110, data.options.Option2 , LEFT + MIDSIZE + TEXT_COLOR); lcd.setColor(TEXT_COLOR,TC) --L Shems return to originial color for other widgets. end return { name="RssiBeeps", options=options, create=create, update=update, refresh=refresh, background=background }