theta-ble-client-react-native
Version:
This library provides a way to control RICOH THETA using
224 lines (212 loc) • 6.46 kB
JavaScript
/* eslint no-useless-catch: 0 */
import { ThetaService } from './theta-service';
import { BleServiceEnum } from './values';
import * as ThetaBleClient from '../native';
/**
* Camera Status Command Service
*
* Service: 8AF982B1-F1FF-4D49-83F0-A56DB4C431A7
*/
export class CameraStatusCommand extends ThetaService {
constructor(device) {
super();
this.service = BleServiceEnum.CAMERA_STATUS_COMMAND;
this.device = device;
}
/**
* Acquires the battery level of the camera.
*
* Service: 8AF982B1-F1FF-4D49-83F0-A56DB4C431A7
* Characteristic: 875FC41D-4980-434C-A653-FD4A4D4410C4
*
* @returns battery level. 0 to 100
*/
async getBatteryLevel() {
try {
return await ThetaBleClient.nativeGetBatteryLevel(this.device.id);
} catch (error) {
throw error;
}
}
/**
* Set the battery level notification.
*
* Service: 8AF982B1-F1FF-4D49-83F0-A56DB4C431A7
* Characteristic: 875FC41D-4980-434C-A653-FD4A4D4410C4
*
* @param callback Notification function
*/
async setBatteryLevelNotify(callback) {
try {
await ThetaBleClient.nativeSetBatteryLevelNotify(this.device.id, callback ? true : false);
this.device.notifyList.set('BATTERY_LEVEL', callback ? event => {
var _event$params;
callback((_event$params = event.params) === null || _event$params === void 0 ? void 0 : _event$params.batteryLevel, event.error);
} : undefined);
} catch (error) {
throw error;
}
}
/**
* Acquires the charging state of the camera.
*
* Service: 8AF982B1-F1FF-4D49-83F0-A56DB4C431A7
* Characteristic: 5429B6A0-66D6-491B-B906-902737D5442F
*
* @returns charging state
*/
async getBatteryStatus() {
try {
return await ThetaBleClient.nativeGetBatteryStatus(this.device.id);
} catch (error) {
throw error;
}
}
/**
* Set the charging state notification.
*
* Service: 8AF982B1-F1FF-4D49-83F0-A56DB4C431A7
* Characteristic: 5429B6A0-66D6-491B-B906-902737D5442F
*
* @param callback Notification function
*/
async setBatteryStatusNotify(callback) {
try {
await ThetaBleClient.nativeSetBatteryStatusNotify(this.device.id, callback ? true : false);
this.device.notifyList.set('BATTERY_STATUS', callback ? event => {
var _event$params2;
callback((_event$params2 = event.params) === null || _event$params2 === void 0 ? void 0 : _event$params2.batteryState, event.error);
} : undefined);
} catch (error) {
throw error;
}
}
/**
* Acquires the camera's start-up status.
*
* Service: 8AF982B1-F1FF-4D49-83F0-A56DB4C431A7
* Characteristic: B58CE84C-0666-4DE9-BEC8-2D27B27B3211
*
* @returns start-up status
*/
async getCameraPower() {
try {
return await ThetaBleClient.nativeGetCameraPower(this.device.id);
} catch (error) {
throw error;
}
}
/**
* Set the camera's start-up status.
*
* When the camera is turned off or put to sleep, it is necessary to reauthorize from connect.
*
* Service: 8AF982B1-F1FF-4D49-83F0-A56DB4C431A7
* Characteristic: B58CE84C-0666-4DE9-BEC8-2D27B27B3211
*
* @param value start-up status
*/
async setCameraPower(value) {
try {
return await ThetaBleClient.nativeSetCameraPower(this.device.id, value);
} catch (error) {
throw error;
}
}
/**
* Set the camera's start-up status notification.
*
* When the camera is turned off or put to sleep, it is necessary to reauthorize from connect.
*
* Service: 8AF982B1-F1FF-4D49-83F0-A56DB4C431A7
* Characteristic: B58CE84C-0666-4DE9-BEC8-2D27B27B3211
*
* @param callback Notification function
*/
async setCameraPowerNotify(callback) {
try {
await ThetaBleClient.nativeSetCameraPowerNotify(this.device.id, callback ? true : false);
this.device.notifyList.set('CAMERA_POWER', callback ? event => {
var _event$params3;
callback((_event$params3 = event.params) === null || _event$params3 === void 0 ? void 0 : _event$params3.cameraPower, event.error);
} : undefined);
} catch (error) {
throw error;
}
}
/**
* Set the camera's error description in detail notification.
*
* Service: 8AF982B1-F1FF-4D49-83F0-A56DB4C431A7
* Characteristic: 4B03D05E-02D2-412B-A20B-578AE82B9C01
*
* @param callback Notification function
*/
async setCommandErrorDescriptionNotify(callback) {
try {
await ThetaBleClient.nativeSetCommandErrorDescriptionNotify(this.device.id, callback ? true : false);
this.device.notifyList.set('COMMAND_ERROR_DESCRIPTION', callback ? event => {
var _event$params4;
callback((_event$params4 = event.params) === null || _event$params4 === void 0 ? void 0 : _event$params4.commandErrorDescription, event.error);
} : undefined);
} catch (error) {
throw error;
}
}
/**
* Acquires the plugin power status.
*
* RICOH THETA V firmware v2.21.1 or later.
*
* Service: 8AF982B1-F1FF-4D49-83F0-A56DB4C431A7
* Characteristic: A88732D5-6786-4312-9364-B9A4514DC123
*
* @returns plugin control
*/
async getPluginControl() {
try {
return await ThetaBleClient.nativeGetPluginControl(this.device.id);
} catch (error) {
throw error;
}
}
/**
* Starts or stops plugin.
*
* RICOH THETA V firmware v2.21.1 or later.
*
* Service: 8AF982B1-F1FF-4D49-83F0-A56DB4C431A7
* Characteristic: A88732D5-6786-4312-9364-B9A4514DC123
*
* @param value plugin control
* @returns
*/
async setPluginControl(value) {
try {
return await ThetaBleClient.nativeSetPluginControl(this.device.id, value);
} catch (error) {
throw error;
}
}
/**
* Set the plugin power status notification.
*
* RICOH THETA V firmware v2.21.1 or later.
*
* Service: 8AF982B1-F1FF-4D49-83F0-A56DB4C431A7
* Characteristic: A88732D5-6786-4312-9364-B9A4514DC123
*
* @param callback Notification function
*/
async setPluginControlNotify(callback) {
try {
await ThetaBleClient.nativeSetPluginControlNotify(this.device.id, callback ? true : false);
this.device.notifyList.set('PLUGIN_CONTROL', callback ? event => {
callback(event.params, event.error);
} : undefined);
} catch (error) {
throw error;
}
}
}
//# sourceMappingURL=camera-status-command.js.map