 unsigned long lastTriggerSignalTime = 0;
 bool lastTriggerType = false;
 
+// can be digital pins
 uint8_t heartbeatLEDGreenPin = 10;
 uint8_t heartbeatLEDRedPin = 6;
 

#if !defined(DISABLE_DISPLAY) && ROLE == ROLE_GROUND
LiquidCrystal display(10, 9, 5, 4, 3, 2);
#endif
byte addresses[][6] = { *(byte*)"1Node", *(byte*)"2Node" };
byte primaryPipeIndex = 1;

// TODO: Choose numbers that make sense
const byte triggerVal = 0b11111111;
const byte resetVal = 0b10101010;
const byte heightInitialVal = 0b01010101;
const byte ackVal = 0b11110000;

#if ROLE == ROLE_GROUND
#define HEARTBEAT_THRESH_MILLIS 1000
#define DISPLAY_TIME_MILLIS 1000

uint8_t triggerButtonPin = A0;
uint8_t resetButtonPin = A1;


            byte packetData[sizeof(float) + 1] = { heightInitialVal };
            float* packetFloatPortion = (float*)&packetData[1];
            *packetFloatPortion = altitude;

            validateAck(sendData(&packetData, sizeof(packetData)));
            break;
        default:
            Serial.print(F("Received unknown signal "));
            Serial.println((int)recvByte);
            break;
        }
    }
#endif
}

void validateAck(byte ackResponse) {
    boolean correctResponse = (ackResponse == ackVal);

    if (correctResponse) {
        Serial.println(F("Comms healthy"));
    }
    else {
        Serial.println(F("Bad ack received! This probably means that the connection is unstable."));
    }

#if ROLE == ROLE_GROUND
    isCommHealthy = correctResponse;
    // We have validated that data was successfully sent; we can consider this a heartbeat.
    lastHeartbeat = millis();
#endif
}

// receives numBytes bytes from the radio into recvBuf
bool receiveData(void* recvBuf, uint8_t numBytes) {
    if (radio.available()) {
        radio.read(recvBuf, numBytes);
        // acks that we received it
        radio.writeAckPayload(1, &ackVal, 1);
        return true;
    }
    else {
        return false;
    }
}

// receives a single byte from the radio
byte receiveByte() {
    byte val = 0;
    receiveData(&val, 1);
    return val;
}

// send numBytes bytes on the radio from val
byte sendData(void* val, int numBytes) {
    byte recvByte;

    if (radio.available())
        Serial.println(F("Data available before request was sent! This probably means something was not read correctly."));

    Serial.print(F("Sending data {"));
    for (int i = 0; i < numBytes; i++)
    {
        Serial.print(((byte*)val)[i]);
        Serial.print(F(", "));
    }
    Serial.println(F("}"));

    radio.stopListening();
    bool writeResult = radio.write(val, numBytes);
    radio.startListening();

    if (writeResult) {
        if (!radio.available()) {
            Serial.println(F("Empty recv!"));
            return 0;
        }
        else {
            radio.read(&recvByte, 1);
            radio.writeAckPayload(1, &ackVal, 1);

            Serial.print(F("Received ack"));
        }
    }
    else {
        Serial.println(F("Unknown radio write failure"));
        return 0;
    }

    return recvByte;
}

// send a single byte on the radio
byte sendByte(byte val)
{
    return sendData(&val, 1);
}
