BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
b455a75
Branches
Tags
master
Blinker
src
noarch
FlexiPix.cpp
added flexipix output support added auto-configuration stuff to makefile
Stefan Schuermans
commited
b455a75
at 2011-12-14 22:02:48
FlexiPix.cpp
Blame
History
Raw
/* Blinker Copyright 2011 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 "CallMgr.h" #include "Directory.h" #include "File.h" #include "FlexiPix.h" #include "InStreamFile.h" #include "Module.h" #include "Size.h" #include "StreamMgr.h" #include "StreamRecv.h" #include "Time.h" #include "TimeCallee.h" namespace Blinker { /** * @brief constructor * @param[in] callMgr callback manager * @param[in] streamMgr stream manager * @param[in] dirBase base directory */ FlexiPix::FlexiPix(CallMgr &callMgr, StreamMgr &streamMgr, const Directory &dirBase): Module(callMgr, streamMgr, dirBase), m_fileInStream(dirBase.getFile("instream"), 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_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_callMgr.requestTimeCall(this, Time::now() + Time(1)); // for refresh } #endif // #ifdef BLINKER_CFG_FLEXIPIX } } // namespace Blinker