Example #1
0
void setup() {
#ifdef ARDUINO_ARCH_AVR
	sleep_setup();	// if you want to use sleep, or use the optiboot watchdog
#endif
	//wdt_disable();

	Serial.begin(115200);
#ifdef ARDUINO_ARCH_AVR
	printf_begin();
#endif
	printf_P(PSTR("HomeMesh 1.0\r\n"));
	printf_P(PSTR("(c) koverg70 %s %s\r\n"), __DATE__, __TIME__);

	/*
	pinMode(LED_PIN, OUTPUT);
	for (int i=1; i<3; ++i) {
		digitalWrite(LED_PIN, HIGH);
		delay(500);
		digitalWrite(LED_PIN, LOW);
		delay(500);
	}
	*/

	printf_P(PSTR("NodeID: %d, CE pin: %d, CS pin: %d\r\n"), NODE_ID, NRF24_CE_PIN, NRF24_CS_PIN);

  	// a very simple RF24 radio test
	delay(500);

	mesh.setNodeID(NODE_ID);
	printf_P(PSTR("NodeID: %d, CE pin: %d, CS pin: %d\r\n"), NODE_ID, NRF24_CE_PIN, NRF24_CS_PIN);
	mesh.begin();
	printf_P(PSTR("NodeID: %d, CE pin: %d, CS pin: %d\r\n"), NODE_ID, NRF24_CE_PIN, NRF24_CS_PIN);

	// --- now we initialize the tasks the are regularily called with new messages and to process information ----

	addTask(new TimeSync(60000, 0));		// sync frequency and target node to require time from
#if NODE_ID == 0
	Master *master = new Master();
	addTask(master);					// TODO: where to store received data
#ifdef ESP8266
	addTask(new ESP8266Ntp());
	addTask(new ESP8266Web(master->getSensors()));
#else
//	addTask(new Wifi(master->getSensors()));
	addTask(new Ethernet(master->getSensors()));
#endif
#else
	addTask(new Sensors(0));				// the target node to send sensor data to
#endif
#ifdef SCHEDULE_PIN
	addTask(new Schedule(SCHEDULE_PIN));	// sync frequency and target node to require time from
#endif

	// ------------------------------------------------------------------------------------------------------------

  	for (int i = 0; i < taskCount; ++i) {
  		tasks[i]->begin();
		printf_P(PSTR("Task started: %s\r\n"), tasks[i]->name());
  	}
}
Example #2
0
int
main (void)
{
    led_t led1;
    button_t button1;

    /* Initialise LED.  */
    led1 = led_init (&led1_cfg);

    /* Turn on LED.  */
    led_set (led1, 1);

    /* Initialise button.  */
    button1 = button_init (&button1_cfg);

    button_poll_count_set (BUTTON_POLL_COUNT (BUTTON_POLL_RATE));

    pacer_init (BUTTON_POLL_RATE);

    while (1)
    {
        pacer_wait ();

        button_poll (button1);

        if (button_pushed_p (button1))
        {
            /* Turn off LED.  */
            led_set (led1, 0);        

            sleep_setup ();
        }
    }
    return 0;
}
Example #3
0
void __attribute__ ((interrupt)) TIMER1_IRQHandler() {
    // Clear interrupt flag 
    *TIMER1_IFC = 1;
    
	//check if at end of note, may go to next note
	if ( counter >= current_note_length ) {
        counter = 0;
        note_counter++;
    } else {
        counter++;
    }
	
	//check if at end of song, resets values if true and end function
    if ( note_counter >= current_song->length ) {
        music_cleanup();
        gpio_led_clear();
        dac_disable();
        timer_disable();
        sleep_setup(0b110);
        return;
    }
    
	//creates temp pointer to note, play that frequency
    Note* n_temp = current_song->notes[note_counter];
    int offset = (song_iterator % n_temp->length);
    music_note_to_dac(n_temp, offset);
    song_iterator++;
}
Example #4
0
int main() {
    sleep_setup(0b110);
    gpio_setup();
    NVIC_setup();
     music_play_song(&ONEUP, 0x71f);
    while(1) {
		__asm__("wfi");
	}
    return 0;
}
int
rw_enter(struct rwlock *rwl, int flags)
{
	const struct rwlock_op *op;
	struct sleep_state sls;
	unsigned long inc, o;
	int error;

	op = &rw_ops[flags & RW_OPMASK];

	inc = op->inc + RW_PROC(curproc) * op->proc_mult;
retry:
	while (__predict_false(((o = rwl->rwl_owner) & op->check) != 0)) {
		unsigned long set = o | op->wait_set;
		int do_sleep;

		rw_enter_diag(rwl, flags);

		if (flags & RW_NOSLEEP)
			return (EBUSY);

		sleep_setup(&sls, rwl, op->wait_prio, rwl->rwl_name);
		if (flags & RW_INTR)
			sleep_setup_signal(&sls, op->wait_prio | PCATCH);

		do_sleep = !rw_cas(&rwl->rwl_owner, o, set);

		sleep_finish(&sls, do_sleep);
		if ((flags & RW_INTR) &&
		    (error = sleep_finish_signal(&sls)) != 0)
			return (error);
		if (flags & RW_SLEEPFAIL)
			return (EAGAIN);
	}

	if (__predict_false(rw_cas(&rwl->rwl_owner, o, o + inc)))
		goto retry;

	/*
	 * If old lock had RWLOCK_WAIT and RWLOCK_WRLOCK set, it means we
	 * downgraded a write lock and had possible read waiter, wake them
	 * to let them retry the lock.
	 */
	if (__predict_false((o & (RWLOCK_WRLOCK|RWLOCK_WAIT)) ==
	    (RWLOCK_WRLOCK|RWLOCK_WAIT)))
		wakeup(rwl);

	return (0);
}