void ICACHE_FLASH_ATTR
temperature_object_init() {
	temperature_init();
	pando_object temperature_object = {
		1,
		temperature_object_pack,
		temperature_object_unpack,
	};
	register_pando_object(temperature_object);
}
Пример #2
0
int main(void)
{
	Display* display = 0;
	struct temperature* temperature = 0;
	int ret = EXIT_FAILURE;

	signal(SIGINT, &signal_handler);
	signal(SIGTERM, &signal_handler);
	setlocale(LC_ALL, u8"");

	display = XOpenDisplay(0);
	if (!display)
	{
		fprintf(stderr, u8"Could not open X11 display.\n");
		goto cleanup;
	}

	temperature = temperature_init();
	if (!temperature)
	{
		fprintf(stderr, u8"Could not initialize temperature.\n");
		goto cleanup;
	}

	while (running)
	{
		char buffer[1024];
		char* cur = buffer;
		size_t size = sizeof buffer;
		size_t check = 0;

		check = print_temperature(cur, size, temperature);
		size -= check;
		cur += check;

		check = print_time(cur, size);
		size -= check;
		cur += check;

		XStoreName(display, DefaultRootWindow(display), buffer);
		XSync(display, False);
		sleep(1);
	}

	ret = EXIT_SUCCESS;

cleanup:
	temperature_cleanup(temperature);
	if (display)
		XCloseDisplay(display);

	return ret;
}
Пример #3
0
/**
 * Return the current temperature.
 */
float temperature_read()
{
    // Set the pointer register to the temperature register
    temperature_init();
    tmp100_send_byte(TMP100_PTR_TMP);

    // Empty the buffer and reset the pointer and counter
    ptr = tbuf;
    counter = 0;
    tmp100_read();
    temperature_deinit();

    // Construct the value to be returned
    int16_t tmp = (tbuf[0] << 8) | tbuf[1];
    return (float)(tmp >> 4) * 0.0625;
}
Пример #4
0
//* ************************************************************************************************
/// @fn			init_application(void)
/// @brief		Init the watch's program
/// @return		none
//* ************************************************************************************************
void init_application(void)
{
	volatile unsigned char *ptr;
	
	// ---------------------------------------------------------------------
	// Enable watchdog
	
	// Watchdog triggers after 16 seconds when not cleared
#ifdef USE_WATCHDOG
	WDTCTL = WDTPW + WDTIS__512K + WDTSSEL__ACLK;
#else
	WDTCTL = WDTPW + WDTHOLD;
#endif
	
	// ---------------------------------------------------------------------
	// Configure PMM
	
	SetVCore(3);
	
	// Set global high power request enable
	PMMCTL0_H  = 0xA5;
	PMMCTL0_L |= PMMHPMRE;
	PMMCTL0_H  = 0x00;
	
	// ---------------------------------------------------------------------
	// Enable 32kHz ACLK
	
	P5SEL |= 0x03;				// Select XIN, XOUT on P5.0 and P5.1
	UCSCTL6 &= ~XT1OFF;			// XT1 On, Highest drive strength
	UCSCTL6 |= XCAP_3;			// Internal load cap
	
	UCSCTL3 = SELA__XT1CLK;		// Select XT1 as FLL reference
	UCSCTL4 = SELA__XT1CLK | SELS__DCOCLKDIV | SELM__DCOCLKDIV;
	
	// ---------------------------------------------------------------------
	// Configure CPU clock for 12MHz
	
	_BIS_SR(SCG0);				// Disable the FLL control loop
	UCSCTL0 = 0x0000;			// Set lowest possible DCOx, MODx
	UCSCTL1 = DCORSEL_5;		// Select suitable range
	UCSCTL2 = FLLD_1 + 0x16E;	// Set DCO Multiplier
	_BIC_SR(SCG0);				// Enable the FLL control loop
	
	// Worst-case settling time for the DCO when the DCO range bits have been
	// changed is n x 32 x 32 x f_MCLK / f_FLL_reference. See UCS chapter in 5xx
	// UG for optimization.
	// 32 x 32 x 8 MHz / 32,768 Hz = 250000 = MCLK cycles for DCO to settle
	
#if __GNUC_MINOR__ > 5 || __GNUC_PATCHLEVEL__ > 8
	
	__delay_cycles(250000);
	
#else
	
	__delay_cycles(62500);
	__delay_cycles(62500);
	__delay_cycles(62500);
	__delay_cycles(62500);
	
#endif
	
	// Loop until XT1 & DCO stabilizes, use do-while to insure that 
	// body is executed at least once
	do
	{
		UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG);
		SFRIFG1 &= ~OFIFG;		// Clear fault flags
	}
	while ((SFRIFG1 & OFIFG));
	
	// ---------------------------------------------------------------------
	// Configure port mapping
	
	// Disable all interrupts
	__disable_interrupt();
	// Get write-access to port mapping registers:
	PMAPPWD = 0x02D52;
	// Allow reconfiguration during runtime:
	PMAPCTL = PMAPRECFG;
	
	// P2.7 = TA0CCR1A or TA1CCR0A output (buzzer output)
	ptr  = &P2MAP0;
	*(ptr + 7) = PM_TA1CCR0A;
	P2OUT &= ~BIT7;
	P2DIR |= BIT7;
	
	// P1.5 = SPI MISO input
	ptr  = &P1MAP0;
	*(ptr + 5) = PM_UCA0SOMI;
	// P1.6 = SPI MOSI output
	*(ptr + 6) = PM_UCA0SIMO;
	// P1.7 = SPI CLK output
	*(ptr + 7) = PM_UCA0CLK;
	
	// Disable write-access to port mapping registers:
	PMAPPWD = 0;
	// Re-enable all interrupts
	__enable_interrupt();
	
	// Init the hardwre real time clock (RTC_A)
	rtca_init();
	
	// ---------------------------------------------------------------------
	// Configure ports
	
	// ---------------------------------------------------------------------
	// Reset radio core
	
	radio_reset();
	radio_powerdown();
	
	// ---------------------------------------------------------------------
	// Init acceleration sensor
	
#ifdef CONFIG_MOD_ACCELEROMETER
	as_init();
#else
	as_disconnect();
#endif
	
	// ---------------------------------------------------------------------
	// Init LCD
	
	lcd_init();
	
	// ---------------------------------------------------------------------
	// Init buttons

	init_buttons();
	
	// ---------------------------------------------------------------------
	// Configure Timer0 for use by the clock and delay functions
	
	timer0_init();
	
	// Init buzzer
	buzzer_init();
	
	// ---------------------------------------------------------------------
	// Init pressure sensor
	
#ifdef CONFIG_PRESSURE_SENSOR
	ps_init();
#endif
	
	// ---------------------------------------------------------------------
	// Init other sensors
	
	// From: "driver/battery"
	battery_init();
	
	// From: "drivers/temperature"
	temperature_init();
	
	/// @todo What is this ?
#ifdef CONFIG_INFOMEM
	
	if (infomem_ready() == -2)
		infomem_init(INFOMEM_C, INFOMEM_C + 2 * INFOMEM_SEGMENT_SIZE);
	
#endif

}
Пример #5
0
void calibrate_init(void)
{
    float_pack_t pack;
    bool found_acc_matrix = 0;

    // Make FLASH writable while initializing the virtual EEPROM
    FLASH_Unlock();
    EE_Init();
    FLASH_Lock();

    // Set defaults of no change if any of the values are not found
    if (EE_ReadVariable(EE_GYRO_OFF_X_L, &pack.s[0]) || EE_ReadVariable(EE_GYRO_OFF_X_H, &pack.s[1]))
        g_cal.gyro_offset[0] = 0.0;
    else
        g_cal.gyro_offset[0] = pack.f;

    if (EE_ReadVariable(EE_GYRO_OFF_Y_L, &pack.s[0]) || EE_ReadVariable(EE_GYRO_OFF_Y_H, &pack.s[1]))
        g_cal.gyro_offset[1] = 0.0;
    else
        g_cal.gyro_offset[1] = pack.f;

    if (EE_ReadVariable(EE_GYRO_OFF_Z_L, &pack.s[0]) || EE_ReadVariable(EE_GYRO_OFF_Z_H, &pack.s[1]))
        g_cal.gyro_offset[2] = 0.0;
    else {
        g_cal.gyro_offset[2] = pack.f;
        // mark if we were able to successfully load a gyro offset from EEPROM
        stored_gyro_offset = 1;
    }

    // Read the 3x3 scale and cross axis matrix
    for (uint8_t i = 0; i < 3; i++) {
        for (uint8_t j = 0; j < 3; j++) {
            if (EE_ReadVariable(EE_GYRO_SCALE_START + (i*3 + j)*2, &pack.s[0]) || EE_ReadVariable(EE_GYRO_SCALE_START + (i*3 + j)*2 + 1, &pack.s[1]))
                // Fill missing values with the identity matrix
                g_cal.gyro_scale[i][j] = (i == j) ? 1.0 : 0.0;
            else
                g_cal.gyro_scale[i][j] = pack.f;
        }
    }

    // Read the 3x3 scale and cross axis matrix
    for (uint8_t i = 0; i < 3; i++) {
        for (uint8_t j = 0; j < 3; j++) {
            if (EE_ReadVariable(EE_ACC_SCALE_START + (i*3 + j)*2, &pack.s[0]) || EE_ReadVariable(EE_ACC_SCALE_START + (i*3 + j)*2 + 1, &pack.s[1])) {
                // Fill missing values with the identity matrix
                g_cal.acc_scale[i][j] = (i == j) ? 1.0 : 0.0;
            } else {
                g_cal.acc_scale[i][j] = pack.f;
                found_acc_matrix = 1;
            }
        }
    }

    if (!found_acc_matrix)
        init_legacy_acc();

    if (EE_ReadVariable(EE_ACC_OFF_X_L, &pack.s[0]) || EE_ReadVariable(EE_ACC_OFF_X_H, &pack.s[1]))
        g_cal.acc_offset[0] = 0.0;
    else
        g_cal.acc_offset[0] = pack.f;

    if (EE_ReadVariable(EE_ACC_OFF_Y_L, &pack.s[0]) || EE_ReadVariable(EE_ACC_OFF_Y_H, &pack.s[1]))
        g_cal.acc_offset[1] = 0.0;
    else
        g_cal.acc_offset[1] = pack.f;

    if (EE_ReadVariable(EE_ACC_OFF_Z_L, &pack.s[0]) || EE_ReadVariable(EE_ACC_OFF_Z_H, &pack.s[1]))
        g_cal.acc_offset[2] = 0.0;
    else
        g_cal.acc_offset[2] = pack.f;

    if (EE_ReadVariable(EE_TEMPERATURE_L, &pack.s[0]) || EE_ReadVariable(EE_TEMPERATURE_H, &pack.s[1]))
        g_cal.temperature = 0.0;  // Just pick a fake temperature
    else
        g_cal.temperature = pack.f;

    // If we have calibration, and the calibration was performed with the cross
    // axis sign error, fix it
    if (found_acc_matrix) {
        uint16_t version = 0;
        EE_ReadVariable(EE_CAL_VERSION, &version);
        // CALIBRATE_HD and newer have the fix
        if (version < CALIBRATE_HD) {
            fix_cross_axis();
        }
    }

    // Start at the factory calibrated gyro offset
    memcpy(current_offset.offset, g_cal.gyro_offset, sizeof(float)*3);
    current_offset.temperature_actual = g_cal.temperature;

    // Initialize the gyro offset temperature bins
    temperature_init(&current_offset);
}
Пример #6
0
/*------Done in a subroutine to keep main routine stack usage small--------*/
void initialize(void)
{
  watchdog_init();
  watchdog_start();

  init_lowlevel();

  clock_init();

  forwarding_enabled = get_forwarding_from_eeprom();


#if ANNOUNCE_BOOT
  PRINTF("\n*******Booting %s*******\n",CONTIKI_VERSION_STRING);
#endif

/* rtimers needed for radio cycling */
  rtimer_init();

 /* Initialize process subsystem */
  process_init();
 /* etimers must be started before ctimer_init */
  process_start(&etimer_process, NULL);

#if RF230BB || RF212BB

  ctimer_init();
  /* Start radio and radio receive process */

    NETSTACK_RADIO.init();
  /* Set addresses BEFORE starting tcpip process */

  rimeaddr_t addr;
  memset(&addr, 0, sizeof(rimeaddr_t));
  get_mac_from_eeprom(addr.u8);
 
#if UIP_CONF_IPV6 
  memcpy(&uip_lladdr.addr, &addr.u8, 8);
#endif  
#if RF230BB
  rf230_set_pan_addr(
	get_panid_from_eeprom(),
	get_panaddr_from_eeprom(),
	(uint8_t *)&addr.u8
  );
  rf230_set_channel(CHANNEL_802_15_4);

#elif RF212BB
  rf212_set_pan_addr(
	get_panid_from_eeprom(),
 	get_panaddr_from_eeprom(),
 	(uint8_t *)&addr.u8
   );
#endif

	extern uint16_t mac_dst_pan_id;
	extern uint16_t mac_src_pan_id;
	//set pan_id for frame creation
	mac_dst_pan_id = get_panid_from_eeprom();
	mac_src_pan_id = mac_dst_pan_id;

  rimeaddr_set_node_addr(&addr); 

  PRINTFD("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]);

  /* Initialize stack protocols */
  queuebuf_init();
  NETSTACK_RDC.init();
  NETSTACK_MAC.init();
  NETSTACK_NETWORK.init();

#if ANNOUNCE_BOOT
 #if RF230BB
  PRINTF("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name, rf230_get_channel());
 #elif RF212BB
  PRINTF("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name, rf212_get_channel());
 #endif /* RF230BB */
  if (NETSTACK_RDC.channel_check_interval) {//function pointer is zero for sicslowmac
    unsigned short tmp;
    tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\
                                   NETSTACK_RDC.channel_check_interval());
    if (tmp<65535) printf_P(PSTR(", check rate %u Hz"),tmp);
  }
  PRINTF("\n");

#if UIP_CONF_IPV6_RPL
  PRINTF("RPL Enabled\n");
#endif
#if UIP_CONF_ROUTER
  PRINTF("Routing Enabled\n");
#endif

#endif /* ANNOUNCE_BOOT */

// rime_init(rime_udp_init(NULL));
// uip_router_register(&rimeroute);

  process_start(&tcpip_process, NULL);

#else
/* Original RF230 combined mac/radio driver */
/* mac process must be started before tcpip process! */
  process_start(&mac_process, NULL);
  process_start(&tcpip_process, NULL);
#endif /*RF230BB || RF212BB*/

#if WEBSERVER
  process_start(&webserver_nogui_process, NULL);
#endif

  /* Handler for HEXABUS UDP Packets */
  process_start(&udp_handler_process, NULL);

  /* Process for periodic sending of HEXABUS data */
#if VALUE_BROADCAST_ENABLE
#if VALUE_BROADCAST_AUTO_INTERVAL
  process_start(&value_broadcast_process, NULL);
#else
  init_value_broadcast();
#endif
#endif

  /* process handling received HEXABUS broadcasts */
#if STATE_MACHINE_ENABLE
  process_start(&state_machine_process, NULL);
#endif

  /*Init Relay */
  relay_init();

#if SHUTTER_ENABLE
  /*Init Shutter*/
  shutter_init();

  /* process for shutter control*/
  process_start(&shutter_process, NULL);

  /* calibrate and go to initial position */
  process_start(&shutter_setup_process, NULL);

#endif

#if HEXAPUSH_ENABLE
  process_start(&hexapush_process, NULL);
#endif

#if PRESENCE_DETECTOR_ENABLE
  presence_detector_init();
#endif

  mdns_responder_init();

  /* Datetime service*/
#if DATETIME_SERVICE_ENABLE
  process_start(&datetime_service_process, NULL);
#endif

  /* Button Process */
  process_start(&button_pressed_process, NULL);

  /* Init Metering */
  metering_init();

  /* Init Temp Sensor */
#if TEMPERATURE_ENABLE
  temperature_init();
#endif

#if HEXONOFF_ENABLE
  hexonoff_init();
#endif

#if ANALOGREAD_ENABLE
  analogread_init();
#endif

  /*Init Relay */
  relay_init();

  /* Autostart other processes */
  autostart_start(autostart_processes);

  /*---If using coffee file system create initial web content if necessary---*/
#if COFFEE_FILES
  int fa = cfs_open( "/index.html", CFS_READ);
  if (fa<0) {     //Make some default web content
    PRINTF("No index.html file found, creating upload.html!\n");
    PRINTF("Formatting FLASH file system for coffee...");
    cfs_coffee_format();
    PRINTF("Done!\n");
    fa = cfs_open( "/index.html", CFS_WRITE);
    int r = cfs_write(fa, &"It works!", 9);
    if (r<0) PRINTF("Can''t create /index.html!\n");
    cfs_close(fa);
//  fa = cfs_open("upload.html"), CFW_WRITE);
// <html><body><form action="upload.html" enctype="multipart/form-data" method="post"><input name="userfile" type="file" size="50" /><input value="Upload" type="submit" /></form></body></html>
  }
#endif /* COFFEE_FILES */

/* Add addresses for testing */
#if 0
{  
  uip_ip6addr_t ipaddr;
  uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
  uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF);
//  uip_ds6_prefix_add(&ipaddr,64,0);
}
#endif

/*--------------------------Announce the configuration---------------------*/
#if ANNOUNCE_BOOT

#if WEBSERVER
  uint8_t i;
  char buf[80];
  unsigned int size;

  for (i=0;i<UIP_DS6_ADDR_NB;i++) {
	if (uip_ds6_if.addr_list[i].isused) {	  
	   httpd_cgi_sprint_ip6(uip_ds6_if.addr_list[i].ipaddr,buf);
       PRINTF("IPv6 Address: %s\n",buf);
	}
  }
	eeprom_read_block(buf, (const void*) EE_DOMAIN_NAME, EE_DOMAIN_NAME_SIZE);
	buf[EE_DOMAIN_NAME_SIZE] = 0;
	size=httpd_fs_get_size();
#ifndef COFFEE_FILES
   PRINTF(".%s online with fixed %u byte web content\n",buf,size);
#elif COFFEE_FILES==1
   PRINTF(".%s online with static %u byte EEPROM file system\n",buf,size);
#elif COFFEE_FILES==2
   PRINTF(".%s online with dynamic %u KB EEPROM file system\n",buf,size>>10);
#elif COFFEE_FILES==3
   PRINTF(".%s online with static %u byte program memory file system\n",buf,size);
#elif COFFEE_FILES==4
   PRINTF(".%s online with dynamic %u KB program memory file system\n",buf,size>>10);
#endif /* COFFEE_FILES */

#else
   PRINTF("Online\n");
#endif /* WEBSERVER */

#endif /* ANNOUNCE_BOOT */
}
Пример #7
0
void init_application(void)
{
	volatile unsigned char *ptr;

	// ---------------------------------------------------------------------
	// Enable watchdog

	// Watchdog triggers after 16 seconds when not cleared
#ifdef USE_WATCHDOG
	WDTCTL = WDTPW + WDTIS__512K + WDTSSEL__ACLK;
#else
	WDTCTL = WDTPW + WDTHOLD;
#endif

	// ---------------------------------------------------------------------
	// Configure port mapping

	// Disable all interrupts
	__disable_interrupt();
	// Get write-access to port mapping registers:
	PMAPPWD = 0x02D52;
	// Allow reconfiguration during runtime:
	PMAPCTL = PMAPRECFG;

	// P2.7 = TA0CCR1A or TA1CCR0A output (buzzer output)
	ptr  = &P2MAP0;
	*(ptr + 7) = PM_TA1CCR0A;
	P2OUT &= ~BIT7;
	P2DIR |= BIT7;

	// P1.5 = SPI MISO input
	ptr  = &P1MAP0;
	*(ptr + 5) = PM_UCA0SOMI;
	// P1.6 = SPI MOSI output
	*(ptr + 6) = PM_UCA0SIMO;
	// P1.7 = SPI CLK output
	*(ptr + 7) = PM_UCA0CLK;

	// Disable write-access to port mapping registers:
	PMAPPWD = 0;
	// Re-enable all interrupts
	__enable_interrupt();

	// Init the hardwre real time clock (RTC_A)
	rtca_init();

	// ---------------------------------------------------------------------
	// Configure ports

	// ---------------------------------------------------------------------
	// Reset radio core
	radio_reset();
	radio_powerdown();

#ifdef CONFIG_ACCELEROMETER
	// ---------------------------------------------------------------------
	// Init acceleration sensor
	as_init();
#else
	as_disconnect();
#endif

	// ---------------------------------------------------------------------
	// Init buttons
	init_buttons();

	// ---------------------------------------------------------------------
	// Configure Timer0 for use by the clock and delay functions
	timer0_init();

	/* Init buzzer */
	buzzer_init();

	// ---------------------------------------------------------------------
	// Init pressure sensor
	ps_init();

	/* drivers/battery */
	battery_init();

	/* drivers/temperature */
	temperature_init();

#ifdef CONFIG_INFOMEM
	if (infomem_ready() == -2) {
		infomem_init(INFOMEM_C, INFOMEM_C + 2 * INFOMEM_SEGMENT_SIZE);
	}
#endif
}