forked from sudar/MissileLauncher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MissileLauncher.cpp
67 lines (54 loc) · 1.67 KB
/
MissileLauncher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
MissileLauncher - Arduino library to work with USB MissileLauncher
http://sudarmuthu.com/arduino/missilelauncher
Requires v2.0 of USB Host Shield Library available at https://github.com/felis/USB_Host_Shield_2.0
Copyright 2011 Sudar Muthu (email : [email protected])
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <[email protected]> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer or coffee in return - Sudar
* ----------------------------------------------------------------------------
*/
#include "MissileLauncher.h"
// constructor
MissileLauncher::MissileLauncher() : USB() {
addr = 1; // Todo need to change it if connected through a USB Hub
endPoint = 0;
bmReqType = 0x21;
bRequest = 0x09;
wValLo = 0x00;
wValHi = 0x02;
wInd = 0;
total = 1;
}
// Move Down
void MissileLauncher::moveDown() {
issueCommand(DOWN);
}
// Move Up
void MissileLauncher::moveUp() {
issueCommand(UP);
}
// Move Left
void MissileLauncher::moveLeft() {
issueCommand(LEFT);
}
// Move Right
void MissileLauncher::moveRight() {
issueCommand(RIGHT);
}
// fire
void MissileLauncher::fire() {
issueCommand(FIRE);
}
//stop
void MissileLauncher::stop() {
issueCommand(STOP);
}
// private helper function
void MissileLauncher::issueCommand(MissileLauncherActions action) {
byte data[1] = {action};
ctrlReq(addr, endPoint, bmReqType, bRequest, wValLo, wValHi, wInd, total, sizeof(data)/sizeof(byte), data, NULL);
}