50 lines
1.6 KiB
C++
50 lines
1.6 KiB
C++
/*
|
|
* PinFromDecoderSetupv2.cpp
|
|
*
|
|
* Created on: 22 îêò. 2019 ã.
|
|
* Author: user
|
|
*/
|
|
|
|
|
|
#include "PinFromDecoderv2Setup.hh"
|
|
|
|
#include "../../systemic/SystemException.hh"
|
|
|
|
struct GpioPinDecoderError : public systemic::SystemException {
|
|
|
|
const char * what() const noexcept { return "driver::GpioPinDecoder_v2::grab return nullptr"; }
|
|
std::size_t id() const noexcept { return 3873; };
|
|
std::pair<const char *, std::size_t> binary() const noexcept {
|
|
return {reinterpret_cast<const char *>(this), sizeof(GpioPinDecoderError)};
|
|
}
|
|
|
|
GpioPinDecoderError( configuration::Environment::Id decoder_id, uint16_t pin_id ) : decoder_id(decoder_id), pin_id(pin_id) {}
|
|
|
|
configuration::Environment::Id decoder_id;
|
|
uint16_t pin_id;
|
|
};
|
|
|
|
bool application::virtualization::PinFromDecoder_v2Setup::input( Environment & env ) {
|
|
|
|
return grab( pin_decoder, env.rholder.getShared< driver::GpioPinDecoder_v2 >( links.gpio_decoder_id ) );
|
|
|
|
}
|
|
|
|
void application::virtualization::PinFromDecoder_v2Setup::build( Environment & env ) {
|
|
|
|
Local< driver::GpioPinDecoder_v2 > decoder( pin_decoder, *env.rholder.getShared< driver::GpioPinDecoder_v2 >( links.gpio_decoder_id ) );
|
|
|
|
peripheral::IGpio * pin = decoder->grab( config.pin_id );
|
|
|
|
if( not pin )
|
|
throw GpioPinDecoderError( links.gpio_decoder_id, config.pin_id );
|
|
|
|
if( links.gpio_id )
|
|
env.rholder.share( *pin, links.gpio_id );
|
|
|
|
}
|
|
|
|
application::virtualization::PinFromDecoder_v2Setup::PinFromDecoder_v2Setup(
|
|
const Links & links, const Setting & config ) : links(links), config(config)
|
|
{}
|