-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathedison.js
182 lines (168 loc) · 4.26 KB
/
edison.js
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env node
/**
* This is Edison, a CLI tool to help developers get up and running with Intel Edison.
*/
/**
* Define version, help info here
*/
var program = require('commander'),
edisonCLI = require('./edison-cli.js');
/**
* Define version, help info here
*/
program
.version('0.0.5')
.usage('[options] <keywords>');
/**
* Make Edison start blinking.
*/
program
.command('blink')
.option("-p, --pin [option]", "Pin you would like to blink, defaults to 13.")
.option("-i, --interval [option]", "Blink speed in seconds, defaults to 1.")
.description('Blink the on-board LED using Cylon.js.')
.action(function(options){
//Initiate a connection to an attached Edison.
var interval = (options.interval)?options.interval:1;
var pin = (options.pin)?options.pin:13;
edisonCLI.blink(interval,pin,function handleBlink(err, result){
if ( err ) {
console.log(err);
} else {
// Success?
console.log(result);
}
(err)?process.exit(1):process.exit(0);
});
});
/**
* Get a local weather report, takes in a city and an API key from weather underground
*/
program
.command('weather')
.option("-c, --city [option]", "Weather city, default to Seattle.")
.option("-s, --state [option]", "Weather state, default to WA.")
.option("-k, --key [option]", "Weather Underground API Key, required.")
.description('Logs a weather report using the Weather Channel API.')
.action(function(options){
//Initiate a connection to an attached Edison.
var city = (options.city)?options.city:"seattle";
var state = (options.state)?options.state:"wa";
var key = (options.key)?options.key:"";
edisonCLI.weather(key,state,city,function handleWeather(err, result){
if ( err ) {
console.log(err);
} else {
// Success?
console.log(result);
}
(err)?process.exit(1):process.exit(0);
});
});
/**
* Get a local weather report, takes in a city and an API key from weather underground
*/
program
.command('status')
.description('Gets a general overview of Edison\'s current status.')
.action(function(){
//Initiate a connection to an attached Edison.
edisonCLI.status(function handleStatus(err, result){
if ( err ) {
console.log(err);
} else {
// Success?
console.log(result);
}
(err)?process.exit(1):process.exit(0);
});
});
/**
* Get the current installed version of libMRAA
*/
program
.command('mraa-version')
.description('Output the current version of libMRAA installed on this Intel Edison')
.action(function(){
console.log(require("mraa").getVersion());
});
/**
* Update the current installed version of libMRAA
*/
program
.command('update-mraa')
.description('Update the version of libMRAA installed on this Intel Edison')
.action(function(){
edisonCLI.updateLibMRAA(function handleUpgrade(err, result){
if ( err ) {
console.log(err);
} else {
console.log(result);
}
(err)?process.exit(1):process.exit(0);
});
});
/**
* Get Edison online via wi-fi
*/
program
.command('wifi')
.description('Scan for a wi-fi network to join.')
.action(function(){
edisonCLI.scanWiFi(function handleWiFi(err, result){
if ( err ) {
console.log(err);
} else {
console.log(result);
}
(err)?process.exit(1):process.exit(0);
});
});
/**
* Turn Edison into an iBeacon
*/
/*
program
.command('beacon')
.description('Turn Intel Edison into an iBeacon using Bleno.')
.action(function(){
//Initiate a connection to an attached Edison.
edisonCLI.status(function handleBeacon(err, result){
if ( err ) {
console.log(err);
} else {
// Success?
console.log(result);
}
(err)?process.exit(1):process.exit(0);
});
});
*/
/**
* Install + Enable Bluetooth Smart
*/
/*
program
.command('ble-enable')
.description('Configure Edison for BLE development.')
.action(function(){
//Initiate a connection to an attached Edison.
edisonCLI.enableBluetoothSmart(function handleBLEEnable(err, result){
if ( err ) {
console.log(err);
} else {
// Success?
console.log(result);
}
(err)?process.exit(1):process.exit(0);
});
});
*/
/**
* Parse the args (e.g. --a etc)
*/
program.parse(process.argv);
/**
* Show help by default.
*/
if(!program.args.length) program.help();