CVB++ 15.0
detail_emu_device.hpp
1#pragma once
2
3#include <memory>
4
5#include "../../global.hpp"
6
7#include "../_decl/decl_indexed_stream.hpp"
8#include "../_decl/decl_emu_device.hpp"
9#include "../_decl/decl_emu_image.hpp"
10#include "../_decl/decl_digital_io.hpp"
11
12namespace Cvb
13{
14
15 CVB_BEGIN_INLINE_NS
16
17 namespace Driver
18 {
19
21 {
22 auto digitalIO = DigitalIO();
23 return std::chrono::milliseconds(digitalIO->ReadOutputGroup(CExports::Emu::DelayGroup).to_ulong());
24 }
25
26 inline DeviceImagePtr EmuDevice::CreateDeviceImage() const
27 {
29 }
30
31 inline StreamBasePtr EmuDevice::CreateStream(int, StreamType streamType) const
32 {
33 if (streamType != StreamType::Legacy)
34 throw std::logic_error("this device supports only legacy streams");
36 }
37
38 inline EmuDevice::EmuStream::EmuStream(const DevicePtr &device)
39 : IndexedStream(device)
40 , layout_(Driver::BufferImage::ImageLayout::FromIMGHandle(device->Handle()))
41 , imageCount_(static_cast<int>(device->DigitalIO()->ReadInputGroup(CExports::Emu::ImageCountGroup).to_ulong()))
42 {
43 }
44
45 inline StreamImagePtr EmuDevice::EmuStream::MakeSnapshotImage()
46 {
47 auto frameTime = std::dynamic_pointer_cast<const Driver::EmuDevice>(Parent())->FrameTime();
48 return Driver::BufferImage::Create(Parent(), *layout_, static_cast<double>(ImageIndex() * frameTime.count()));
49 }
50
51 inline int EmuDevice::EmuStream::ImageIndex() const
52 {
53 auto digitalIO = Parent()->DigitalIO();
54 return static_cast<int>(digitalIO->ReadOutputGroup(CExports::Emu::CurrentImageIndexGroup).to_ullong());
55 }
56
57 inline void EmuDevice::EmuStream::SetImageIndex(int index)
58 {
59 if (index < 0 || index >= ImageCount())
60 throw std::out_of_range("image index out of range");
61
62 auto digitalIO = Parent()->DigitalIO();
63 digitalIO->WriteOutputGroup(CExports::Emu::CurrentImageIndexGroup,
64 std::bitset<32>(static_cast<std::uint32_t>(index)));
65 std::dynamic_pointer_cast<const EmuDevice>(Parent())->OnImageAcquired();
66 }
67
68 } // namespace Driver
69
70 CVB_END_INLINE_NS
71
72} // namespace Cvb
DigitalIOPtr DigitalIO() const
Gets the DigitalIO interface if present.
Definition detail_device.hpp:167
std::chrono::milliseconds FrameTime() const
Gets the time when frame is valid.
Definition detail_emu_device.hpp:20
DevicePtr Parent() const noexcept
Gets the parent device of this stream.
Definition stream_base.hpp:42
T make_shared(T... args)
Namespace for driver or device related operations.
Definition decl_composite.hpp:28
std::shared_ptr< StreamImage > StreamImagePtr
Convenience shared pointer for StreamImage.
Definition driver.hpp:93
std::shared_ptr< DeviceImage > DeviceImagePtr
Convenience shared pointer for DeviceImage.
Definition driver.hpp:61
std::shared_ptr< StreamBase > StreamBasePtr
Convenience shared pointer for StreamBase.
Definition driver.hpp:113
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::shared_ptr< Device > DevicePtr
Convenience shared pointer for Device.
Definition global.hpp:98
T const_pointer_cast(T... args)