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 one of the 2 possible DC motors on a L298 Dual
30// H-Bridge.  For controlling a stepper motor, see the l298-stepper
31// example.
32var myHBridge_obj = new HBridge_lib.L298(3, 4, 7);
33
34/*****************************
35 * Instantiate H-bridge object
36******************************/
37myHBridge_obj.goForward = function()
38{
39	console.log("Starting motor at 50% for 3 seconds...");
40	myHBridge_obj.setSpeed(50);
41	myHBridge_obj.setDirection(HBridge_lib.L298.DIR_CW);
42	myHBridge_obj.enable(true);
43};
44
45myHBridge_obj.reverseDirection = function()
46{
47	console.log("Reversing direction...");
48	myHBridge_obj.setDirection(HBridge_lib.L298.DIR_NONE); // fast stop
49	myHBridge_obj.setDirection(HBridge_lib.L298.DIR_CCW);
50};
51
52myHBridge_obj.stop = function()
53{
54	myHBridge_obj.setSpeed(0);
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!
70*************************/
71myHBridge_obj.goForward();
72setTimeout(myHBridge_obj.reverseDirection, 3000);
73setTimeout(function()
74{
75	myHBridge_obj.stop();
76	myHBridge_obj.quit();
77}, 6000);
78