コード例 #1
0
ファイル: main.c プロジェクト: Jimmy-Dinis/flm02
int main(void)
{
	uint8_t i;

	cli();
	MCUSR = 0;
	wdt_disable();

	//TODO replace by an ana comp polling loop
	_delay_ms(10);

	setup_datastructs();
	setup_led();
	setup_ar_uart();
	setup_adc();
	setup_pulse_input();
	setup_analog_comparator();
	setup_timer0();
	setup_timer1();
	
	// initialize the CTRL buffers
	ctrlInit();
	// initialize the SPI in slave mode
	setup_spi(SPI_MODE_0, SPI_MSB, SPI_INTERRUPT, SPI_SLAVE);

	// initialize the Si4421/RFM12 radio and buffers
	rfm12_init();

	// the clk/8 fuse bit is set
	clock_prescale_set(clock_div_1);
	FLAG_CLR_ICF1();
	sei();


	for(;;) {
		if (spi_status & SPI_NEW_CTRL_MSG) {
			ctrlDecode();
			spi_status &= ~SPI_NEW_CTRL_MSG;
		}

		for (i = 0; i < max_analog_sensors; i++) {
			if (state[i].flags & STATE_POWER_CALC) {
				calculate_power(&state[i]);
				state[i].flags &= ~STATE_POWER_CALC;
				state[i].flags |= STATE_POWER;
			}
		}

		rfm12_tick();
	}

	return 0;
}
コード例 #2
0
ファイル: main.c プロジェクト: jgoller/flm02
int main(void)
{
	uint8_t i;

	cli();

	// RS-485: Configure PD5=DE as output pin with low as default
	DDRD |= (1<<DDD5);
	// set high to transmit
	//PORTD |= (1<<PD5);

	setup_datastructs();
	setup_led();
	setup_adc();
	setup_pulse_input();
	setup_analog_comparator();
	setup_timer1();
	
	// initialize the CTRL buffers
	ctrlInit();
	// initialize the UART hardware and buffers
	uartInit();
	// initialize the SPI in slave mode
	setup_spi(SPI_MODE_2, SPI_MSB, SPI_INTERRUPT, SPI_SLAVE);

	sei();


	for(;;) {
		if (spi_status & SPI_NEW_CTRL_MSG) {
			ctrlDecode();
			spi_status &= ~SPI_NEW_CTRL_MSG;
		}

		for (i = 0; i < MAX_ANALOG_SENSORS; i++) {
			if (state[i].flags & STATE_POWER_CALC) {
				calculate_power(&state[i]);
				state[i].flags &= ~STATE_POWER_CALC;
				state[i].flags |= STATE_POWER;
			}
		}
	}

	return 0;
}
コード例 #3
0
ファイル: main.c プロジェクト: vastin/iliad-hacking
int main(int argc, char *argv[])
{
    GtkWidget*  window;
    shareMgr_t* theShareMgr;
    int         nRet;
    gboolean    ok;

    // catch the SIGTERM signal
    struct sigaction on_term;
    memset(&on_term, 0x00, sizeof(on_term));
    on_term.sa_handler = on_sigterm;
    sigaction(SIGTERM, &on_term, NULL);

    DL_WARNPRINTF(PACKAGE_STRING);

    parse_arguments(argc, argv);

    // minimum battery charge required for background mode
    if (g_background)
    {
        if (get_battery_charge() <= BATTERY_MINCHARGE_BACKGROUND)
        {
            DL_ERRORPRINTF("Insufficient battery [%d] for background PC connect -> quit", get_battery_charge());
            return NO_ERROR;
        }
    }
    
    /* init threads */
    g_thread_init(NULL);
    gdk_threads_init();

    // open the RC file associated with this program (re-use the downloadMgr one)
    gtk_rc_parse(DATA_DIR "/downloadMgr.rc");
    DL_LOGPRINTF("rc file %s", DATA_DIR "/downloadMgr.rc");

    gtk_init(&argc, &argv);

    load_registry();
    languagesInit();
    
    // create/init the channel to communicate with the content lister
    nRet = erIpcStartClient(ER_CONTENTLISTER_CHANNEL, &contentListerChannel);
    if (nRet != 0)
    {
        DL_ERRORPRINTF("erIpcStartClient returned %d", nRet);
        contentListerChannel = NULL;
    }

    // create the main, top level, window 
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), PACKAGE " " VERSION);
    gtk_window_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_container_set_border_width(GTK_CONTAINER(window), 0);
    // gtk_widget_set_size_request(GTK_WIDGET(window), SCREEN_WIDTH, SCREEN_HEIGHT);
    gtk_window_set_modal(GTK_WINDOW(window), FALSE);
    gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
    gtk_window_fullscreen(GTK_WINDOW(window)); // Fullscreen overlap taskbars

    theShareMgr = ctrlInit(window);

    if (theShareMgr)
    {
        // Connect the destroy event of the window with our on_destroy function
        // When the window is about to be destroyed we get a notification and
        // stop the main GTK loop
        g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(on_destroy), NULL);

        // make sure that everything, window and label, are visible 
        if ( !g_background )
        {
            gtk_widget_show(window);
        }
    }

    // Start the download thread
    ok = shareThread_start((gpointer)theShareMgr);
    if (!ok)
    {
        printf("%s %s: ", __FILE__, __FUNCTION__);
        perror("Could not create thread\n");
    }

    // run the GTK main loop
    DL_LOGPRINTF("Before gtk_main");
    gdk_threads_enter();
    gtk_main();
    gdk_threads_leave();
    nRet = theShareMgr->returnVal;
    DL_LOGPRINTF("exitValue after gtk_main [%d]", nRet);

    // GTK done, abort any copying that might be running
    shareThread_stop();
    shareThread_wait(15);

    DL_WARNPRINTF("PC Share Manager quitting with return value \"%d\"", nRet);
    ctrlDestroy(theShareMgr);

    release_registry();

    return nRet;
}