mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
Lint
This commit is contained in:
+73
-51
@@ -3,55 +3,81 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#if __aarch64__
|
#if __aarch64__
|
||||||
#else
|
#else
|
||||||
struct gpiod_chip *gpiod_chip_open(const char *path){return NULL;}
|
struct gpiod_chip *gpiod_chip_open(const char *path)
|
||||||
struct gpiod_line_settings *gpiod_line_settings_new(void){}
|
{
|
||||||
int gpiod_line_settings_set_direction(struct gpiod_line_settings *settings,
|
return NULL;
|
||||||
enum gpiod_line_direction direction){return 0;}
|
}
|
||||||
int gpiod_line_settings_set_output_value(struct gpiod_line_settings *settings,
|
struct gpiod_line_settings *gpiod_line_settings_new(void)
|
||||||
enum gpiod_line_value value){return 0;}
|
{
|
||||||
struct gpiod_line_config *gpiod_line_config_new(void){return NULL;}
|
}
|
||||||
int gpiod_line_config_add_line_settings(struct gpiod_line_config *config,
|
int gpiod_line_settings_set_direction(struct gpiod_line_settings *settings, enum gpiod_line_direction direction)
|
||||||
const unsigned int *offsets,
|
{
|
||||||
size_t num_offsets,
|
return 0;
|
||||||
struct gpiod_line_settings *settings){return 0;}
|
}
|
||||||
struct gpiod_request_config *gpiod_request_config_new(void){}
|
int gpiod_line_settings_set_output_value(struct gpiod_line_settings *settings, enum gpiod_line_value value)
|
||||||
void gpiod_request_config_set_consumer(struct gpiod_request_config *config,
|
{
|
||||||
const char *consumer){}
|
return 0;
|
||||||
struct gpiod_line_request *
|
}
|
||||||
gpiod_chip_request_lines(struct gpiod_chip *chip,
|
struct gpiod_line_config *gpiod_line_config_new(void)
|
||||||
struct gpiod_request_config *req_cfg,
|
{
|
||||||
struct gpiod_line_config *line_cfg){return NULL;}
|
return NULL;
|
||||||
int gpiod_line_request_set_value(struct gpiod_line_request *request,
|
}
|
||||||
unsigned int offset,
|
int gpiod_line_config_add_line_settings(struct gpiod_line_config *config, const unsigned int *offsets,
|
||||||
enum gpiod_line_value value){}
|
size_t num_offsets, struct gpiod_line_settings *settings)
|
||||||
enum gpiod_line_value
|
{
|
||||||
gpiod_line_request_get_value(struct gpiod_line_request *request,
|
return 0;
|
||||||
unsigned int offset) {}
|
}
|
||||||
void gpiod_line_request_release(struct gpiod_line_request *request) {}
|
struct gpiod_request_config *gpiod_request_config_new(void)
|
||||||
void gpiod_request_config_free(struct gpiod_request_config *config){}
|
{
|
||||||
void gpiod_line_config_free(struct gpiod_line_config *config){}
|
}
|
||||||
void gpiod_line_settings_free(struct gpiod_line_settings *settings){}
|
void gpiod_request_config_set_consumer(struct gpiod_request_config *config, const char *consumer)
|
||||||
void gpiod_chip_close(struct gpiod_chip *chip){}
|
{
|
||||||
|
}
|
||||||
|
struct gpiod_line_request *gpiod_chip_request_lines(struct gpiod_chip *chip, struct gpiod_request_config *req_cfg,
|
||||||
|
struct gpiod_line_config *line_cfg)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
int gpiod_line_request_set_value(struct gpiod_line_request *request, unsigned int offset, enum gpiod_line_value value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
enum gpiod_line_value gpiod_line_request_get_value(struct gpiod_line_request *request, unsigned int offset)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void gpiod_line_request_release(struct gpiod_line_request *request)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void gpiod_request_config_free(struct gpiod_request_config *config)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void gpiod_line_config_free(struct gpiod_line_config *config)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void gpiod_line_settings_free(struct gpiod_line_settings *settings)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void gpiod_chip_close(struct gpiod_chip *chip)
|
||||||
|
{
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
GPIO::GPIO(Direction dir, uint8_t gpio, bool state, QObject* parent)
|
GPIO::GPIO(Direction dir, uint8_t gpio, bool state, QObject *parent) : QObject(parent), m_offset(gpio)
|
||||||
: QObject(parent), m_offset(gpio)
|
|
||||||
{
|
{
|
||||||
if (dir == Direction::Output)
|
if (dir == Direction::Output)
|
||||||
{
|
{
|
||||||
m_request = request_output_line("/dev/gpiochip0", gpio, (enum gpiod_line_value)state, "unisim_cpp");
|
m_request = request_output_line("/dev/gpiochip0", gpio, (enum gpiod_line_value)state, "unisim_cpp");
|
||||||
if (!m_request) {
|
if (!m_request)
|
||||||
SPDLOG_ERROR("failed to request line: {}",
|
{
|
||||||
strerror(errno));
|
SPDLOG_ERROR("failed to request line: {}", strerror(errno));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (dir == Direction::Input)
|
if (dir == Direction::Input)
|
||||||
{
|
{
|
||||||
m_request = request_input_line("/dev/gpiochip0", gpio, "unisim_cpp");
|
m_request = request_input_line("/dev/gpiochip0", gpio, "unisim_cpp");
|
||||||
if (!m_request) {
|
if (!m_request)
|
||||||
fprintf(stderr, "failed to request line: %s\n",
|
{
|
||||||
strerror(errno));
|
fprintf(stderr, "failed to request line: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,9 +107,8 @@ bool GPIO::value()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
struct gpiod_line_request *
|
struct gpiod_line_request *GPIO::request_output_line(const char *chip_path, unsigned int offset,
|
||||||
GPIO::request_output_line(const char *chip_path, unsigned int offset,
|
enum gpiod_line_value value, const char *consumer)
|
||||||
enum gpiod_line_value value, const char *consumer)
|
|
||||||
{
|
{
|
||||||
struct gpiod_request_config *req_cfg = NULL;
|
struct gpiod_request_config *req_cfg = NULL;
|
||||||
struct gpiod_line_request *request = NULL;
|
struct gpiod_line_request *request = NULL;
|
||||||
@@ -100,20 +125,19 @@ GPIO::request_output_line(const char *chip_path, unsigned int offset,
|
|||||||
if (!settings)
|
if (!settings)
|
||||||
goto close_chip;
|
goto close_chip;
|
||||||
|
|
||||||
gpiod_line_settings_set_direction(settings,
|
gpiod_line_settings_set_direction(settings, GPIOD_LINE_DIRECTION_OUTPUT);
|
||||||
GPIOD_LINE_DIRECTION_OUTPUT);
|
|
||||||
gpiod_line_settings_set_output_value(settings, value);
|
gpiod_line_settings_set_output_value(settings, value);
|
||||||
|
|
||||||
line_cfg = gpiod_line_config_new();
|
line_cfg = gpiod_line_config_new();
|
||||||
if (!line_cfg)
|
if (!line_cfg)
|
||||||
goto free_settings;
|
goto free_settings;
|
||||||
|
|
||||||
ret = gpiod_line_config_add_line_settings(line_cfg, &offset, 1,
|
ret = gpiod_line_config_add_line_settings(line_cfg, &offset, 1, settings);
|
||||||
settings);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto free_line_config;
|
goto free_line_config;
|
||||||
|
|
||||||
if (consumer) {
|
if (consumer)
|
||||||
|
{
|
||||||
req_cfg = gpiod_request_config_new();
|
req_cfg = gpiod_request_config_new();
|
||||||
if (!req_cfg)
|
if (!req_cfg)
|
||||||
goto free_line_config;
|
goto free_line_config;
|
||||||
@@ -137,9 +161,7 @@ close_chip:
|
|||||||
return request;
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct gpiod_line_request *GPIO::request_input_line(const char *chip_path,
|
struct gpiod_line_request *GPIO::request_input_line(const char *chip_path, unsigned int offset, const char *consumer)
|
||||||
unsigned int offset,
|
|
||||||
const char *consumer)
|
|
||||||
{
|
{
|
||||||
struct gpiod_request_config *req_cfg = NULL;
|
struct gpiod_request_config *req_cfg = NULL;
|
||||||
struct gpiod_line_request *request = NULL;
|
struct gpiod_line_request *request = NULL;
|
||||||
@@ -162,12 +184,12 @@ struct gpiod_line_request *GPIO::request_input_line(const char *chip_path,
|
|||||||
if (!line_cfg)
|
if (!line_cfg)
|
||||||
goto free_settings;
|
goto free_settings;
|
||||||
|
|
||||||
ret = gpiod_line_config_add_line_settings(line_cfg, &offset, 1,
|
ret = gpiod_line_config_add_line_settings(line_cfg, &offset, 1, settings);
|
||||||
settings);
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto free_line_config;
|
goto free_line_config;
|
||||||
|
|
||||||
if (consumer) {
|
if (consumer)
|
||||||
|
{
|
||||||
req_cfg = gpiod_request_config_new();
|
req_cfg = gpiod_request_config_new();
|
||||||
if (!req_cfg)
|
if (!req_cfg)
|
||||||
goto free_line_config;
|
goto free_line_config;
|
||||||
|
|||||||
+40
-29
@@ -5,49 +5,60 @@
|
|||||||
#ifdef __aarch64__
|
#ifdef __aarch64__
|
||||||
#include <gpiod.h>
|
#include <gpiod.h>
|
||||||
#else
|
#else
|
||||||
struct gpiod_line_request{};
|
struct gpiod_line_request
|
||||||
struct gpiod_request_config{};
|
{
|
||||||
struct gpiod_line_settings{};
|
|
||||||
struct gpiod_line_config{};
|
|
||||||
struct gpiod_chip{};
|
|
||||||
enum gpiod_line_value {
|
|
||||||
GPIOD_LINE_VALUE_ERROR = -1,
|
|
||||||
/**< Returned to indicate an error when reading the value. */
|
|
||||||
GPIOD_LINE_VALUE_INACTIVE = 0,
|
|
||||||
/**< Line is logically inactive. */
|
|
||||||
GPIOD_LINE_VALUE_ACTIVE = 1,
|
|
||||||
/**< Line is logically active. */
|
|
||||||
};
|
};
|
||||||
enum gpiod_line_direction {
|
struct gpiod_request_config
|
||||||
GPIOD_LINE_DIRECTION_AS_IS = 1,
|
{
|
||||||
/**< Request the line(s), but don't change direction. */
|
};
|
||||||
GPIOD_LINE_DIRECTION_INPUT,
|
struct gpiod_line_settings
|
||||||
/**< Direction is input - for reading the value of an externally driven
|
{
|
||||||
* GPIO line. */
|
};
|
||||||
GPIOD_LINE_DIRECTION_OUTPUT,
|
struct gpiod_line_config
|
||||||
/**< Direction is output - for driving the GPIO line. */
|
{
|
||||||
|
};
|
||||||
|
struct gpiod_chip
|
||||||
|
{
|
||||||
|
};
|
||||||
|
enum gpiod_line_value
|
||||||
|
{
|
||||||
|
GPIOD_LINE_VALUE_ERROR = -1,
|
||||||
|
/**< Returned to indicate an error when reading the value. */
|
||||||
|
GPIOD_LINE_VALUE_INACTIVE = 0,
|
||||||
|
/**< Line is logically inactive. */
|
||||||
|
GPIOD_LINE_VALUE_ACTIVE = 1,
|
||||||
|
/**< Line is logically active. */
|
||||||
|
};
|
||||||
|
enum gpiod_line_direction
|
||||||
|
{
|
||||||
|
GPIOD_LINE_DIRECTION_AS_IS = 1,
|
||||||
|
/**< Request the line(s), but don't change direction. */
|
||||||
|
GPIOD_LINE_DIRECTION_INPUT,
|
||||||
|
/**< Direction is input - for reading the value of an externally driven
|
||||||
|
* GPIO line. */
|
||||||
|
GPIOD_LINE_DIRECTION_OUTPUT,
|
||||||
|
/**< Direction is output - for driving the GPIO line. */
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class GPIO : public QObject {
|
class GPIO : public QObject
|
||||||
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum Direction {
|
enum Direction
|
||||||
|
{
|
||||||
Input,
|
Input,
|
||||||
Output
|
Output
|
||||||
};
|
};
|
||||||
explicit GPIO(Direction dir, uint8_t gpio, bool state = false, QObject* parent = nullptr);
|
explicit GPIO(Direction dir, uint8_t gpio, bool state = false, QObject *parent = nullptr);
|
||||||
~GPIO();
|
~GPIO();
|
||||||
void set_value(bool val);
|
void set_value(bool val);
|
||||||
bool value();
|
bool value();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct gpiod_line_request *
|
struct gpiod_line_request *request_output_line(const char *chip_path, unsigned int offset,
|
||||||
request_output_line(const char *chip_path, unsigned int offset,
|
enum gpiod_line_value value, const char *consumer);
|
||||||
enum gpiod_line_value value, const char *consumer);
|
struct gpiod_line_request *request_input_line(const char *chip_path, unsigned int offset, const char *consumer);
|
||||||
struct gpiod_line_request *request_input_line(const char *chip_path,
|
|
||||||
unsigned int offset,
|
|
||||||
const char *consumer);
|
|
||||||
|
|
||||||
struct gpiod_line_request *m_request;
|
struct gpiod_line_request *m_request;
|
||||||
unsigned int m_offset;
|
unsigned int m_offset;
|
||||||
|
|||||||
Reference in New Issue
Block a user