Class: TermuxRubyApi::SubSystems::Sensor
- Defined in:
- lib/termux_ruby_api/sub_systems/sensor.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#capture(delay: 1000, limit: nil, sensors:, &block) ⇒ Object
Produces continues updates of the selected sensors If a block is passed, the results are yielded to the block as soon as they’re ready in the form of an array of hashes, where each element of the array corresponds to one of the captured sensors.
-
#capture_once(*sensors, &block) ⇒ Object
Gets a single update of the selected sensors If a block is passed, the results are yielded to the block as soon as they’re ready in the form of an array of hashes, where each element of the array corresponds to one of the captured sensors.
-
#list ⇒ String
Returns the list of available sensors.
Methods inherited from Base
Constructor Details
This class inherits a constructor from TermuxRubyApi::SubSystems::Base
Instance Method Details
#capture(delay: 1000, limit: nil, sensors:, &block) ⇒ Object
If limit==nil this method never returns. In that case is normal to invoke it from inside a thread or a child process.
Produces continues updates of the selected sensors If a block is passed, the results are yielded to the block as soon as they’re ready in the form of an array of hashes, where each element of the array corresponds to one of the captured sensors. If no block is passed, the IO object for the output string and the wait Thread are returned. See Base#json_streamed_api_command for details.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/termux_ruby_api/sub_systems/sensor.rb', line 16 def capture(delay: 1000, limit: nil, sensors:, &block) args = [] args += ['-n', limit.to_s] unless limit.nil? args += ['-d', delay.to_s] unless delay.nil? args += ['-s', sensors.join(',')] if block_given? owner.json_streamed_api_command('sensor', nil, *args) do |json_result| yield json_result end else return owner.json_streamed_api_command('sensor', nil, *args) end end |
#capture_once(*sensors, &block) ⇒ Object
Gets a single update of the selected sensors If a block is passed, the results are yielded to the block as soon as they’re ready in the form of an array of hashes, where each element of the array corresponds to one of the captured sensors. If no block is passed, the array of hashes is returned.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/termux_ruby_api/sub_systems/sensor.rb', line 36 def capture_once(*sensors, &block) data = nil capture(limit: 1, sensors: sensors) do |json_result| data = json_result end if block_given? yield data else return data end end |
#list ⇒ String
Returns the list of available sensors
50 51 52 |
# File 'lib/termux_ruby_api/sub_systems/sensor.rb', line 50 def list owner.json_api_command('sensor', nil, '-l')&.fetch(:sensors) end |