Browse Source

The version that is used in the new Nano. Seems to work on the desc.

Thomas Chef 8 years ago
parent
commit
c31855d9ad
6 changed files with 56 additions and 97 deletions
  1. 0 0
      led_blink.ino_not_used
  2. 1 1
      luxsensor.ino
  3. 1 46
      nexa.ino
  4. 2 2
      queue.h
  5. 3 3
      queue.ino
  6. 49 45
      repeater.ino

led_blink.ino → led_blink.ino_not_used


+ 1 - 1
luxsensor.ino

@@ -44,7 +44,7 @@ void initLuxSensor(void)
   } 
   else 
   {
-    Serial.println("No sensor found ... check your wiring?");
+    //Serial.println("XNo sensor found ... check your wiring?");
     while (1);
   }
   /* Configure the sensor */

+ 1 - 46
nexa.ino

@@ -86,52 +86,7 @@ static int decode (unsigned int width) {
 #define TOO_SHORT 100
 
 bool nextPulseNexa (unsigned int width) {
-/*	unsigned int decodew = 0;
-  
-	static unsigned int totw = 0;
-	static int mode=0;
-
-
-	if( state != T0 ) {
-
-		switch( mode ) {
-		case 0:
-			totw = width;
-			mode = 1;
-			break;
-		case 1:
-			if( width < TOO_SHORT ) {
-				totw += width;
-				mode = 2;
-			}
-			else {
-				decodew = totw;
-				totw = width;
-			}
-			break;
-		case 2:
-			totw += width;
-			//if( width < TOO_SHORT ) {  // This change caused less reception
-			//	mode = 2;
-			//}
-			//else {
-				mode = 1;
-			//}
-			break;
-		}
-	}
-	else {
-		// T0-State, send right through
-		decodew = totw;
-		totw = width;
-		if( width < TOO_SHORT ) {
-			mode = 2;
-		}
-		else {
-			mode = 1;
-		}
-	} */
-//decodew = width;
+
 	if( width > 0 ) {
 		if (state != DONE)
 

+ 2 - 2
queue.h

@@ -3,11 +3,11 @@
 
 
 
-#define NEXA_QUEUE_SIZE 700	// Queue size from Nexa-remotes
+#define NEXA_QUEUE_SIZE 500	// Queue size from Nexa-remotes
 
 
 unsigned char rcvDeQueue( unsigned int *value );
-unsigned char rcvEnQueue( unsigned int value );
+unsigned char rcvEnQueue( uint16_t value );
 unsigned char rcvRollbackQueue();
 unsigned int getQueueUsed();
 void  rcvInitQueue(  );

+ 3 - 3
queue.ino

@@ -3,7 +3,7 @@
 static int read_d;				/*!< Read index points to the place in the queue that has already been read */
 static int write_d;				/*!< The write index points to the place where the next write in the queue will take place. */
 
-static unsigned int nexaQueueBuffer[NEXA_QUEUE_SIZE];
+static uint16_t nexaQueueBuffer[NEXA_QUEUE_SIZE];
 
 
 void  rcvInitQueue(  ) {
@@ -17,7 +17,7 @@ unsigned int getQueueUsed() {
   return (write_d-read_d);
 }
 
-unsigned char rcvEnQueue( unsigned int value ) {
+unsigned char rcvEnQueue( uint16_t value ) {
     
 	// Is the queue full ?
 	if( write_d == read_d )
@@ -35,7 +35,7 @@ unsigned char rcvEnQueue( unsigned int value ) {
 	return 1u;
 }
 
-unsigned char  rcvDeQueue( unsigned int *value ) {
+unsigned char  rcvDeQueue( uint16_t *value ) {
     
 	int writePos = write_d;
     

+ 49 - 45
repeater.ino

@@ -43,9 +43,7 @@ void setup() {
   rcvInitQueue();
   
   cli(); // Clear interrupt
-
   setup_timer_interrupt();
-  
   sei(); // Enable interrupt
   
   disableRx = false;
@@ -55,7 +53,29 @@ void setup() {
 //                       INTERRUPT FUNCTIONS
 //********************************************************************
 
-void rxInterrupt() {
+void setup_timer_interrupt()
+{
+  //set timer1 interrupt at 10Hz
+  TCCR1A = 0;// set entire TCCR1A register to 0
+  TCCR1B = 0;// same for TCCR1B
+  TCNT1  = 0;//initialize counter value to 0
+  // set compare match register for 1hz increments
+  
+  //  OCR1A = 40. This results is 16MHz / 8 / 40 = 20 uS between interrupts
+  OCR1A = 40;
+
+  // turn on CTC mode
+  TCCR1B |= (1 << WGM12);
+
+  // Set CS12:CS10 to 010 = /8 prescaler
+  TCCR1B |= (1 << CS11);  
+ 
+  // enable timer compare interrupt
+  TIMSK1 |= (1 << OCIE1A);
+}  
+
+// 10uS timer interrupt function
+ISR(TIMER1_COMPA_vect,ISR_NOBLOCK) {
   
     static unsigned char currValue = 0;
     static unsigned short samples = 0;
@@ -76,7 +96,8 @@ void rxInterrupt() {
     }
 
     if( newSamples == 3 ) {
-        rcvEnQueue(samples * 20);
+        uint16_t queSamples = (uint16_t)((samples*20 > 60000)? 60000 : samples*20);
+        rcvEnQueue(queSamples); // Max 46000
         samples = newSamples;
         newSamples = 0;
         currValue = value;    
@@ -99,21 +120,10 @@ void stopInterrupts() {
 extern unsigned long x_data; // Receive data from Nexa
 extern unsigned long temp1_x_data; // Receive data from temp1
 
-void loopB() {
-  
-  uint32_t lux = readLuxSensor();
-  
-  Serial.println(lux);
-  
-  delay(1000);
-  
-}
-
 void loop() {
   
   static int rxMode = SER_RX_MODE_WAIT;
   static int rxNum = 0;
-  //static unsigned char rxChars[20];
   
   static unsigned long last_rx_time = 0;
   
@@ -125,11 +135,9 @@ void loop() {
   static unsigned long previous_temp1_x_data = 0;
   static unsigned long temp1_old_time=0;
   
-  //static char hex[100];
-  
-  static boolean firstRun = true;
+  //static boolean firstRun = true;
 
-  static unsigned int width;
+  static uint16_t width;
   
   static unsigned long txCode = 0;
   
@@ -145,10 +153,10 @@ void loop() {
   }
   
   // Display version information 10 sec after startup
-  if( firstRun == true && now > 10000 ) {
+  /* if( firstRun == true && now > 30000 ) {
     Serial.println("433MHz Repeater module. (Arduino nano) Ver: 170211 14:46");  // **** VERSION ****
     firstRun = false;
-  }
+  } */
   
   if( now > previous_lux_time  ) {
       // Yes ! It's time to measure lux value
@@ -167,7 +175,7 @@ void loop() {
       txCode  = 0x6AD50000;
       txCode |= (lux & 0x0000FFFF);
       
-      blinkTheLED();
+      //blinkTheLED();
   }
   
   if( rcvDeQueue(&width) ) {
@@ -179,43 +187,39 @@ void loop() {
         
           if( x_data != previous_nexa_x_data || now > (nexa_old_time+1000) ) {
 
-	    unsigned long  remote_id = (x_data & 0xFFFFFFC0) >>6;
-	    int group     = (x_data & 0x00000020) >>5;
-	    int onOff     = (x_data & 0x00000010) >>4;
-	    int channel   = (x_data & 0x0000000C) >>2;
-	    int button    = (x_data & 0x00000003);
+        	    unsigned long  remote_id = (x_data & 0xFFFFFFC0) >>6;
+        	    int group     = (x_data & 0x00000020) >>5;
+        	    int onOff     = (x_data & 0x00000010) >>4;
+        	    int channel   = (x_data & 0x0000000C) >>2;
+        	    int button    = (x_data & 0x00000003);
 
-        Serial.println("Nexa");
+              //Serial.println(remote_id);
 
-            if( remote_id == 11067169UL && txDataReady == 0 ) {
+              if( ( remote_id == 11067169UL || remote_id == 20071093UL ) && txDataReady == 0 ) {
               
-              remote_id++;
-              txDataReady = 1;
-              
-
-		txCode  = ((remote_id << 6) & 0xFFFFFFC0 );
-		txCode |= ((group     << 5) & 0x00000020 );
-		txCode |= ((onOff     << 4) & 0x00000010 );
-		txCode |= ((channel   << 2) & 0x0000000C );
-		txCode |= ((button        ) & 0x00000003 );
+                  remote_id++;      // Increase the remote id with one ( = the real id of the nexa remote control )
+                  txDataReady = 1;
+                  
+    
+              		txCode  = ((remote_id << 6) & 0xFFFFFFC0 );
+              		txCode |= ((group     << 5) & 0x00000020 );
+              		txCode |= ((onOff     << 4) & 0x00000010 );
+              		txCode |= ((channel   << 2) & 0x0000000C );
+              		txCode |= ((button        ) & 0x00000003 );
               
-
-              //Serial.println(remote_id);
-              //Serial.println(onOff);
-            }
+              }
 
               previous_nexa_x_data = x_data;
           }
           
           nexa_old_time = now;
           resetDecoder();
-          blinkTheLED();
       }
   }
   
   if( txDataReady == 1 && (now > (last_rx_time+200)) ) { // Transmit if it has passed more than 100mS since last rx
-    txDataReady = 0;
-    sendNexaCode(txCode);
+      txDataReady = 0;
+      sendNexaCode(txCode);
   }
   
   previous_now = now;  // Store to check for wrapping of millis()