Esempio n. 1
0
static void blinkfunc (osjob_t* j) {
    // toggle LED
    ledstate = !ledstate;
    debug_led(ledstate);
    // reschedule blink job
    os_setTimedCallback(j, os_getTime()+ms2osticks(100), blinkfunc);
}
Esempio n. 2
0
// called by EXTI_IRQHandler
// (set preprocessor option CFG_EXTI_IRQ_HANDLER=sensorirq)
void sensorirq () {
    if((EXTI->PR & (1<<INP_PIN)) != 0) { // pending
        EXTI->PR = (1<<INP_PIN); // clear irq
        // run application callback function in 50ms (debounce)
        os_setTimedCallback(&irqjob, os_getTime()+ms2osticks(50), irqjob.func);
    }
}
void do_send(osjob_t* j){
//      Serial.print("Time: ");
//      Serial.println(millis() / 1000);
  printf("Time: %lu\n", (unsigned int) (millis() / 1000));
      // Show TX channel (channel numbers are local to LMIC)
//      Serial.print("Send, txCnhl: ");
//      Serial.println(LMIC.txChnl);
//      Serial.print("Opmode check: ");
        printf("Send, txCnhl: %u Opmode check: ", LMIC.txChnl);
      // Check if there is not a current TX/RX job running
    if (LMIC.opmode & (1 << 7)) {
      //Serial.println("OP_TXRXPEND, not sending");
        printf("OP_TXRXPEND, not sending\n");
    } else {
      //Serial.println("ok");
      printf("ok\n");
      // Prepare upstream data transmission at the next possible time.
      //   LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0);
      char buf[128];
      sprintf(buf, "NYC TTN test packet %u\n", xmit_count++);
      LMIC_setTxData2(1, (unsigned char *) buf, strlen(buf)-1, 0);
      printf("sending %s\n", buf);
    }
    // Schedule a timed job to run at the given timestamp (absolute system time)
    os_setTimedCallback(j, os_getTime()+sec2osticks(TRANSMIT_INTERVAL), do_send);
         
}