Skip to content

Commit

Permalink
Use map to send sensors for future proofing
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexios80 committed Feb 15, 2022
1 parent 03c8cc4 commit 44954cd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
14 changes: 6 additions & 8 deletions example/tizen/tizen-manifest.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest api-version="4.0" package="dev.rexios.workout_example" version="1.0.0"
xmlns="http://tizen.org/ns/packages">
<profile name="common" />
<ui-application api-version="4" appid="dev.rexios.workout_example" exec="Runner.dll"
launch_mode="single" multiple="false" nodisplay="false" taskmanage="true" type="dotnet">
<manifest api-version="4.0" package="dev.rexios.workout_example" version="1.0.0" xmlns="http://tizen.org/ns/packages">
<profile name="wearable"/>
<ui-application api-version="4" appid="dev.rexios.workout_example" exec="Runner.dll" launch_mode="single" multiple="false" nodisplay="false" taskmanage="true" type="dotnet">
<label>workout_example</label>
<icon>ic_launcher.png</icon>
<metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true" />
<metadata key="http://tizen.org/metadata/direct-launch" value="yes" />
<metadata key="http://tizen.org/metadata/prefer_dotnet_aot" value="true"/>
<metadata key="http://tizen.org/metadata/direct-launch" value="yes"/>
</ui-application>
<feature name="http://tizen.org/feature/screen.size.all" />
<feature name="http://tizen.org/feature/screen.size.all"/>
<privileges>
<privilege>http://tizen.org/privilege/healthinfo</privilege>
</privileges>
Expand Down
2 changes: 1 addition & 1 deletion lib/src/workout_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Workout {
// This is Tizen
sensors = await _initTizen();
}
return _channel.invokeMethod<void>('start', sensors);
return _channel.invokeMethod<void>('start', {'sensors': sensors});
}

Future<List<String>> _initWearOS() async {
Expand Down
28 changes: 13 additions & 15 deletions tizen/src/workout_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ class WorkoutPlugin : public Plugin {
void HandleMethodCall(
const MethodCall<EncodableValue> &method_call,
unique_ptr<MethodResult<EncodableValue> > result) {
const auto &arguments = *method_call.arguments();

if (method_call.method_name() == "start") {
string error = start(arguments);
const auto *arguments = get_if<EncodableMap>(method_call.arguments());
const auto sensors_it = arguments->find(EncodableValue("sensors"));
const auto sensors = get<EncodableList>(sensors_it->second);
string error = start(sensors);
if (error.empty()) {
result->Success();
} else {
Expand All @@ -63,19 +64,16 @@ class WorkoutPlugin : public Plugin {

list<sensor_listener_h> sensorListeners;

string start(const EncodableValue arguments) {
string start(const EncodableList sensors) {
string error = "";
if (holds_alternative<EncodableList>(arguments)) {
const EncodableList argumentList = get<EncodableList>(arguments);
for (int i = 0; i < argumentList.size(); i++) {
string stringArgument = get<string>(argumentList[i]);
sensor_listener_h listener = nullptr;
sensorListeners.push_front(listener);
if (stringArgument == "heartRate") {
error += "" + startSensor(SENSOR_HRM, listener);
} else if (stringArgument == "pedometer") {
error += "" + startSensor(SENSOR_HUMAN_PEDOMETER, listener);
}
for (int i = 0; i < sensors.size(); i++) {
string stringArgument = get<string>(sensors[i]);
sensor_listener_h listener = nullptr;
sensorListeners.push_front(listener);
if (stringArgument == "heartRate") {
error += "" + startSensor(SENSOR_HRM, listener);
} else if (stringArgument == "pedometer") {
error += "" + startSensor(SENSOR_HUMAN_PEDOMETER, listener);
}
}

Expand Down

0 comments on commit 44954cd

Please sign in to comment.