#include <stdio.h>
#include <stdint.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <unistd.h>
#include "GPIOHeatingController.h"
-#include <pigpio.h>
using namespace std;
GPIOHeatingController::GPIOHeatingController(uint32_t aPin)
: mPin(aPin)
{
- gpioInitialise();
- gpioSetMode(mPin, PI_OUTPUT);
+ char buffer[256];
+ ssize_t bytes_written;
+ int fd;
+
+ fd = open("/sys/class/gpio/export", O_WRONLY);
+ if (-1 == fd) {
+ fprintf(stderr, "Failed to open export for writing!\n");
+ return;
+ }
+
+ bytes_written = snprintf(buffer, 256, "%d", mPin);
+ write(fd, buffer, bytes_written);
+ close(fd);
+
+ snprintf(buffer, 256, "/sys/class/gpio/gpio%d/direction", mPin);
+ fd = open(buffer, O_WRONLY);
+ if (-1 == fd) {
+ fprintf(stderr, "Failed to set gpio direction.\n");
+ }
+
+ write(fd, "out", 3);
+ close(fd);
}
void
GPIOHeatingController::setHeatingActive(bool aActive)
{
- if (aActive) {
- gpioWrite(mPin, 1);
- }
- else {
- gpioWrite(mPin, 0);
+ char buffer[256];
+ int fd;
+
+ snprintf(buffer, 256, "/sys/class/gpio/gpio%d/value", mPin);
+ fd = open(buffer, O_WRONLY);
+ if (-1 == fd) {
+ fprintf(stderr, "Failed to output gpio.\n");
+ return;
}
+
+ write(fd, aActive ? "1" : "0", 1);
+ close(fd);
}