François Gautrais 9 tahun lalu
induk
melakukan
0a3cdd3ece
3 mengubah file dengan 18 tambahan dan 136 penghapusan
  1. 0 6
      bus.c
  2. 5 34
      recv.c
  3. 13 96
      send.c

+ 0 - 6
bus.c

@@ -35,11 +35,6 @@ void bus_init_recv(bus_t* bus, int d, int  clk, int ack)
 	bus->ack=ack;
 	bus->ismaster=0;
 	file_init(&bus->buffer);
-	if (wiringPiSetup() == -1)
-	{
-		perror("Unable to setup wiring pi\n");
-    exit (1);
-  }else printf("WiringPi successfully setup\n");
 }
 
 
@@ -56,7 +51,6 @@ void bus_init_send(bus_t* bus, int d, int  clk, int ack)
 void _bus_write(bus_t* bus, char x)
 {
 	int i;
-	unsigned long ref= time_micros();
 	if(!bus->ismaster) return;
 	for(i=0; i<8; i++)
 	{

+ 5 - 34
recv.c

@@ -28,41 +28,12 @@ int main()
 	{
 		uint32_t c;
 		char buffer[16];
-		bus_read(&bus, buffer, 5);
-		buffer[5]=0;
-		//file=fopen("data", "r+");
-		printf("'%s'\n", buffer);
-		//fprintf(file,"%u\n", c);
-		//fclose(file);
+		bus_read(&bus, &c, 4);
+		printf("%ld' s  %ld ms %'d us \n", c/1000000, c%1000000/1000, c%1000);
+
 	}
-	/*printf("Strat\n");
-	while(1)
-	{
-		int i;
-		for(i=2; i<5; i++)
-		{
-			int a = read_pin(i);
-			if(a!=data[i])
-			{
-				printf("pin[%d] : %d -> %d\n", i, data[i], a);
-				data[i]=a;
-			}else printf("pin[%d] : %d \n", i, a);
-			
-		}
-		sleep(1);
-	}*/
-	free_fifo(PIN_DATA, PIN_CLK, PIN_ACK);
-	/*int i;
-	setup_io();
-	INP_GPIO(2);
-	INP_GPIO(3);
-	while(1)
-	{
-		printf("%d ", GET_GPIO(2));
-		printf("%d ", GET_GPIO(3));
-		printf("\n");
-		sleep(1);
-	}*/
+
+
 }
 
 

+ 13 - 96
send.c

@@ -12,126 +12,43 @@
 #include "bus.h"
 #include "timer.h"
 
+
+
 void init_interrupt()
 {
 	MCUSR = 0;
 	wdt_disable();
-	DDRB &= ~(1<<PB3); /* Set PB0 as input */
-	PORTB |= (1<<PB3); /* Activate PULL UP resistor */ 
+	DDRB &= ~(1<<PB4); /* Set PB0 as input */
+	PORTB |= (1<<PB4); /* Activate PULL UP resistor */ 
 
-	PCMSK |= (1 << PCINT3); /* Enable PCINT0 */
+	PCMSK |= (1 << PCINT4); /* Enable PCINT0 */
 	GIMSK |= (1 << PCIE); /* Activate interrupt on enabled PCINT7-0 */
 	sei ();
+	
 }
 int main()
 {
-	int  wait=0, state=0;
 	unsigned long last=0;
+	unsigned long current_data = 0;
 	bus_t bus;
 	init();
 	init_write_pin(PIN_DATA,PIN_CLK,PIN_ACK);
-	//init_interrupt();
 	pinMode(PIN_IN, INPUT);
 	pinMode(PIN_LED, OUTPUT);
 	bus_init_send(&bus, PIN_DATA, PIN_CLK, PIN_ACK);
-	/*while(1)
-	{
-		if(!wait && read_pin(PIN_IN) )
-		{
-			unsigned long val;
-			val=micros()-last;
-			if(val<5000) continue;
-			wait=1;
-			last=micros();
-			//bus_write_sync(&bus, &val, 4);
-			state=(!state)?1:0;
-			digitalWrite(PIN_LED, state);
-		}
-		
-		if(!read_pin(PIN_IN)) wait=0;
-	}*/
-	
-	pinMode(PIN_IN, INPUT);
-	int i;
-	/*for(i=0; i<3; i++)
-	{
-		digitalWrite(PIN_CLK, 0);
-		micro_sleep(500000);
-		
-		digitalWrite(PIN_CLK, 1);
-		micro_sleep(500000);
-		digitalWrite(PIN_CLK, 0);
-	}*/
-	while(1)
-	{
-		bus_write_sync(&bus, "Salut", 5);
-		delay(250);
-		//digitalWrite(PIN_DATA, digitalRead(PIN_ACK));
-	}
-}
-
-
-
-
-
-
-/*
- * #include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "io.h"
 
-#define PIN_DATA 0
-#define PIN_CLK  1
-#define PIN_ACK  2
-#define PIN_IN   3
-#define PIN_LED  4
-
-#include "bus.h"
-
-void init_interrupt()
-{
-	MCUSR = 0;
-	wdt_disable();
-	DDRB &= ~(1<<PB3); 
-	PORTB |= (1<<PB3); 
-
-	PCMSK |= (1 << PCINT3); 
-	GIMSK |= (1 << PCIE); 
-	sei ();
-}
-
-bus_t bus;
-
-int main()
-{
-	init();
-	init_write_pin(PIN_DATA,PIN_CLK,PIN_ACK);
-	init_interrupt();
 	pinMode(PIN_IN, INPUT);
-	pinMode(PIN_LED, OUTPUT);
-	bus_init_send(&bus, PIN_DATA, PIN_CLK, PIN_ACK);
 	while(1)
 	{
-		//bus_send_thread(&bus);
+		while(digitalRead(PIN_IN)) delay(1);			
+		while(!digitalRead(PIN_IN)) delay(1);			
+		current_data=micros()-last;
+		if(current_data<10000) continue;
+		last=micros();
+		bus_write_sync(&bus, &current_data, 4);
 	}
 }
 
-unsigned long last=0;
-uint8_t ledstate=0;
-
-ISR (PCINT0_vect){
-   uint8_t x = (PORTB&(1<<PB3))>>PB3;
-   if(x)
-   {
-		 uint32_t val=micros()-last;
-		 last=micros();
-		 bus_write(&bus, &val, 4);
-		 ledstate=(ledstate)?0:1;
-		 digitalWrite(PIN_LED, ledstate);
-	 }
-}
 
-*/