Skip to content

Implementing new sensors

mhupfauer edited this page May 23, 2021 · 1 revision

Adding new sensors is easy.

There are pre-made abstract classes that define the required interfaces

Implementation design

Place actual implementation in picure/picure/Backend/io/implementations

Use this as super class picure.Backend.io.prototypes.proto_sensor.SensorProto

Please include external libraries inside setup.py to keep the project installable.

Guide

picure.Backend.io.prototypes.base.Base and picure.Backend.io.prototypes.proto_sensor provide you with two properties:

  • name: Stores the name of the sensor (i.e.: SENSOR_TEMP)
  • sensor: Stores the reference to the library / implementation to read data

The class hardware_controller.py will instantiate the classes via the abstraction layer provided inside sensor.py. Make sure to add your implementation in the __new__() function. You can now alter your config.yaml to direct hardware_controller.py instantiate your sensor type via the property SENSOR_TYPE:.

The SensorProto abstract class will require at least a get() function to be implemented. Please return the sanitized sensor values as float. You have to provide the implementation for your get function to return a metric value. You may also add the suffix _imperial to an additional implementation to output imperial values. Please make sure that your suffix is unambiguous and one can clearly differentiate US imperial and GB imperial values.