fix(pkg/types): use measured values as struct instead interface
This commit is contained in:
@ -25,7 +25,7 @@ func (s *BME280) GetSensorModel() types.SensorModel {
|
||||
}
|
||||
|
||||
// Read measured values
|
||||
func (s *BME280) Read() ([]types.MeasuredValue, error) {
|
||||
func (s *BME280) Read() ([]*types.MeasuredValue, error) {
|
||||
|
||||
// Create new connection to i2c-bus on 1 line with address 0x76.
|
||||
// Use i2cdetect utility to find device address over the i2c-bus
|
||||
@ -62,27 +62,30 @@ func (s *BME280) Read() ([]types.MeasuredValue, error) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
measuredValues := []types.MeasuredValue{
|
||||
&types.Humidity{
|
||||
HumidityID: uuid.NewV4().String(),
|
||||
HumidityValue: float64(humidityValue),
|
||||
HumidityFromDate: time.Now(),
|
||||
HumidityTillDate: time.Now(),
|
||||
SensorID: s.SensorID,
|
||||
measuredValues := []*types.MeasuredValue{
|
||||
&types.MeasuredValue{
|
||||
ID: uuid.NewV4().String(),
|
||||
Value: float64(humidityValue),
|
||||
ValueType: types.MeasuredValueTypeHumidity,
|
||||
FromDate: time.Now(),
|
||||
TillDate: time.Now(),
|
||||
SensorID: s.SensorID,
|
||||
},
|
||||
&types.Pressure{
|
||||
PressureID: uuid.NewV4().String(),
|
||||
PressureValue: float64(pressureValue),
|
||||
PressureFromDate: time.Now(),
|
||||
PressureTillDate: time.Now(),
|
||||
SensorID: s.SensorID,
|
||||
&types.MeasuredValue{
|
||||
ID: uuid.NewV4().String(),
|
||||
Value: float64(pressureValue),
|
||||
ValueType: types.MeasuredValueTypePressure,
|
||||
FromDate: time.Now(),
|
||||
TillDate: time.Now(),
|
||||
SensorID: s.SensorID,
|
||||
},
|
||||
&types.Temperature{
|
||||
TemperatureID: uuid.NewV4().String(),
|
||||
TemperatureValue: float64(temperatureValue),
|
||||
TemperatureFromDate: time.Now(),
|
||||
TemperatureTillDate: time.Now(),
|
||||
SensorID: s.SensorID,
|
||||
&types.MeasuredValue{
|
||||
ID: uuid.NewV4().String(),
|
||||
Value: float64(temperatureValue),
|
||||
ValueType: types.MeasuredValueTypeTemperature,
|
||||
FromDate: time.Now(),
|
||||
TillDate: time.Now(),
|
||||
SensorID: s.SensorID,
|
||||
},
|
||||
}
|
||||
|
||||
@ -91,7 +94,7 @@ func (s *BME280) Read() ([]types.MeasuredValue, error) {
|
||||
|
||||
// ReadChannel reads the measured values from the sensor and writes them to a
|
||||
// channel.
|
||||
func (s *BME280) ReadChannel(measuredValuesChannel chan<- []types.MeasuredValue, errorChannel chan<- error, wg *sync.WaitGroup) {
|
||||
func (s *BME280) ReadChannel(measuredValuesChannel chan<- []*types.MeasuredValue, errorChannel chan<- error, wg *sync.WaitGroup) {
|
||||
if wg != nil {
|
||||
defer wg.Done()
|
||||
}
|
||||
@ -108,7 +111,7 @@ func (s *BME280) ReadChannel(measuredValuesChannel chan<- []types.MeasuredValue,
|
||||
|
||||
// ReadContinously reads the measured values continously from the sensor and
|
||||
// writes them to a channel.
|
||||
func (s *BME280) ReadContinously(ctx context.Context, measuredValuesChannel chan<- []types.MeasuredValue, errorChannel chan<- error) {
|
||||
func (s *BME280) ReadContinously(ctx context.Context, measuredValuesChannel chan<- []*types.MeasuredValue, errorChannel chan<- error) {
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
Reference in New Issue
Block a user