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) :
OutputItem(output_gpio_interface, i2c_address, data_pin, name),
activated(activated)
{
// TODO Auto-generated constructor stub
}
{}
Lamp::~Lamp()
{
// TODO Auto-generated destructor stub
}
{}
void Lamp::activate()
{
// activate
OutputItem::activate();
}
void Lamp::deactivate()
{
// deactivate
OutputItem::deactivate();
}
} /* namespace output */
}

View File

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

View File

@@ -24,27 +24,17 @@ Solenoid::~Solenoid()
// 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()
{
this->activate();
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()
{
std::async(std::launch::async, &Solenoid::triggerTask);
}
} /* 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);
virtual ~Solenoid();
//muss task sein
void trigger();
private:
std::future<void> wait_thread;
std::chrono::milliseconds deactivation_time;
void activate();
void deactivate();
void deactivate_after_wait();
};
virtual void triggerTask();
} /* namespace output */
}

View File

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

View File

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