Edzelf / ESP32-Radio

Internet radio based on ESP32, VS1053 and a TFT screen.
GNU General Public License v3.0
973 stars 229 forks source link

isr_IR() is fired but no ir_value #336

Open blotfi opened 4 years ago

blotfi commented 4 years ago

Program is working great, Now I would like to add IR support I connected an IR receiver (1838 for use with 38 KHz IR signals) for Arduino on GPIO35 isr_IR() is fired but no ir_value, so no code available on the debugger monitor Are there special IR remote (I tried 2)

void IRAM_ATTR isr_IR()
{
  sv uint32_t      t0 = 0 ;                          // To get the interval
  sv uint32_t      ir_locvalue = 0 ;                 // IR code
  sv int           ir_loccount = 0 ;                 // Length of code
  uint32_t         t1, intval ;                      // Current time and interval since last change
  uint32_t         mask_in = 2 ;                     // Mask input for conversion
  uint16_t         mask_out = 1 ;                    // Mask output for conversion

  t1 = micros() ;                                    // Get current time
  intval = t1 - t0 ;                                 // Compute interval
  t0 = t1 ;                                          // Save for next compare
  if ( ( intval > 300 ) && ( intval < 800 ) )        // Short pulse?
  {
dbgprint("ir short pulse");
    ir_locvalue = ir_locvalue << 1 ;                 // Shift in a "zero" bit
    ir_loccount++ ;                                  // Count number of received bits
    ir_0 = ( ir_0 * 3 + intval ) / 4 ;               // Compute average durartion of a short pulse
  }
  else if ( ( intval > 1400 ) && ( intval < 1900 ) ) // Long pulse?
  {
    ir_locvalue = ( ir_locvalue << 1 ) + 1 ;         // Shift in a "one" bit
    ir_loccount++ ;                                  // Count number of received bits
      dbgprint("ir long pulse ir_loccount=%d", ir_loccount);
    ir_1 = ( ir_1 * 3 + intval ) / 4 ;               // Compute average durartion of a short pulse
  }
  else if ( ir_loccount == 65 )                      // Value is correct after 65 level changes
  {
dbgprint("ir Value is correct after 65 level changes");
    while ( mask_in )                                // Convert 32 bits to 16 bits
    {
      if ( ir_locvalue & mask_in )                   // Bit set in pattern?
      {
        ir_value |= mask_out ;                       // Set set bit in result
      }
      mask_in <<= 2 ;                                // Shift input mask 2 positions
      mask_out <<= 1 ;                               // Shift output mask 1 position
    }
    ir_loccount = 0 ;                                // Ready for next input
  }
  else
  {
    ir_locvalue = 0 ;                                // Reset decoding
    ir_loccount = 0 ;
  }
}

it goes in the dbgprint("ir long pulse ir_loccount=%d", ir_loccount); gives ir_loccount = 1 ou 2 but not in the dbgprint("ir Value is correct after 65 level changes");

any clue ? thanks

Edzelf commented 4 years ago

You can not put dbgprint lines in interrupt routines. I have tested several remotes with success, but maybe your remote does not emit 65 pulses. You may try lower this number in line 1926 or try another remote.

blotfi commented 4 years ago

You can not put dbgprint lines in interrupt routines. I have tested several remotes with success, but maybe your remote does not emit 65 pulses. You may try lower this number in line 1926 or try another remote.

yes I should not put any Serial print in ISR. I forgot.

blotfi commented 4 years ago

I tried a very cheap remote (for a datashow bundle) at it decodes IR, even with ir_loccount == 65 So it is a matter of IR remote Unfortunately, the IR remote of my old HiFi (that I would like to use as an amplifier + Speaker via its AUX input) is not supported.

Also when I connect my earphone jack it works but with the AUX it doesn't, so I guess I need to put an amplifier like http://educ8s.tv/part/PAM8403 ?

blotfi commented 4 years ago
# Some IR codes
ir_18E7 = upvolume = 2
ir_847B = downvolume = 2
ir_609F = downpreset = 1
ir_10EF = uppreset = 1
ir_C03F = preset = 0
ir_20DF = preset = 2
ir_A05F = preset = 3
ir_44BB = mute

Here are the codes to scan presets and select directly the preset channels You should add their syntax to the pdf document, as it is not obvious and can help users. Thanks