Exemple #1
0
void lamp_flash_on (lampnum_t lamp)
{
	if (!bit_test (lamp_flash_matrix, lamp))
	{
		/* Enable flashing on this lamp */
		bit_on (lamp_flash_matrix, lamp);

		/* Set the initial flash state of the lamp to match that of all
		other lamps that are flashing.  If any of the flashing lamps
		are on now, then this one should be on, too.  Otherwise, leave
		it off. */
		disable_interrupts ();
		if (!bit_test_all_off (lamp_flash_matrix_now))
			bit_on (lamp_flash_matrix_now, lamp);
		else
			bit_off (lamp_flash_matrix_now, lamp);
		enable_interrupts ();
	}
}
Exemple #2
0
void radio_on_receive(Radio * radio)
{
	if(radio->transmitting || !radio->callback_receive)
		return;

	radio_time time = radio->microseconds();
	radio_time duration = time - radio->last_time;
	radio->last_time = time;

	if(time < radio->last_time) {
		reset_receiver(radio);
		return;
	}

	if(duration < 300) {
		reset_receiver(radio);
		return;
	}

	if(!radio->receiving) {
		radio->receiving = 1;
		radio->delay = duration /* sync */ / 31;
		radio->delay_tolerance = radio->delay * radio->tolerance * 0.01;
		radio->bit_count = 0;
		radio->received_bytes_count = 0;
	}

	if(between(duration, radio->delay, 3 * radio->delay, radio->delay_tolerance)) {
		if(byte_odd(radio->change_count)) {
			if(radio->received_bytes_count >= radio->buffer_size) {
				// Overflow
				// Realloc on simple uc would result in memory fragmentation
				// and freeze
				radio->received_bytes_count = 0;
				reset_receiver(radio);
				return;
			}

			if(received_one(radio, duration))
				bit_on(&radio->received_message[radio->received_bytes_count],
				       7 - radio->bit_count++);
			else if(received_zero(radio, duration))
				bit_off(&radio->received_message[radio->received_bytes_count],
				        7 - radio->bit_count++);
			else {
				reset_receiver(radio);
				return;
			}

			if(radio->bit_count == 8) {
				radio->bit_count = 0;
				radio->received_bytes_count++;
			}
		}
	} else if(radio->change_count > 1) {
		reset_receiver(radio);
		return;
	}

	radio->change_count++;
}
Exemple #3
0
void leff_off (lampnum_t lamp)
{
	bit_off (leff_data_set, lamp);
}
Exemple #4
0
void lamp_flash_off (lampnum_t lamp)
{
	bit_off (lamp_flash_matrix, lamp);
	bit_off (lamp_flash_matrix_now, lamp);
}
Exemple #5
0
void lamp_off (lampnum_t lamp)
{
	bit_off (lamp_matrix, lamp);
}