Skip to content

Commit

Permalink
hardware: add helper for setting IR power (#34245)
Browse files Browse the repository at this point in the history
* hardware: add helper for setting IR power

* fix
  • Loading branch information
adeebshihadeh authored Dec 14, 2024
1 parent 70fa0ab commit ba0e7c4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions selfdrive/pandad/pandad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
panda->set_ir_pwr(ir_pwr);
Hardware::set_ir_power(ir_pwr);
prev_ir_pwr = ir_pwr;
}
}
Expand Down
1 change: 1 addition & 0 deletions system/hardware/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class HardwareNone {
static void reboot() {}
static void poweroff() {}
static void set_brightness(int percent) {}
static void set_ir_power(int percentage) {}
static void set_display_power(bool on) {}

static bool get_ssh_enabled() { return false; }
Expand Down
23 changes: 23 additions & 0 deletions system/hardware/tici/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <fstream>
#include <map>
#include <string>
#include <algorithm> // for std::clamp

#include "common/params.h"
#include "common/util.h"
Expand Down Expand Up @@ -68,6 +69,28 @@ class HardwareTici : public HardwareNone {
}
}

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() {
std::map<std::string, std::string> ret = {
{"/BUILD", util::read_file("/BUILD")},
Expand Down

0 comments on commit ba0e7c4

Please sign in to comment.