From a03817ab960ab30c648c960f343c2eecd4326963 Mon Sep 17 00:00:00 2001 From: Wojtek Rzepecki Date: Fri, 15 Oct 2021 18:11:01 +0200 Subject: [PATCH] [EGD-7766] Vibration level PWM addition PWM channels separate control added. --- .../windows/apps/PhoneWindow.cpp | 4 +- module-audio/Audio/Profiles/Profile.hpp | 6 +- .../rt1051/bellpx/board/BoardDefinitions.hpp | 5 +- .../bsp/eink_frontlight/eink_frontlight.cpp | 9 +- .../board/rt1051/bsp/vibrator/vibrator.cpp | 14 +- .../board/rt1051/drivers/RT1051DriverPWM.cpp | 181 +++++++++++++----- .../board/rt1051/drivers/RT1051DriverPWM.hpp | 48 +++-- .../board/rt1051/puretx/board/pin_mux.h | 3 - module-bsp/drivers/pwm/DriverPWM.cpp | 3 + module-bsp/drivers/pwm/DriverPWM.hpp | 8 +- .../service-audio/AudioServiceAPI.cpp | 8 +- .../service-audio/ServiceAudio.cpp | 3 +- .../include/service-audio/AudioServiceAPI.hpp | 2 +- .../api/EventManagerServiceAPI.cpp | 20 +- .../service-evtmgr/EVMessages.hpp | 2 +- .../service-evtmgr/EventManagerServiceAPI.hpp | 25 +-- .../services/evtmgr/EventManager.cpp | 7 +- 17 files changed, 218 insertions(+), 130 deletions(-) diff --git a/module-apps/application-settings/windows/apps/PhoneWindow.cpp b/module-apps/application-settings/windows/apps/PhoneWindow.cpp index bb5470fa3..f4f33c487 100644 --- a/module-apps/application-settings/windows/apps/PhoneWindow.cpp +++ b/module-apps/application-settings/windows/apps/PhoneWindow.cpp @@ -26,11 +26,12 @@ namespace gui switchVibrationState(); }); +#if DEVELOPER_SETTINGS_OPTIONS == 1 if (mVibrationsEnabled) { optionList.emplace_back(std::make_unique( utils::translate("app_settings_volume"), mAudioModel->getVibrationLevel(), - std::ceil(10.0), + 10, [&](uint8_t value) { mAudioModel->setVibrationLevel(value); return true; @@ -41,6 +42,7 @@ namespace gui [&]() { application->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); }, true)); } +#endif // DEVELOPER_SETTINGS_OPTIONS mWidgetMaker.addSwitchOption( optionList, utils::translate("app_settings_sound"), mSoundEnabled, [&]() { switchSoundState(); }); diff --git a/module-audio/Audio/Profiles/Profile.hpp b/module-audio/Audio/Profiles/Profile.hpp index 1b9ae22a2..4bc5352c6 100644 --- a/module-audio/Audio/Profiles/Profile.hpp +++ b/module-audio/Audio/Profiles/Profile.hpp @@ -12,11 +12,11 @@ namespace audio { - using Volume = uint32_t; - using Gain = uint32_t; + using Volume = std::uint32_t; + using Gain = std::uint32_t; using Position = float; using Vibrate = bool; - using VibrationLevel = uint32_t; + using VibrationLevel = std::uint32_t; using EnableSound = bool; using IsSystemSound = bool; diff --git a/module-bsp/board/rt1051/bellpx/board/BoardDefinitions.hpp b/module-bsp/board/rt1051/bellpx/board/BoardDefinitions.hpp index 751207e16..b4e00315a 100644 --- a/module-bsp/board/rt1051/bellpx/board/BoardDefinitions.hpp +++ b/module-bsp/board/rt1051/bellpx/board/BoardDefinitions.hpp @@ -107,8 +107,9 @@ enum class BoardDefinitions AUDIO_PLL = static_cast(drivers::PLLInstances::PLL4_Audio), - VIBRATOR_GPIO = static_cast(drivers::GPIOInstances::GPIO_1), - VIBRATOR_EN = 0, // GPIO_AD_B0_00 + VIBRATOR_PWM_INSTANCE = 2, // GPIO_AD_B0_00 = FLEXPWM2_PWM3_A + VIBRATOR_PWM_MODULE = 3, + VIBRATOR_PWM_CHANNEL = 0, // A MAGNETOMETER_I2C = AUDIOCODEC_I2C, MAGNETOMETER_I2C_BAUDRATE = AUDIOCODEC_I2C_BAUDRATE, diff --git a/module-bsp/board/rt1051/bsp/eink_frontlight/eink_frontlight.cpp b/module-bsp/board/rt1051/bsp/eink_frontlight/eink_frontlight.cpp index 50aba266b..b65082fa9 100644 --- a/module-bsp/board/rt1051/bsp/eink_frontlight/eink_frontlight.cpp +++ b/module-bsp/board/rt1051/bsp/eink_frontlight/eink_frontlight.cpp @@ -20,13 +20,14 @@ namespace bsp::eink_frontlight std::clamp(brightness, 0.0f, 100.0f); return static_cast(100 * std::pow((brightness / 100.0f), gammaFactor)); } + constexpr auto pwmChannel = static_cast(BoardDefinitions::EINK_FRONTLIGHT_PWM_CHANNEL); } // namespace void init() { drivers::DriverPWMParams pwmParams; - pwmParams.channel = static_cast(BoardDefinitions::EINK_FRONTLIGHT_PWM_CHANNEL); + pwmParams.channel = pwmChannel; pwmParams.frequency = PWM_FREQUENCY_HZ; pwm = drivers::DriverPWM::Create( @@ -43,18 +44,18 @@ namespace bsp::eink_frontlight void setBrightness(BrightnessPercentage brightness) { if (pwm) { - pwm->SetDutyCycle(gammaCorrection(brightness)); + pwm->SetDutyCycle(gammaCorrection(brightness), pwmChannel); } } void turnOn() { - pwm->Start(); + pwm->Start(pwmChannel); } void turnOff() { - pwm->Stop(); + pwm->Stop(pwmChannel); } void setGammaFactor(float gamma) diff --git a/module-bsp/board/rt1051/bsp/vibrator/vibrator.cpp b/module-bsp/board/rt1051/bsp/vibrator/vibrator.cpp index 201c4f07e..0e04b242f 100644 --- a/module-bsp/board/rt1051/bsp/vibrator/vibrator.cpp +++ b/module-bsp/board/rt1051/bsp/vibrator/vibrator.cpp @@ -3,7 +3,7 @@ #include "bsp/vibrator/vibrator.hpp" -#include +#include "board/BoardDefinitions.hpp" #include #include @@ -15,11 +15,13 @@ namespace bsp std::shared_ptr pwm; constexpr inline auto PWM_FREQUENCY_HZ = 20000; + constexpr inline auto levelMultiplier = 10; + constexpr auto pwmChannel = static_cast(BoardDefinitions::VIBRATOR_PWM_CHANNEL); void init(std::chrono::milliseconds pulse) { drivers::DriverPWMParams pwmParams; - pwmParams.channel = static_cast(BoardDefinitions::VIBRATOR_PWM_CHANNEL); + pwmParams.channel = pwmChannel; pwmParams.frequency = PWM_FREQUENCY_HZ; pwm = @@ -36,12 +38,12 @@ namespace bsp void enable() { - pwm->Start(); + pwm->Start(pwmChannel); } void disable() { - pwm->Stop(); + pwm->Stop(pwmChannel); } void updateClockFrequency(CpuFrequencyHz newFrequency) @@ -51,7 +53,9 @@ namespace bsp void setVibrationLevel(unsigned int vibrationLevel) { - pwm->SetDutyCycle(vibrationLevel * 10); + if (pwm) { + pwm->SetDutyCycle(vibrationLevel * levelMultiplier, pwmChannel); + } } } // namespace vibrator } // namespace bsp diff --git a/module-bsp/board/rt1051/drivers/RT1051DriverPWM.cpp b/module-bsp/board/rt1051/drivers/RT1051DriverPWM.cpp index 83b278234..0a37312ae 100644 --- a/module-bsp/board/rt1051/drivers/RT1051DriverPWM.cpp +++ b/module-bsp/board/rt1051/drivers/RT1051DriverPWM.cpp @@ -9,6 +9,11 @@ namespace drivers { + namespace + { + constexpr pwm_mode_t pwmMode = kPWM_SignedCenterAligned; + } + RT1051DriverPWM::RT1051DriverPWM(PWMInstances inst, PWMModules mod, const DriverPWMParams ¶ms) : DriverPWM(inst, mod, params) { @@ -61,7 +66,14 @@ namespace drivers PWM_Init(base, pwmModule, &pwmConfig); SetupPWMChannel(parameters.channel); - Start(); + Start(parameters.channel); + } + + void RT1051DriverPWM::InitNextChannel(const DriverPWMParams ¶ms) + { + LOG_INFO("Channel from this PWM module already enabled - PWM will use parameters from initial config"); + SetupPWMChannel(params.channel); + Start(params.channel); } RT1051DriverPWM::~RT1051DriverPWM() @@ -70,27 +82,38 @@ namespace drivers LOG_DEBUG("Deinit: PWM"); } - void RT1051DriverPWM::SetDutyCycle(std::uint8_t dutyCyclePercent) + void RT1051DriverPWM::SetDutyCycle(std::uint8_t dutyCyclePercent, PWMChannel channel) { - pwm_mode_t pwmMode = kPWM_SignedCenterAligned; - std::uint8_t dutyCycle = std::clamp(dutyCyclePercent, static_cast(0), static_cast(100)); - pwmSignalConfig.dutyCyclePercent = dutyCycle; - PWM_UpdatePwmDutycycle(base, pwmModule, pwmSignalConfig.pwmChannel, pwmMode, dutyCycle); + + auto pwmChannel = getChannelMask(channel); + for (unsigned i = 0; i < enabledChannels.size(); ++i) { + if (pwmSignalsConfig[i].pwmChannel == pwmChannel) { + pwmSignalsConfig[i].dutyCyclePercent = dutyCycle; + } + } + + PWM_UpdatePwmDutycycle(base, pwmModule, pwmChannel, pwmMode, dutyCycle); PWM_SetPwmLdok(base, 1 << pwmModule, true); } - void RT1051DriverPWM::Start() + void RT1051DriverPWM::Start(PWMChannel channel) { - RestorePwmOutput(); - PWM_StartTimer(base, 1 << pwmModule); + pwmChannelState[channel] = RT1051DriverPWM::PwmState::On; + RestorePwmOutput(channel); + if (not otherChannelRunning(channel)) { + PWM_StartTimer(base, 1 << pwmModule); + } } - void RT1051DriverPWM::Stop() + void RT1051DriverPWM::Stop(PWMChannel channel) { - PWM_StopTimer(base, 1 << pwmModule); - ForceLowOutput(); + if (not otherChannelRunning(channel)) { + PWM_StopTimer(base, 1 << pwmModule); + } + ForceLowOutput(channel); + pwmChannelState[channel] = RT1051DriverPWM::PwmState::Off; } RT1051DriverPWM::PwmState RT1051DriverPWM::GetPwmState() @@ -105,47 +128,46 @@ namespace drivers void RT1051DriverPWM::SetupPWMChannel(PWMChannel channel) { - switch (parameters.channel) { - case PWMChannel::A: - pwmSignalConfig.pwmChannel = kPWM_PwmA; - LOG_DEBUG("Init: PWM channel A"); - break; - case PWMChannel::B: - pwmSignalConfig.pwmChannel = kPWM_PwmB; - LOG_DEBUG("Init: PWM channel B"); - break; - case PWMChannel::X: - pwmSignalConfig.pwmChannel = kPWM_PwmX; - LOG_DEBUG("Init: PWM channel X"); - break; + if (channelNotEnabled(channel)) { + auto currentInstance = enabledChannels.size(); + auto pwmChannel = getChannelMask(channel); + + pwmSignalsConfig[currentInstance].pwmChannel = pwmChannel; + pwmSignalsConfig[currentInstance].dutyCyclePercent = 0; + pwmSignalsConfig[currentInstance].level = kPWM_HighTrue; + pwmSignalsConfig[currentInstance].deadtimeValue = 0; + pwmSignalsConfig[currentInstance].faultState = kPWM_PwmFaultState0; + + clockFrequency = DEFAULT_SYSTEM_CLOCK; + SetupPWMInstance(&pwmSignalsConfig[currentInstance], 1, clockFrequency); + + PWM_SetupFaultDisableMap(base, pwmModule, pwmChannel, kPWM_faultchannel_0, 0); + + // Force logic config + PWM_SetupSwCtrlOut(base, pwmModule, pwmChannel, false); + base->SM[pwmModule].CTRL2 |= PWM_CTRL2_FRCEN(1U); + + enabledChannels.push_back(channel); } - - // Currently connected to IPbus clock - const auto clockSource = CLOCK_GetFreq(kCLOCK_IpgClk); - SetupPWMInstance(clockSource); - - PWM_SetupFaultDisableMap(base, pwmModule, pwmSignalConfig.pwmChannel, kPWM_faultchannel_0, 0); - - // Force logic config - PWM_SetupSwCtrlOut(base, pwmModule, pwmSignalConfig.pwmChannel, false); - base->SM[pwmModule].CTRL2 |= PWM_CTRL2_FRCEN(1U); } - void RT1051DriverPWM::SetupPWMInstance(std::uint32_t clockFrequency) + void RT1051DriverPWM::SetupPWMInstance(pwm_signal_param_t *config, + unsigned numOfChannels, + std::uint32_t _clockFrequency) { pwm_mode_t pwmMode = kPWM_SignedCenterAligned; - PWM_SetupPwm(base, pwmModule, &pwmSignalConfig, 1, pwmMode, parameters.frequency, clockFrequency); + PWM_SetupPwm(base, pwmModule, config, numOfChannels, pwmMode, parameters.frequency, _clockFrequency); } - void RT1051DriverPWM::ForceLowOutput() + void RT1051DriverPWM::ForceLowOutput(PWMChannel channel) { - PWM_SetupForceSignal(base, pwmModule, pwmSignalConfig.pwmChannel, kPWM_SoftwareControl); + PWM_SetupForceSignal(base, pwmModule, getChannelMask(channel), kPWM_SoftwareControl); base->SM[pwmModule].CTRL2 |= PWM_CTRL2_FORCE(1U); } - void RT1051DriverPWM::RestorePwmOutput() + void RT1051DriverPWM::RestorePwmOutput(PWMChannel channel) { - PWM_SetupForceSignal(base, pwmModule, pwmSignalConfig.pwmChannel, kPWM_UsePwm); + PWM_SetupForceSignal(base, pwmModule, getChannelMask(channel), kPWM_UsePwm); base->SM[pwmModule].CTRL2 |= PWM_CTRL2_FORCE(1U); } @@ -153,11 +175,78 @@ namespace drivers { cpp_freertos::LockGuard lock(frequencyChangeMutex); - SetupPWMInstance(newFrequency); - if (GetPwmState() == PwmState::On) { - Stop(); - SetDutyCycle(pwmSignalConfig.dutyCyclePercent); - Start(); + if (clockFrequency != newFrequency) { + SetupPWMInstance(pwmSignalsConfig.data(), enabledChannels.size(), newFrequency); + if (GetPwmState() == PwmState::On) { + stopAll(); + restoreDutyCycle(); + startAll(); + } + clockFrequency = newFrequency; + } + } + + pwm_channels_t RT1051DriverPWM::getChannelMask(PWMChannel channel) + { + switch (channel) { + case PWMChannel::A: + return kPWM_PwmA; + case PWMChannel::B: + return kPWM_PwmB; + case PWMChannel::X: + return kPWM_PwmX; + } + LOG_FATAL("No mask for given PWM channel!"); + return kPWM_PwmB; + } + + bool RT1051DriverPWM::channelNotEnabled(PWMChannel channel) + { + for (const auto &chan : enabledChannels) { + if (chan == channel || chan == PWMChannel::X) { + LOG_FATAL("PWM Channel already enabled!"); + return false; + } + } + return true; + } + + bool RT1051DriverPWM::otherChannelRunning(PWMChannel channel) + { + for (const auto &[otherChannel, state] : pwmChannelState) { + if (channel != otherChannel && state == RT1051DriverPWM::PwmState::On) { + return true; + } + } + return false; + } + + void RT1051DriverPWM::stopAll() + { + PWM_StopTimer(base, 1 << pwmModule); + for (const auto &[channel, state] : pwmChannelState) { + if (state == RT1051DriverPWM::PwmState::On) { + ForceLowOutput(channel); + } + } + } + + void RT1051DriverPWM::startAll() + { + for (const auto &[channel, state] : pwmChannelState) { + if (state == RT1051DriverPWM::PwmState::On) { + RestorePwmOutput(channel); + } + } + PWM_StartTimer(base, 1 << pwmModule); + } + + void RT1051DriverPWM::restoreDutyCycle() + { + for (unsigned i = 0; i < enabledChannels.size(); ++i) { + PWM_UpdatePwmDutycycle( + base, pwmModule, pwmSignalsConfig[i].pwmChannel, pwmMode, pwmSignalsConfig[i].dutyCyclePercent); + PWM_SetPwmLdok(base, 1 << pwmModule, true); } } diff --git a/module-bsp/board/rt1051/drivers/RT1051DriverPWM.hpp b/module-bsp/board/rt1051/drivers/RT1051DriverPWM.hpp index ecde634f9..fd39fb1ee 100644 --- a/module-bsp/board/rt1051/drivers/RT1051DriverPWM.hpp +++ b/module-bsp/board/rt1051/drivers/RT1051DriverPWM.hpp @@ -5,11 +5,13 @@ #include "drivers/pwm/DriverPWM.hpp" -#include "../fsl_drivers/fsl_common.h" -#include "../fsl_drivers/fsl_pwm.h" +#include "fsl_common.h" +#include "fsl_pwm.h" -#include "mutex.hpp" +#include +#include +#include namespace drivers { class RT1051DriverPWM : public DriverPWM @@ -19,11 +21,13 @@ namespace drivers ~RT1051DriverPWM() final; - void SetDutyCycle(std::uint8_t dutyCyclePercent) final; + void InitNextChannel(const DriverPWMParams ¶ms) final; - void Start() final; + void SetDutyCycle(std::uint8_t dutyCyclePercent, PWMChannel channel) final; - void Stop() final; + void Start(PWMChannel channel) final; + + void Stop(PWMChannel channel) final; void UpdateClockFrequency(std::uint32_t newFrequency) final; @@ -38,25 +42,39 @@ namespace drivers void SetupPWMChannel(PWMChannel channel); - void SetupPWMInstance(std::uint32_t clockFrequency); + void SetupPWMInstance(pwm_signal_param_t *config, unsigned numOfChannels, std::uint32_t clockFrequency); - void ForceLowOutput(); + void ForceLowOutput(PWMChannel channel); - void RestorePwmOutput(); + void RestorePwmOutput(PWMChannel channel); + + pwm_channels_t getChannelMask(PWMChannel channel); + + bool channelNotEnabled(PWMChannel channel); + + bool otherChannelRunning(PWMChannel channel); + + void stopAll(); + + void startAll(); + + void restoreDutyCycle(); PWM_Type *base = nullptr; pwm_submodule_t pwmModule = kPWM_Module_0; - pwm_signal_param_t pwmSignalConfig = {.pwmChannel = kPWM_PwmB, - .dutyCyclePercent = 0, - .level = kPWM_HighTrue, - .deadtimeValue = 0, - .faultState = kPWM_PwmFaultState0}; - std::uint8_t lastDutyCycle = 0; + std::array pwmSignalsConfig; + + std::vector enabledChannels; + std::map pwmChannelState = { + {PWMChannel::A, PwmState::Off}, {PWMChannel::B, PwmState::Off}, {PWMChannel::X, PwmState::Off}}; + cpp_freertos::MutexStandard frequencyChangeMutex; + + std::uint32_t clockFrequency = 0; }; } // namespace drivers diff --git a/module-bsp/board/rt1051/puretx/board/pin_mux.h b/module-bsp/board/rt1051/puretx/board/pin_mux.h index 42456c9a8..70c3c1857 100644 --- a/module-bsp/board/rt1051/puretx/board/pin_mux.h +++ b/module-bsp/board/rt1051/puretx/board/pin_mux.h @@ -1,6 +1,3 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - /* * The Clear BSD License * Copyright 2017-2018 NXP diff --git a/module-bsp/drivers/pwm/DriverPWM.cpp b/module-bsp/drivers/pwm/DriverPWM.cpp index e46dc970e..af91a62a3 100644 --- a/module-bsp/drivers/pwm/DriverPWM.cpp +++ b/module-bsp/drivers/pwm/DriverPWM.cpp @@ -39,6 +39,9 @@ namespace drivers pwmDrivers[static_cast(instance)][static_cast(module)] = inst; } + else { + inst->InitNextChannel(params); + } cpp_freertos::CriticalSection::Exit(); diff --git a/module-bsp/drivers/pwm/DriverPWM.hpp b/module-bsp/drivers/pwm/DriverPWM.hpp index 950fba027..79384133f 100644 --- a/module-bsp/drivers/pwm/DriverPWM.hpp +++ b/module-bsp/drivers/pwm/DriverPWM.hpp @@ -50,12 +50,14 @@ namespace drivers virtual ~DriverPWM() = default; + virtual void InitNextChannel(const DriverPWMParams ¶ms) = 0; + // Duty cycle in percent: 0 - 100 - virtual void SetDutyCycle(std::uint8_t duty_cycle) = 0; + virtual void SetDutyCycle(std::uint8_t duty_cycle, PWMChannel channel) = 0; - virtual void Start() = 0; + virtual void Start(PWMChannel channel) = 0; - virtual void Stop() = 0; + virtual void Stop(PWMChannel channel) = 0; virtual void UpdateClockFrequency(std::uint32_t) = 0; diff --git a/module-services/service-audio/AudioServiceAPI.cpp b/module-services/service-audio/AudioServiceAPI.cpp index b20c3d216..394acac34 100644 --- a/module-services/service-audio/AudioServiceAPI.cpp +++ b/module-services/service-audio/AudioServiceAPI.cpp @@ -176,9 +176,9 @@ namespace AudioServiceAPI return GetSettingState(serv, audio::Setting::EnableVibration, playbackType); } - audio::RetCode SetVibrationLevelSetting(sys::Service *serv, const audio::VibrationLevel vol) + audio::RetCode SetVibrationLevelSetting(sys::Service *serv, const audio::VibrationLevel vibrationLevel) { - return SetSetting(serv, audio::Setting::VibrationLevel, std::to_string(vol), PlaybackType::System); + return SetSetting(serv, audio::Setting::VibrationLevel, std::to_string(vibrationLevel), PlaybackType::System); } std::optional GetVibrationLevelSetting(sys::Service *serv) @@ -188,7 +188,7 @@ namespace AudioServiceAPI return static_cast( std::stoi(GetSetting(serv, audio::Setting::VibrationLevel, PlaybackType::System))); } - catch (const std::exception &e) { + catch (const std::logic_error &e) { LOG_ERROR("exception %s", e.what()); return std::nullopt; } @@ -225,7 +225,7 @@ namespace AudioServiceAPI try { return static_cast(std::stoi(GetSetting(serv, audio::Setting::Volume, playbackType))); } - catch (const std::exception &e) { + catch (const std::logic_error &e) { LOG_ERROR("exception %s", e.what()); return std::nullopt; } diff --git a/module-services/service-audio/ServiceAudio.cpp b/module-services/service-audio/ServiceAudio.cpp index b57fb4327..fa13f2505 100644 --- a/module-services/service-audio/ServiceAudio.cpp +++ b/module-services/service-audio/ServiceAudio.cpp @@ -34,6 +34,7 @@ static constexpr auto defaultVolumeLow = "5"; static constexpr auto defaultVolumeMuted = "0"; static constexpr auto defaultTrue = "1"; static constexpr auto defaultFalse = "0"; +static constexpr auto defaultVibrationLevel = "5"; static constexpr auto defaultCallRingtonePath = "assets/audio/ringtone/ringtone_drum_2.mp3"; static constexpr auto defaultTextMessageRingtonePath = "assets/audio/sms/sms_drum_2.mp3"; static constexpr auto defaultNotificationsPath = "assets/audio/alarm/alarm_hang_drum.mp3"; @@ -90,7 +91,7 @@ static constexpr std::initializer_list #include -#include namespace sys { @@ -35,44 +34,31 @@ bsp::Board EventManagerServiceAPI::GetBoard(sys::Service *serv) return bsp::Board::none; } -/* - * @brief Call single vibration pulse - */ void EventManagerServiceAPI::vibrationPulseOnce(sys::Service *serv) { serv->bus.sendUnicast(std::make_shared(bsp::vibrator::Action::pulse), service::name::evt_manager); } -/* - * @brief Call vibration to stop - */ + void EventManagerServiceAPI::vibrationStop(sys::Service *serv) { serv->bus.sendUnicast(std::make_shared(bsp::vibrator::Action::stop), service::name::evt_manager); } -/* - * @brief Call repetitive vibration pulses for given time [ms] - */ + void EventManagerServiceAPI::vibrationPulseRepeat(sys::Service *serv, std::chrono::milliseconds time) { serv->bus.sendUnicast(std::make_shared(bsp::vibrator::Action::pulseRepeat, time), service::name::evt_manager); } -/* - * @brief Call repetitive vibration pulses until stop message is sent - */ + void EventManagerServiceAPI::vibrationPulseRepeatUntilStop(sys::Service *serv) { serv->bus.sendUnicast(std::make_shared(bsp::vibrator::Action::pulseRepeatInfinite), service::name::evt_manager); } -/* - * @brief Set vibration level - */ void EventManagerServiceAPI::setVibrationLevel(sys::Service *serv, unsigned int vibrationLevel) { - LOG_ERROR("Message sie wysyla tak ?"); serv->bus.sendUnicast(std::make_shared(vibrationLevel), service::name::evt_manager); } diff --git a/module-services/service-evtmgr/service-evtmgr/EVMessages.hpp b/module-services/service-evtmgr/service-evtmgr/EVMessages.hpp index a0c8139fb..8de62f7b0 100644 --- a/module-services/service-evtmgr/service-evtmgr/EVMessages.hpp +++ b/module-services/service-evtmgr/service-evtmgr/EVMessages.hpp @@ -142,7 +142,7 @@ namespace sevm : DataMessage(MessageType::VibratorLevelMessage), vibrationLevel(vibrationLevel) {} - unsigned int vibrationLevel; + const unsigned int vibrationLevel; }; class FlushLogsRequest : public sys::DataMessage diff --git a/module-services/service-evtmgr/service-evtmgr/EventManagerServiceAPI.hpp b/module-services/service-evtmgr/service-evtmgr/EventManagerServiceAPI.hpp index f8313ac8f..383cd7481 100644 --- a/module-services/service-evtmgr/service-evtmgr/EventManagerServiceAPI.hpp +++ b/module-services/service-evtmgr/service-evtmgr/EventManagerServiceAPI.hpp @@ -16,35 +16,22 @@ namespace sys namespace EventManagerServiceAPI { - /* - * @brief Gets board version. - * @return board type - */ + /// Gets board version bsp::Board GetBoard(sys::Service *serv); - /* - * @brief Call single vibra pulse - */ + /// Call single vibrator pulse void vibrationPulseOnce(sys::Service *serv); - /* - * @brief Call vibra to stop - */ + /// Call vibrator to stop void vibrationStop(sys::Service *serv); - /* - * @brief Call repetitive vibra pulses for given time [ms] - */ + /// Call repetitive vibrator pulses for given time [ms] void vibrationPulseRepeat(sys::Service *serv, std::chrono::milliseconds time); - /* - * @brief Call repetitive vibra pulses until stop message is sent - */ + /// Call repetitive vibrator pulses until stop message is sent void vibrationPulseRepeatUntilStop(sys::Service *serv); - /* - * @brief Set vibration level - */ + /// Set vibrator level void setVibrationLevel(sys::Service *serv, unsigned int vibrationLevel); } // namespace EventManagerServiceAPI diff --git a/products/PurePhone/services/evtmgr/EventManager.cpp b/products/PurePhone/services/evtmgr/EventManager.cpp index 9ff5260f3..8fbf44b34 100644 --- a/products/PurePhone/services/evtmgr/EventManager.cpp +++ b/products/PurePhone/services/evtmgr/EventManager.cpp @@ -16,8 +16,6 @@ #include #include -#include "log/log.hpp" - namespace { constexpr std::array sliderKeyCodes = { @@ -70,13 +68,13 @@ void EventManager::initProductEvents() return msg; }); - connect(sevm::VibratorMessage(bsp::vibrator::Action::stop), [&](sys::Message *msgl) { + connect(typeid(sevm::VibratorMessage), [&](sys::Message *msgl) { auto request = static_cast(msgl); processVibratorRequest(request->action, request->repetitionTime); return sys::msgHandled(); }); - connect(sevm::VibratorLevelMessage(0), [&](sys::Message *msgl) { + connect(typeid(sevm::VibratorLevelMessage), [&](sys::Message *msgl) { auto request = static_cast(msgl); processVibratorLevel(request->vibrationLevel); return sys::msgHandled(); @@ -215,6 +213,5 @@ void EventManager::processVibratorRequest(bsp::vibrator::Action act, std::chrono void EventManager::processVibratorLevel(unsigned int vibrationLevel) { - LOG_ERROR("Odbieram poziom vibracji %d", vibrationLevel); vibrator->SetVibrationLevel(vibrationLevel); }