示例#1
0
int main(void) {
  setup();
  all_off();
  onboardled(ON);
  around_the_world();

  // blink
  while (1) {
    if(PIND & (1<<5)) {
      onboardled(ON);
      ultraviolet(ON);
      headlamp(ON);

      handlebars(ON);
      forks(ON);
      backleft(ON);
      backright(ON);
      rack(OFF);
      _delay_ms(250);

      forks(OFF);
      rack(ON);
      _delay_ms(150);

      forks(ON);
      handlebars(OFF);
      backleft(ON);
      backright(OFF);
      rack(OFF);
      _delay_ms(250);

      handlebars(ON);
      backleft(OFF);
      backright(ON);
      _delay_ms(250);
    } else  {
      all_off();
      onboardled(ON);
      _delay_ms(350);
      onboardled(OFF);
      _delay_ms(350);
    }
  }
}
示例#2
0
void read_button(void){
	_delay_ms(200);
	uint32_t lock_timer=0;
	start_timer();
	if(LEFT_PRESSED){
		old_led_selected = led_selected;
		led_selected = 0;
		RED_OFF;GREEN_OFF;BLUE_ON;
		if(power_mode==MODE_OFF){
			if(unlock_stage==0 || unlock_stage==2){
				unlock_stage+=1;
				old_led_selected = 1;
			}
		}else{
			if(power_mode>MODE_LOW){
				power_mode-=1;
			}else{
				power_mode=1;
			}
		}
		apply_power();
		while(LEFT_PRESSED){lock_timer+=1;if(lock_timer==100000){all_off();}};
		apply_led(old_led_selected);
		_delay_ms(200);
		return;
	}
	if(RIGHT_PRESSED){
		old_led_selected = led_selected;
		led_selected = 0;
		RED_OFF;GREEN_OFF;BLUE_ON;
		if(power_mode==MODE_OFF){
			if(unlock_stage==1){
				unlock_stage+=1;
				old_led_selected = 1;
			}
		}else{
			if(power_mode>=MODE_LOW){ // проскакиваем аварийные режимы
				power_mode+=1;
			}else{
				power_mode=MODE_LOW;
			}
		}
		apply_power();
		while(RIGHT_PRESSED){};
		apply_led(old_led_selected);
		_delay_ms(200);
	}

}
示例#3
0
void launch_fast_stagger (void)
{
	port_zero_on();
	delay_ms(1000);
	port_zero_off();

	port_one_on();
	delay_ms(1000);
	port_one_off();
	
	port_two_on();
	delay_ms(1000);
	port_two_off();
	
	port_three_on();
	delay_ms(1000);
	port_three_off();
	
	all_off();	
}
示例#4
0
文件: main_matlab.c 项目: dfmuir/LED3
int main (void) {
 
 
 
 
    init_ports();
    init_spi();
 
    
    
    
    memcpy(buffer[7],america7,24);
    memcpy(buffer[6],america6,24);
    memcpy(buffer[5],america5,24);
    memcpy(buffer[4],america4,24);
    memcpy(buffer[3],america3,24);
    memcpy(buffer[2],america2,24);
    memcpy(buffer[1],america1,24);
    memcpy(buffer[0],america0,24);
    
    update();
    
    /*
    memcpy(current_cube[0],green,24);
    memcpy(current_cube[1],cyan,24);
    memcpy(current_cube[2],red,24);
    memcpy(current_cube[3],green,24);
    memcpy(current_cube[4],blue,24);
    memcpy(current_cube[5],yellow,24);
    memcpy(current_cube[6],pink,24);
    memcpy(current_cube[7],off,24);*/

    int i = 0;
    all_off();

    while(1) {

        write(current_cube[i], 24, i);
        i = (i + 1) % 8;
    }
}
示例#5
0
/*
 * This just sucked beyond words.  I was always planning on rewriting this,
 * but the crecendo of complaints with regards to this just got to be too 
 * irritating, so i fixed it early.
 */
int	make_status (Window *window, int must_redraw)
{
	int	status_line;
	u_char	buffer	    [BIG_BUFFER_SIZE + 1];
	u_char	lhs_buffer  [BIG_BUFFER_SIZE + 1];
	u_char	rhs_buffer  [BIG_BUFFER_SIZE + 1];
	Char	*func_value [MAX_FUNCTIONS];
	u_char	*ptr;
	size_t	save_size;

	/* We do NOT redraw status bars for hidden windows */
	if (!window->screen || !status_updates_permitted)
		return -1;

	for (status_line = 0; status_line < window->status.double_status + 1; status_line++)
	{
		u_char	lhs_fillchar[6],
			rhs_fillchar[6],
			*fillchar = lhs_fillchar,
			*lhp = lhs_buffer,
			*rhp = rhs_buffer,
			*cp,
			*start_rhs = 0,
			*str;
		int	in_rhs = 0,
			pr_lhs = 0,
			pr_rhs = 0,
			line,
			*prc = &pr_lhs, 
			i;

		fillchar[0] = fillchar[1] = 0;

		/*
		 * If status line gets to one, then that means that
		 * window->double_status is not zero.  That means that
		 * the status line we're working on is STATUS2.
		 */
		if (status_line)
			line = 2;

		/*
		 * If status_line is zero, and window->double_status is
		 * not zero (double status line is on) then we're working
		 * on STATUS1.
		 */
		else if (window->status.double_status)
			line = 1;

		/*
		 * So status_line is zero and window->double_status is zero.
		 * So we're working on STATUS (0).
		 */
		else
			line = 0;


		/*
		 * Sanity check:  If the status format doesnt exist, dont do
		 * anything for it.
		 */
		if (!window->status.line[line].format)
			continue;

		/*
		 * Run each of the status-generating functions from the the
		 * status list.  Note that the retval of the functions is no
		 * longer malloc()ed.  This saves 40-some odd malloc/free sets
		 * each time the status bar is updated, which is non-trivial.
		 */
		for (i = 0; i < MAX_FUNCTIONS; i++)
		{
			if (window->screen == NULL)
				return -1;

			if (window->status.line[line].func[i] == NULL)
				panic("status callback null.  Window [%d], line [%d], function [%d]", window->refnum, line, i);
			func_value[i] = window->status.line[line].func[i]
				(window, window->status.line[line].map[i],
				 window->status.line[line].key[i]);
		}

		/*
		 * If the REVERSE_STATUS_LINE var is on, then put a reverse
		 * character in the first position (itll get translated to
		 * the tcap code in the output code.
		 */
		if (get_int_var(REVERSE_STATUS_LINE_VAR))
			*buffer = REV_TOG , str = buffer + 1;
		else
			str = buffer;

		/*
		 * Now press the status line into "buffer".  The magic about
		 * setting status_format is handled elsewhere.
		 */
		snprintf(str, BIG_BUFFER_SIZE - 1, window->status.line[line].format,
		    func_value[0], func_value[1], func_value[2], 
		    func_value[3], func_value[4], func_value[5],
		    func_value[6], func_value[7], func_value[8], func_value[9],
		    func_value[10], func_value[11], func_value[12],
		    func_value[13], func_value[14], func_value[15],
		    func_value[16], func_value[17], func_value[18],
		    func_value[19], func_value[20], func_value[21],
		    func_value[22], func_value[23], func_value[24],
		    func_value[25], func_value[26], func_value[27],
		    func_value[28], func_value[29], func_value[30],
		    func_value[31], func_value[32], func_value[33],
		    func_value[34], func_value[35], func_value[36], 
		    func_value[37], func_value[38], func_value[39]); 

		/*
		 * If the user wants us to, pass the status bar through the
		 * expander to pick any variables/function calls.
		 * This is horribly expensive, but what do i care if you
		 * want to waste cpu cycles? ;-)
		 */
		if (get_int_var(STATUS_DOES_EXPANDOS_VAR))
		{
			int  af = 0;
			int  old_fs = from_server;
			Window *old = current_window;
			int	owd = window_display;

			current_window = window;
			from_server = current_window->server;
			window_display = 0;
			str = expand_alias(buffer, empty_string, &af, NULL);
			window_display = owd;
			from_server = old_fs;
			current_window = old;
			strlcpy(buffer, str, sizeof buffer);
			new_free(&str);
		}


		/*
		 * This converts away any ansi codes in the status line
		 * in accordance with the currenet settings.  This leaves us
		 * with nothing but logical characters, which are then easy
		 * to count. :-)
		 */
		str = normalize_string(buffer, 3);

		/*
		 * Count out the characters.
		 * Walk the entire string, looking for nonprintable
		 * characters.  We count all the printable characters
		 * on both sides of the %> tag.
		 */
		ptr = str;
		cp = lhp;
		lhs_buffer[0] = rhs_buffer[0] = 0;

		while (*ptr)
		{
			/*
			 * The FIRST such %> tag is used.
			 * Using multiple %>s is bogus.
			 */
			if (*ptr == '\f' && start_rhs == NULL)
			{
				ptr++;
				start_rhs = ptr;
				fillchar = rhs_fillchar;
				in_rhs = 1;
				*cp = 0;
				cp = rhp;
				prc = &pr_rhs;
			}

                        /*
                         * Skip over attribute changes, not useful.
                         */
                        else if (*ptr == '\006')
                        {
                                /* Copy the next 5 values */
                                *cp++ = *ptr++;
                                *cp++ = *ptr++;
                                *cp++ = *ptr++;
                                *cp++ = *ptr++;
                                *cp++ = *ptr++;
                        }

			/*
			 * XXXXX This is a bletcherous hack.
			 * If i knew what was good for me id not do this.
			 */
			else if (*ptr == 9)	/* TAB */
			{
				fillchar[0] = ' ';
				fillchar[1] = 0;
				do
					*cp++ = ' ';
				while (++(*prc) % 8);
				ptr++;
			}

			/*
			 * So it is a printable character.
			 */
			else
			{
				*prc += 1;
				fillchar[0] = *cp++ = *ptr++;
				fillchar[1] = 0;
			}

			/*
			 * Dont allow more than CO printable characters
			 */
			if (pr_lhs + pr_rhs >= window->screen->co)
			{
				*cp = 0;
				break;
			}
		}
		*cp = 0;

		/* What will we be filling with? */
		if (get_int_var(STATUS_NO_REPEAT_VAR))
		{
			lhs_fillchar[0] = ' ';
			lhs_fillchar[1] = 0;
			rhs_fillchar[0] = ' ';
			rhs_fillchar[1] = 0;
		}

		/*
		 * Now if we have a rhs, then we have to adjust it.
		 */
		if (start_rhs)
		{
			int numf = 0;

			numf = window->screen->co - pr_lhs - pr_rhs -1;
			while (numf-- >= 0)
				strlcat(lhs_buffer, lhs_fillchar, 
						sizeof lhs_buffer);
		}

		/*
		 * No rhs?  If the user wants us to pad it out, do so.
		 */
		else if (get_int_var(FULL_STATUS_LINE_VAR))
		{
			int chars = window->screen->co - pr_lhs - 1;

			while (chars-- >= 0)
				strlcat(lhs_buffer, lhs_fillchar, 
						sizeof lhs_buffer);
		}

		save_size = strlen(all_off());
		strlcpy(buffer, lhs_buffer, sizeof buffer - save_size);
		strlcat(buffer, rhs_buffer, sizeof buffer - save_size);
		strlcat(buffer, all_off(), sizeof buffer);
		new_free(&str);

		/*
		 * Ends up that BitchX always throws this hook and
		 * people seem to like having this thrown in standard
		 * mode, so i'll go along with that.
		 */
		do_hook(STATUS_UPDATE_LIST, "%d %d %s", 
			window->refnum, 
			status_line, 
			buffer);

		if (dumb_mode || !foreground)
			continue;

		/*
		 * Update the status line on the screen.
		 * First check to see if it has changed
		 * Remember this is only done in full screen mode.
		 */
		if (must_redraw || !window->status.line[status_line].result ||
			strcmp(buffer, window->status.line[status_line].result))
		{
			/*
			 * Roll the new back onto the old
			 */
			malloc_strcpy(&window->status.line[status_line].result,
					buffer);

			/*
			 * Output the status line to the screen
			 */
			output_screen = window->screen;
			term_move_cursor(0, window->bottom + status_line);
			output_with_count(buffer, 1, 1);
			cursor_in_display(window);
		}
	}

	cursor_to_input();
	return 0;
}
示例#6
0
int main(void){
	// PA0 - ADC IN
	// PA2 - RED
	// PA3 - GREEN
	// PA4 - BLUE
	// PA7(OC0B) - PWM output.
	// PB0 - out (EN)
	// PB1 - hall1, PB2 - hall2

	DDRA   = 0b11111110;
	PORTA  = 0b00000000;

	DDRB   = 0b0001;
	PORTB  = 0b0110;

	TCCR0A = (1 << COM0B1) | (1 << WGM00);// | (1 << WGM01);  		// PWM mode
	TCCR0B = (1 << CS01);							// clock source = CLK/8, start PWM

	PCMSK1 = (1<<PCINT9) | (1<<PCINT10);
	GIMSK = (1<<PCIE1);//interrupt on pin change0

	ADMUX = 0b10000000; // ADC0 - int

	apply_led(1);
	DRIVER_ON;
	OCR0B = 8;
	_delay_ms(500);
	all_off();

	eeprom_read_block(&seconds_on, &nv_seconds_on, sizeof(seconds_on));
	eeprom_read_block(&times_on,   &nv_times_on,   sizeof(times_on)  );
	eeprom_read_block(&max_on,     &nv_max_on,     sizeof(max_on)    );
	prev_power_mode = MODE_OFF;
	sei();

	while(1){
		// ADC8 = 330 - ~70 degrees Celcium
		// 9V =  714
		// 10V = 793
		// 11V = 872
		// 12V = 951
		// 12.6V = 999
		if(power_mode==MODE_OFF && unlock_stage==0){
			seconds = 0;
			d_seconds = 0;
			stop_timer();
			disable_adc();
			set_sleep_mode(SLEEP_MODE_PWR_DOWN);
			sleep_enable();
			sleep_bod_disable();
			sleep_cpu();
			sleep_disable();
		}
		if(seconds>1 && power_mode==MODE_OFF){
			all_off();
		}
		if(unlock_stage==0 && power_mode!=MODE_OFF){
			if(d_seconds==0){
				adc_channel = 0;
				ADMUX = 0b10000000; // ADC0 - int
			}
			if(d_seconds==5){
				adc_channel = 1;
				ADMUX = 0b10100010; // int reference and temp sensor
			}

			if(seconds%2==0){
				if(power_mode==MODE_LOW_VOLTAGE){
					RED_ON;GREEN_OFF;BLUE_OFF;
				}
				if(power_mode==MODE_OVERTEMP){
					RED_ON;GREEN_ON;BLUE_OFF;
				}
			}else{
				if(power_mode==MODE_OVERTEMP||power_mode==MODE_LOW_VOLTAGE){
					apply_led(0);
				}
			}

			// if((seconds%5==0) && ADMUX == 0b10000000){ //measure voltage in active mode
			if(adc_channel ==0 && d_seconds == 4){ //measure voltage in active mode
				if(val<LIMIT_9V){
					if(check_and_set_times(0)){
					  all_off();//completely discharged. turning off
					}
				}
				else if(power_mode!=MODE_OVERTEMP && power_mode!=MODE_LOW_VOLTAGE && power_mode>=MODE_IDLE){ //show voltage always, except overtemp
					if(val<((LIMIT_9V+LIMIT_10V)/2)){
						if(power_mode>=MODE_LOW && check_and_set_times(1)){ // усвловие нужно, чтобы не задалбывать функцию - в ней будут логи
							apply_led(0);
							power_mode = MODE_LOW_VOLTAGE;//low voltage
							apply_power();
						}
					}else if(val<LIMIT_10V){
						if(led_selected==0 || check_and_set_times(2) ){
							apply_led(1);
						}
						led_selected = 1;
					}else if(val<LIMIT_11V){
						if(led_selected==0 || check_and_set_times(3)){
							apply_led(2);
						}
						led_selected = 2;
					}else{
						if(led_selected==0 || check_and_set_times(4)){
							apply_led(3);
						}
						led_selected = 3;
					}
				}
			}
			while(d_seconds==4){}

			if(adc_channel ==1 && d_seconds == 8){ //measure temp in active mode
				if(val>330 && power_mode>=MODE_LOW && check_and_set_times(5)){// усвловие нужно, чтобы не задалбывать функцию - в ней будут логи
					power_mode = MODE_OVERTEMP;
					apply_power(); //overtemp. reduce current cunsumption
				}
			}
			while(d_seconds==8){}

			if(power_mode==MODE_IDLE && seconds>=7200){ //выключение через два часа из режима простоя
				all_off();
			}


			// if(seconds==0 && d_seconds<5 && power_mode>=MODE_LOW){
			// 	GIMSK = 0;//вырубим прерывания на первые 500мс, чтобы не кнопать кнопкой сильно часто
			// }else{
			// 	GIMSK = (1<<PCIE1);//interrupt on pin change0
			// }
		}
	}
}
示例#7
0
int poll_udp()
{
        int port_l,value,rtn,bytes;
        int addr_len,i;
	int ntmp,man,exp,sign;
	float fvalue,fman;
	char sfloat[5];
	short s;
	char button[20],comment[5];
	float pvalue;
	time_t tt,tloc;
	char buf[40],tmp[20];
	for (i=0;i<100;i++) Buffer[i] = '\0';
        //Buffer[0]='\0';
        addr_len = sizeof(addr);
        //format of input is * Port A/B/C and value
        bytes = recvfrom(sd, Buffer,100 , 0, (struct sockaddr*)&addr, &addr_len);
        //strcpy(rcvfrom,(char *) inet_ntoa(addr.sin_addr));
        //if (!Daemon) printf("main:listen_io24 Data:%d bytes\tfrom %s\t port %c\tdata 0x%X\t buffer[0]=%d or %c\n",bytes,inet_ntoa(addr.sin_addr),buffer[1],value,buffer[0],buffer[0]);
	if (!Daemon) printf("bytes=%d\t  %s\t%d\n",bytes,Buffer,Buffer[bytes-1]);
	for(i=0;i<bytes;i++)
	{
		printf ("%d\t0x%x\t%d\t%c\n",i,Buffer[i],Buffer[i],Buffer[i]);
	}
	sscanf(Buffer,"%s %s %f",button,comment,&fvalue);
	//sscanf(Buffer,"%s%d%s%d%d%f",button,comment,&i,&i,&fvalue);
	//printf("Button= %s\tComment=%s\tFloat is %f\n",button,comment,fvalue);
/*
	sfloat[0] = Buffer[bytes-4];
	sfloat[1] = Buffer[bytes-3];
	sfloat[2] = Buffer[bytes-2];
	sfloat[3] = Buffer[bytes-1];
	sfloat[4] = '\0';
	sscanf(sfloat,"%f",&fvalue);
	sign = sfloat[0] & 0x080;
	if (sign)
	{
		sign = -1;
	} else {
		sign = 1;
	}
	
	exp = sfloat[0] & 0x7F;
	exp = exp << 1;
	ntmp = sfloat[1] & 0x080;
	ntmp = ntmp >> 7;
	exp = exp + ntmp;
	exp = exp - 127;	//127 is the mid point 

	man = sfloat[4] & 0xFF;	
	ntmp = sfloat[3] & 0xFF;
	man = (man << 8) + ntmp;
	ntmp = sfloat[2] & 0x8F;
	ntmp = ntmp << 16;
	man = man + ntmp;
	fman = (float)man;
	fman = 1 + (fman / 10000000);

	fvalue = sign * (2 ^ exp) * fman;
	printf("sign = %d\texp = %d\tfman = %f\tfvalue = %f\n",sign,exp,fman,fvalue);
	//printf("Fvalue = %f\n",fvalue);
*/


	printf ("size of char = %ld\n",sizeof(char));
	pvalue = (float)Buffer[bytes-4];	//pppppp
	printf("pvalue = %f\n",pvalue);

/*

IEEE floating point 32 standard is:

1 bit for sign
8 bits for exponent, not 7
23 bits for mantissa, not 24

0/1000010 0/1010101 01100110 00101010

Sign Bit
Exponent Bits
Mantissa Bits
*/
	//printf("Button= %s\tFloat = %f\n",button,fvalue);
	//Rate = 8;
	tt = time(&tloc);
	if (Buffer[5] == 'b')	//button
	{
		if (Buffer[11] == '1')	//button 1
		{
			if (Buffer[bytes-1] == 1)
			{
				Button[0] = 1;
				if (tt - Last_read[0] < 2)
				{
					if (!Daemon) printf("Double click button 1\n");
					find_insteon_data(0,1);
				} else {
					find_insteon_data(0,0);
				}
				Last_read[0] = tt;
			} else {
				Button[0] = 0;
			}

		}
		if (Buffer[11] == '2')	//button 1
		{
			if (Buffer[bytes-1] == 1)
			{
				Button[1] = 1;
				if (tt - Last_read[1] < 2)
				{
					if (!Daemon) printf("Double click button 2\n");
				}
				Last_read[1] = tt;
				find_insteon_data(1,0);
				if ((Button[0] == 1) && (Button[1] == 1))
				{
					all_on();
				}
			} else {
				Button[1] = 0;
			}
		}
		if (Buffer[11] == '3')	//button 1
		{
			if (Buffer[bytes-1] == 1)
			{
				Button[2] = 1;
				if (tt - Last_read[2] < 2)
				{
					if (!Daemon) printf("Double click button 3\n");
				}
				Last_read[2] = tt;
				find_insteon_data(2,0);
				if ((Button[0] == 1) && (Button[2] == 1))
				{
					all_off();
				}
			} else {
				Button[2] = 0;
			}
		}
		if (Buffer[11] == '4')	//button 1
		{
			if (Buffer[bytes-1] == 1)
			{
				Button[3] = 1;
				Last_read[3] = tt;
			} else {
				Button[3] = 0;
			}
		}
	}
	if (Buffer[5] == 's')
	{
		if (Button[3] == 0)
		{
			Slider = Buffer[bytes-1];
			Level = Slider;
			//printf("Setting Level to %d\n",Level);
		} else {
			Rate = Buffer[bytes-1];
			//printf("Setting Rate to %d\n",Rate);
		}
		//printf("Level = %d\tRate = %d\n",Level,Rate);
	}
}