コード例 #1
0
// Toggle different operational modes
void userbutton_callback(button_id_t button_id)
{
	#ifdef PLATFORM_EFM32GG_STK3700
	lcd_write_string("Butt %d", button_id);
	#else
	  lcd_write_string("button: %d\n", button_id);
	#endif
}
コード例 #2
0
uint8_t lcd_create_view(const char *str, uint8_t x, uint8_t y, uint8_t num, uint8_t flush)
{
	static int8_t lcd_view[49];

	uint8_t	i,
			pos;
	/* invalid line position */
	if (x > 15) {
		return 0xFE;
	}

	/* invalid row position */
	if (y > 2) {
		return 0xFF;
	}

	pos = x + y * 16;

	if(num == 0) {
		num = 48;
	}

	/* if string is empty determinat string on given position */
	if(*str == 0 && num == 48) {
		lcd_view[pos] = 0;
	}
	else {
		/* copy string on given position */
		while(*str != 0 && pos < 48 && str != 0 && num > 0) {//&& num > 0) {
			lcd_view[pos++] = *(str++);
			num--;
		}
	}

	/* Normal flush with over writing lcd_view with blanks */
	if(flush == 1) {
		lcd_set_courser(0,1);
		lcd_write_string(lcd_view,48);
		for(i = 48; i-- > 0;)	{
			lcd_view[i] = ' ';
		}
		lcd_view[48] = 0;
	}

	/* Init lcd_view with blanks */
	if(flush == 2) {
		for(i = 48; i-- > 0;) {
			lcd_view[i] = 0x20;
		}
		lcd_view[48] = 0;
		lcd_set_courser(0,1);
		lcd_write_string(lcd_view,48);
	}

	return 0;
}
コード例 #3
0
ファイル: bggame.c プロジェクト: beerriot/blockgame
void bggame_over(uint16_t score) {
    // game is over (no more moves)
    nklcd_stop_blinking();
    lcd_clear_and_home();
    lcd_goto_position(0, 6);
    lcd_write_string(PSTR("GAME OVER"));
    lcd_goto_position(2, 4);
    lcd_write_string(PSTR("score: "));
    lcd_write_int16(score);
    nktimer_simple_delay(300);
}
コード例 #4
0
void read_rssi()
{
    timestamped_rssi_t rssi_measurement;
    rssi_measurement.tick = timer_get_counter_value();

    char rssi_samples_str[5 * RSSI_SAMPLES_PER_MEASUREMENT] = "";
    int16_t max_rssi_sample = -200;
    for(int i = 0; i < RSSI_SAMPLES_PER_MEASUREMENT; i++)
    {
        rssi_measurement.rssi[i] = hw_radio_get_rssi();
        if(rssi_measurement.rssi[i] > max_rssi_sample)
            max_rssi_sample = rssi_measurement.rssi[i];

        sprintf(rssi_samples_str + (i * 5), ",%04i", rssi_measurement.rssi[i]);
        // TODO delay?
    }

    char str[80];
    char channel_str[8] = "";


    channel_id_to_string(&rx_cfg.channel_id, channel_str, sizeof(channel_str));
    lcd_write_string(channel_str);
    sprintf(str, "%7s,%i%s\n", channel_str, rssi_measurement.tick, rssi_samples_str);
    console_print(str);

#ifdef PLATFORM_EFM32GG_STK3700
    //lcd_all_on();
    lcd_write_number(max_rssi_sample);
#elif defined HAS_LCD
    sprintf(str, "%7s,%d\n", channel_str, max_rssi_sample);
    lcd_write_string(str);
#endif

    if(!use_manual_channel_switching)
    {
        switch_next_channel();
        sched_post_task(&start_rx);
    }
    else
    {
    	sched_post_task(&process_uart_rx_fifo); // check for UART commands first
        uint16_t delay = rand() % 5000;
        timer_post_task_delay(&read_rssi, delay);
    }

    hw_watchdog_feed();
}
コード例 #5
0
void bootstrap()
{
#ifdef HAS_LCD
    lcd_write_string("NOISE");
#endif

#if NUM_USERBUTTONS > 1
    ubutton_register_callback(0, &userbutton_callback);
    ubutton_register_callback(1, &userbutton_callback);
#endif

    prepare_channel_indexes();

    hw_radio_init(NULL, NULL);

    fifo_init(&uart_rx_fifo, uart_rx_buffer, sizeof(uart_rx_buffer));

    console_set_rx_interrupt_callback(&uart_rx_cb);
    console_rx_interrupt_enable(true);

    sched_register_task(&read_rssi);
    sched_register_task(&start_rx);
    sched_register_task(&process_uart_rx_fifo);
    timer_post_task_delay(&start_rx, TIMER_TICKS_PER_SEC * 3);

    sched_register_task((&execute_sensor_measurement));
    timer_post_task_delay(&execute_sensor_measurement, TEMPERATURE_PERIOD);

    measureTemperature();
}
コード例 #6
0
ファイル: bghighscore.c プロジェクト: beerriot/blockgame
void bghighscore_new(int8_t rank, uint16_t score) {
    int8_t i;
    nkbuttons_t button_state;
    uint8_t pressed_buttons;
    nkbuttons_clear(&button_state);
    for (i = 0; i < INITIALS; i++)
        highscores[rank].initials[i] = 'a';
    highscores[rank].score = score;

    lcd_clear_and_home();
    lcd_goto_position(0, 2);
    lcd_write_string(PSTR("NEW HIGH SCORE"));
    bghighscore_display_line(rank, 2);
    lcd_goto_position(2, 6);
    nklcd_start_blinking();
    i = 0;

    while(1) {
        if (nktimer_animate()) {
            pressed_buttons = nkbuttons_read(&button_state);

            if(pressed_buttons) {
                nklcd_stop_blinking();
                alter_highscore_initials(pressed_buttons, rank, i);
                if(bghighscore_move_cursor(pressed_buttons, &i))
                    break;
                bghighscore_display_line(rank, 2);
                lcd_goto_position(2, 6+i);
                nklcd_start_blinking();
            }
        }
    }

    bghighscore_write();
}
コード例 #7
0
static void start()
{
    counter = 0;
    missed_packets_counter = 0;
    received_packets_counter = 0;

    switch(current_state)
    {
        case STATE_CONFIG_DIRECTION:
            is_mode_rx? sprintf(lcd_msg, "PER RX") : sprintf(lcd_msg, "PER TX");
            break;
        case STATE_CONFIG_DATARATE:
            switch(current_channel_id.channel_header.ch_class)
            {
                case PHY_CLASS_LO_RATE:
                    sprintf(lcd_msg, "LO-RATE");
                    break;
                case PHY_CLASS_NORMAL_RATE:
                    sprintf(lcd_msg, "NOR-RATE");
                    break;
                case PHY_CLASS_HI_RATE:
                    sprintf(lcd_msg, "HI-RATE");
                    break;
            }
            break;
        case STATE_RUNNING:
            if(is_mode_rx)
            {
                sprintf(lcd_msg, "RUN RX");
                lcd_write_string(lcd_msg);
                sprintf(record, "%s,%s,%s,%s,%s,%s\n", "channel_id", "counter", "rssi", "tx_id", "rx_id", "timestamp");
                uart_transmit_message(record, strlen(record));
                rx_cfg.channel_id = current_channel_id;
                timer_post_task(&start_rx, TIMER_TICKS_PER_SEC * 5);
            }
            else
            {
                hw_radio_set_idle();
                sprintf(lcd_msg, "RUN TX");
                lcd_write_string(lcd_msg);
                timer_post_task(&transmit_packet, TIMER_TICKS_PER_SEC * 5);
            }
            break;
    }

    lcd_write_string(lcd_msg);
}
コード例 #8
0
ファイル: ui.c プロジェクト: equinoxorg/standalone_v2
void lcd_debug_display (void)
{
	unsigned char j;

	//Unlock Count
	lcd_clear();
	//lcd_write_string_XY(0, 0, "Unlock Count:");
	lcd_write_int_XY(0, 1, local_ee_data.unlock_count);
	os_dly_wait(300);
	
	//Box ID
	lcd_clear();
	//lcd_write_string_XY(0, 0, "Box_ID:");
	lcd_write_int(local_ee_data.box_id);
	os_dly_wait(300);
	
	//Full Unlock
	lcd_clear();
	if (local_ee_data.full_unlock == EE_FULL_UNLOCK_CODE) {
		lcd_write_string("Full Unlock");
	} else {
		lcd_write_string("Not Full Unlock");
	}
	os_dly_wait(300);
	/*
	lcd_clear();
	lcd_write_int(get_unlock_days ());
	os_dly_wait(300);
	*/
	//RTC Test
	for (j = 0; j < 50; j++) {
		char str[16];
		lcd_clear();
		
		get_time_str(&str[0]);
		lcd_write_string_XY(0,0, str);

		str[0] = '\0';
		get_date_str(&str[0]);
		lcd_write_string_XY(0,1, str);
		
		//200ms delay
		os_dly_wait(20);
	}
	
	lcd_clear();
}
コード例 #9
0
static void packet_received(hw_radio_packet_t* packet) {
    uint16_t crc = __builtin_bswap16(crc_calculate(packet->data, packet->length - 2));
    if(memcmp(&crc, packet->data + packet->length + 1 - 2, 2) != 0)
    {
        DPRINT("CRC error");
        missed_packets_counter++;
    }
    else
    {
		#if HW_NUM_LEDS > 0
			led_toggle(0);
		#endif
		uint16_t msg_counter = 0;
        uint64_t msg_id;
        memcpy(&msg_id, packet->data + 1, sizeof(msg_id));
        memcpy(&msg_counter, packet->data + 1 + sizeof(msg_id), sizeof(msg_counter));
        char chan[8];
        channel_id_to_string(&(packet->rx_meta.rx_cfg.channel_id), chan, sizeof(chan));
        console_printf("%7s,%i,%i,%lu,%lu,%i\n", chan, msg_counter, packet->rx_meta.rssi, (unsigned long)msg_id, (unsigned long)id, packet->rx_meta.timestamp);
    

		if(counter == 0)
		{
			// just start, assume received all previous counters to reset PER to 0%
			received_packets_counter = msg_counter - 1;
			counter = msg_counter - 1;
		}

		uint16_t expected_counter = counter + 1;
		if(msg_counter == expected_counter)
		{
			received_packets_counter++;
			counter++;
		}
		else if(msg_counter > expected_counter)
		{
			missed_packets_counter += msg_counter - expected_counter;
			counter = msg_counter;
		}
		else
		{
            sched_post_task(&start);
		}

	    double per = 0;
	    if(msg_counter > 0)
	        per = 100.0 - ((double)received_packets_counter / (double)msg_counter) * 100.0;

	    sprintf(lcd_msg, "%i %i", (int)per, packet->rx_meta.rssi);

#ifdef PLATFORM_EFM32GG_STK3700
	    lcd_write_string(lcd_msg);
#else
	    lcd_write_line(4, lcd_msg);
#endif

    }
}
コード例 #10
0
void start_radio(){
#if defined USE_SI4460
#ifdef HAS_LCD
    lcd_write_string("Start sending \n");
#endif
#elif defined USE_CC1101
    cc1101_interface_strobe(RF_SCAL);
    cc1101_interface_strobe(RF_STX);
#endif
}
コード例 #11
0
void start_rx()
{
    log_print_string("start RX");

#ifdef HAS_LCD
    char channel_str[10] = "";
    channel_id_to_string(&rx_cfg.channel_id, channel_str, sizeof(channel_str));
    lcd_write_string(channel_str);
#endif
	hw_radio_set_rx(&rx_cfg, NULL, &rssi_valid);
}
コード例 #12
0
void __platform_post_framework_init()
{
    __ubutton_init();

#ifdef PLATFORM_EFM32HG_STK3400_LCD_ENABLED
    uint64_t id = hw_get_unique_id();
    // nano spec of newlib does not support 64bit ...
    lcd_write_string("%.8x", (uint32_t)(id >> 32));
    lcd_write_string("%.8x", (uint32_t)id);
#endif
}
コード例 #13
0
static void start() {
    counter = 0;
    missed_packets_counter = 0;
    received_packets_counter = 0;
    uint8_t lcd_line = 0;

    switch(current_state)
    {
        case STATE_CONFIG_DIRECTION:
            is_mode_rx? sprintf(lcd_msg, "PER RX") : sprintf(lcd_msg, "PER TX");
            break;
        case STATE_CONFIG_DATARATE:
        	lcd_line = 1;
            switch(current_channel_id.channel_header.ch_class)
            {
                case PHY_CLASS_LO_RATE:
                    sprintf(lcd_msg, "LO-RATE");
                    break;
                case PHY_CLASS_NORMAL_RATE:
                    sprintf(lcd_msg, "NOR-RATE");
                    break;
                case PHY_CLASS_HI_RATE:
                    sprintf(lcd_msg, "HI-RATE");
                    break;
            }
            break;
        case STATE_RUNNING:
        	lcd_line = 2;
            if(is_mode_rx)
            {
                sprintf(lcd_msg, "RUN RX");
                //lcd_write_string(lcd_msg);
                console_printf("%s,%s,%s,%s,%s,%s\n", "channel_id", "counter", "rssi", "tx_id", "rx_id", "timestamp");
                rx_cfg.channel_id = current_channel_id;
                timer_post_task(&start_rx, TIMER_TICKS_PER_SEC * 5);
            }
            else
            {
                hw_radio_set_idle();
                sprintf(lcd_msg, "RUN TX");
                //lcd_write_string(lcd_msg);
                timer_post_task(&transmit_packet, TIMER_TICKS_PER_SEC * 5);
            }
            break;
    }

#ifdef PLATFORM_EFM32GG_STK3700
    lcd_write_string(lcd_msg);
#else
    lcd_write_line(lcd_line, lcd_msg);
#endif

}
コード例 #14
0
void change_eirp(){
#if defined USE_SI4460
    ezradio_set_property(0x22, 0x01, 0x01, current_eirp_level);
#elif defined USE_CC1101
    cc1101_interface_write_single_patable(current_eirp_level);
#endif
#ifdef HAS_LCD
    char string[10] = "";
    sprintf(string, "ptx %3x", current_eirp_level);
    lcd_write_string(string);
#endif
}
コード例 #15
0
ファイル: main.c プロジェクト: olatief/Headstage
void lcd_update(char * l0, char * l1)
{
  xdata uint8_t  n0, n1;
  xdata char temp_l0[17], temp_l1[17]; 

  static xdata char curr_l0[17] = {0}, curr_l1[17] = {0}; 

  n0 = strlen(l0);
  n1 = strlen(l1);

  strcpy(temp_l0, l0);
  strcpy(temp_l1, l1);


  // Pad with white spaces at end of line
  for(; n0 < 16; n0++)
  {
    temp_l0[n0] = ' ';
  }
  temp_l0[16] = 0;
  
  for(; n1 < 16; n1++)
  {
    temp_l1[n1] = ' ';
  }
  temp_l1[16] = 0;

  if(strcmp(curr_l0, temp_l0) != 0)
  {
    strcpy(curr_l0, temp_l0);
    lcd_write_string(curr_l0, 0, 0);
  }
  
  if(strcmp(curr_l1, temp_l1) != 0)
  {
    strcpy(curr_l1, temp_l1);
    lcd_write_string(curr_l1, 1, 0);
    delay_ms(5);
  }
}
コード例 #16
0
void getTemp() {
	uint16_t last_sample = 0;
	double this_temp;
	double temp_avg;
	uint16_t i;
	temp_avg = 0.0;

	for (i=0; i<500; i++) {
		last_sample = adc_read();
		this_temp = sampleToFahrenheit(last_sample);
		temp_avg = temp_avg + this_temp/500.0;
	}

	double c = fahrenheitToCelsius(temp_avg);
	double k = celsiusToKelvin(c);

	// write message to LCD
	lcd_init();
	FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE);
	lcd_home();
	lcd_write_string(PSTR("ADC: "));
	lcd_write_int16(last_sample);
	lcd_write_string(PSTR(" of 1024 "));
	lcd_line_two();

	fprintf_P(&lcd_stream, PSTR("%.2f"), temp_avg);
	lcd_write_data(0xdf);
	lcd_write_string(PSTR("F"));

	lcd_line_three();
	fprintf_P(&lcd_stream, PSTR("%.2f"), c);
	lcd_write_data(0xdf);
	lcd_write_string(PSTR("C"));

	lcd_line_four();
	fprintf_P(&lcd_stream, PSTR("%.2f"), k);
	lcd_write_data(0xdf);
	lcd_write_string(PSTR("K"));
}
コード例 #17
0
ファイル: bghighscore.c プロジェクト: beerriot/blockgame
void bghighscore_screen() {
    int8_t s;
    // game is over (no more moves)
    lcd_clear_and_home();
    nklcd_stop_blinking();
    lcd_goto_position(0, 5);
    lcd_write_string(PSTR("HIGH SCORES"));
    for (s = 0; s < HIGH_SCORES; s++) {
        bghighscore_display_line(s, 1+s);
    }

    nktimer_simple_delay(300);
}
コード例 #18
0
int main() {
	DDRC |= (1<<PC4);
	_delay_ms(100);
	lcd_init();
	FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0,_FDEV_SETUP_WRITE);
	int i = 0;
	
	lcd_clear_and_home();
	lcd_write_string(PSTR("Alex + Christina"));

	while (1) {
		lcd_line_two();
		if (i) {
			lcd_write_string(PSTR("   I LOVE YOU"));
		} else {
			lcd_write_string(PSTR("             "));
		}
		i = (i+1) % 2;
		_delay_ms(1000);
	}
	

	return 0;
}
コード例 #19
0
ファイル: main.c プロジェクト: DlutLiuZhao/ThermostaticBath
void main()
{
	lcd_init();
	lcd_pos(0, 0);
	lcd_write_string("Ξ�½ΠΑυξΘ£Ί1234‘ζ");
	UART_Init();
	while (1) 
	{
		LED_ON();
		delay_ms(100);
		LED_OFF();
		delay_ms(100);
		SendData('b');
		SendData('\n');
	}
}
コード例 #20
0
static void packet_transmitted(hw_radio_packet_t* packet)
{
#if HW_NUM_LEDS > 0
    led_toggle(0);
#endif
    DPRINT("packet transmitted");
    sprintf(lcd_msg, "TX %i", counter);
    lcd_write_string(lcd_msg);

    timer_tick_t delay;
    if(tx_packet_delay_s == 0)
        delay = TIMER_TICKS_PER_SEC / 5;
    else
        delay = TIMER_TICKS_PER_SEC * tx_packet_delay_s;

    timer_post_task(&transmit_packet, delay);
}
コード例 #21
0
int main(void){
	DDRD = 0xFF;
	lcd_4bit_init();
	lcd_write_command(LCDBLINK);
	lcd_write_string("testtext", 8);
	
	lcd_set_cursor(5, 2);
	
	/*
	while (1)
	{
		PORTD ^= (1<<7);	// Toggle PORTD.7
		_delay_ms( 250 );
	}
	*/

	return 1;
}
コード例 #22
0
static void packet_transmitted(hw_radio_packet_t* packet) {
#if HW_NUM_LEDS > 0
    led_toggle(0);
#endif
    DPRINT("packet transmitted");
    sprintf(lcd_msg, "TX %i", counter);
#ifdef PLATFORM_EFM32GG_STK3700
	    lcd_write_string(lcd_msg);
#else
	    lcd_write_line(4, lcd_msg);
#endif

    timer_tick_t delay;
    if(tx_packet_delay_s == 0)
        delay = TIMER_TICKS_PER_SEC / 5;
    else
        delay = TIMER_TICKS_PER_SEC * tx_packet_delay_s;

    //increase_channel();
    timer_post_task(&transmit_packet, delay);
}
コード例 #23
0
//we override __assert_func to flash the leds (so we know something bad has happend)
//and to repeat the error message repeatedly (so we have a chance to attach the device to a serial console before the error message is gone)
void __assert_func( const char *file, int line, const char *func, const char *failedexpr)
{
#if defined FRAMEWORK_DEBUG_ASSERT_REBOOT // make sure this parameter is used also when including assert.h instead of debug.h
        hw_reset();
#endif

	start_atomic();
	led_on(0);
	led_on(1);
#ifdef PLATFORM_USE_USB_CDC
	// Dissable all IRQs except the one for USB
	for(uint32_t j=0;j < EMU_IRQn; j++)
		NVIC_DisableIRQ(j);

	NVIC_EnableIRQ( USB_IRQn );

	end_atomic();
#endif

	lcd_clear();
	lcd_write_string("ERROR");
	lcd_write_number(timer_get_counter_value());

    __asm__("BKPT"); // break into debugger

	while(1)
	{
		printf("assertion \"%s\" failed: file \"%s\", line %d%s%s\n",failedexpr, file, line, func ? ", function: " : "", func ? func : "");

		for(uint32_t j = 0; j < 20; j++)
		{
			//blink at twice the frequency of the _exit call, so we can identify which of the two events has occurred
			for(uint32_t i = 0; i < 0xFFFFF; i++){}
			led_toggle(0);
			led_toggle(1);
		}
	}
	end_atomic();

}
コード例 #24
0
void start()
{
    hw_rx_cfg_t rx_cfg;
    rx_cfg.channel_id.channel_header.ch_coding = PHY_CODING_PN9;
    rx_cfg.channel_id.channel_header.ch_class = current_channel_class;
    rx_cfg.channel_id.channel_header.ch_freq_band = current_channel_band;
    rx_cfg.channel_id.center_freq_index = channel_indexes[current_channel_indexes_index];

#ifdef HAS_LCD
    char string[10] = "";
    char rate;
    char band[3];
    switch(current_channel_class)
    {
        case PHY_CLASS_LO_RATE: rate = 'L'; break;
        case PHY_CLASS_NORMAL_RATE: rate = 'N'; break;
        case PHY_CLASS_HI_RATE: rate = 'H'; break;
    }

    switch(current_channel_band)
    {
        case PHY_BAND_433: strncpy(band, "433", sizeof(band)); break;
        case PHY_BAND_868: strncpy(band, "868", sizeof(band)); break;
        case PHY_BAND_915: strncpy(band, "915", sizeof(band)); break;
    }

    sprintf(string, "%.3s%c-%i", band, rate, rx_cfg.channel_id.center_freq_index),
    lcd_write_string(string);
#endif

    hw_radio_set_rx(&rx_cfg, NULL, &rssi_valid_cb); // we 'misuse' hw_radio_set_rx to configure the channel (using the public API)
    hw_radio_set_idle(); // go straight back to idle

    cc1101_interface_write_single_reg(0x08, 0x22); // PKTCTRL0 random PN9 mode + disable data whitening
    //cc1101_interface_write_single_reg(0x12, 0x30); // MDMCFG2: use OOK modulation to clearly view centre freq on spectrum analyzer, comment for GFSK
    cc1101_interface_write_single_patable(0xc0); // 10dBm TX EIRP
    cc1101_interface_strobe(0x35); // strobe TX
}
コード例 #25
0
void bootstrap()
{
    DPRINT("Device booted at time: %d\n", timer_get_counter_value()); // TODO not printed for some reason, debug later

#ifdef HAS_LCD
    lcd_write_string("cont tx");
#endif

    switch(current_channel_class)
    {
        // TODO only 433 for now
        case PHY_CLASS_NORMAL_RATE:
        	channel_count = NORMAL_RATE_CHANNEL_COUNT;
            realloc(channel_indexes, channel_count);
            for(int i = 0; i < channel_count; i++)
                channel_indexes[i] = i * 8;

            break;
        case PHY_CLASS_LO_RATE:
        	channel_count = LO_RATE_CHANNEL_COUNT;
            realloc(channel_indexes, channel_count);
            for(int i = 0; i < channel_count; i++)
                channel_indexes[i] = i;

            break;
    }

#if NUM_USERBUTTONS > 1
    ubutton_register_callback(0, &userbutton_callback);
    ubutton_register_callback(1, &userbutton_callback);
#endif

    hw_radio_init(NULL, NULL);

    sched_register_task(&start);
    timer_post_task_delay(&start, TIMER_TICKS_PER_SEC * 5);
}
コード例 #26
0
void start()
{
    tx_cfg.channel_id.channel_header.ch_coding = PHY_CODING_PN9;
    tx_cfg.channel_id.channel_header.ch_class = current_channel_class;
    tx_cfg.channel_id.channel_header.ch_freq_band = current_channel_band;
    tx_cfg.channel_id.center_freq_index = channel_indexes[current_channel_indexes_index];
    tx_cfg.eirp = 10;

#ifdef HAS_LCD
    char string[10] = "";
    char rate;
    char band[3];
    switch(current_channel_class)
    {
        case PHY_CLASS_LO_RATE: rate = 'L'; break;
        case PHY_CLASS_NORMAL_RATE: rate = 'N'; break;
        case PHY_CLASS_HI_RATE: rate = 'H'; break;
    }

    switch(current_channel_band)
    {
        case PHY_BAND_433: strncpy(band, "433", sizeof(band)); break;
        case PHY_BAND_868: strncpy(band, "868", sizeof(band)); break;
        case PHY_BAND_915: strncpy(band, "915", sizeof(band)); break;
    }

    sprintf(string, "%.3s%c-%i\n", band, rate, tx_cfg.channel_id.center_freq_index),
    lcd_write_string(string);
#endif

    /* Configure */
    configure_radio(current_modulation);

    /* start the radio */
    start_radio();

}
コード例 #27
0
void bootstrap()
{
    DPRINT("Device booted at time: %d\n", timer_get_counter_value()); // TODO not printed for some reason, debug later

#ifdef HAS_LCD
    lcd_write_string("cont TX \n");
#endif

    switch(current_channel_class)
    {
        case PHY_CLASS_NORMAL_RATE:
          channel_count = NORMAL_RATE_CHANNEL_COUNT;
            realloc(channel_indexes, channel_count);
            for(int i = 0; i < channel_count; i++)
                channel_indexes[i] = i * 8;

            break;
        case PHY_CLASS_LO_RATE:
          channel_count = LO_RATE_CHANNEL_COUNT;
            realloc(channel_indexes, channel_count);
            for(int i = 0; i < channel_count; i++)
                channel_indexes[i] = i;

            break;
    }

#if PLATFORM_NUM_BUTTONS > 1
    ubutton_register_callback(0, &userbutton_callback);
    ubutton_register_callback(1, &userbutton_callback);
#endif

    hw_radio_init(&alloc_packet_callback, &release_packet_callback);

    sched_register_task(&start);
    timer_post_task_delay(&start, 500);
}
コード例 #28
0
ファイル: main.c プロジェクト: TeamBarrel/Gregory
void main(void)
{
	init();
	STOP();

	lcd_set_cursor(0x00);
	lcd_write_string("(-,-) - -- --- -"); //x/y of robot, explore/return, zone of victim/got victim, walls, way went
	lcd_set_cursor(0x40);
	lcd_write_string("- - - (3,1) GREG"); //orientation, cliff detected, v.wall detected, x/y of final destination
	char victimIndicator = 0;
	while(!home)
	{

		if(start.pressed && ready == FALSE)
		{
			findWalls();
			if(leftWall && rightWall && frontWall) 		//if facing east
				turnAround(); 							//turn to face west	
			else if (rightWall && frontWall)			//if facing north
				turnLeft90(); 							//turn to face west
			else if(leftWall && frontWall)				//if facing south
				turnRight90(); 							//turn to face west
			ready = TRUE; 								//commence exploring the map
			lcd_set_cursor(0x06);
			lcd_write_data('E');						//Explore mode
			play_iCreate_song(1);										
		}	
		

		//EEPROM Serial Transfer
		if(eepromSerial.pressed && ready == FALSE)
		{
			eepromSerial.pressed = FALSE;
			lcd_set_cursor(0x00);
			lcd_write_string("EEPROM Serial         ");
			lcd_set_cursor(0x40);
			lcd_write_string("Please Wait...        ");
			writeEEPROMTestData();
			EEPROMToSerial();
			lcd_set_cursor(0x40);
			lcd_write_string("Complete              ");
		}
		
		if(start.pressed)
		{
			ready = TRUE;
			checkForFinalDestination();

			lookForVictim();

			findWalls();
			play_iCreate_song(5);
			if(leftWall)
			{
				rotateIR(24,CCW);
				leftAngleCorrect();
				rotateIR(24,CW);
			}
			play_iCreate_song(5);
			if(frontWall)
				frontWallCorrect();
			play_iCreate_song(5);
			switch(node) // Gives the Create specific movement instructions for certain squares to go shortest path home and collecting the victim
			{
				case 0:
					goToNextCell();
					break;
				case 1:
					if (goingHome)
					{
						if (victimZone == 1)
							goRight();
						else if (getOrientation() == EAST)
							goForward();
						else if (getOrientation() == SOUTH)
							goRight();
						else
							goToNextCell();
					}
					else
						goToNextCell();
					break;
				case 2:
					if (goingHome)
					{
						if (victimZone == 2)
							goForward();
						else if (getOrientation() == SOUTH)
							goRight();
						else if (getOrientation() == NORTH)
							goLeft();
						else
							goToNextCell();
					}
					else
						goToNextCell();
					break;
				case 3:
					if (goingHome)
					{
						if (victimZone == 3)
							goRight();
						else if (getOrientation() == EAST)
							goForward();
						else if (getOrientation() == SOUTH)
							goLeft();
						else
							goToNextCell();
					}
					else
						goToNextCell();
					break;
				case 4:
					if (getOrientation() == EAST)
						goRight(); 
					else
						goToNextCell();
					break;
				case 5:
					if (getOrientation() == NORTH)
						goRight(); 
					else
						goToNextCell();
					break;
				case 6:
					if (getOrientation() == WEST)
					{
						play_iCreate_song(6);
						goForward();
					}
					else
						goToNextCell();
					break;
				default:
					break;
			}
			play_iCreate_song(5);
			if(getSuccessfulDrive())
			{
				//Send EEPROM data for current cell
				if(xVictim == xCoord && yVictim == yCoord)
				{
					victimIndicator = 1;
				}
				/*if(xVirtual == xCoord && yVirtual == yCoord)
				{
					switch(dVirtual)
					{
						case WEST:
						{
							updateMapData(1,0,0,0,victimIndicator,getOrientation());
							break;
						}
						case SOUTH:
						{
							updateMapData(0,1,0,0,victimIndicator,getOrientation());
							break;
						}
						case EAST:
						{
							updateMapData(0,0,1,0,victimIndicator,getOrientation());
							break;
						}
						case NORTH:
						{
							updateMapData(0,0,0,1,victimIndicator,getOrientation());
							break;
						}
						default:
							updateMapData(0,0,0,0,victimIndicator,getOrientation());
					}
				}*/
				
				updateMapData(0,0,0,0,victimIndicator,getOrientation());
				
				victimIndicator = 0;
				
				updateLocation();
				updateNode();		
				if(goingHome)
					checkIfHome();
			}
		}
	}
}
コード例 #29
0
ファイル: ui.c プロジェクト: equinoxorg/standalone_v2
/**
  * @brief  Task which handles all UI including keypad, LCD and all user power outputs.
	* 				Responds to events caused by other tasks and ISRs
  * @param  None
  * @retval Should never exit
  */
__task void ui (void)
{
	uint16_t event_flag = 0;
	uint8_t key;
	int i;
	uint64_t entry_code = 0;
	
	lcd_init();
	keypad_init();
	
	lcd_backlight(1);
	
	buzzer_init();
	
	pwr_sw_init();
	
	usb_outputs_init();
	dc_outputs_init();

	
	lcd_clear();
	lcd_write_string("    e.quinox    ");
	lcd_goto_XY(0,1);
	lcd_write_string("    izuba.box   ");
	

	//2 second timeout
	os_dly_wait(200);
	
	if ( get_unlock_days () >= 0 )
	{
		ui_state = STATE_NORM;
	}
	
	if( local_ee_data.lvdc_flag == 1 )
	{
		ui_state = STATE_LVDC;
	}
	
	reset_display();
	reset_outputs();
	
	while(1)
	{
		//Wait for any task event or timeout after 1 second
		if ( os_evt_wait_or(0xFFFF, 100) == OS_R_EVT )
		{
			//Find which event 
			event_flag = os_evt_get();
			
			if ( event_flag & UI_BOX_SETUP )
			{
				ui_state = STATE_SETUP;
				lcd_clear();
				reset_display();
				reset_outputs();
			}
			
			if ( (event_flag & UI_LVDC) )
			{
				if ( (ui_state != STATE_LVDC) && (ui_state != STATE_OFF) )
				{
					ui_state = STATE_LVDC;
					local_ee_data.lvdc_flag = 1;
					update_lvdc(1);
					//Turn off outputs
					reset_outputs();
					lcd_power(1);
					lcd_clear();
					lcd_write_string_XY(0, 0, "  Battery Empty ");
					lcd_write_string_XY(0, 1, "  Turning Off   ");

					//Delay and Buzz
					//20 Seconds
					for ( i = 0; i < 5; i++)
					{
						buzz(1);
						//4 second wait
						os_dly_wait(400);
					}
					
					//Turn off Screen
					lcd_power(0);
					
				}
				
			}
			
			if ( event_flag & UI_PWR_SW )
			{
				if ( ui_state != STATE_OFF)
				{
					//Turn off all outputs and UI devices
					//Wait only for UI_PWR_SW tasks
					lcd_power(0);
								
					ui_state = STATE_OFF;
					reset_outputs();
				}
				else
				{
					//Re-init LCD
					lcd_clear();
					lcd_power(1);
					
					check_display_debug();
					
					lcd_splash_screen(2);
					
					if(get_soc() >= CHARGED)
					{
						local_ee_data.lvdc_flag = 0;
						update_lvdc(0);
					}

					if(local_ee_data.lvdc_flag == 1)
					{
						ui_state = STATE_LVDC;
					}
					
					if(ui_state != STATE_LVDC)
					{
						if (get_unlock_days () >= 0 )
							ui_state = STATE_NORM;
						else
							ui_state = STATE_AWAIT_PAYMENT;
					}
					
					reset_outputs();
					reset_display();
				}
				
				//1 second delay
				os_dly_wait(100);
				EXTI_ClearITPendingBit(EXTI_Line0);
			}
			
			if ( event_flag & UI_EVT_USB_OC )
			{
				os_dly_wait(100);
                           
				if(EXTI_GetITStatus(EXTI_Line5) != RESET || EXTI_GetITStatus(EXTI_Line6) != RESET)
				{

					if(EXTI_GetITStatus(EXTI_Line5) != RESET)
						USB1_DISABLE();

					if(EXTI_GetITStatus(EXTI_Line6) != RESET)
						USB2_DISABLE();

					lcd_clear();
					lcd_write_string_XY(0, 0, "       USB      ");
					lcd_write_string_XY(0, 1, "      error!    ");
					//2s wait
					os_dly_wait(200);
					reset_display();
				}
			}

		
			if ( event_flag & (UI_EVT_KEYPAD_1 | UI_EVT_KEYPAD_2 | UI_EVT_KEYPAD_3) )
			{
				if ( (ui_state == STATE_AWAIT_PAYMENT) || (ui_state == STATE_NORM) || (ui_state == STATE_SETUP) )
				{
					//Read which key is pressed
					i = 0;
					do
					{
						key = keypad_get_key();		
						i++;
						os_dly_wait(1);
						if ( i > 20)
							break;
					} while (key == KEY_NONE);
					
					if (key != KEY_NONE)
					{					
						lcd_backlight(1);
						buzz(1);
					}
					
					if (ui_state == STATE_SETUP)
					{
						//If 5 digits and tick then set box_id
						if (key == KEY_CROSS) {
							//'X' Pressed
							//LCDWriteString("x");
							display_str[0] = '\0';
							digit_count = 0;
							local_ee_data.box_id = 0;
							reset_display();
						} else if (key == KEY_NONE) {
							//Do nothing
						} else if ( key == KEY_TICK ) {
							if(digit_count == 5){
								os_dly_wait(50);
								
								//Send message to payment control task
								os_evt_set(PC_SET_BOX_ID, payment_control_t);
								
								ui_state = STATE_AWAIT_PAYMENT;
								display_str[0] = '\0';
								digit_count = 0;
								reset_display();
								reset_outputs();
							}
							}else{
								if(digit_count <5){
									//Add the keypad value to the box id
									display_str[0] = '\0';
									local_ee_data.box_id = (local_ee_data.box_id * 10) + key;
									utoa_b(display_str, local_ee_data.box_id, 10, digit_count);
									lcd_write_string_XY(7, 0, display_str);
									lcd_goto_XY((8 + digit_count), 0);
									reset_display();
								}
								else { // do nothing
								}
								digit_count++;
						}
					}
					else if (ui_state == STATE_AWAIT_PAYMENT)
					{
						if (key == KEY_CROSS) {
							//'X' Pressed
							//LCDWriteString("x");
							display_str[0] = '\0';
							digit_count = 0;
							entry_code = 0;
							lcd_write_string_XY(6, 0, "__________");
							lcd_goto_XY(6, 0);
							//key = KEY_NONE;
							
						} else if (key == KEY_TICK) {
							//Tick Pressed
							//LCDWriteString("./");
						} else if (key == KEY_NONE) {
							//Tick Pressed
							//LCDWriteString("./");
						} else {
							//Add the keypad to the entry code
							entry_code = (entry_code * 10) + key;
							
							//Make the 
							display_str[0] = '\0';
							utoa_b(display_str, entry_code, 10, digit_count);
							lcd_write_string_XY(6, 0, display_str);
							lcd_goto_XY((7 + digit_count), 0);

							if (digit_count++ == 9) {
								os_dly_wait(50);
								
								//Send code to payment control task
								// but send (uint32_t)entry_code							
								if ( check_unlock_code((uint32_t)entry_code))
								{
									TRACE_INFO("2,1,%s\n", display_str);
									ui_state = STATE_NORM;
									// Edited Code
									lcd_clear();
									lcd_write_string_XY(0, 0, "      Valid      ");
									lcd_write_string_XY(0, 1, "      code!    ");
									entry_code = 0;
									digit_count = 0;
									display_str[0] = '\0';
									//2s wait
									os_dly_wait(200);
									// End of Edit
									reset_display();
									reset_outputs();
								}
								else
								{							
									TRACE_INFO("2,0,%s\n", display_str);
									// Edited Code
									lcd_clear();
									lcd_write_string_XY(0, 0, "      Wrong      ");
									lcd_write_string_XY(0, 1, "      code!    ");
									//2s wait
									os_dly_wait(200);
									// End of Edit
									
									entry_code = 0;
									digit_count = 0;
									display_str[0] = '\0';
									reset_display();
									reset_outputs();
								}
							}
						}
					}
					else
					{											
						switch (key)
						{
							case KEY_NONE:
								//No Action
								break;
							//Special Key Cases
							case KEY_TICK:
								TRACE_DEBUG("Key: ./ \n");
								break;
							case KEY_CROSS:
								TRACE_DEBUG("Key: X \n");
								break;
							default:
								//Print the key number
								TRACE_DEBUG("Key: %i \n", key);			
						}
					}
					
					//Wait for release of key (with time-out)
					i = 0;
					while( keypad_get_key() != KEY_NONE )
					{
						i++;
						os_dly_wait(1);
						if ( i > 20)
							break;
					}			
				}					
			}
			
			if(local_ee_data.lvdc_flag == 0)
			{
				if ( event_flag & UI_PAYMENT_INVALID )
				{
					ui_state = STATE_AWAIT_PAYMENT;
					lcd_clear();
					reset_display();
					reset_outputs();
				}
			}
			
			if(local_ee_data.lvdc_flag == 1)
			{
				lcd_clear();
				lcd_write_string_XY(0, 0, "  Battery Low   ");
				lcd_batt_level( get_soc(), get_charging_rate() );
				
				if(get_soc() >= CHARGED)
				{
					local_ee_data.lvdc_flag = 0;
					update_lvdc(0);
				}
			}
			//clear event flags
			os_evt_clr(event_flag, ui_t);
			
		}
		
		/* Debugging Info on LCD
	  sprintf(str, "P=%.2f", get_adc_voltage(ADC_SOL_V)*get_adc_voltage(ADC_SOL_I));
 		lcd_goto_XY(0,0);
 		lcd_write_string(str);
 		
 		str[0] = NULL;
 		
 		sprintf(str, "T=%.2f", get_adc_voltage(ADC_TEMP));
 		lcd_goto_XY(8,0);
 		lcd_write_string(str);
 		
 		str[0] = NULL;
 		
 		sprintf(str, "V=%.2f", get_adc_voltage(ADC_BATT_V));
 		lcd_goto_XY(0,1);
 		lcd_write_string(str);
		
 		str[0] = NULL;
 		
 		sprintf(str, "I=%.2f", get_adc_voltage(ADC_BATT_I));
 		lcd_goto_XY(8,1);
 		lcd_write_string(str);
 		
 		str[0] = NULL;
*/
		//Update battery levels, days remaining and if normal state then time/date
		
		if(local_ee_data.lvdc_flag == 1)
		{
			lcd_write_string_XY(0, 0, "  Battery Low   ");
			lcd_batt_level( get_soc(), get_charging_rate() );
				
			if(get_soc() >= CHARGED)
			{
				local_ee_data.lvdc_flag = 0;
				update_lvdc(0);
				
				if(get_unlock_days () >= 0 )
				{
					ui_state = STATE_NORM;
				}
				else
				{
					ui_state = STATE_AWAIT_PAYMENT;
				}
				
				reset_display();
				reset_outputs();
				
			}
		}
		
		if ( (ui_state == STATE_NORM) || (ui_state == STATE_AWAIT_PAYMENT) )
		{
			lcd_batt_level( get_soc(), get_charging_rate() );
		}
		
		if (ui_state == STATE_NORM)
		{
			//Update remaining days
			if(local_ee_data.full_unlock == EE_FULL_UNLOCK_CODE){
				lcd_write_string_XY(0, 1, "        Unlocked");
				lcd_batt_level( get_soc(), get_charging_rate() );
			}
			else{
				lcd_write_string_XY(0, 1, "            days");
				lcd_write_int_XY(10, 1, get_unlock_days() );
				lcd_batt_level( get_soc(), get_charging_rate() );
			}			
		}

	}
}
コード例 #30
0
ファイル: gynmech.c プロジェクト: dsblue/GynMech
void poll(){
  // Main polling loop
  
  // Check for a character from the USART
  // See if there is a command comming in
  if (uart_char_is_waiting()) {
    char c = uart_read();
    
    // Update the command state-machine
    if (c == '\n' || c == '\r' ) {
      // End of a command, process it and reset the command string
      if (current_command == COMMAND_NONE) {
      } else if (current_command == COMMAND_INFLATE) {
	syringe_inflate();
	current_state = STATE_INFLATE;
      } else if (current_command == COMMAND_DEFLATE) {
	syringe_deflate();
	current_state = STATE_DEFLATE;
      } else if (current_command == COMMAND_SET_PRESSURE) {
	int ret = sscanf_P(value_str, PSTR("%d"), &target_pressure);
	//	printf_P(PSTR("1 = %d\r\n"), ret );  
	//	printf_P(PSTR("2 = %d\r\n"), target_pressure );
      }
      value_str_i = 0;
      current_command = COMMAND_NONE;
      current_command_state = CMD_STATE_COMMAND;
    } else {
      // In a command string
      if (current_command_state == CMD_STATE_COMMAND) {
	// Command character
	if (c == 'i') {
	  // Inflate
	  current_command = COMMAND_INFLATE;
	} else if (c == 'd') {
	  // Deflate
	  current_command = COMMAND_DEFLATE;
	} else if (c == 'p') {
	  // Set pressure point
	  current_command = COMMAND_SET_PRESSURE;
	} else {
	  current_command = COMMAND_NONE;
	}
	current_command_state = CMD_STATE_EQUAL;
      } else if (current_command_state == CMD_STATE_EQUAL) {
	// Assume the second char is always '='
	current_command_state = CMD_STATE_VALUE;
      } else if (current_command_state == CMD_STATE_VALUE) {
	// In value part of command
	value_str[value_str_i++] = c;
	if (value_str_i >= MAX_VALUE_LENGTH) {
	  value_str_i = MAX_VALUE_LENGTH-1;
	}
	value_str[value_str_i] = 0; // Write NULL terminator
      }
    }
  }
  
  // Check the current pressure
  // take 100 samples and average them!
  // holder variables for temperature data
  uint16_t last_sample = 0;
  double this_temp;
  double pres_avg = 0.0;
  uint8_t i;
  
  for(i=0; i<100; i++) {
    last_sample = adc_read();
    //this_temp = sampleTokPi(last_sample);
    this_temp = last_sample;
    
    // add this contribution to the average
    pres_avg = pres_avg + this_temp/100.0;
  }

  // Check to see if we hit the target presure
  if ( current_state == STATE_INFLATE ) {
    if ( pres_avg >= target_pressure ) {
      // Stop Inflating
      syringe_off();
      current_state = STATE_IDLE;
    }
  } else if ( current_state == STATE_DEFLATE ) {
    if ( pres_avg <= target_pressure ) {
      // Stop Deflating
      syringe_off();
      current_state = STATE_IDLE;      
    }
  }   

  // write message to LCD
  lcd_home();
  lcd_write_string(PSTR("ADC: "));
  lcd_write_int16(last_sample);
  lcd_write_string(PSTR(" of 1024   "));
  lcd_line_two();
  if ( current_state == STATE_IDLE ) {
    fprintf_P(&lcd_stream, PSTR("State: Idle      "));
  } else if ( current_state == STATE_RECV ) {
    fprintf_P(&lcd_stream, PSTR("State: Recv      "));
  } else if ( current_state == STATE_INFLATE ) {
    fprintf_P(&lcd_stream, PSTR("State: Inflate   "));
  } else if ( current_state == STATE_DEFLATE ) {
    fprintf_P(&lcd_stream, PSTR("State: Deflate   "));
  }
  lcd_line_three();
  fprintf_P(&lcd_stream, PSTR("Target Pres: %d"), target_pressure );
  // write message to serial port
  //printf_P(PSTR("%.2f degrees F\r\n"), temp_avg);
  //printf_P(PSTR("Pres = %d\r\n"), target_pressure );
  //printf_P(PSTR("Value = %s\r\n"), value_str );

}