cjq4435: C port, C++ wraps C

Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
Jon Trulson
2017-01-20 12:01:31 -07:00
parent 8d5278b9d4
commit 123e611f45
8 changed files with 534 additions and 157 deletions

View File

@@ -1,6 +1,6 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
* Copyright (c) 2015-2017 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -23,103 +23,104 @@
*/
#pragma once
#include <mraa/pwm.h>
#include "cjq4435.h"
namespace upm {
/**
* @brief CJQ4435 MOSFET library
* @defgroup cjq4435 libupm-cjq4435
* @ingroup seeed gpio pwm electric robok
*/
/**
* @library cjq4435
* @sensor cjq4435
* @comname Grove MOSFET
* @altname CJQ4435
* @type electric
* @man seeed
* @con gpio pwm
* @kit robok
*
* @brief API for the CJQ4435 MOSFET
*
* UPM module for the CJQ4435 MOSFET. It was developed using the
* Grove MOSFET module. A MOSFET is like a switch, but it can
* switch much faster than a mechanical relay. Here, we implement
* support via MRAA pulse width modulation (PWM) functions.
* Note: available periods vary depending on
* the capabilities of your device.
*
* @image html cjq4435.jpg
* @snippet cjq4435.cxx Interesting
*/
class CJQ4435 {
public:
/**
* CJQ4435 constructor
* @brief CJQ4435 MOSFET library
* @defgroup cjq4435 libupm-cjq4435
* @ingroup seeed gpio pwm electric robok
*/
/**
* @library cjq4435
* @sensor cjq4435
* @comname Grove MOSFET
* @altname CJQ4435
* @type electric
* @man seeed
* @con gpio pwm
* @kit robok
*
* @param pin Digital pin to use; this pin must be PWM-capable
*/
CJQ4435(int pin);
/**
* CJQ4435 destructor
*/
~CJQ4435();
/**
* Sets a period in microseconds
* @brief API for the CJQ4435 MOSFET
*
* @param us Period in microseconds
*/
void setPeriodUS(int us);
/**
* Sets a period in milliseconds
* UPM module for the CJQ4435 MOSFET. It was developed using the
* Grove MOSFET module, but could be used with any MOSFET. A
* MOSFET is like a switch, but it can switch much faster than a
* mechanical relay. Here, we implement support via MRAA pulse
* width modulation (PWM) functions. Note: available periods vary
* depending on the capabilities of your platform.
*
* @param ms Period in milliseconds
* @image html cjq4435.jpg
* @snippet cjq4435.cxx Interesting
*/
void setPeriodMS(int ms);
class CJQ4435 {
public:
/**
* CJQ4435 constructor
*
* @param pin Digital pin to use; this pin must be PWM-capable
*/
CJQ4435(int pin);
/**
* Sets a period in seconds
*
* @param seconds Period in seconds
*/
void setPeriodSeconds(float seconds);
/**
* CJQ4435 destructor
*/
~CJQ4435();
/**
* Enables output
*
* @param enable Enables PWM output if true, disables otherwise
*/
void enable(bool enable);
/**
* Sets a period in microseconds
*
* @param us Period in microseconds
*/
void setPeriodUS(int us);
/**
* Sets a duty cycle. Duty cycle is a floating-point number
* between 0.0 (always off) and 1.0 (always on). It represents a
* proportion of time, per period, during which the output is
* driven high.
*
* @param dutyCycle Duty cycle to use
*/
void setDutyCycle(float dutyCycle);
/**
* Sets a period in milliseconds
*
* @param ms Period in milliseconds
*/
void setPeriodMS(int ms);
/**
* Shortcut to turn the output to continuous on (high)
*/
void on();
/**
* Sets a period in seconds
*
* @param seconds Period in seconds
*/
void setPeriodSeconds(float seconds);
/**
* Shortcut to turn the output to continuous off (low)
*/
void off();
/**
* Enables output
*
* @param enable Enables PWM output if true, disables otherwise
*/
void enable(bool enable);
private:
bool m_enabled;
mraa_pwm_context m_pwm;
};
/**
* Sets a duty cycle. Duty cycle is a floating-point number
* between 0.0 (always off) and 1.0 (always on). It represents a
* proportion of time, per period, during which the output is
* driven high.
*
* @param dutyCycle Duty cycle to use
*/
void setDutyCycle(float dutyCycle);
/**
* Shortcut to turn the output to continuous on (high)
*/
void on();
/**
* Shortcut to turn the output to continuous off (low)
*/
void off();
protected:
cjq4435_context m_cjq4435;
private:
};
}