Esempio n. 1
0
void LEDOverlay::unset()
{
	os::MutexLocker mlock(mutex);

	// Removing ourselves from the list
	for (int i = 0; i < MAX_LAYERS; i++) {
		if (layers[i] == this) {
			layers[i] = nullptr;
			os::lowsyslog("LED: 0x%08x unregistered from pos %d\n", reinterpret_cast<unsigned>(this), i);
			break;
		}
	}

	// Defragmenting the list
	LEDOverlay* new_layers[MAX_LAYERS] = {};
	for (int src = 0, dst = 0; src < MAX_LAYERS; src++) {
		if (layers[src] != nullptr) {
			new_layers[dst++] = layers[src];
		}
	}
	std::copy_n(new_layers, MAX_LAYERS, layers);

	// Activating the last item
	for (int i = (MAX_LAYERS - 1); i >= 0; i--) {
		if (layers[i] != nullptr) {
			os::lowsyslog("LED: 0x%08x reactivated at pos %d\n", reinterpret_cast<unsigned>(layers[i]), i);
			set_hex_impl(layers[i]->color);
			break;
		}
	}
}
Esempio n. 2
0
void Overlay::set_hex_rgb(std::uint32_t hex_rgb)
{
	mutex.lock();

	color = hex_rgb;

	// Checking if this layer is registered
	int position = -1;
	for (int i = 0; i < MAX_LAYERS; i++) {
		if (layers[i] == this) {
			position = i;
			break;
		}
	}

	// Not registered - fixing
	if (position < 0) {
		for (int i = 0; i < MAX_LAYERS; i++) {
			if (layers[i] == nullptr) {
				position = i;
				layers[i] = this;
				::lowsyslog("LED: 0x%08x registered at pos %d\n",
				            reinterpret_cast<unsigned>(this), position);
				break;
			}
		}
	}

	// Failed to register - ignore the command
	if (position < 0) {
		::lowsyslog("LED: 0x%08x failed to register\n", reinterpret_cast<unsigned>(this));
		goto leave;
	}

	// Checking if we're at the top
	if ((position >= (MAX_LAYERS - 1)) || (layers[position + 1] == nullptr)) {
		set_hex_impl(color);
	}

leave:
	chibios_rt::BaseThread::unlockMutex();
}
Esempio n. 3
0
void LEDOverlay::set_hex_rgb(std::uint32_t hex_rgb)
{
	os::MutexLocker mlock(mutex);

	color = hex_rgb;

	// Checking if this layer is registered
	int position = -1;
	for (int i = 0; i < MAX_LAYERS; i++) {
		if (layers[i] == this) {
			position = i;
			break;
		}
	}

	// Not registered - fixing
	if (position < 0) {
		for (int i = 0; i < MAX_LAYERS; i++) {
			if (layers[i] == nullptr) {
				position = i;
				layers[i] = this;
				os::lowsyslog("LED: 0x%08x registered at pos %d\n",
				            reinterpret_cast<unsigned>(this), position);
				break;
			}
		}
	}

	// Failed to register - ignore the command
	if (position < 0) {
		os::lowsyslog("LED: 0x%08x failed to register\n", reinterpret_cast<unsigned>(this));
		return;
	}

	// Checking if we're at the top
	if ((position >= (MAX_LAYERS - 1)) || (layers[position + 1] == nullptr)) {
		set_hex_impl(color);
	}
}
Esempio n. 4
0
void led_emergency_override(LEDColor color)
{
	set_hex_impl(unsigned(color));
}
Esempio n. 5
0
void emergency_override(Color color)
{
	set_hex_impl(unsigned(color));
}