ADD sensor device classes

This commit is contained in:
fastium 2024-10-23 10:59:38 +02:00
parent a2d3ca3096
commit b1d04badfb
3 changed files with 124 additions and 0 deletions

54
common/constants.hpp Normal file
View File

@ -0,0 +1,54 @@
// Copyright 2022 Haute école d'ingénierie et d'architecture de Fribourg
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/****************************************************************************
* @file constants.hpp
* @author Serge Ayer <serge.ayer@hefr.ch>
*
* @brief Constants definition used for implementing the bike system
*
* @date 2023-08-20
* @version 1.0.0
***************************************************************************/
#pragma once
#include <stdint.h>
#include "mbed.h"
namespace bike_computer {
// gear related constants
static constexpr uint8_t kMinGear = 1;
static constexpr uint8_t kMaxGear = 9;
// smallest gear (= 1) corresponds to a gear size of 20
// when the gear increases, the gear size descreases
static constexpr uint8_t kMaxGearSize = 20;
static constexpr uint8_t kMinGearSize = kMaxGearSize - kMaxGear;
// pedal related constants
// When compiling and linking with gcc, we get a link error when using static
// constexpr. The error is related to template instantiation.
// definition of pedal rotation initial time (corresponds to 80 turn / min)
static constexpr std::chrono::milliseconds kInitialPedalRotationTime = 750ms;
// definition of pedal minimal rotation time (corresponds to 160 turn / min)
static constexpr std::chrono::milliseconds kMinPedalRotationTime = 375ms;
// definition of pedal maximal rotation time (corresponds to 10 turn / min)
static constexpr std::chrono::milliseconds kMaxPedalRotationTime = 1500ms;
// definition of pedal rotation time change upon acceleration/deceleration
static constexpr std::chrono::milliseconds kDeltaPedalRotationTime = 25ms;
} // namespace bike_computer

21
common/sensor_device.cpp Normal file
View File

@ -0,0 +1,21 @@
#include "sensor_device.hpp"
namespace bike_computer {
SensorDevice::SensorDevice() : _hdc1000(I2C_SDA, I2C_SCL, STMOD_11)
{}
bool SensorDevice::init() {
return this->_hdc1000.probe();
}
float SensorDevice::readTemperature(void) {
return this->_hdc1000.getTemperature();
}
float SensorDevice::readHumidity(void) {
return this->_hdc1000.getHumidity();
}
} // bike_computer

49
common/sensor_device.hpp Normal file
View File

@ -0,0 +1,49 @@
// Copyright 2022 Haute école d'ingénierie et d'architecture de Fribourg
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/****************************************************************************
* @file sensor_device.hpp
* @author Serge Ayer <serge.ayer@hefr.ch>
*
* @brief SensorDevice header file (static scheduling)
*
* @date 2023-08-20
* @version 1.0.0
***************************************************************************/
#pragma once
#include "hdc1000.hpp"
#include "mbed.h"
namespace bike_computer {
class SensorDevice {
public:
// constructor
SensorDevice();
// method for initializing the device
bool init();
// methods used for
float readTemperature(void);
float readHumidity(void);
private:
// data members
advembsof::HDC1000 _hdc1000;
};
} // namespace bike_computer