Continued work
This commit is contained in:
@@ -9,15 +9,10 @@ using namespace bsp;
|
||||
/**** Private constants ****/
|
||||
/**** Private variables ****/
|
||||
/**** Private function declarations ****/
|
||||
|
||||
/**** Public function definitions ****/
|
||||
bsp::DigitalIn::DigitalIn(uint8_t gpio_ch, uint8_t inverted, uint8_t init_value)
|
||||
bsp::DigitalIn::DigitalIn(void)
|
||||
{
|
||||
this->gpio_ch = gpio_ch;
|
||||
this->invert = inverted;
|
||||
|
||||
if(init_value) this->last_read = DIN_HIGH;
|
||||
else this->last_read = DIN_LOW;
|
||||
return;
|
||||
}
|
||||
|
||||
bsp::DigitalIn::~DigitalIn(void)
|
||||
@@ -25,16 +20,29 @@ bsp::DigitalIn::~DigitalIn(void)
|
||||
return;
|
||||
}
|
||||
|
||||
void bsp::DigitalIn::init(uint8_t gpio_ch, uint8_t inverted)
|
||||
{
|
||||
this->gpio_ch = gpio_ch;
|
||||
if(inverted == 0) this->is_inverted = 0;
|
||||
else this->is_inverted = 1;
|
||||
this->last_read = 0;
|
||||
}
|
||||
|
||||
|
||||
uint8_t bsp::DigitalIn::read(void)
|
||||
{
|
||||
uint8_t lvl = mcu::gpio_read(this->gpio_ch);
|
||||
// Read ADC
|
||||
this->last_read = mcu::gpio_read(this->gpio_ch);
|
||||
|
||||
if(this->invert) lvl = util::invert(lvl);
|
||||
|
||||
if(lvl>0) this->last_read = DIN_HIGH;
|
||||
else this->last_read = DIN_LOW;
|
||||
// Invert if necessary
|
||||
if(this->is_inverted)
|
||||
{
|
||||
if(this->last_read==0) this->last_read = 1;
|
||||
else this->last_read = 0;
|
||||
};
|
||||
|
||||
return this->last_read;
|
||||
}
|
||||
|
||||
/**** Private function definitions ****/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user