mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 17:31:13 +03:00
cjq4435: Initial implementation
This module was tested on the Grove MOSFET. Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: Zion Orent <zorent@ics.com> Signed-off-by: John Van Drasek <john.r.van.drasek@intel.com>
This commit is contained in:

committed by
John Van Drasek

parent
0ebb7e0417
commit
6a0a7b6159
@ -81,6 +81,7 @@ add_executable (adxl345-example adxl345.cxx)
|
||||
add_executable (rpr220-example rpr220.cxx)
|
||||
add_executable (rpr220-intr-example rpr220-intr.cxx)
|
||||
add_executable (mma7660-example mma7660.cxx)
|
||||
add_executable (cjq4435-example cjq4435.cxx)
|
||||
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
||||
@ -147,6 +148,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/rotaryencoder)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/adxl345)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/rpr220)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/mma7660)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/cjq4435)
|
||||
|
||||
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
@ -231,3 +233,4 @@ target_link_libraries (adxl345-example adxl345 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (rpr220-example rpr220 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (rpr220-intr-example rpr220 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mma7660-example mma7660 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (cjq4435-example cjq4435 ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
77
examples/cjq4435.cxx
Normal file
77
examples/cjq4435.cxx
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "cjq4435.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
|
||||
int main ()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate a CJQ4435 MOSFET on a PWM capable digital pin D3
|
||||
upm::CJQ4435* mosfet = new upm::CJQ4435(3);
|
||||
|
||||
mosfet->setPeriodMS(10);
|
||||
mosfet->enable(true);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
// start with a duty cycle of 0.0 (off) and increment to 1.0 (on)
|
||||
for (float i=0.0; i <= 1.0; i+=0.1)
|
||||
{
|
||||
mosfet->setDutyCycle(i);
|
||||
usleep(100000);
|
||||
}
|
||||
sleep(1);
|
||||
// Now take it back down
|
||||
// start with a duty cycle of 1.0 (on) and decrement to 0.0 (off)
|
||||
for (float i=1.0; i >= 0.0; i-=0.1)
|
||||
{
|
||||
mosfet->setDutyCycle(i);
|
||||
usleep(100000);
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete mosfet;
|
||||
return 0;
|
||||
}
|
85
examples/javascript/cjq4435.js
Normal file
85
examples/javascript/cjq4435.js
Normal file
@ -0,0 +1,85 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
|
||||
/*
|
||||
* Author: Zion Orent <zorent@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var MOSFETsensor = require("jsupm_cjq4435");
|
||||
|
||||
var g_addnumBool = true;
|
||||
var g_cycleNum = 0.0;
|
||||
var g_cycleCount = 0;
|
||||
|
||||
// Instantiate a CJQ4435 MOSFET on a PWM capable digital pin D3
|
||||
var myMOSFETsensor = new MOSFETsensor.CJQ4435(3);
|
||||
|
||||
myMOSFETsensor.setPeriodMS(10);
|
||||
myMOSFETsensor.enable(true);
|
||||
|
||||
// A note on timing:
|
||||
// In the C++ example, the system sleeps 11 times for 100 milliseconds
|
||||
// between each duty cycle. After reaching the last point of the cycle,
|
||||
// the system sleeps again for 1 second.
|
||||
// The sleeps are cumulative, so the system has slept for 2.1 seconds
|
||||
// sum total for each cycle.
|
||||
// setInterval and setTimeout make asynchronous function calls;
|
||||
// they aren't cumulative.
|
||||
// In order to approximate the behavior of the C++ example, we need
|
||||
// to call each iteration 2.1 seconds apart instead of 1 second apart.
|
||||
|
||||
var myInterval = setInterval(function()
|
||||
{
|
||||
setDutyCycle();
|
||||
}, (1000 + (11*100)) );
|
||||
|
||||
|
||||
// We start with a duty cycle of 0.0 (off) and increment to 1.0 (on)
|
||||
// Then we take it back down,
|
||||
// starting with a duty cycle of 1.0 (on) and decrement to 0.0 (off)
|
||||
function setDutyCycle()
|
||||
{
|
||||
myMOSFETsensor.setDutyCycle(g_cycleNum);
|
||||
if (g_addnumBool)
|
||||
g_cycleNum += 0.1;
|
||||
else
|
||||
g_cycleNum -= 0.1;
|
||||
g_cycleCount++;
|
||||
if (g_cycleCount > 10)
|
||||
{
|
||||
g_addnumBool = !g_addnumBool;
|
||||
g_cycleCount = 0;
|
||||
}
|
||||
else
|
||||
setTimeout(setDutyCycle, 100);
|
||||
}
|
||||
|
||||
|
||||
// When exiting: clear interval and print exit message
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
clearInterval(myInterval);
|
||||
myMOSFETsensor.off();
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
Reference in New Issue
Block a user