diff --git a/lib/hardware/hardware.hpp b/lib/hardware/hardware.hpp index eb7eea4f..da44f943 100644 --- a/lib/hardware/hardware.hpp +++ b/lib/hardware/hardware.hpp @@ -2,6 +2,7 @@ #define HARDWARE_HPP #include "clock.hpp" +#include "vibrator.hpp" namespace hardware { diff --git a/lib/hardware/vibrator.cpp b/lib/hardware/vibrator.cpp new file mode 100644 index 00000000..855a9ee4 --- /dev/null +++ b/lib/hardware/vibrator.cpp @@ -0,0 +1,41 @@ +#include + + +namespace hardware +{ + namespace vibrator { + std::vector pattern; + + void play(std::vector pattern) + { + vibrator::pattern = pattern; + } + + void thread(void* data) + { + #ifdef ESP_PLATFORM + while (true) + { + if(GSM::state.callState == GSM::CallState::RINGING) + { + delay(200); hardware::setVibrator(true); delay(100); hardware::setVibrator(false); + } + + if(pattern.size() > 0) + { + hardware::setVibrator(pattern[0]); + pattern.erase(pattern.begin()); + delay(100); + + if(pattern.size() == 0) + { + hardware::setVibrator(false); + } + } + + delay(1); + } + #endif + } + } +} \ No newline at end of file diff --git a/lib/hardware/vibrator.hpp b/lib/hardware/vibrator.hpp new file mode 100644 index 00000000..8ff875a4 --- /dev/null +++ b/lib/hardware/vibrator.hpp @@ -0,0 +1,12 @@ +#include +#include +#include + +namespace hardware +{ + namespace vibrator { + void play(std::vector pattern); + + void thread(void* data); + } +} \ No newline at end of file diff --git a/lib/lua/src/lua_file.cpp b/lib/lua/src/lua_file.cpp index 86e0705d..41270f22 100755 --- a/lib/lua/src/lua_file.cpp +++ b/lib/lua/src/lua_file.cpp @@ -331,7 +331,8 @@ void LuaFile::load() if (perms.acces_hardware) // si hardware est autorisé { lua.new_usertype("hardware", - "flash", &LuaHardware::flash); + "flash", &LuaHardware::flash, + "vibrate", hardware::vibrator::play); lua["hardware"] = &lua_hardware; } @@ -628,22 +629,22 @@ void LuaFile::load() } return true; }, - [&](std::string name) - { - try - { - AppManager::get(name)->run(false, {}); - } - catch (std::runtime_error &e) - { - std::cerr << "Erreur: " << e.what() << std::endl; - // Ajout message d'erreur - GuiManager &guiManager = GuiManager::getInstance(); - guiManager.showErrorMessage(e.what()); - } - - return true; - })); + [&](std::string name) + { + try + { + AppManager::get(name)->run(false, {}); + } + catch (std::runtime_error &e) + { + std::cerr << "Erreur: " << e.what() << std::endl; + // Ajout message d'erreur + GuiManager &guiManager = GuiManager::getInstance(); + guiManager.showErrorMessage(e.what()); + } + + return true; + })); } if (perms.acces_time) diff --git a/src/main.cpp b/src/main.cpp index 485cdba4..03c350be 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,22 +34,6 @@ SET_LOOP_TASK_STACK_SIZE(16 * 1024); using namespace gui::elements; - - -void ringingVibrator(void* data) -{ - #ifdef ESP_PLATFORM - while (true) - { - if(GSM::state.callState == GSM::CallState::RINGING) - { - delay(200); hardware::setVibrator(true); delay(100); hardware::setVibrator(false); - } - delay(10); - } - #endif -} - void mainLoop(void* data) { #ifdef ESP_PLATFORM if (!backtrace_saver::isBacktraceEmpty()) { @@ -264,7 +248,7 @@ void setup() GSM::ExternalEvents::onNewMessage = []() { #ifdef ESP_PLATFORM - eventHandlerBack.setTimeout(new Callback<>([](){delay(200); hardware::setVibrator(true); delay(100); hardware::setVibrator(false);}), 0); + eventHandlerBack.setTimeout(new Callback<>([](){hardware::vibrator::play({1, 0, 1});}), 0); #endif AppManager::event_onmessage(); @@ -276,7 +260,7 @@ void setup() }; #ifdef ESP_PLATFORM - ThreadManager::new_thread(CORE_BACK, &ringingVibrator, 16000); + ThreadManager::new_thread(CORE_BACK, &hardware::vibrator::thread, 16000); #endif // gestion de la détection du toucher de l'écran @@ -296,6 +280,7 @@ void setup() AppManager::init(); + hardware::vibrator::play({1, 1, 0, 0, 1, 0, 1}); mainLoop(NULL); }