Class: DeviceControl::RateLimiter

Inherits:
Object
  • Object
show all
Includes:
Updateable
Defined in:
lib/device_control.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Updateable

#update

Constructor Details

#initialize(max_step, val: 0) ⇒ RateLimiter

Returns a new instance of RateLimiter.



305
306
307
308
# File 'lib/device_control.rb', line 305

def initialize(max_step, val: 0)
  @max_step = max_step
  @val = val
end

Instance Attribute Details

#valObject

Returns the value of attribute val.



303
304
305
# File 'lib/device_control.rb', line 303

def val
  @val
end

Instance Method Details

#input=(val) ⇒ Object

never allow @val to grow / shrink more than @max_step



311
312
313
314
# File 'lib/device_control.rb', line 311

def input=(val)
  diff = val - @val
  @val += diff.clamp(-1 * @max_step, @max_step)
end

#outputObject



316
317
318
# File 'lib/device_control.rb', line 316

def output
  @val
end