Skip to content

Commit

Permalink
Added switch/motion sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
NorthernMan54 committed Sep 25, 2019
1 parent aabf903 commit a29948e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
51 changes: 26 additions & 25 deletions ffmpeg.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,32 +182,33 @@ FFMPEG.prototype.handleSnapshotRequest = function(request, callback) {
if (err) {
self.log("ERROR:", err.message);
callback(err);
}
imageBuffer = data;
// self.log("Snapshot-1", imageBuffer);
(async () => {
if (self.gphotos.params) {
const photo = await self.gphotos.upload("/var/tmp/" + self.gFileName);
// self.log("addPhoto", self.fileName);
const album = await self.gphotos.searchOrCreateAlbum((self.cameraConfig.album ? self.cameraConfig.album : 'Camera Pictures'));
await album.addPhoto(photo);
self.log("Uploaded", self.gFileName);
} else {
self.log("Not logged in, not uploaded", self.fileName);
}
fs.unlink("/var/tmp/" + self.fileName, (err) => {
if (err) {
self.log("ERROR: deleting " + self.fileName);
// throw err;
}
});
fs.unlink("/var/tmp/" + self.gFileName, (err) => {
if (err) {
self.log("ERROR: deleting " + self.gFileName);
} else {
imageBuffer = data;
// self.log("Snapshot-1", imageBuffer);
(async () => {
if (self.gphotos.params) {
const photo = await self.gphotos.upload("/var/tmp/" + self.gFileName);
// self.log("addPhoto", self.fileName);
const album = await self.gphotos.searchOrCreateAlbum((self.cameraConfig.album ? self.cameraConfig.album : 'Camera Pictures'));
await album.addPhoto(photo);
self.log("Uploaded", self.gFileName);
} else {
self.log("Not logged in, not uploaded", self.fileName);
}
});
})();
callback(null, imageBuffer);
fs.unlink("/var/tmp/" + self.fileName, (err) => {
if (err) {
self.log("ERROR: deleting " + self.fileName);
// throw err;
}
});
fs.unlink("/var/tmp/" + self.gFileName, (err) => {
if (err) {
self.log("ERROR: deleting " + self.gFileName);
}
});
})();
callback(null, imageBuffer);
}
});
})();
} else {
Expand Down
18 changes: 18 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,29 @@ ffmpegPlatform.prototype.didFinishLaunching = function() {
if (cameraConfig.firmwareRevision) {
cameraAccessoryInfo.setCharacteristic(Characteristic.FirmwareRevision, cameraConfig.firmwareRevision);
}

self.button = new Service.Switch(cameraName + " button");
cameraAccessory.addService(self.button);

self.motion = new Service.MotionSensor(cameraName + " motion");
cameraAccessory.addService(self.motion);

self.button.getCharacteristic(Characteristic.On)
.on('set', _setOn.bind(self));

var cameraSource = new FFMPEG(hap, cameraConfig, self.log, videoProcessor, interfaceName);
cameraAccessory.configureCameraSource(cameraSource);
configuredAccessories.push(cameraAccessory);
});

self.api.publishCameraAccessories("Camera-ffmpeg", configuredAccessories);
}
};

function _setOn(on, callback, context) {
this.log("Setting switch to " + on);

this.motion.setCharacteristic(Characteristic.MotionDetected, (on ? 1 : 0));

callback();
}

0 comments on commit a29948e

Please sign in to comment.