Welcome to mirror list, hosted at ThFree Co, Russian Federation.

leds.cpp « app « pastilda « emb - github.com/thirdpin/pastilda.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e000c80633997afe1732cac4172612c854ecaa59 (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
38
39
40
41
42
#include "leds.h"

using namespace LEDS_API;

LEDS_api::LEDS_api()
{
	_leds[0] = new GPIO_ext(LED_R);
	_leds[1] = new GPIO_ext(LED_G);
	_leds[2] = new GPIO_ext(LED_B);
	_leds[0]->mode_setup(Mode::OUTPUT, PullMode::NO_PULL);
	_leds[1]->mode_setup(Mode::OUTPUT, PullMode::NO_PULL);
	_leds[2]->mode_setup(Mode::OUTPUT, PullMode::NO_PULL);

	_leds_state = LEDS_INI_STATE;
	_timer_leds_toggle = new TimerMs(TimerMode::CYCLE, LEDS_TOGGLE_PERIOD_MS);
}

void LEDS_api::toggle()
{
	if (_timer_leds_toggle->timeout()) {
		leds_toggle();
	}
}

void LEDS_api::leds_toggle()
{
	uint8_t mask = LEDS_INI_STATE;
	for(int i = 0; i < LEDS_COUNT; i++) {
		if (!(_leds_state & mask)) {
			_leds[i]->set();
	    }
	    else {
	    	_leds[i]->clear();
	    }

	    mask = mask << 1;
	}

	if( ++_leds_state > LEDS_MAX_STATE ) {
		_leds_state = LEDS_INI_STATE;
	}
}