Beispiel #1
0
void shift_register_latch_output(Shift_register *shift_register){
	for(int j = 0; j < shift_register->size; j++){ 
		char data = shift_register->data[j];

	for(int i = 0; i < 8; i++){
		if(  data & 0x01 )
		pin_high(shift_register->serial);
		else
		pin_low(shift_register->serial);
		//delay(speed1);
		
		pin_high(shift_register->clk);
		//delay(speed1);
		pin_low(shift_register->clk);
		//delay(speed1);
		data = data>>1;
		}
	}

	//latch data
	pin_high(shift_register->latch);
	//delay(speed1);
	pin_low(shift_register->latch);
	//delay(speed1);



}
Beispiel #2
0
static void
handle_serial_input(void)
{
	while (1) {
		switch (serial_getchar()) {
		case '\0':
			cli();
			if (!serial_available())
				events &= ~EV_SERIAL;
			sei();
			return;

		case 'O': /* open */
			pin_low(PIN_GREEN_LED);
			pin_low(PIN_OPEN_LOCK);
			_delay_ms(500);
			pin_high(PIN_OPEN_LOCK);
			serial_print("OPENAKCK\n");
			pin_high(PIN_GREEN_LED);
			break;

		case 'D': /* day */
			pin_low(PIN_GREEN_LED);
			pin_low(PIN_DAYMODE);     /* day mode   */
			pin_high(PIN_STATUS_LED); /* status on  */
			break;

		case 'N': /* night */
			pin_high(PIN_GREEN_LED);
			pin_high(PIN_DAYMODE);    /* nightmode  */
			pin_low(PIN_STATUS_LED);  /* status off */
			break;

		case 'R': /* rejected */
			pin_low(PIN_YELLOW_LED);
			_delay_ms(200);
			pin_high(PIN_YELLOW_LED);
			_delay_ms(200);
			pin_low(PIN_YELLOW_LED);
			_delay_ms(200);
			pin_high(PIN_YELLOW_LED);
			break;

		case 'V': /* validated */
			pin_low(PIN_GREEN_LED);
			_delay_ms(300);
			pin_high(PIN_GREEN_LED);
			_delay_ms(200);
			pin_low(PIN_GREEN_LED);
			_delay_ms(300);
			pin_high(PIN_GREEN_LED);
			_delay_ms(200);
			pin_low(PIN_GREEN_LED);
			_delay_ms(300);
			pin_high(PIN_GREEN_LED);
			break;
		}
	}
}
Beispiel #3
0
void valve_set_state(unsigned char state)
{
	if(state){
		pin_low(DRV1_N);
		pin_high(DRV1_P);
		pin_low(DRV2_N);
		pin_high(DRV2_P)
	}else{
void spwm_init()
{
	// Pin directions
	as_output(SPWM_CLK);
	as_output(SPWM_STR);
	as_output(SPWM_DATA);

	// Initial states
	pin_low(SPWM_CLK);
	pin_low(SPWM_STR);
}
Beispiel #5
0
void gotoXY(LCD *lcd, char x, char y){
	pin_low(lcd->enb);
	pin_low(lcd->mode);

	spi_put( 0x80 | x );
	_delay_us(100);
	spi_put( 0x40 | y );
	_delay_us(100);


	pin_high(lcd->enb);
	pin_high(lcd->mode);
}
Beispiel #6
0
void beep_enable(unsigned char state)
{
	if(state)
	{
		pin_low(BUZZER);
		TCCR1B=0x5;
		OCR1AL=0xFF;
		TCCR1A=0x83;		
	}else{
	    TCCR1B=0;
		pin_low(BUZZER);
	}
}
Beispiel #7
0
LCD* lcd_new(Pin *mode, Pin *reset, Pin *enable){
        LCD *lcd = (LCD * ) malloc( sizeof( LCD ) );

	lcd->spi = spi_init();
	lcd->mode = mode;
	lcd->rst = reset;
	lcd->enb = enable;
	lcd->col = 14;
	lcd->row = 6;
	lcd->cursor = 0;
	lcd->buffer = circular_buffer_new(128);

	pin_config_out(mode);
	pin_config_out(reset);
	pin_config_out(enable);

	pin_low(enable);

	//active low reset pulse
	pin_high(reset);
	pin_pulse(reset);

	//enter config mode
	pin_low(mode);

	//config lcd driver
	_delay_us(100);
	spi_put(0x21);
	_delay_us(100);
	spi_put(0xA0);
	_delay_us(100);
	spi_put(0x04);
	_delay_us(100);
	spi_put(0x14);
	_delay_us(100);
	spi_put(0x20);
	_delay_us(100);
	spi_put(0x0C);
	_delay_us(100);

	pin_high(mode);
	clear_screen(lcd);
	
	//ready to accept data
	gotoXY(lcd,0,0);

	pin_high(enable);
	return lcd;
}
Beispiel #8
0
__attribute__((noreturn)) int main () {
    double c = 24.0;

    /* setup uart */
    serial_baud_4800();
    serial_mode_8n1(); 
    serial_transmitter_enable();
    stdout = &mystdout;

    pin_mode_output(XBEE);
    pin_mode_output(LED_1);

    while(1) {
        
        xbee_hibrinate_disable();
        pin_high(LED_1);

        printf("i%2.1f,", 4.0);
        printf("v%2.1f,", 12.0);
        printf("c%2.1f,", 24.0);
        printf("lux%2.1f", 3.0);
        printf(";");

        while(!serial_writeable())
            ;

        // xbee_hibrinate_enable();
        pin_low(LED_1);
        _delay_ms(500);
    }
}
Beispiel #9
0
static void step(STEPPER_MOTOR* stepper){
	L297* motor = (L297*)stepper;

	// Send a 1uS pulse to the step pin
	pin_low(motor->pulse);
	pin_high(motor->pulse);
}
Beispiel #10
0
void send_heartbeat(){
        printf("send heartbeat\n");

        //Set image on device
        system(fanny_heartbeat_image_path);

        int heartbeat_pattern[] = {1000, 255, 300, 225, 1000, 225, 300, 225}; 
        int repeat = 4;

        int r=0;
        while(r < repeat){

                int i = 0;
                while(i < 8){
                        usleep(heartbeat_pattern[i] * 1000);
                        i++; 
                        pin_high(8,39);

                        usleep(heartbeat_pattern[i] * 1000);
                        i++;
                        pin_low(8,39);
                }
        r++;   
        }

       
        system(black_image_path); //Set black image on device
}
Beispiel #11
0
static void step(STEPPER_MOTOR* stepper){
	POLOLU_A4983* motor = (POLOLU_A4983*)stepper;

	// Send a 1uS pulse to the step pin
	pin_high(motor->pulse);
	pin_low(motor->pulse);
}
Beispiel #12
0
int
main(void)
{
	watchdog_off();
	clock_init_1MHz();

	/* set all pins to output high */
	port1_direction = 0xFF;
	port1_output = 0xFF;

	/* initialize serial clock, tx and rx parts */
	serial_init_clock();
	serial_init_tx();
	serial_init_rx();

	/* enable interrupts */
	__eint();

	pin_low(LED1);
	pin_high(LED2);

	while (1) {
		unsigned char c;

		pin_toggle(LED1);
		pin_toggle(LED2);

		c = serial_getchar();
		serial_putchar(c);
		if (c == '\r')
			serial_putchar('\n');
	}
}
Beispiel #13
0
int
main(void)
{
	int del;
	iolib_init(); /* Initialize I/O library - required */
	iolib_setdir(8,11, BBBIO_DIR_IN);   /* Set pin P8 - 11 as input */
	iolib_setdir(8,12, BBBIO_DIR_OUT);  /* Set pin P8 - 12 as output */

	int count = 0;
	while(count < 50)
	{
		count ++ ;
		if (is_high(8,11))   /* Check if in is high (i.e. button pressed) */
		{
			del=100; /* fast speed */
		}
		if (is_low(8,11))    /* Check if in is low (i.e button is released) */
		{
			del=500; /* slow speed */
		}

		pin_high(8,12);       /* Set pin to high - LED on */
		iolib_delay_ms(del);  /* Delay for 'del' msec */
		pin_low(8,12);		  /* Set pin to low - LED off */
		iolib_delay_ms(del);  /* Delay for 'del' msec */

	}
	iolib_free();  /* Release I/O library prior to program exit - required */
	return(0);
}
Beispiel #14
0
uint8_t segled_put_char(SEGLED* led, uint8_t ch){
	init(led);
	uint8_t mask=segled8_get_mask(ch);	// get the mask
	if(mask & 0b00000001){
		// it uses the full stop
		if(!led->segment[7]){
			// no full stop - so just light segment D
			mask = 0b00010000;
		}
	}

	if(!led->activeHigh){
	 	mask ^= 0b11111111;
	}

	for(uint8_t i=0; i<8;i++){
		const IOPin* pin = led->segment[i];
		if(mask & 0b10000000){
			pin_high(pin);
		}else{
			pin_low(pin);
		}
		mask <<= 1;
	}
	return ch;
}
/*
 * Class:     org_bulldog_beagleboneblack_jni_NativeGpio
 * Method:    digitalWrite
 * Signature: (III)V
 */
JNIEXPORT void JNICALL Java_org_bulldog_beagleboneblack_jni_NativeGpio_digitalWrite
  (JNIEnv * env, jclass clazz, jint port, jint pin, jint val) {
	if(val == 1) {
		pin_high(port, pin);
	} else {
		pin_low(port, pin);
	}
}
Beispiel #16
0
void stepup_set_state(unsigned char state)
{
	if(state){
		pin_high(STEP_UP);
	}else{
		pin_low(STEP_UP);
	}
}
Beispiel #17
0
void beep(unsigned int t)
{
	for(unsigned int i=0;i<t;i++){
		pin_high(BUZZER);
		_delay_ms(0.95);
		pin_low(BUZZER);
		_delay_ms(0.95);
	}
}
Beispiel #18
0
//Thread that will playback any recording
void *playbackThreadBody(void *arg) {
	int oldstate;
	pthread_setcanceltype(PTHREAD_CANCEL_ENABLE, &oldstate);

	while (1) {
		//Will only run if in recording state
		pthread_mutex_lock(&stateMutex);
		while (state != 2) {
			pthread_cond_wait(&playbackStateCond, &stateMutex);
		}
		pthread_mutex_unlock(&stateMutex);

		// Declare variables needed for playback
		unsigned char* buffer;
		FILE *fp;
		unsigned long fileLen;
		int i;

		if ((fp = fopen(FILE_NAME, "rb")) == NULL) {
			printf("Error opening file\n");
		}

		// Get the file length for playback
		fseek(fp, 0, SEEK_CUR);
		fileLen = ftell(fp);
		fseek(fp, 0, SEEK_SET);

		// Allocate memory into the buffer
		buffer = (unsigned char *) malloc(fileLen + 1);
		if (!buffer) {
			fprintf(stderr, "Memory error!");
			fclose(fp);
			return NULL;
		}

		// Read file contents into buffer
		fread(buffer, fileLen, 1, fp);
		fclose(fp);

		// Run through the file and play the music
		for (i = 0; (i < fileLen) && (state == 2); ++i) {
			if (buffer[i] == '1')
				pin_high(9, 28);
			else
				pin_low(9, 28);

			nanosleep((const struct timespec[] ) { {0, 651.041667L}}, NULL);
			if (playButton == 1) {// while play button is held down, it will restart playing back the file
				i = 0;
			}
		}

		//If recording is full played, the state will automatically switch to Recorder state (idle)
		pthread_mutex_lock(&stateMutex);
		state = 3;
		pthread_mutex_unlock(&stateMutex);
	}
Beispiel #19
0
void
init_mfrc522(void)
{
  pin_mode_output(MFRC522_NRSTPD);
  pin_high(MFRC522_NRSTPD);
  /* Slave select pin, high (deselected) initially. */
  pin_mode_output(MFRC522_SS);
  pin_high(MFRC522_SS);
  pin_mode_output(MFRC522_MOSI);
  pin_low(MFRC522_MOSI);
  pin_mode_input(MFRC522_MISO);
  pin_mode_output(MFRC522_SCK);
  pin_low(MFRC522_SCK);

  spi_mode_master();
  spi_enable();

  mfrc522_init();
}
/** Send _buff to SIPO */
void _send_buffer()
{
	for (int8_t i = SPWM_CHANNELS - 1; i >= 0; i--)
	{
		#if (SPWM_INVERT)
		set_pin(SPWM_DATA, !_buff[i]); /* Common anode */
		#else
		set_pin(SPWM_DATA, _buff[i]);  /* Common cathode */
		#endif

		// send a CLK pulse
		pin_high(SPWM_CLK);
		pin_low(SPWM_CLK);
	}

	// send a STR pulse
	pin_high(SPWM_STR);
	pin_low(SPWM_STR);
}
Beispiel #21
0
//uart job reads the base station state from bluetooth
void handle_bluetooth(void * pointer){

    struct remote_state * rstate = (struct remote_state *)pointer;
    pin_outputable(PIN_26);

    for (;;) {

        for (;;) {
            pin_low(PIN_26);
            //read from uart
            unsigned char b;
            size_t num;
            if (uart_recv(rstate->bluetooth_uart, &b, 1, &num, 0)!=0) error();
            if (num !=1 ) continue;
            //try to find the framing byte (uint 255)
            if (b != 255U) continue;

            break;

        }
        pin_high(PIN_26);

        unsigned char buffer [4];
        size_t num;
        if (uart_recv(rstate->bluetooth_uart, buffer, sizeof(buffer), &num, 0)!=0) error();
        if (num != sizeof(buffer)) continue;

        uint8_t x;
        memcpy(&x, buffer, 1);
        uint8_t y;
        memcpy(&y, buffer+1, 1);
        uint8_t button;
        memcpy(&button, buffer+2, 1);
        uint8_t is_automatic_mode;
        memcpy(&is_automatic_mode, buffer+3, 1);

        if (mutex_lock(rstate->mutex) != 0) error();

        if (rstate->is_dead) {
            rstate->joy_x = 127;
            rstate->joy_y = 127;
            rstate->button_pressed = 0;
            rstate->is_automatic_mode = 0;
        } else {
            rstate->joy_x = x;
            rstate->joy_y = y;
            rstate->button_pressed = button;
            rstate->is_automatic_mode = is_automatic_mode;
        }

        if (mutex_unlock(rstate->mutex) != 0) error();

    }

}
Beispiel #22
0
void write_string(LCD *lcd,char *s){
	int i = 0;
	pin_low(lcd->enb);
	pin_high(lcd->mode);
	while(s[i] != 0){
		write_character(lcd,s[i]);
		i++;
	}
	write_buffer(lcd);
	pin_high(lcd->enb);
}
Beispiel #23
0
/**
 * Turn on one LED.
 *
 * @param lednumber the index of the LED to turn off.
 */
void led_off(uint8_t lednumber)
{
#ifdef COMMON_ANODE
	pin_high(lednumber);
#else
#ifdef COMMON_CATHODE
	pin_low(lednumber);
#else
#  error Need to #define COMMON_ANODE or COMMON_CATHODE
#endif
#endif
}
Beispiel #24
0
void send_hug(){
        printf("send hug\n"); //Debug

        system(fanny_hug_image_path); //Set image on device

        //Send signal
        pin_high(8,30); 
        sleep(5); 
        pin_low(8,30); 

        system(black_image_path); //Set black image on device
}
Beispiel #25
0
static void
handle_rfid_input(void)
{
	static char buf[14];
	static uint8_t idx = 0;
	int c;
	uint8_t checksum;
	uint8_t i;

	for (;;) {
		c = softserial_getchar();
		switch (c) {
		case SOFTSERIAL_EOF:
			return;
		case 2:
			idx = 0;
			break;
		case 3:
			if (idx == 14 && cnt == 0) {
				/* Check for correct checksum and CR / LF */
				checksum = 0;
				for (i = 0; i < 12; i += 2)
					checksum ^= ((hex2int(buf[i]) << 4) |
						     hex2int(buf[i+1]));
				if (checksum)
					break;
				if (buf[12] != 13 || buf[13] != 10)
					break;

				/*
				  We got an RFID tag.
				  Copy it into the card reader buffer to
				  emulate a read card data string.
				*/
				for (i = 0; i < 10 && cnt < 255; ++i, ++cnt)
					data[cnt] = buf[i];
				for (i = 0; i < 3; i++) {
					pin_low(PIN_YELLOW_LED);
					_delay_ms(80);
					pin_high(PIN_YELLOW_LED);
					_delay_ms(80);
				}
			}
		default:
			if (idx < 14)
			{
				buf[idx++] = c;
				second = 0;
			}
			break;
		}
	}
}
Beispiel #26
0
/**
 * We have just hit top and are starting to count down again.
 * The new PWM duty cycle has been clocked in for the next servo
 */
static void service(const Timer *timer, void* data){
	SERVO_DRIVER* driver = data;
	uint8_t i;

	// Move to the next servo
	uint8_t index = (driver->specific.softwareMUX.currentServo + 1)& 7;
	driver->specific.softwareMUX.currentServo = index;

	// Set the multiplex pins so the pulse goes to the correct servo
	// This needs to be done quickly to stop the start of the pulse
	// going to the wrong sevo
	uint8_t bits = index;
	for (i = 0; i < NUM_MUX_PINS; i++){
		const IOPin* pin = driver->specific.softwareMUX.muxPins[i];
		if(bits & 1){
			pin_high(pin);
		}else{
			pin_low(pin);
		}
		bits >>= 1;
	}

	// Keep track of the lowest value of the timer counter
	// Setting a delay between this value and TOP will mean the mux bits dont get changed in time
	uint16_t thisDelay = timerGetCounter(timer);
	if(thisDelay < maxDelay){
		maxDelay = thisDelay;
	}

	// Time critical part is over
	// Now calculate the pulse width for next servo
	uint16_t newPos=0;
	index = (index + 1) & 7;
	if(index < driver->num_servos){
		SERVO* servo = (SERVO *)pgm_read_word(&driver->servos[index]);
		if(servo->actuator.connected){
			newPos = servo->delay;

			// Limit to the maximum value
			uint16_t limit = maxDelay;
			if(newPos > limit){
				newPos = limit;
			}

		}
	}

	// Set the threshold inline - to save more registers push/pops
	//compareSetThreshold(channel,newPos);
	PORT port = driver->specific.softwareMUX.pwmPort;
	_SFR_MEM16(port) = newPos; 					// set 16 bit word
}
Beispiel #27
0
/** Enter WRITE mode */
void _lcd_mode_w()
{
	if (_lcd_mode == 0) return;  // already in W mode

	pin_low(LCD_RW);

	as_output(LCD_D7);
	as_output(LCD_D6);
	as_output(LCD_D5);
	as_output(LCD_D4);

	_lcd_mode = 0;
}
Beispiel #28
0
int
ADT7301_read()
{
    int value = 0;
    int data_count =0;
    int i =0 ;

    pin_high(ADT7301_SCLK_PORT,ADT7301_SCLK_PIN);

    value =0;
    //set CS to 1 , why pin_low ? because CS in ADT7301 is inverse pin
    pin_low(ADT7301_CS_PORT,ADT7301_CS_PIN);

    //set DIN to 0
    pin_low(ADT7301_DIN_PORT,ADT7301_DIN_PIN);

    //read temperature Data
    for(i=0;i<16;i++)
    {
        //generate half cycle(1)
        pin_low(ADT7301_SCLK_PORT ,ADT7301_SCLK_PIN);
        iolib_delay_ms(1);

        //generate half cycle(0)
        pin_high(ADT7301_SCLK_PORT,ADT7301_SCLK_PIN);
        iolib_delay_ms(1);

        value <<= 1 ;
        int get_value = is_high(ADT7301_DOUT_PORT,ADT7301_DOUT_PIN) ;
        value |= get_value;
    }

    //set CS to 1
    pin_high(ADT7301_CS_PORT,ADT7301_CS_PIN);

    // return RAW value , this valuse is
    return value ;
}
Beispiel #29
0
void cube_shutdown(uint8_t unused)
{
	// Set harder powersave mode
	old_mode = mode;
	mode = MODE_SLEEP;
	power_adc_disable();
	power_spi_disable();
	power_timer0_disable();
	power_timer1_disable();

	/* Pulling BLANK down reduces current consumption to
	 * 50mA. Doing that. We pull all other signals low, too. */
	pin_high(BLANK);
	pin_low(XLAT);
}
Beispiel #30
0
static void uartswTxBitService(const TimerCompare *channel, void* _uart)
{
	SW_UART* uart = (SW_UART*) _uart;
	if(uart->txBitNum)
	{
		// there are bits still waiting to be transmitted
		if(uart->txBitNum > 1)
		{
			// transmit data bits (inverted, LSB first)
			if( (uart->txData & 0x01) )
				pin_high(uart->_uart_.tx_pin);
			else
				pin_low(uart->_uart_.tx_pin);
			// shift bits down
			uart->txData >>= 1;
		}
		else
		{
			// transmit stop bit
			if(uart->inverted){
				pin_low(uart->_uart_.tx_pin);
			}else{
				pin_high(uart->_uart_.tx_pin);
			}
		}
		// schedule the next bit
		uint16_t top = 1 + timerGetTOP(compareGetTimer(channel));
		uint16_t next = (compareGetThreshold(channel) + uart->dataBitLength);
		if(next >= top){
			next -= top;
		}
		compareSetThreshold(channel, next );

		// count down
		uart->txBitNum--;
	}