// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "Vibra.hpp" #include "SystemManager/Constants.hpp" #include #include namespace vibra_handle { Vibra::Vibra(sys::Service *parent) { vibratorTimerOneshot = std::make_unique("VibraOneshotTimer", parent, bsp::vibrator::defaultVibraPulseMs); vibratorTimerPause = std::make_unique("VibraPauseTimer", parent, bsp::vibrator::defaultVibraPauseMs); vibratorTimerOneshot->connect(nullTimerCallback); vibratorTimerPause->connect(nullTimerCallback); vibratorTimerOneshot->stop(); vibratorTimerPause->stop(); } void Vibra::intPulse(bool repetitive) { if (repetitive) { vibratorTimerOneshot->connect([&](sys::Timer &) { bsp::vibrator::disable(); vibratorTimerPause->start(); }); } else { vibratorTimerOneshot->connect([&](sys::Timer &) { bsp::vibrator::disable(); }); } bsp::vibrator::enable(); vibratorTimerOneshot->start(); } void Vibra::Pulse() { intPulse(false); } void Vibra::PulseRepeat(sys::ms time) { repetitions = static_cast(time) / (static_cast(bsp::vibrator::defaultVibraPulseMs) + static_cast(bsp::vibrator::defaultVibraPauseMs)); vibratorTimerPause->connect([&](sys::Timer &) { if (repetitions) /// call itself for calculated number of repetitions { repetitions--; intPulse(true); } }); intPulse(true); } void Vibra::PulseRepeat() { vibratorTimerPause->connect([&](sys::Timer &) { intPulse(true); }); intPulse(true); } void Vibra::PulseRepeatStop() { repetitions = 1; bsp::vibrator::disable(); vibratorTimerPause->stop(); vibratorTimerOneshot->stop(); } } // namespace vibra_handle