SSCMA-Micro CPP SDK  v2.0.0
SSCMA-Micro is a cross-platform machine learning inference framework designed for embedded devices.
ma_sensor.h
Go to the documentation of this file.
1 #ifndef _MA_SENSOR_H_
2 #define _MA_SENSOR_H_
3 
4 #include <core/ma_types.h>
5 
6 #include <cstdint>
7 #include <string>
8 #include <vector>
9 
10 namespace ma {
11 
12 class Sensor {
13  public:
14  enum class Type : int {
15  kUnknown = 0,
16  kCamera = 1,
17  kMicrophone = 2,
18  kIMU = 3,
19  };
20 
21  static std::string __repr__(Type type) noexcept {
22  switch (type) {
23  case Type::kCamera:
24  return "Camera";
25  case Type::kMicrophone:
26  return "Microphone";
27  case Type::kIMU:
28  return "IMU";
29  default:
30  return "Unknown";
31  }
32  }
33 
34  struct Preset {
35  const char* description = nullptr;
36  };
37 
38  using Presets = std::vector<Preset>;
39 
40  public:
41  explicit Sensor(size_t id, Type type) noexcept : m_id(id), m_type(type), m_initialized(false), m_preset_idx(0) {
42  if (m_presets.empty()) {
43  m_presets.push_back({.description = "Default"});
44  }
45  }
46  virtual ~Sensor() = default;
47 
48  [[nodiscard]] virtual ma_err_t init(size_t preset_idx) noexcept = 0;
49  virtual void deInit() noexcept = 0;
50 
51  [[nodiscard]] operator bool() const noexcept { return m_initialized; }
52 
53  [[nodiscard]] size_t getID() const noexcept { return m_id; }
54  [[nodiscard]] Type getType() const noexcept { return m_type; }
55 
56  const Presets& availablePresets() const noexcept { return m_presets; }
57  const Preset& currentPreset() const noexcept {
58  if (m_preset_idx < m_presets.size()) {
59  return m_presets[m_preset_idx];
60  }
61  return m_presets[0];
62  }
63  const size_t currentPresetIdx() const noexcept { return m_preset_idx; }
64 
65  protected:
66  const size_t m_id;
67  const Type m_type;
69  size_t m_preset_idx;
71 };
72 
73 } // namespace ma
74 
75 #endif
Definition: ma_sensor.h:12
const size_t m_id
Definition: ma_sensor.h:66
const Type m_type
Definition: ma_sensor.h:67
std::vector< Preset > Presets
Definition: ma_sensor.h:38
const size_t currentPresetIdx() const noexcept
Definition: ma_sensor.h:63
virtual ~Sensor()=default
Presets m_presets
Definition: ma_sensor.h:70
const Preset & currentPreset() const noexcept
Definition: ma_sensor.h:57
virtual ma_err_t init(size_t preset_idx) noexcept=0
Type
Definition: ma_sensor.h:14
static std::string __repr__(Type type) noexcept
Definition: ma_sensor.h:21
Type getType() const noexcept
Definition: ma_sensor.h:54
virtual void deInit() noexcept=0
bool m_initialized
Definition: ma_sensor.h:68
Sensor(size_t id, Type type) noexcept
Definition: ma_sensor.h:41
size_t m_preset_idx
Definition: ma_sensor.h:69
const Presets & availablePresets() const noexcept
Definition: ma_sensor.h:56
size_t getID() const noexcept
Definition: ma_sensor.h:53
ma_err_t
Definition: ma_types.h:21
Definition: ma_cv.cpp:7
Definition: ma_sensor.h:34
const char * description
Definition: ma_sensor.h:35