grove: rotary angle sensor

Signed-off-by: Mihai Tudor Panu <mihai.t.panu@intel.com>
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Mihai Tudor Panu
2014-11-06 10:01:12 -08:00
committed by Brendan Le Foll
parent e91b69230c
commit b2ffcdd9ea
6 changed files with 261 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
/*
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Contributions: Mihai Tudor Panu <mihai.t.panu@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
@@ -115,3 +116,47 @@ float GroveLight::raw_value()
{
return (float) mraa_aio_read(m_aio);
}
//// GroveRotary ////
GroveRotary::GroveRotary(unsigned int pin)
{
mraa_init();
m_aio = mraa_aio_init(pin);
m_name = "Rotary Angle Sensor";
}
GroveRotary::~GroveRotary()
{
mraa_aio_close(m_aio);
}
float GroveRotary::abs_value()
{
return (float) mraa_aio_read(m_aio);
}
float GroveRotary::abs_deg()
{
return GroveRotary::abs_value() * (float) m_max_angle / 1023.0;
}
float GroveRotary::abs_rad()
{
return GroveRotary::abs_deg() * M_PI / 180.0;
}
float GroveRotary::rel_value()
{
return GroveRotary::abs_value() - 512.0;
}
float GroveRotary::rel_deg()
{
return GroveRotary::rel_value() * (float) m_max_angle / 1023.0;
}
float GroveRotary::rel_rad()
{
return GroveRotary::rel_deg() * M_PI / 180.0;
}