diff --git a/common/constants.hpp b/common/constants.hpp new file mode 100644 index 0000000..8774f8f --- /dev/null +++ b/common/constants.hpp @@ -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 + * + * @brief Constants definition used for implementing the bike system + * + * @date 2023-08-20 + * @version 1.0.0 + ***************************************************************************/ + +#pragma once + +#include + +#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 \ No newline at end of file diff --git a/common/sensor_device.cpp b/common/sensor_device.cpp new file mode 100644 index 0000000..4aa7ef2 --- /dev/null +++ b/common/sensor_device.cpp @@ -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 + diff --git a/common/sensor_device.hpp b/common/sensor_device.hpp new file mode 100644 index 0000000..d6ead2c --- /dev/null +++ b/common/sensor_device.hpp @@ -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 + * + * @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 \ No newline at end of file