added some tasks

This commit is contained in:
Jonas Zeunert
2018-11-21 00:08:59 +01:00
parent c1e4c0d658
commit 6cd1b21162
6 changed files with 32 additions and 40 deletions

View File

@@ -15,25 +15,22 @@ namespace output
Lamp::Lamp(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int i2c_address, int data_pin, std::string name, bool activated) : Lamp::Lamp(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int i2c_address, int data_pin, std::string name, bool activated) :
OutputItem(output_gpio_interface, i2c_address, data_pin, name), OutputItem(output_gpio_interface, i2c_address, data_pin, name),
activated(activated) activated(activated)
{ {}
// TODO Auto-generated constructor stub
}
Lamp::~Lamp() Lamp::~Lamp()
{ {}
// TODO Auto-generated destructor stub
}
void Lamp::activate() void Lamp::activate()
{ {
// activate OutputItem::activate();
} }
void Lamp::deactivate() void Lamp::deactivate()
{ {
// deactivate OutputItem::deactivate();
} }
} /* namespace output */ } /* namespace output */
} }

View File

@@ -31,6 +31,9 @@ protected:
std::string name; std::string name;
std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface; std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface;
void activate();
void deactivate();
}; };
} /* namespace output */ } /* namespace output */

View File

@@ -24,27 +24,17 @@ Solenoid::~Solenoid()
// TODO Auto-generated destructor stub // TODO Auto-generated destructor stub
} }
void Solenoid::triggerTask()
{
OutputItem::activate();
std::this_thread::sleep_for(50 /*todo change magic number */);
OutputItem::deactivate();
}
void Solenoid::trigger() void Solenoid::trigger()
{ {
this->activate(); std::async(std::launch::async, &Solenoid::triggerTask);
this->wait_thread = std::async(this->deactivate_after_wait);
}
void Solenoid::activate()
{
}
void Solenoid::deactivate_after_wait()
{
this->std::this_thread::sleep_for(deactivation_time);
this->deactivate();
}
void Solenoid::deactivate()
{
} }
} /* namespace output */ } /* namespace output */

View File

@@ -26,18 +26,10 @@ public:
Solenoid(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int i2c_address, int data_pin, std::string name, std::chrono::milliseconds deactivation_time); Solenoid(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interface, int i2c_address, int data_pin, std::string name, std::chrono::milliseconds deactivation_time);
virtual ~Solenoid(); virtual ~Solenoid();
//muss task sein
void trigger(); void trigger();
private: private:
std::future<void> wait_thread; virtual void triggerTask();
std::chrono::milliseconds deactivation_time;
void activate();
void deactivate();
void deactivate_after_wait();
};
} /* namespace output */ } /* namespace output */
} }

View File

@@ -7,6 +7,8 @@
#include "Sound.h" #include "Sound.h"
#include <future>
namespace flippR_driver namespace flippR_driver
{ {
namespace output namespace output
@@ -18,9 +20,16 @@ Sound::Sound(std::shared_ptr<utility::IOutputGPIOInterface> output_gpio_interfac
void Sound::play() void Sound::play()
{ {
// this->output_gpio_interface->activate(this); std::async(std::launch::async, &Sound::playTask);
// wait }
// deactivate()
void Sound::playTask()
{
OutputItem::activate();
std::this_thread::sleep_for(50 /*todo change magic number */);
OutputItem::deactivate();
} }
} /* namespace output */ } /* namespace output */

View File

@@ -29,6 +29,7 @@ public:
virtual void play(); virtual void play();
private: private:
virtual void playTask();
}; };
} /* namespace output */ } /* namespace output */