mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
DS1808LC: Add string based cons for Controller
Signed-off-by: Adelin Dobre <adelin.dobre@rinftech.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
parent
6cbfa60729
commit
f608b0fa98
@ -4,6 +4,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "ds1808lc.hpp"
|
#include "ds1808lc.hpp"
|
||||||
#include "mraa-utils.hpp"
|
#include "mraa-utils.hpp"
|
||||||
|
#include "upm_string_parser.hpp"
|
||||||
|
|
||||||
#define DS1808_I2C_ADDR 0x28
|
#define DS1808_I2C_ADDR 0x28
|
||||||
#define DS1808_POT2_OFFSET 0x40
|
#define DS1808_POT2_OFFSET 0x40
|
||||||
@ -11,6 +12,10 @@
|
|||||||
#define DS1808_LOW_VALUE 32 // Lowest pot value that the eye can differentiate from 0
|
#define DS1808_LOW_VALUE 32 // Lowest pot value that the eye can differentiate from 0
|
||||||
#define DS1808_HIGH_VALUE 51 // Highest pot value that the eye can differentiate from full
|
#define DS1808_HIGH_VALUE 51 // Highest pot value that the eye can differentiate from full
|
||||||
|
|
||||||
|
static bool operator!(mraa::MraaIo &mraaIo)
|
||||||
|
{
|
||||||
|
return mraaIo.getMraaDescriptors() == NULL;
|
||||||
|
}
|
||||||
|
|
||||||
namespace upm {
|
namespace upm {
|
||||||
DS1808LC::DS1808LC(int gpioPower, int i2cBus)
|
DS1808LC::DS1808LC(int gpioPower, int i2cBus)
|
||||||
@ -22,8 +27,41 @@ DS1808LC::DS1808LC(int gpioPower, int i2cBus)
|
|||||||
getBrightness();
|
getBrightness();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DS1808LC::DS1808LC(std::string initStr) : mraaIo(initStr)
|
||||||
|
{
|
||||||
|
std::vector<std::string> upmTokens;
|
||||||
|
|
||||||
|
mraa_set_log_level(7);
|
||||||
|
if(!mraaIo.i2cs.empty()) {
|
||||||
|
i2c = &mraaIo.i2cs[0];
|
||||||
|
} else {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.init() failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
status = i2c->address(DS1808_I2C_ADDR);
|
||||||
|
|
||||||
|
if(!mraaIo.getLeftoverStr().empty()) {
|
||||||
|
upmTokens = UpmStringParser::parse(mraaIo.getLeftoverStr());
|
||||||
|
}
|
||||||
|
|
||||||
|
for(std::string tok : upmTokens) {
|
||||||
|
if(tok.substr(0, 10) == "gpioPower:") {
|
||||||
|
int gpioPower = std::stoi(tok.substr(10), nullptr, 0);
|
||||||
|
pinPower = gpioPower;
|
||||||
|
}
|
||||||
|
if(tok.substr(0, 14) == "setBrightness:") {
|
||||||
|
int dutyPercent = std::stoi(tok.substr(14), nullptr, 0);
|
||||||
|
setBrightness(dutyPercent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getBrightness();
|
||||||
|
}
|
||||||
|
|
||||||
DS1808LC::~DS1808LC()
|
DS1808LC::~DS1808LC()
|
||||||
{
|
{
|
||||||
|
if(!mraaIo)
|
||||||
|
delete i2c;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DS1808LC::isPowered()
|
bool DS1808LC::isPowered()
|
||||||
|
@ -21,8 +21,10 @@
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "mraa/i2c.hpp"
|
#include "mraa/i2c.hpp"
|
||||||
|
#include "mraa/initio.hpp"
|
||||||
|
|
||||||
namespace upm
|
namespace upm
|
||||||
{
|
{
|
||||||
@ -56,6 +58,7 @@ class DS1808LC
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DS1808LC(int gpioPower, int i2cBus);
|
DS1808LC(int gpioPower, int i2cBus);
|
||||||
|
DS1808LC(std::string initStr);
|
||||||
~DS1808LC();
|
~DS1808LC();
|
||||||
|
|
||||||
const char* getModuleName() { return "ds1808lc"; }
|
const char* getModuleName() { return "ds1808lc"; }
|
||||||
@ -73,6 +76,7 @@ private:
|
|||||||
|
|
||||||
mraa::Result status;
|
mraa::Result status;
|
||||||
mraa::I2c* i2c;
|
mraa::I2c* i2c;
|
||||||
|
mraa::MraaIo mraaIo;
|
||||||
int pinPower;
|
int pinPower;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user