-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
40 lines (33 loc) · 1.14 KB
/
index.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
var PayloadProcessor = require('./payloadProcessor.js')
var OTAUpdater = require('./otaUpdater.js')
var events = require('events')
var util = require('util')
var CypressDFU = function () {
var cypressDFU = this
this.startUpdate = function (payload, writeMethod) {
this.otaUpdater = new OTAUpdater(writeMethod)
this.onData = this.otaUpdater.onData
this.attachEventListeners()
var payloadProcessor = new PayloadProcessor(payload)
payloadProcessor.analyzeHeader()
payloadProcessor.readDataLines()
this.otaUpdater.start(payloadProcessor)
return this.otaUpdater
}
this.attachEventListeners = function () {
this.otaUpdater.on('progress', function (percentage) {
cypressDFU.emit('progress', percentage)
})
this.otaUpdater.on('flashStart', function () {
cypressDFU.emit('flashStart')
})
this.otaUpdater.on('flashFinished', function () {
cypressDFU.emit('flashFinished')
})
this.otaUpdater.on('error', function (err, code, message) {
cypressDFU.emit('error', err, code, message)
})
}
}
util.inherits(CypressDFU, events.EventEmitter)
module.exports = new CypressDFU()