1/*jslint node:true, vars:true, bitwise:true, unparam:true */
2/*jshint unused:true */
3/*
4* Author: Zion Orent <zorent@ics.com>
5* Copyright (c) 2015 Intel Corporation.
6*
7* Permission is hereby granted, free of charge, to any person obtaining
8* a copy of this software and associated documentation files (the
9* "Software"), to deal in the Software without restriction, including
10* without limitation the rights to use, copy, modify, merge, publish,
11* distribute, sublicense, and/or sell copies of the Software, and to
12* permit persons to whom the Software is furnished to do so, subject to
13* the following conditions:
14*
15* The above copyright notice and this permission notice shall be
16* included in all copies or substantial portions of the Software.
17*
18* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25*/
26
27var HBridge_lib = require('jsupm_l298');
28
29// Instantiate a Stepper motor on a L298 Dual H-Bridge.
30// This was tested with the NEMA-17 12V, 350mA, with 200 steps per rev.
31var myHBridge_obj = new HBridge_lib.L298(200, 3, 4, 7, 8, 9);
32
33/**************************************
34 * Instantiate H-bridge stepper object
35***************************************/
36myHBridge_obj.goForward = function()
37{
38	myHBridge_obj.setSpeed(10); // 10 RPMs
39	myHBridge_obj.setDirection(HBridge_lib.L298.DIR_CW);
40	myHBridge_obj.enable(true);
41	console.log("Rotating 1 full revolution at 10 RPM speed.");
42	// move 200 steps, a full rev
43	myHBridge_obj.stepperSteps(200);
44};
45
46myHBridge_obj.reverseDirection = function()
47{
48	console.log("Rotating 1/2 revolution in opposite direction at 10 RPM speed.");
49	myHBridge_obj.setDirection(HBridge_lib.L298.DIR_CCW);
50	myHBridge_obj.stepperSteps(100);
51};
52
53myHBridge_obj.stop = function()
54{
55	myHBridge_obj.enable(false);
56};
57
58myHBridge_obj.quit = function()
59{
60	myHBridge_obj = null;
61	HBridge_lib.cleanUp();
62	HBridge_lib = null;
63	console.log("Exiting");
64	process.exit(0);
65};
66
67
68/************************
69 * Run H-bridge stepper!
70*************************/
71myHBridge_obj.goForward();
72setTimeout(myHBridge_obj.reverseDirection, 2000);
73setTimeout(function()
74{
75	myHBridge_obj.stop();
76	myHBridge_obj.quit();
77}, 4000);
78