hardware: add helper for setting IR power (#34245)

* hardware: add helper for setting IR power

* fix
pull/34247/head
Adeeb Shihadeh 4 months ago committed by GitHub
parent 70fa0ab4c1
commit ba0e7c4719
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      selfdrive/pandad/pandad.cc
  2. 1
      system/hardware/base.h
  3. 23
      system/hardware/tici/hardware.h

@ -416,6 +416,7 @@ void process_peripheral_state(Panda *panda, PubMaster *pm, bool no_fan_control)
if (ir_pwr != prev_ir_pwr || sm.frame % 100 == 0 || ir_pwr >= 50.0) { if (ir_pwr != prev_ir_pwr || sm.frame % 100 == 0 || ir_pwr >= 50.0) {
panda->set_ir_pwr(ir_pwr); panda->set_ir_pwr(ir_pwr);
Hardware::set_ir_power(ir_pwr);
prev_ir_pwr = ir_pwr; prev_ir_pwr = ir_pwr;
} }
} }

@ -28,6 +28,7 @@ public:
static void reboot() {} static void reboot() {}
static void poweroff() {} static void poweroff() {}
static void set_brightness(int percent) {} static void set_brightness(int percent) {}
static void set_ir_power(int percentage) {}
static void set_display_power(bool on) {} static void set_display_power(bool on) {}
static bool get_ssh_enabled() { return false; } static bool get_ssh_enabled() { return false; }

@ -4,6 +4,7 @@
#include <fstream> #include <fstream>
#include <map> #include <map>
#include <string> #include <string>
#include <algorithm> // for std::clamp
#include "common/params.h" #include "common/params.h"
#include "common/util.h" #include "common/util.h"
@ -68,6 +69,28 @@ public:
} }
} }
static void set_ir_power(int percent) {
auto device = get_device_type();
if (device == cereal::InitData::DeviceType::TICI ||
device == cereal::InitData::DeviceType::TIZI) {
return;
}
percent = std::clamp(percent, 0, 100);
std::ofstream torch_brightness("/sys/class/leds/led:torch_2/brightness");
if (torch_brightness.is_open()) {
torch_brightness << percent << "\n";
torch_brightness.close();
}
std::ofstream switch_brightness("/sys/class/leds/led:switch_2/brightness");
if (switch_brightness.is_open()) {
switch_brightness << percent << "\n";
switch_brightness.close();
}
}
static std::map<std::string, std::string> get_init_logs() { static std::map<std::string, std::string> get_init_logs() {
std::map<std::string, std::string> ret = { std::map<std::string, std::string> ret = {
{"/BUILD", util::read_file("/BUILD")}, {"/BUILD", util::read_file("/BUILD")},

Loading…
Cancel
Save