Exemple #1
0
// Single-Ended 10bit, highbyte aligned.
// 3.85 V -> adval=192, adc_l = 128 -> 3 Red, 8 Green, 5 blue pulses.
static void blink_voltage(uint8_t adval, uint8_t adc_l)
{
  set_led(L_WH1, 0xff); set_led(L_YL1, 0xff);

  _delay_ms(200.0);
  _delay_ms(200.0);

  while (adval >= 50)
    { 
      adval -= 50;
      blink_once(L_RD2, 25);	// 2Hz
    }
  adval = (adval<<1)+((adc_l & 0x80)?1:0);
  led_off(L_WH1); led_off(L_YL1);
  _delay_ms(200.0);

  set_led(L_WH1, 0xff); set_led(L_YL1, 0xff);
  _delay_ms(200.0);
  while (adval >= 10)
    {
      adval -=10;
      blink_once(L_GN1, 17);	// 3Hz
    }
  led_off(L_WH1); led_off(L_YL1);
  _delay_ms(200.0);

  set_led(L_WH1, 0xff); set_led(L_YL1, 0xff);
  _delay_ms(200.0);
  while (adval-- > 0)
    {
      blink_once(L_BL2, 12);	// 4hz
    }
  led_off(L_WH1); led_off(L_YL1);
  _delay_ms(200.0);
}
Exemple #2
0
int main(void)
{
	bool cmd_ok = false;

	wdt_enable(WDTO_8S);

	// ADC enable; prescaler: 128 (156 KHz @ 20MHz)
	ADCSRA |= (_BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0));
	DDRC |= _BV(DDC0);  // LED:OUTPUT

	// NLOCK: locked
	DDRC |= _BV(DDC2);  // OUTPUT
	PORTC &= ~_BV(PORTC2);  // LOW

#ifdef DEBUG
	int m = DEBUG_CMD_DELAY;  // ms
	fdevopen(&serial_putc, 0);  // open the stdout and stderr streams
#endif

	sys_serial.begin(57600);
	IF_DEBUG(printf_P(PSTR("BOOT\r\n")));

	// initiate a sync with the daemon after boot
	// there is a 1:65536 chance that sync will not be lost
	// the daemon will initialize the device by the command
	cmd.set(CMD_COMMON, COMMON_RESET, 0, 0);
	common_device.confirm_boot(&cmd);
	//cmd.reset();  // look to the SerialCommand::read

	sys_log.begin();
	SPI.begin();
	if (radio.begin()) {
		 network.begin(RF24_CHANEL, rx_node);
		 nrf_device.setup(&network);
	}

	while(true)
	{
		wdt_reset();

		// CMD_NRF_FORWARD
		if (nrf_device.read(&cmd)) {
			if (!nrf_device.run(&cmd)) cmd.send_header(-1);
			//cmd.reset();
		}

		// CMD_RNG_SEND
		for (int i = 0; i < WDT_BITS_PER_CYCLE; i++) {
			if (rng_device.read(&cmd)) {
				if (!rng_device.run(&cmd)) cmd.send_header(-1);
				//cmd.reset();
			}
		}

		// watchdog trigger
		wdt_device.update();

#ifdef DEBUG
		if (--m <= 0) {
			m = DEBUG_CMD_DELAY;
			//cmd.set(CMD_COMMON, 1, 1460792071, 0); // look to the SerialCommand::read
			//sys_log.write(sys_time.now(), LOG_BOOT);
		}
		//_delay_ms(1);
#endif

		// serial commands
		if (cmd.read()) {
#ifdef DEBUG
			blink_once();
#endif
			cmd_ok = false;
			switch (cmd.get_type()) {
				case CMD_COMMON:
					cmd_ok = common_device.run(&cmd);
					break;
				case CMD_WDT:
					cmd_ok = wdt_device.run(&cmd);
					break;
				case CMD_RNG:
					cmd_ok = rng_device.run(&cmd);
					break;
				case CMD_NRF:
					cmd_ok = nrf_device.run(&cmd);
					break;
				default:
					break;
			}
			if (!cmd_ok) cmd.send_header(-1);
			//cmd.reset();
		}
	} // while(true)

	sys_serial.end();
	return 0;
} // main
Exemple #3
0
void blink(uint16_t period_ms, uint16_t count)
{
	uint16_t n = count;
	while (n-- || count == 0)
		blink_once(period_ms);
}