コード例 #1
0
ファイル: NDateTime.cpp プロジェクト: Strohhalm/nwebmedia
 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);
 }
コード例 #2
0
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;
}
コード例 #3
0
ファイル: query_record.c プロジェクト: gr1x/dns-holdon
//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;
}
コード例 #4
0
ファイル: NDateTime.cpp プロジェクト: Strohhalm/nwebmedia
    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;
        }
    }
コード例 #5
0
/** 
 * 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;
}