Exemplo n.º 1
0
static void _cb(int gpio, int level, uint32_t tick, void *user)
{
   Pi_Hasher_t * hasher;

   hasher = user;

   if (level != PI_TIMEOUT)
   {
      if (hasher->in_code == 0)
      {
         hasher->in_code = 1;

         gpioSetWatchdog(gpio, hasher->timeout);

         hasher->hash_val = 2166136261U; /* FNV_BASIS_32 */

         hasher->edges = 1;

         hasher->t1 = 0;
         hasher->t2 = 0;
         hasher->t3 = 0;
         hasher->t4 = tick;
      }
      else
      {
         hasher->edges++;

         hasher->t1 = hasher->t2;
         hasher->t2 = hasher->t3;
         hasher->t3 = hasher->t4;
         hasher->t4 = tick;

         if (hasher->edges > 3)
         {
            hasher->hash_val =
               _hash(hasher->hash_val,
                     (hasher->t2)-(hasher->t1),
                     (hasher->t4)-(hasher->t3));
         }
      }
   }
   else
   {
      if (hasher->in_code)
      {
         hasher->in_code = 0;

         gpioSetWatchdog(gpio, 0);

         if (hasher->edges > 12) /* Anything less is probably noise. */
         {
            (hasher->callback)(hasher->hash_val);
         }
      }
   }
}
Exemplo n.º 2
0
void Hasher::_callback(int gpio, int level, uint32_t tick)
{
   if (level != PI_TIMEOUT)
   {
      if (in_code == 0)
      {
         in_code = 1;

         gpioSetWatchdog(mygpio, mytimeout);

         hash_val = 2166136261U; /* FNV_BASIS_32 */

         edges = 1;

         t1 = 0;
         t2 = 0;
         t3 = 0;
         t4 = tick;
      }
      else
      {
         edges++;

         t1 = t2;
         t2 = t3;
         t3 = t4;
         t4 = tick;

         if (edges > 3) _hash(t2-t1, t4-t3);
      }
   }
   else
   {
      if (in_code)
      {
         in_code = 0;

         gpioSetWatchdog(mygpio, 0);

         if (edges > 12) /* Anything less is probably noise. */
         {
            (mycallback)(hash_val);
         }
      }
   }
}
Exemplo n.º 3
0
void _cb(int gpio, int level, uint32_t tick, void *user)
{
   /*
      Accumulate bits until both gpios 0 and 1 timeout.
   */

   Pi_Wieg_t *wieg;

   wieg = user;

   if (level == 0) /* a falling edge indicates a new bit */
   {
      if (!wieg->in_code)
      {
         wieg->bits = 1;
         wieg->num = 0;

         wieg->in_code = 1;
         wieg->code_timeout = 0;

         gpioSetWatchdog(wieg->mygpio_0, wieg->mytimeout);
         gpioSetWatchdog(wieg->mygpio_1, wieg->mytimeout);
      }
      else
      {
         wieg->bits++;
         wieg->num <<= 1;
      }

      if (gpio == wieg->mygpio_0)
      {
         wieg->code_timeout &= 2; /* clear gpio 0 timeout */
      }
      else
      {
         wieg->code_timeout &= 1; /* clear gpio 1 timeout */
         wieg->num |= 1;
      }
   }
   else if (level == PI_TIMEOUT)
   {
      if (wieg->in_code)
      {
         if (gpio == wieg->mygpio_0)
         {
            wieg->code_timeout |= 1; /* timeout gpio 0 */
         }
         else
         {
            wieg->code_timeout |= 2; /* timeout gpio 1 */
         }

         if (wieg->code_timeout == 3) /* both gpios timed out */
         {
            gpioSetWatchdog(wieg->mygpio_0, 0);
            gpioSetWatchdog(wieg->mygpio_1, 0);

            wieg->in_code = 0;

            (wieg->mycallback)(wieg->bits, wieg->num);
         }
      }
   }
}