#pragma once #include #include namespace trygvis { namespace sensor { using namespace trygvis::bluetooth; template using o = boost::optional; enum class sm_cmd_code : uint8_t { SM_CMD_GET_SENSOR_COUNT = 1, SM_CMD_GET_VALUE = 8, SM_CMD_SET_WARNING_VALUE = 3, SM_CMD_GET_WARNING_VALUE = 4, SM_CMD_SET_SENSOR_NAME = 5, SM_CMD_GET_SENSOR_NAME = 6, SM_CMD_SET_UPDATE_INTERVAL = 7, SM_CMD_FAIL = 255, }; extern const boost::uuids::uuid soil_moisture_service; extern const boost::uuids::uuid soil_moisture_characteristic; class SoilMoisture { public: static SoilMoisture create(shared_ptr gatt); uint8_t getSensorCount(); uint16_t getValue(uint8_t sensor); string getName(uint8_t sensor); bool hasTemperatureSensor(); o readTemperature(); private: SoilMoisture(const shared_ptr &gatt, BluetoothGattService &s, const BluetoothGattCharacteristic &soilMoistureCharacteristic, const o temperatureCharacteristic); ByteBuffer writeAndRead(const BluetoothGattCharacteristic &c, ByteBuffer &requestBytes); shared_ptr gatt; BluetoothGattService &s; const BluetoothGattCharacteristic &soilMoistureCharacteristic; const o temperatureCharacteristic; }; } }