summaryrefslogtreecommitdiff
path: root/daemon/src/Gpio.cpp
blob: 75d2ff1f8ed2bd1b439c1b82fa9ef7cf78fac6ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "Gpio.h"

#include <limits>

#include <rpc/server.h>

#include "Assembly.h"


void Gpio::apply(AssemblyContext ctx)
{
	ctx.bind("/set_mode", [&](const unsigned port, const short mode){ set_mode(port, mode); });
	ctx.bind("/write", [&](const unsigned port, const short value){ write(port, value); });
	ctx.bind("/read", [&](const unsigned port) -> short { return read(port); });
}


void Gpio::set_mode(const unsigned port, const short mode)
{
	if (SIZE > port)
		mode_of[port] = mode & 0x1;
}


void Gpio::write(const unsigned port, const short value)
{
	if (SIZE > port && mode_of[port] == 0x1)
		value_of[port] = value & 0x1;
}


short Gpio::read(const unsigned port) const
{
	if (SIZE <= port)
		return std::numeric_limits<short>::max();
	return value_of[port];
}