Initial commit

parents
*~
*.swp
*target*
\ No newline at end of file
src-dirs = src
test-dirs =
include ../../global.inc
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef V4L2CAMERA_H
#define V4L2CAMERA_H
#include <linux/videodev2.h>
#include <libv4l2.h>
#include "lima/Debug.h"
#include "lima/SizeUtils.h"
#include "lima/Constants.h"
#include "lima/HwInterface.h"
namespace lima
{
namespace V4L2
{
class Camera
{
DEB_CLASS_NAMESPC(DebModCamera, "Camera", "V4L2");
public:
class Callback
{
public:
virtual bool newFrame(int frame_id,const unsigned char*) = 0;
};
Camera(Callback*,const char* video_device = "/dev/video0");
~Camera();
// --- Detector Info
void getMaxImageSize(Size&);
void getCurrImageType(ImageType&);
void setCurrImageType(ImageType);
void getDetectorModel(std::string& det_model);
// --- Syn Obj
void getMinMaxExpTime(double& min,double& max);
void setExpTime(double exp_time);
void getExpTime(double& exp_time);
void setNbHwFrames(int nb_frames);
void getNbHwFrames(int& nb_frames);
// --- Acquisition interface
void reset(HwInterface::ResetLevel reset_level);
void prepareAcq();
void startAcq();
void stopAcq();
void getStatus(HwInterface::StatusType& status);
int getNbHwAcquiredFrames();
private:
class _AcqThread;
friend class _AcqThread;
Callback* m_cbk;
int m_fd;
struct v4l2_buffer m_buffer;
unsigned char* m_buffers[2];
std::string m_det_model;
int m_nb_frames;
int m_acq_frame_id;
bool m_acq_started;
bool m_acq_thread_run;
std::list<int> m_available_format;
_AcqThread* m_acq_thread;
int m_pipes[2];
bool m_quit;
Cond m_cond;
};
}
}
#endif
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef V4L2DETINFO_H
#define V4L2DETINFO_H
#include "lima/HwDetInfoCtrlObj.h"
namespace lima
{
namespace V4L2
{
class Camera;
class DetInfoCtrlObj : public HwDetInfoCtrlObj
{
DEB_CLASS_NAMESPC(DebModCamera, "DetInfoCtrlObj", "V4L2");
public:
DetInfoCtrlObj(int fd);
virtual ~DetInfoCtrlObj();
virtual void getMaxImageSize(Size& max_image_size);
virtual void getDetectorImageSize(Size& det_image_size);
virtual void getDefImageType(ImageType& def_image_type);
virtual void getCurrImageType(ImageType& curr_image_type);
virtual void setCurrImageType(ImageType curr_image_type);
virtual void getPixelSize(double& x_size,double &y_size);
virtual void getDetectorType(std::string& det_type);
virtual void getDetectorModel(std::string& det_model);
virtual void registerMaxImageSizeCallback(HwMaxImageSizeCallback& cb);
virtual void unregisterMaxImageSizeCallback(HwMaxImageSizeCallback& cb);
void getAvailableFormat(std::list<int>& formats) const {formats = m_available_format;}
private:
void _maxImageSize(Size&);
void _getCurrentImageType(ImageType&);
HwMaxImageSizeCallbackGen m_mis_cb_gen;
int m_fd;
std::list<int> m_available_format;
std::string m_det_model;
};
}
}
#endif
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef V4L2INTERFACE_H
#define V4L2INTERFACE_H
#include "lima/Debug.h"
#include "lima/HwInterface.h"
namespace lima
{
namespace V4L2
{
class DetInfoCtrlObj;
class SyncCtrlObj;
class Camera;
class Interface : public HwInterface
{
DEB_CLASS_NAMESPC(DebModCamera, "Interface", "V4L2");
public:
Interface(const char* dev_path = "/dev/video0");
virtual ~Interface();
virtual void getCapList(CapList &) const;
virtual void reset(ResetLevel reset_level);
virtual void prepareAcq();
virtual void startAcq();
virtual void stopAcq();
virtual void getStatus(StatusType& status);
virtual int getNbHwAcquiredFrames();
private:
class _Callback;
friend class _Callback;
DetInfoCtrlObj* m_det_info;
SyncCtrlObj* m_sync;
Camera* m_cam;
_Callback* m_cbk;
};
}
}
#endif
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef V4L2SYNCCTRLOBJ_H
#define V4L2SYNCCTRLOBJ_H
#include "lima/HwSyncCtrlObj.h"
#include "V4L2Interface.h"
namespace lima
{
namespace V4L2
{
class SyncCtrlObj : public HwSyncCtrlObj
{
friend class Interface;
DEB_CLASS_NAMESPC(DebModCamera, "SyncCtrlObj", "V4L2");
public:
SyncCtrlObj(int fd);
virtual ~SyncCtrlObj();
virtual bool checkTrigMode(TrigMode trig_mode);
virtual void setTrigMode(TrigMode trig_mode);
virtual void getTrigMode(TrigMode& trig_mode);
virtual void setExpTime(double exp_time);
virtual void getExpTime(double& exp_time);
virtual bool checkAutoExposureMode(AutoExposureMode mode) const;
virtual void setLatTime(double lat_time);
virtual void getLatTime(double& lat_time);
virtual void setNbHwFrames(int nb_frames);
virtual void getNbHwFrames(int& nb_frames);
virtual void getValidRanges(ValidRangesType& valid_ranges);
private:
int m_fd;
int m_nb_frames;
};
}
}
#endif
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#ifndef V4L2VIDEOCTRLOBJ_H
#define V4L2VIDEOCTRLOBJ_H
#include "lima/HwVideoCtrlObj.h"
namespace lima
{
namespace V4L2
{
class DetInfoCtrlObj;
class VideoCtrlObj : public HwVideoCtrlObj
{
DEB_CLASS_NAMESPC(DebModCamera,"VideoCtrlObj","V4L2");
public:
VideoCtrlObj(int fd,DetInfoCtrlObj&);
virtual ~VideoCtrlObj();
virtual void getSupportedVideoMode(std::list<VideoMode>& list) const;
virtual void setVideoMode(VideoMode);
virtual void getVideoMode(VideoMode&) const;
virtual void setLive(bool);
virtual void getLive(bool&) const;
virtual void getGain(double&) const;
virtual void setGain(double);
virtual bool checkAutoGainMode(AutoGainMode) const;
virtual void setHwAutoGainMode(AutoGainMode);
virtual void checkBin(Bin& bin);
virtual void checkRoi(const Roi& set_roi,Roi& hw_roi);
virtual void setBin(const Bin&);
virtual void setRoi(const Roi&);
private:
int m_fd;
DetInfoCtrlObj& m_det_info;
Cond m_cond;
bool m_acq_started;
int m_pipes[2];
};
}
}
#endif
############################################################################
# This file is part of LImA, a Library for Image Acquisition
#
# Copyright (C) : 2009-2011
# European Synchrotron Radiation Facility
# BP 220, Grenoble 38043
# FRANCE
#
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
############################################################################
from Lima import module_helper
mod_path = __path__
depends_on = 'Core'
has_dependent = False
cleanup_data = module_helper.load_prepare(mod_path, depends_on, has_dependent)
from Lima import Core
cleanup_data = module_helper.load_dep_cleanup(cleanup_data)
from Lima.Tutorial.limatutorial import Tutorial as _Tuto
globals().update(_Tuto.__dict__)
module_helper.load_cleanup(cleanup_data)
del mod_path, depends_on, has_dependent, cleanup_data
del module_helper
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
namespace Tutorial
{
class Camera
{
%TypeHeaderCode
#include <TutorialCamera.h>
%End
public:
class Callback
{
public:
virtual bool newFrame(int frame_id,const unsigned char*) = 0;
};
Camera(Callback*,const char* video_device = "/dev/video0");
~Camera();
// --- Detector Info
void getMaxImageSize(Size& /Out/);
void getCurrImageType(ImageType& /Out/);
void setCurrImageType(ImageType);
void getDetectorModel(std::string& det_model /Out/);
// --- Syn Obj
void getMinMaxExpTime(double& min /Out/,double& max /Out/);
void setExpTime(double exp_time);
void getExpTime(double& exp_time /out/);
void setNbHwFrames(int nb_frames);
void getNbHwFrames(int& nb_frames /Out/);
// --- Acquisition interface
void reset(HwInterface::ResetLevel reset_level);
void prepareAcq();
void startAcq();
void stopAcq();
void getStatus(HwInterface::StatusType& status /Out/);
int getNbHwAcquiredFrames();
};
};
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
namespace Tutorial
{
class Interface : HwInterface
{
%TypeHeaderCode
#include <TutorialInterface.h>
%End
public:
Interface(const char* dev_path = "/dev/video0");
virtual ~Interface();
virtual void getCapList(std::vector<HwCap> &cap_list /Out/) const;
virtual void reset(ResetLevel reset_level);
virtual void prepareAcq();
virtual void startAcq();
virtual void stopAcq();
virtual void getStatus(StatusType& status /Out/);
virtual int getNbHwAcquiredFrames();
};
};
*.o
*.P
*.d
tutorial-objs = TutorialDetInfoCtrlObj.o TutorialSyncCtrlObj.o TutorialInterface.o TutorialCamera.o
SRCS = $(tutorial-objs:.o=.cpp)
CXXFLAGS += -I../include -I../../../hardware/include -I../../../common/include -I../../../third-party/Processlib/core/include -pthread -fPIC -g
all: Tutorial.o
Tutorial.o: $(tutorial-objs)
$(LD) -o $@ -r $+
clean:
rm -f *.o *.P
.PHONY: check-syntax
check-syntax:
$(CXX) -Wall -Wextra -pedantic -fsyntax-only $(CXXFLAGS) $(CHK_SOURCES)
%.o : %.cpp
$(COMPILE.cpp) -MD $(CXXFLAGS) -o $@ $<
@cp $*.d $*.P; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
rm -f $*.d
-include $(SRCS:.cpp=.P)
.PHONY: check-syntax
check-syntax:
$(CXX) -Wall -Wextra -fsyntax-only $(CXXFLAGS) $(CHK_SOURCES)
This diff is collapsed.
This diff is collapsed.
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#include "V4L2Interface.h"
#include "V4L2DetInfoCtrlObj.h"
#include "V4L2SyncCtrlObj.h"
#include "V4L2Camera.h"
using namespace lima;
using namespace lima::V4L2;
class Interface::_Callback : public Camera::Callback
{
DEB_CLASS_NAMESPC(DebModCamera, "Interface::_Callback", "V4L2");
public:
_Callback(Interface& i) : m_interface(i) {}
virtual bool newFrame(int frame_id,const unsigned char* srcPt)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(frame_id);
StdBufferCbMgr& buffer_mgr = m_interface.m_buffer_ctrl_obj.getBuffer();
void* framePt = buffer_mgr.getFrameBufferPtr(frame_id);
const FrameDim& fDim = buffer_mgr.getFrameDim();
memcpy(framePt,srcPt,fDim.getMemSize());
HwFrameInfoType frame_info;
frame_info.acq_frame_nb = frame_id;
return buffer_mgr.newFrameReady(frame_info);
}
private:
Interface& m_interface;
};
Interface::Interface(const char* dev_path)
{
DEB_CONSTRUCTOR();
m_cbk = new _Callback(*this);
m_cam = new Camera(m_cbk,dev_path);
m_det_info = new DetInfoCtrlObj(*m_cam);
m_sync = new SyncCtrlObj(*m_cam);
}
Interface::~Interface()
{
DEB_DESTRUCTOR();
delete m_sync;
delete m_det_info;
delete m_cam;
}
void Interface::getCapList(CapList &cap_list) const
{
DEB_MEMBER_FUNCT();
cap_list.push_back(HwCap(m_sync));
cap_list.push_back(HwCap(m_det_info));
cap_list.push_back(HwCap(&m_buffer_ctrl_obj));
}
void Interface::reset(ResetLevel reset_level)
{
//Not managed
}
void Interface::prepareAcq()
{
DEB_MEMBER_FUNCT();
m_cam->prepareAcq();
}
void Interface::startAcq()
{
DEB_MEMBER_FUNCT();
StdBufferCbMgr& buffer_mgr = m_buffer_ctrl_obj.getBuffer();
buffer_mgr.setStartTimestamp(Timestamp::now());
m_cam->startAcq();
}
void Interface::stopAcq()
{
DEB_MEMBER_FUNCT();
m_cam->stopAcq();
}
void Interface::getStatus(StatusType &status)
{
DEB_MEMBER_FUNCT();
m_cam->getStatus(status);
DEB_RETURN() << DEB_VAR1(status);
}
int Interface::getNbHwAcquiredFrames()
{
DEB_MEMBER_FUNCT();
int acq_frames = m_cam->getNbHwAcquiredFrames();
DEB_RETURN() << DEB_VAR1(acq_frames);
return acq_frames;
}
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#include <cmath>
#include <errno.h>
#include "V4L2SyncCtrlObj.h"
#include "V4L2Camera.h"
using namespace lima;
using namespace lima::V4L2;
SyncCtrlObj::SyncCtrlObj(int fd) :
m_fd(fd),
m_nb_frames(1)
{
}
SyncCtrlObj::~SyncCtrlObj()
{
}
bool SyncCtrlObj::checkTrigMode(TrigMode trig_mode)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(trig_mode);
bool returnValue = trig_mode == IntTrig;
DEB_RETURN() << DEB_VAR1(returnValue);
return returnValue;
}
void SyncCtrlObj::setTrigMode(TrigMode trig_mode)
{
DEB_MEMBER_FUNCT();
DEB_PARAM() << DEB_VAR1(trig_mode);
if(!checkTrigMode(trig_mode))
THROW_HW_ERROR(InvalidValue) << DEB_VAR1(trig_mode) << " is not supported";
}
void SyncCtrlObj::getTrigMode(TrigMode& trig_mode)
{
DEB_MEMBER_FUNCT();
trig_mode = IntTrig;
DEB_RETURN() << DEB_VAR1(trig_mode);
}
void SyncCtrlObj::setExpTime(double)
{
DEB_MEMBER_FUNCT();