User Tools

Site Tools


visual_object_array_tip

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
visual_object_array_tip [2021/07/22 12:47] emozolyakvisual_object_array_tip [2021/07/22 13:12] – [The solution] emozolyak
Line 14: Line 14:
  
 {{ ::дашборд_сушило_cleaned.png?direct&600 |}} {{ ::дашборд_сушило_cleaned.png?direct&600 |}}
 +
 +==== The solution ====
 +
 +The solution was to pack all the elements into one string object, with each character reflecting the state of the respective process object. 
 +
 +The idea is shown on the following gif image:
 +{{ :2021-07-22_15-51-00.gif?direct |}}
 +
 +== The code which makes the trick ==
 +
 +<code lua>
 +TRUE_SYMBOL =  '⚠'
 +FALSE_SYMBOL = '-'
 +NUMBER_OF_SPACES = 2 
 +
 +function main (userId)
 +    
 +   local bit_mask = R("demo_mask")
 +   local t = {}
 +   
 +   for b = 8, 1, -1 do 
 +        local symbol = hasbit(bit_mask, b) and TRUE_SYMBOL or FALSE_SYMBOL
 +        table.insert(t, symbol)
 +   end 
 +   
 +   local out = table.concat(t, string.rep(' ', NUMBER_OF_SPACES)) ; INFO("result_table: " .. out)
 +   
 +   U("demo_string", out)
 +end
 +
 +-- HELPERS -- 
 +function bw(n) 
 +    return 2 ^ (n - 1)   -- returns weight of the bit in pos. n
 +end
 + 
 +function hasbit(x, b) 
 +  local p = bw(b)
 +  return x % (p + p) >= p  -- returns if b is true/false; if hasbit(value, b) then ...
 +end
 +
 +function U(reg, new_value)
 +    local cur_value = R(reg)
 +    if cur_value and new_value and (cur_value ~= new_value) then 
 +        WriteReg(reg, new_value)
 +    end 
 +end 
 +
 +</code>
 +
 +Using the font size and spacing adjusment in the lua script you can get necessary dimensions of this object.
  
  
visual_object_array_tip.txt · Last modified: 2022/01/16 15:14 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki