BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
b6b2996
Branches
Tags
master
Blinker
src
noarch
FlexiPix.cpp
update copyright years
Stefan Schuermans
commited
b6b2996
at 2014-01-02 21:57:13
FlexiPix.cpp
Blame
History
Raw
/* Blinker Copyright 2011-2014 Stefan Schuermans <stefan@blinkenarea.org> Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html a blinkenarea.org project */ #include <iostream> #include <stdlib.h> #include <string> #include <string.h> #include <BlinkenLib/BlinkenFrame.h> #include <BlinkenLib/BlinkenProto.h> #ifdef BLINKER_CFG_FLEXIPIX extern "C" { #include <flexipix/flexipix.h> } // extern "C" #endif // #ifdef BLINKER_CFG_FLEIXPIX #include "Directory.h" #include "File.h" #include "FlexiPix.h" #include "InStreamFile.h" #include "Mgrs.h" #include "Module.h" #include "Size.h" #include "StreamRecv.h" #include "Time.h" #include "TimeCallee.h" namespace Blinker { /** * @brief constructor * @param[in] name module name * @param[in] mgrs managers * @param[in] dirBase base directory */ FlexiPix::FlexiPix(const std::string &name, Mgrs &mgrs, const Directory &dirBase): Module(name, mgrs, dirBase), m_fileInStream(dirBase.getFile("instream"), mgrs.m_streamMgr), m_fileConfig(dirBase.getFile("flexipix.flp")), m_pDisplay(NULL) { // set up m_fileInStream.setStreamRecv(this); createDisplay(); } /// virtual destructor FlexiPix::~FlexiPix() { // clean up destroyDisplay(); m_fileInStream.setStreamRecv(NULL); m_mgrs.m_callMgr.cancelTimeCall(this); } /// check for update of configuration void FlexiPix::updateConfig() { // input stream name file was modified -> re-get input stream if (m_fileInStream.checkModified()) m_fileInStream.update(); // FlexiPix config file was modified -> re-create display if (m_fileConfig.checkModified()) createDisplay(); } /** * @brief set current frame * @param[in] stream stream name * @param[in] pFrame current frame (NULL for none) */ void FlexiPix::setFrame(const std::string &stream, stBlinkenFrame *pFrame) { displayFrame(pFrame); (void)stream; // unused } /// callback when requested time reached void FlexiPix::timeCall() { // refresh frame sendFrame(); } /// (re-)create FlexiPix display void FlexiPix::createDisplay() { #ifdef BLINKER_CFG_FLEXIPIX destroyDisplay(); // create a display m_pDisplay = flp_display_create(m_fileConfig.getPath().c_str(), NULL, NULL); if (!m_pDisplay) return; // get size of display flp_display_get_size(m_pDisplay, &m_size.m_width, &m_size.m_height); // output current frame displayFrame(m_fileInStream.getCurFrame()); #endif // #ifdef BLINKER_CFG_FLEXIPIX } /// destroy FlexiPix display void FlexiPix::destroyDisplay() { #ifdef BLINKER_CFG_FLEXIPIX if (m_pDisplay) { flp_display_free(m_pDisplay); m_pDisplay = NULL; } #endif // #ifdef BLINKER_CFG_FLEXIPIX } /** * @brief display frame on FlexiPix * @param[in] pFrame frame to display (or NULL) */ void FlexiPix::displayFrame(stBlinkenFrame *pFrame) { #ifdef BLINKER_CFG_FLEXIPIX char data[65536]; bool haveData = false; stBlinkenFrame *pClonedFrame; // leave if no display if (!m_pDisplay) return; // convert frame to needed size and then to MCUF data as FlexiPix library // can read data section of MCUF packet // frame available if (pFrame) { // format matches (size matches and 24bit RGB as required by FlexiPix) if (BlinkenFrameGetWidth(pFrame) == (int)m_size.m_width && BlinkenFrameGetHeight(pFrame) == (int)m_size.m_height && BlinkenFrameGetChannels(pFrame) == 3 && BlinkenFrameGetMaxval(pFrame) == 255) { // convert to MCUF packet haveData = BlinkenFrameToNetwork(pFrame, BlinkenProtoMcuf, data, sizeof(data)) >= 0; } // format does not match else { // convert format: clone and resize pClonedFrame = BlinkenFrameClone(pFrame); if (pClonedFrame) { BlinkenFrameResize(pClonedFrame, m_size.m_height, m_size.m_width, 3, 255); // convert to MCUF packet haveData = BlinkenFrameToNetwork(pFrame, BlinkenProtoMcuf, data, sizeof(data)) >= 0; // free clones frame BlinkenFrameFree(pClonedFrame); } } } // data available -> to FlexiPix display if (haveData) flp_display_data(m_pDisplay, (flp_u8_t*)(data + 12), 3, m_size.m_width * 3, 0, 0, m_size.m_width, m_size.m_height); // no data available -> clear FlexiPix display else flp_display_data_clear(m_pDisplay); // send configured frame sendFrame(); #else // #ifdef BLINKER_CFG_FLEXIPIX (void)pFrame; #endif // #ifdef BLINKER_CFG_FLEXIPIX else } /// (re-)send frame to FlexiPix void FlexiPix::sendFrame() { #ifdef BLINKER_CFG_FLEXIPIX if (m_pDisplay) { flp_display_send(m_pDisplay); m_mgrs.m_callMgr.requestTimeCall(this, Time::now() + Time(1)); // refresh } #endif // #ifdef BLINKER_CFG_FLEXIPIX } } // namespace Blinker