Exemple #1
0
 void NDateTime::addMilliSeconds(const nint milliseconds)
 {
     nint _milliseconds = milliseconds;
     while (getMillisecond() * _milliseconds > 999)
     {
         _milliseconds -= 1000;
         addSeconds(1);
     }
     while (getMillisecond() + _milliseconds < 0)
     {
         _milliseconds += 1000;
         addSeconds(-1);
     }
     m_Time.addMilliSeconds(_milliseconds);
 }
int main (int argc,char* argv[])
{
  if (argc < 3) {
    printf("Usage example: ./%s button_gpio_port led_gpio_port\n", argv[0]);
    return 1;
  }
  int buttonGpioPort = atoi(argv[1]);
  ledGpioPort = atoi(argv[2]);

  wiringPiSetup();

  // register the function to deal with the button events
  wiringPiISR(buttonGpioPort, INT_EDGE_FALLING, &interrupt2DoSth);
  
  // set mode to output, which will be used to turn on/off the LED
  pinMode(ledGpioPort, OUTPUT);

  recordMillisecond = getMillisecond();

  int currentLevel = 0;
  while(true) {
    if (currentLevel != level) {
      printf("Caught an interrupt\n");
      currentLevel = level;
    }
  }

  return 0;
}
Exemple #3
0
//new_id is the index
QR *qr_add( QR  history[], int old_id,int  new_id, char *name, struct sockaddr_in *client_addr)
{
    if(old_id <0 || new_id < 0 || new_id > MAX_QUERY_ID )
    {
        return NULL;
    }
    QR * pt = &history[new_id];
    pt->old_id=old_id;
    pt->new_id=new_id;
    pt->num_answers = 0;
    pt->time_reply = 0;
    strncpy(pt->query_name ,name , MAX_NAME_LEN);
    memcpy(&pt->client_addr, client_addr, sizeof (struct sockaddr_in));
    pt->time_query=getMillisecond();
    return pt;
}
Exemple #4
0
    nint NDateTime::compareTo(const INObject * other) const
    {
        if (this == other)
            return 0;
        try
        {
            const NDateTime * obj = dynamic_cast<const NDateTime *>(other);

            if (obj != NULL)
            {
                int result = 0;
                if ((result = getYear() - obj->getYear()) == 0)
                {
                    if ((result = getMonth() - obj->getMonth()) == 0)
                    {
                        if ((result = getDay() - obj->getDay()) == 0)
                        {
                            if ((result = getHour() - obj->getHour()) == 0)
                            {
                                if ((result = getMinute() - obj->getMinute()) == 0)
                                {
                                    if ((result = getSecond() - obj->getSecond()) == 0)
                                    {
                                        result = getMillisecond() - obj->getMillisecond();
                                    }
                                }
                            }
                        }
                    }
                }
                return result;
            }
            else
            {
                return 1;
            }
        }
        catch (bad_cast &)
        {
            return 1;
        }
    }
/** 
 * The function to deal with the interrupt signal triggered by a button. 
 */
void interrupt2DoSth(void) {
  if (INVALID_GPIO_PORT == ledGpioPort) {
    printf("LED GPIO port was not set properly\n");
    return;
  }

  /* in a time period, we only allow the signal to be triggered once */
  long long currentMillisecond = getMillisecond();
  if (currentMillisecond - recordMillisecond < DEBOUNCE_TIME) {
    printf("Debouncing triggered @ %lld\n", currentMillisecond);
    return;
  }

  if (0 == level) {
    level = 1;
  } else {
    level = 0;
  }
  digitalWrite(ledGpioPort, level);  // turn on/off the LED

  // update the record time, to prepared for the next round debouncing
  recordMillisecond = currentMillisecond;
}