ds5-thermal-monitor.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2021 Intel Corporation. All Rights Reserved.
3 
4 #include <iostream>
5 #include <chrono>
6 #include "ds5-color.h"
7 #include "ds5-private.h"
8 #include "ds5-thermal-monitor.h"
9 
10 namespace librealsense
11 {
12  ds5_thermal_monitor::ds5_thermal_monitor(std::shared_ptr<option> temp_option,
13  std::shared_ptr<option> tl_toggle) :
14  _monitor([this](dispatcher::cancellable_timer cancellable_timer)
15  {
16  polling(cancellable_timer);
17  }),
18  _poll_intervals_ms(2000), // Temperature check routine to be invoked every 2 sec
20  _temp_base(0.f),
21  _hw_loop_on(false),
22  _temperature_sensor(temp_option),
23  _tl_activation(tl_toggle)
24  {
25  }
26 
28  {
29  _monitor.stop();
30  _temp_base = 0.f;
31  _hw_loop_on = false;
32  }
33 
35  {
36  if (on != _monitor.is_active())
37  {
38  if (!on)
39  {
40  _monitor.stop();
41  _hw_loop_on = false;
42  notify(0);
43  }
44  else
45  {
46  _monitor.start();
47  }
48  }
49  }
50 
52  {
53  if (cancellable_timer.try_sleep(_poll_intervals_ms))
54  {
55  try
56  {
57  // Verify TL is active on FW level
58  if (auto tl_active = _tl_activation.lock())
59  {
60  bool tl_state = (std::fabs(tl_active->query()) > std::numeric_limits< float >::epsilon());
61  if (tl_state != _hw_loop_on)
62  {
63  _hw_loop_on = tl_state;
64  if (!_hw_loop_on)
65  notify(0);
66 
67  }
68 
69  if (!tl_state)
70  return;
71  }
72 
73  // Track temperature and update on temperature changes
74  auto ts = (uint64_t)std::chrono::high_resolution_clock::now().time_since_epoch().count();
75  if (auto temp = _temperature_sensor.lock())
76  {
77  auto cur_temp = temp->query();
78 
79  if (fabs(_temp_base - cur_temp) >= _thermal_threshold_deg)
80  {
81  LOG_DEBUG_THERMAL_LOOP("Thermal calibration adjustment is triggered on change from "
82  << std::dec << std::setprecision(1) << _temp_base << " to " << cur_temp << " deg (C)");
83 
84  notify(cur_temp);
85  }
86  }
87  else
88  {
89  LOG_ERROR("Thermal Compensation: temperature sensor option is not present");
90  }
91  }
92  catch (const std::exception& ex)
93  {
94  LOG_ERROR("Error during thermal compensation handling: " << ex.what());
95  }
96  catch (...)
97  {
98  LOG_ERROR("Unresolved error during Thermal Compensation handling");
99  }
100  }
101  else
102  {
103  LOG_DEBUG_THERMAL_LOOP("Thermal Compensation is being shut-down");
104  }
105  }
106 
107  void ds5_thermal_monitor::notify(float temperature)
108  {
109  _temp_base = temperature;
110  for (auto&& cb : _thermal_changes_callbacks)
111  cb(temperature);
112  }
113 }
void polling(dispatcher::cancellable_timer cancellable_timer)
bool is_active() const
Definition: concurrency.h:405
#define LOG_DEBUG_THERMAL_LOOP(...)
Definition: ds5-private.h:18
GLdouble f
unsigned __int64 uint64_t
Definition: stdint.h:90
ds5_thermal_monitor(std::shared_ptr< option > temp_option, std::shared_ptr< option > tl_toggle)
std::weak_ptr< option > _temperature_sensor
std::weak_ptr< option > _tl_activation
#define LOG_ERROR(...)
Definition: src/types.h:242
std::vector< std::function< void(float)> > _thermal_changes_callbacks
bool try_sleep(std::chrono::milliseconds::rep ms)
Definition: concurrency.h:204


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:13