Enrico Granata | 60a818d | 2019-05-09 09:56:09 -0700 | [diff] [blame^] | 1 | // Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include <base/logging.h> |
| 6 | #include <base/macros.h> |
| 7 | |
| 8 | #include "mems_setup/sensor_kind.h" |
| 9 | |
| 10 | namespace mems_setup { |
| 11 | |
| 12 | namespace { |
| 13 | constexpr char kAccelName[] = "accel"; |
| 14 | constexpr char kGyroName[] = "anglvel"; |
| 15 | constexpr char kLightName[] = "illuminance"; |
| 16 | } // namespace |
| 17 | |
| 18 | std::string SensorKindToString(SensorKind kind) { |
| 19 | switch (kind) { |
| 20 | case SensorKind::ACCELEROMETER: |
| 21 | return kAccelName; |
| 22 | case SensorKind::GYROSCOPE: |
| 23 | return kGyroName; |
| 24 | case SensorKind::LIGHT: |
| 25 | return kLightName; |
| 26 | } |
| 27 | |
| 28 | NOTREACHED(); |
| 29 | } |
| 30 | |
| 31 | base::Optional<SensorKind> SensorKindFromString(const std::string& name) { |
| 32 | if (name == kAccelName) |
| 33 | return SensorKind::ACCELEROMETER; |
| 34 | if (name == kGyroName) |
| 35 | return SensorKind::GYROSCOPE; |
| 36 | if (name == kLightName) |
| 37 | return SensorKind::LIGHT; |
| 38 | |
| 39 | return base::nullopt; |
| 40 | } |
| 41 | |
| 42 | } // namespace mems_setup |