Skip to content

Commit

Permalink
Ajout du vibreur pour lua. => on peut maintenant jouer une séquence d…
Browse files Browse the repository at this point in the history
…e vibrations. (hardware:vibrate({1, 0, 1...})
  • Loading branch information
paxo-rch committed Oct 28, 2024
1 parent eacaf28 commit eb4624d
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 35 deletions.
1 change: 1 addition & 0 deletions lib/hardware/hardware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define HARDWARE_HPP

#include "clock.hpp"
#include "vibrator.hpp"

namespace hardware
{
Expand Down
41 changes: 41 additions & 0 deletions lib/hardware/vibrator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <vibrator.hpp>


namespace hardware
{
namespace vibrator {
std::vector<bool> pattern;

void play(std::vector<bool> 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
}
}
}
12 changes: 12 additions & 0 deletions lib/hardware/vibrator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <hardware.hpp>
#include <gsm.hpp>
#include <vector>

namespace hardware
{
namespace vibrator {
void play(std::vector<bool> pattern);

void thread(void* data);
}
}
35 changes: 18 additions & 17 deletions lib/lua/src/lua_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ void LuaFile::load()
if (perms.acces_hardware) // si hardware est autorisé
{
lua.new_usertype<LuaHardware>("hardware",
"flash", &LuaHardware::flash);
"flash", &LuaHardware::flash,
"vibrate", hardware::vibrator::play);

lua["hardware"] = &lua_hardware;
}
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 3 additions & 18 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -296,6 +280,7 @@ void setup()

AppManager::init();

hardware::vibrator::play({1, 1, 0, 0, 1, 0, 1});
mainLoop(NULL);
}

Expand Down

0 comments on commit eb4624d

Please sign in to comment.