Skip to content

Commit

Permalink
add _cameraPower option (#392)
Browse files Browse the repository at this point in the history
* add _cameraPower option.

* rn lint fix.

* add unknown to _cameraPower.

* delete comment for A1

* [kmm] add _cameraPower option.

* [kmp]delete SLEEP from _cameraPower.

* [RN, flutter] add _cameraPower option for X.

* upgrade upload-artifact version for github-action.

* fixed RN build error by new XCode.

* remove unnecessary code.
  • Loading branch information
LassicYM authored Sep 27, 2024
1 parent d1871d6 commit f453af3
Show file tree
Hide file tree
Showing 27 changed files with 515 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-kmp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
arguments: testReleaseUnitTest --info
- name: Archive code coverage results
if: always()
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: test-kmp-report
path: kotlin-multiplatform/build/reports/tests/testReleaseUnitTest
2 changes: 1 addition & 1 deletion .github/workflows/test-rn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
yarn test --collectCoverage
- name: Archive code coverage results
if: always()
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: test-react-native-report
path: react-native/coverage
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ fun getOptionValueEnum(name: OptionNameEnum, valueName: String): Any? {
OptionNameEnum.BurstMode -> BurstModeEnum.values().find { it.name == valueName }
OptionNameEnum.CameraControlSource -> CameraControlSourceEnum.values().find { it.name == valueName }
OptionNameEnum.CameraMode -> CameraModeEnum.values().find { it.name == valueName }
OptionNameEnum.CameraPower -> CameraPowerEnum.values().find { it.name == valueName }
OptionNameEnum.CaptureMode -> CaptureModeEnum.values().find { it.name == valueName }
OptionNameEnum.ContinuousNumber -> ContinuousNumberEnum.values().find { it.name == valueName }
OptionNameEnum.ExposureCompensation -> ExposureCompensationEnum.values().find { it.name == valueName }
Expand Down
2 changes: 2 additions & 0 deletions flutter/ios/Classes/ConvertUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,8 @@ func setOptionsValue(options: ThetaRepository.Options, name: String, value: Any)
options.cameraControlSource = getEnumValue(values: ThetaRepository.CameraControlSourceEnum.values(), name: value as! String)!
case ThetaRepository.OptionNameEnum.cameramode.name:
options.cameraMode = getEnumValue(values: ThetaRepository.CameraModeEnum.values(), name: value as! String)!
case ThetaRepository.OptionNameEnum.camerapower.name:
options.cameraPower = getEnumValue(values: ThetaRepository.CameraPowerEnum.values(), name: value as! String)!
case ThetaRepository.OptionNameEnum.captureinterval.name:
options.captureInterval = KotlinInt(integerLiteral: value as! Int)
case ThetaRepository.OptionNameEnum.capturemode.name:
Expand Down
36 changes: 36 additions & 0 deletions flutter/lib/options/camera_power.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/// _cameraPower is the power status of camera.
///
/// For RICOH THETA X v2.61.0 or later
enum CameraPowerEnum {
/// Undefined value
unknown('UNKNOWN'),

/// Power ON
on('ON'),

/// Power OFF
off('OFF'),

/// Power on, power saving mode. Camera is closed.
/// Unavailable parameter when plugin is running. In this case, invalidParameterValue error will be returned.
powerSaving('POWER_SAVING'),

/// Power on, silent mode. LCD/LED is turned off.
/// Unavailable parameter when plugin is running. In this case, invalidParameterValue error will be returned.
silentMode('SILENT_MODE');

final String rawValue;

const CameraPowerEnum(this.rawValue);

@override
String toString() {
return rawValue;
}

static CameraPowerEnum? getValue(String rawValue) {
return CameraPowerEnum.values.cast<CameraPowerEnum?>().firstWhere(
(element) => element?.rawValue == rawValue,
orElse: () => null);
}
}
1 change: 1 addition & 0 deletions flutter/lib/options/importer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
library;

export 'bluetooth_role.dart';
export 'camera_power.dart';
export 'ethernet_config.dart';
export 'file_format.dart';
export 'max_recordable_time.dart';
Expand Down
11 changes: 11 additions & 0 deletions flutter/lib/theta_client_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,9 @@ enum OptionNameEnum {
/// Option name _cameraMode
cameraMode('CameraMode', CameraModeEnum),

/// Option name _cameraPower
cameraPower('CameraPower', CameraPowerEnum),

/// Option name captureInterval
captureInterval('CaptureInterval', int),

Expand Down Expand Up @@ -3253,6 +3256,9 @@ class Options {
/// For RICOH THETA X
CameraModeEnum? cameraMode;

/// see [CameraPowerEnum]
CameraPowerEnum? cameraPower;

/// Shooting interval (sec.) for interval shooting.
///
/// ### Support value
Expand Down Expand Up @@ -3526,6 +3532,8 @@ class Options {
return cameraControlSource as T;
case OptionNameEnum.cameraMode:
return cameraMode as T;
case OptionNameEnum.cameraPower:
return cameraPower as T;
case OptionNameEnum.captureInterval:
return captureInterval as T;
case OptionNameEnum.captureMode:
Expand Down Expand Up @@ -3664,6 +3672,9 @@ class Options {
case OptionNameEnum.cameraMode:
cameraMode = value;
break;
case OptionNameEnum.cameraPower:
cameraPower = value;
break;
case OptionNameEnum.captureInterval:
captureInterval = value;
break;
Expand Down
5 changes: 5 additions & 0 deletions flutter/lib/utils/convert_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ class ConvertUtils {
case OptionNameEnum.cameraMode:
result.cameraMode = CameraModeEnum.getValue(entry.value);
break;
case OptionNameEnum.cameraPower:
result.cameraPower = CameraPowerEnum.getValue(entry.value);
break;
case OptionNameEnum.captureInterval:
result.captureInterval = entry.value;
break;
Expand Down Expand Up @@ -624,6 +627,8 @@ class ConvertUtils {
return value.rawValue;
} else if (value is CameraModeEnum) {
return value.rawValue;
} else if (value is CameraPowerEnum) {
return value.rawValue;
} else if (value is CaptureModeEnum) {
return value.rawValue;
} else if (value is ContinuousNumberEnum) {
Expand Down
58 changes: 58 additions & 0 deletions flutter/test/options/option_camera_power_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:theta_client_flutter/theta_client_flutter.dart';
import 'package:theta_client_flutter/theta_client_flutter_method_channel.dart';

void main() {
MethodChannelThetaClientFlutter platform = MethodChannelThetaClientFlutter();
const MethodChannel channel = MethodChannel('theta_client_flutter');

TestWidgetsFlutterBinding.ensureInitialized();

setUp(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, null);
});

tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, null);
});

test('CameraPowerEnum const', () async {
List<List<dynamic>> data = [
[CameraPowerEnum.unknown, 'UNKNOWN'],
[CameraPowerEnum.on, 'ON'],
[CameraPowerEnum.off, 'OFF'],
[CameraPowerEnum.powerSaving, 'POWER_SAVING'],
[CameraPowerEnum.silentMode, 'SILENT_MODE']
];
expect(data.length, CameraPowerEnum.values.length, reason: 'enum count');
for (int i = 0; i < data.length; i++) {
expect(data[i][0].toString(), data[i][1], reason: data[i][1]);
}
});

test('getOptions', () async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
Map<String, dynamic> optionMap = {};
optionMap['CameraPower'] = 'SILENT_MODE';
return Future.value(optionMap);
});
Options options = await platform.getOptions([OptionNameEnum.cameraPower]);
expect(options.cameraPower?.rawValue, 'SILENT_MODE', reason: 'quality');
});

test('setOptions', () async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
var arguments = methodCall.arguments as Map<dynamic, dynamic>;
expect(arguments['CameraPower'], 'POWER_SAVING', reason: 'quality');
return Future.value();
});
final options = Options();
options.cameraPower = CameraPowerEnum.powerSaving;
await platform.setOptions(options);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,12 @@ class ThetaRepository internal constructor(val endpoint: String, config: Config?
*/
CameraMode("_cameraMode", CameraModeEnum::class),

/**
* Option name
* _cameraPower
*/
CameraPower("_cameraPower", CameraPowerEnum::class),

/**
* Option name
* captureInterval
Expand Down Expand Up @@ -1121,6 +1127,11 @@ class ThetaRepository internal constructor(val endpoint: String, config: Config?
*/
var cameraMode: CameraModeEnum? = null,

/**
* @see CameraPowerEnum
*/
var cameraPower: CameraPowerEnum? = null,

/**
* Shooting interval (sec.) for interval shooting.
*
Expand Down Expand Up @@ -1484,6 +1495,7 @@ class ThetaRepository internal constructor(val endpoint: String, config: Config?
burstOption = null,
cameraControlSource = null,
cameraMode = null,
cameraPower = null,
captureInterval = null,
captureMode = null,
captureNumber = null,
Expand Down Expand Up @@ -1546,6 +1558,7 @@ class ThetaRepository internal constructor(val endpoint: String, config: Config?
burstOption = options._burstOption?.let { BurstOption(it) },
cameraControlSource = options._cameraControlSource?.let { CameraControlSourceEnum.get(it) },
cameraMode = options._cameraMode?.let { CameraModeEnum.get(it) },
cameraPower = options._cameraPower?.let { CameraPowerEnum.get(it) },
captureInterval = options.captureInterval,
captureMode = options.captureMode?.let { CaptureModeEnum.get(it) },
captureNumber = options.captureNumber,
Expand Down Expand Up @@ -1617,6 +1630,7 @@ class ThetaRepository internal constructor(val endpoint: String, config: Config?
_burstOption = burstOption?.toTransferredBurstOption(),
_cameraControlSource = cameraControlSource?.value,
_cameraMode = cameraMode?.value,
_cameraPower = cameraPower?.value,
captureInterval = captureInterval,
captureMode = captureMode?.value,
captureNumber = captureNumber,
Expand Down Expand Up @@ -1691,6 +1705,7 @@ class ThetaRepository internal constructor(val endpoint: String, config: Config?
OptionNameEnum.BurstOption -> burstOption
OptionNameEnum.CameraControlSource -> cameraControlSource
OptionNameEnum.CameraMode -> cameraMode
OptionNameEnum.CameraPower -> cameraPower
OptionNameEnum.CaptureInterval -> captureInterval
OptionNameEnum.CaptureMode -> captureMode
OptionNameEnum.CaptureNumber -> captureNumber
Expand Down Expand Up @@ -1766,6 +1781,7 @@ class ThetaRepository internal constructor(val endpoint: String, config: Config?
OptionNameEnum.BurstOption -> burstOption = value as BurstOption
OptionNameEnum.CameraControlSource -> cameraControlSource = value as CameraControlSourceEnum
OptionNameEnum.CameraMode -> cameraMode = value as CameraModeEnum
OptionNameEnum.CameraPower -> cameraPower = value as CameraPowerEnum
OptionNameEnum.CaptureInterval -> captureInterval = value as Int
OptionNameEnum.CaptureMode -> captureMode = value as CaptureModeEnum
OptionNameEnum.CaptureNumber -> captureNumber = value as Int
Expand Down Expand Up @@ -2623,6 +2639,52 @@ class ThetaRepository internal constructor(val endpoint: String, config: Config?
}
}

/**
* _cameraPower is the power status of camera.
*
* For RICOH THETA X v2.61.0 or later
*/
enum class CameraPowerEnum(internal val value: CameraPower) {
/**
* Undefined value
*/
UNKNOWN(CameraPower.UNKNOWN),

/**
* Power ON
*/
ON(CameraPower.ON),

/**
* Power OFF
*/
OFF(CameraPower.OFF),

/**
* Power on, power saving mode. Camera is closed.
* Unavailable parameter when plugin is running. In this case, invalidParameterValue error will be returned.
*/
POWER_SAVING(CameraPower.POWER_SAVING),

/**
* Power on, silent mode. LCD/LED is turned off.
* Unavailable parameter when plugin is running. In this case, invalidParameterValue error will be returned.
*/
SILENT_MODE(CameraPower.SILENT_MODE);

companion object {
/**
* Convert CameraPower to CameraPowerEnum
*
* @param value CameraPower.
* @return CameraPowerEnum
*/
internal fun get(value: CameraPower): CameraPowerEnum? {
return values().firstOrNull { it.value == value }
}
}
}

/**
* Shooting mode.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@ internal data class Options(
*/
var _cameraMode: CameraMode? = null,

/**
* Camera power
*
* @see CameraPower
*/
var _cameraPower: CameraPower? = null,

/**
* Camera power support
*
* @see CameraPower
*/
var _cameraPowerSupport: List<CameraPower>? = null,

/**
* Shooting interval (sec.) for interval shooting.
*/
Expand Down Expand Up @@ -1297,6 +1311,52 @@ internal enum class CameraMode {
PLUGIN,
}

internal object CameraPowerSerializer :
SerialNameEnumIgnoreUnknownSerializer<CameraPower>(CameraPower.entries, CameraPower.UNKNOWN)

/**
* _cameraPower is the power status of camera.
*
* For RICOH THETA X v2.61.0 or later
*/
@Serializable(with = CameraPowerSerializer::class)
internal enum class CameraPower : SerialNameEnum {
/**
* Undefined value
*/
UNKNOWN,

/**
* Power ON
*/
ON {
override val serialName: String = "on"
},

/**
* Power OFF
*/
OFF {
override val serialName: String = "off"
},

/**
* Power on, power saving mode. Camera is closed.
* Unavailable parameter when plugin is running. In this case, invalidParameterValue error will be returned.
*/
POWER_SAVING {
override val serialName: String = "powerSaving"
},

/**
* Power on, silent mode. LCD/LED is turned off.
* Unavailable parameter when plugin is running. In this case, invalidParameterValue error will be returned.
*/
SILENT_MODE {
override val serialName: String = "silentMode"
},
}

/**
* capture Mode
*/
Expand Down
Loading

0 comments on commit f453af3

Please sign in to comment.