Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F123361
MappedInputDeviceLoader.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
MappedInputDeviceLoader.cpp
View Options
#include
<echo/FileSystem/File.h>
#include
<echo/FileSystem/FileSystem.h>
#include
<echo/Util/Configuration.h>
#include
<echo/Util/Protobuf.h>
#include
<echo/Input/Input.h>
#include
<echo/Input/MappedInputDevice.h>
#include
<echo/generated/MappedInputDevice.pb.h>
namespace
Echo
{
namespace
MappedInputDeviceLoader
{
shared_ptr
<
MappedInputDevice
>
LoadDevice
(
File
mappingFile
,
InputManager
&
inputManager
)
{
if
(
!
mappingFile
.
IsOpen
())
{
std
::
cout
<<
"Error MappedInputDeviceLoader::LoadMappings() - file not open
\"
"
<<
mappingFile
.
GetActualFileName
()
<<
"
\"
"
<<
std
::
endl
;
return
shared_ptr
<
MappedInputDevice
>
();
}
std
::
string
wholeFile
;
mappingFile
.
ReadFileIntoString
(
wholeFile
);
Echo
::
Resources
::
MappedInputDevice
mappedData
;
if
(
!
ParseProtobuf
<
Echo
::
Resources
::
MappedInputDevice
>
(
wholeFile
,
mappedData
,
mappingFile
.
GetActualFileName
(),
"MappedInputDeviceLoader::LoadDevice()"
))
{
std
::
cout
<<
"Error: MappedInputDeviceLoader::LoadMappings() Failed to parse input.
\"
"
<<
mappingFile
.
GetActualFileName
()
<<
"
\"
"
<<
std
::
endl
;
return
shared_ptr
<
MappedInputDevice
>
();
}
//Set device name
shared_ptr
<
MappedInputDevice
>
targetMappedDevice
(
new
MappedInputDevice
(
mappedData
.
name
(),
inputManager
));
u32
deviceNumber
=
inputManager
.
InstallDevice
(
mappedData
.
name
(),
targetMappedDevice
);
std
::
stringstream
deviceID
;
deviceID
<<
mappedData
.
name
()
<<
"("
<<
deviceNumber
<<
")"
;
//Analogue inputs
for
(
size_t
i
=
0
;
i
<
mappedData
.
analogue_size
();
++
i
)
{
const
Echo
::
Resources
::
MappedInputDevice
::
AnalogueInput
&
anagloueMapping
=
mappedData
.
analogue
(
i
);
std
::
vector
<
std
::
string
>
inputSourceNames
;
std
::
vector
<
f32
>
analogValues
;
for
(
size_t
s
=
0
;
s
<
anagloueMapping
.
source_size
();
++
s
)
{
inputSourceNames
.
push_back
(
anagloueMapping
.
source
(
s
));
}
for
(
size_t
v
=
0
;
v
<
anagloueMapping
.
value_size
();
++
v
)
{
analogValues
.
push_back
(
anagloueMapping
.
value
(
v
));
}
if
(
!
targetMappedDevice
->
CreateAnalogInput
(
anagloueMapping
.
name
(),
inputSourceNames
,
analogValues
))
{
std
::
cout
<<
"MappedInputDeviceLoader::LoadMappings() : failed to create analogue input mapping "
<<
anagloueMapping
.
name
()
<<
std
::
endl
;
inputManager
.
UninstallDevice
(
deviceID
.
str
());
return
shared_ptr
<
MappedInputDevice
>
();
}
}
//Digital inputs
for
(
size_t
i
=
0
;
i
<
mappedData
.
digital_size
();
++
i
)
{
const
Echo
::
Resources
::
MappedInputDevice
::
DigitalInput
&
digitalMapping
=
mappedData
.
digital
(
i
);
f32
threshold
=
0.5f
;
if
(
digitalMapping
.
has_threshold
())
{
threshold
=
digitalMapping
.
threshold
();
}
if
(
!
targetMappedDevice
->
CreateDigitalInput
(
digitalMapping
.
name
(),
digitalMapping
.
source
(),
threshold
))
{
std
::
cout
<<
"MappedInputDeviceLoader::LoadMappings() : failed to create digital input mapping "
<<
digitalMapping
.
name
()
<<
std
::
endl
;
inputManager
.
UninstallDevice
(
deviceID
.
str
());
return
shared_ptr
<
MappedInputDevice
>
();
}
}
return
targetMappedDevice
;
}
size_t
LoadMappedDevices
(
Configuration
&
configuration
,
InputManager
&
inputManager
,
FileSystem
&
fileSystem
,
std
::
string
optionName
)
{
size_t
devicesLoaded
=
0
;
;
size_t
numberOfOptions
=
configuration
.
GetNumberOfOptionsNamed
(
optionName
);
for
(
size_t
i
=
0
;
i
<
numberOfOptions
;
++
i
)
{
std
::
string
deviceFile
=
configuration
.
GetAtIndex
<
std
::
string
>
(
optionName
,
""
,
i
);
if
(
!
deviceFile
.
empty
())
{
shared_ptr
<
MappedInputDevice
>
device
=
MappedInputDeviceLoader
::
LoadDevice
(
fileSystem
.
Open
(
deviceFile
),
inputManager
);
if
(
device
)
{
std
::
cout
<<
"Loaded mapped input device: "
<<
deviceFile
<<
std
::
endl
;
++
devicesLoaded
;
}
}
}
return
devicesLoaded
;
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Wed, Jan 15, 6:38 PM (39 m, 40 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
72025
Default Alt Text
MappedInputDeviceLoader.cpp (3 KB)
Attached To
Mode
rEE Echo 3
Attached
Detach File
Event Timeline
Log In to Comment