#pragma once #include #include #include namespace trygvis { namespace sensor { using namespace trygvis::bluetooth; template using o = std::experimental::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, // 8 is used SM_CMD_SET_LIGHT = 9, SM_CMD_FAIL = 255, }; extern const Uuid soil_moisture_service; extern const 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(); void setLight(uint8_t light, uint8_t value); private: SoilMoisture(const shared_ptr &gatt, const shared_ptr &s, const shared_ptr &soilMoistureCharacteristic, const o temperatureCharacteristic, const o lightCharacteristic); void writeAndRead(const BluetoothGattCharacteristicPtr &c, ByteBuffer &requestBytes); shared_ptr gatt; shared_ptr s; const BluetoothGattCharacteristicPtr soilMoistureCharacteristic; const o temperatureCharacteristic; const o lightCharacteristic; }; } }