From c27c414e5a18cd4669653065bcc9bb4dfe133e2a Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Thu, 19 Jan 2017 08:56:32 -0800 Subject: [PATCH] AP_HAL_Linux: Led_Sysfs: small fixes - avoid trying to close fd when it's -1 - Keep includes sorted - AP_HAL::panic() doesn't need \n terminator - %u requires unsigned type - #pragma once is the first thing on a header --- libraries/AP_HAL_Linux/Led_Sysfs.cpp | 12 ++++++------ libraries/AP_HAL_Linux/Led_Sysfs.h | 3 +-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/libraries/AP_HAL_Linux/Led_Sysfs.cpp b/libraries/AP_HAL_Linux/Led_Sysfs.cpp index 4094a54c8f..5758cf6043 100644 --- a/libraries/AP_HAL_Linux/Led_Sysfs.cpp +++ b/libraries/AP_HAL_Linux/Led_Sysfs.cpp @@ -19,9 +19,9 @@ #include #include +#include #include #include -#include #include #include @@ -37,7 +37,7 @@ Led_Sysfs::Led_Sysfs(const char *led_name) Led_Sysfs::~Led_Sysfs() { - if (_brightness_fd) { + if (_brightness_fd >= 0) { close(_brightness_fd); } } @@ -48,7 +48,7 @@ bool Led_Sysfs::init() char *max_br_path; if (asprintf(&br_path, "/sys/class/leds/%s/brightness", _led_name) == -1) { - AP_HAL::panic("LinuxLed_Sysfs : Couldn't allocate brightness path\n"); + AP_HAL::panic("LinuxLed_Sysfs : Couldn't allocate brightness path"); } _brightness_fd = open(br_path, O_WRONLY | O_CLOEXEC); @@ -59,11 +59,11 @@ bool Led_Sysfs::init() } if (asprintf(&max_br_path, "/sys/class/leds/%s/max_brightness", _led_name) == -1) { - AP_HAL::panic("LinuxLed_Sysfs : Couldn't allocate max_brightness path\n"); + AP_HAL::panic("LinuxLed_Sysfs : Couldn't allocate max_brightness path"); } if (Util::from(hal.util)->read_file(max_br_path, "%u", &_max_brightness) < 0) { - AP_HAL::panic("LinuxLed_Sysfs : Unable to read max_brightness in %s\n", + AP_HAL::panic("LinuxLed_Sysfs : Unable to read max_brightness in %s", max_br_path); } @@ -79,7 +79,7 @@ bool Led_Sysfs::set_brightness(uint8_t brightness) return false; } - int br = brightness * _max_brightness / UINT8_MAX; + unsigned int br = brightness * _max_brightness / UINT8_MAX; /* Don't log fails since this could spam the console */ if (dprintf(_brightness_fd, "%u", br) < 0) { diff --git a/libraries/AP_HAL_Linux/Led_Sysfs.h b/libraries/AP_HAL_Linux/Led_Sysfs.h index a6c4c2cf0c..ac57e9046b 100644 --- a/libraries/AP_HAL_Linux/Led_Sysfs.h +++ b/libraries/AP_HAL_Linux/Led_Sysfs.h @@ -14,14 +14,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#pragma once #include #include "AP_HAL_Linux.h" #include "Util.h" -#pragma once - namespace Linux { class Led_Sysfs {