AP 0014 - Support for messages on segmented AP

This commit is contained in:
jjwbruijn
2023-05-09 11:27:13 +02:00
parent e3bfaaa62f
commit 1b363860d1
10 changed files with 67 additions and 14 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -4,6 +4,7 @@
#define SOLUM_SEG_UK 0xF0
#define SOLUM_NODISPLAY 0xFF
#define CAPABILITY_HAS_EXT_POWER 0x10
#define CAPABILITY_HAS_WAKE_BUTTON 0x20
#define CAPABILITY_HAS_NFC 0x40
#define CAPABILITY_NFC_WAKE 0x80
@@ -17,3 +18,4 @@
#define DATATYPE_IMG_RAW_1BPP_DIRECT 0x3F // only for 1.54", don't write to EEPROM, but straightaway to the EPD
#define DATATYPE_NFC_RAW_CONTENT 0xA0 // raw memory content for the NT3H1101
#define DATATYPE_NFC_URL_DIRECT 0xA1 // URL format for NT3H1101
#define DATATYPE_UK_SEGMENTED 0x51 // Segmented data for the UK Segmented display type

View File

@@ -25,10 +25,15 @@ extern uint8_t __xdata curPendingData;
extern uint8_t __xdata curNoUpdate;
#if (SCREEN_WIDTH == 1)
// Segmented display type
bool __xdata showAPDisplay = true;
bool __xdata SisInverted = true;
void epdInitialize() {
epdEnable();
pr("Setting up EPD\n");
if (!epdSetup(false)) pr("EPD setup failed\n");
if (!epdSetup(true)) pr("EPD setup failed\n");
epdSetPos(0);
epdpr("boot");
setEPDIcon(EPD_ICON_DIAMOND, true);
@@ -39,6 +44,7 @@ void epdInitialize() {
}
void epdShowRun() {
if(!showAPDisplay) return;
epdClear();
epdSetPos(0);
epdpr("run");
@@ -58,11 +64,13 @@ void epdShowRun() {
if (updateCount == 10) {
while (is_drawing()) {
};
epdSetup(true);
epdSetup(false);
SisInverted = false;
} else if (updateCount == 20) {
while (is_drawing()) {
};
epdSetup(false);
epdSetup(true);
SisInverted = true;
updateCount = 0;
}
}

View File

@@ -36,6 +36,13 @@ static uint8_t blockCount = 0;
static uint32_t __xdata lastRequest = 0;
static bool dataRequested = false;
#if (SCREEN_WIDTH == 1)
extern bool __xdata showAPDisplay;
extern bool __xdata SisInverted;
extern uint8_t __xdata epdSegmentData[12];
#endif
#if (HAS_EEPROM == 1)
static bool validateBlockData() {
struct blockData *bd = (struct blockData *)blockbuffer;
// pr("expected len = %04X, checksum=%04X\n", bd->size, bd->checksum);
@@ -60,6 +67,7 @@ void epdWriteByte(uint8_t b) {
}
void fakeTagGetData() {
// non-segmented
if ((timerGet() - lastRequest) > (1200UL * 1333)) {
if (dataRequested == false) {
if (ad.dataSize) {
@@ -100,14 +108,49 @@ void fakeTagGetData() {
}
}
}
#endif
void fakePendingData(struct pendingData *pd) {
#if (SCREEN_WIDTH == 1)
// segmented data, this contains all the info. No block transfers
if (pd->availdatainfo.dataType == DATATYPE_UK_SEGMENTED) {
if (pd->availdatainfo.dataVer == 0 && pd->availdatainfo.dataSize == 0) {
showAPDisplay = true;
} else {
showAPDisplay = false;
// check if we should re-init the EPD for the correct image (inverted or not)
//if (SisInverted != (pd->availdatainfo.dataTypeArgument & 0x01)) {
if (pd->availdatainfo.dataTypeArgument & 0x01) {
SisInverted = true;
} else {
SisInverted = false;
}
epdSetup(SisInverted);
//}
epdSetPos(0);
char *epdp = (char *)&(pd->availdatainfo.dataVer);
for (uint8_t c = 0; c < 10; c++) {
writeCharEPD(epdp[c]);
}
setEPDIcon(0xFFFF, false);
// memcpy(epdSegmentData, &(pd->availdatainfo.dataVer), 12);
setEPDIcon(*((uint16_t *)(epdp + 10)), true);
epdUpdate();
}
espNotifyXferComplete(fakeTagMac);
}
#else
// non-segmented tags, we'll have to do a block transfer here
if ((pd->availdatainfo.dataType == DATATYPE_IMG_RAW_1BPP) || (pd->availdatainfo.dataType == DATATYPE_IMG_RAW_2BPP) || (pd->availdatainfo.dataType == DATATYPE_IMG_RAW_1BPP_DIRECT)) {
memcpy(&ad, &(pd->availdatainfo), sizeof(struct AvailDataInfo));
blockCount = 0;
fakeTagTrafficPending = true;
dataRequested = false;
}
#endif
}
void fakeTagCheckIn() {
@@ -119,6 +162,7 @@ void fakeTagCheckIn() {
adr->hwType = HW_TYPE;
adr->lastPacketLQI = 100;
adr->lastPacketRSSI = 100;
adr->capabilities |= CAPABILITY_HAS_EXT_POWER;
if (firstboot) {
adr->wakeupReason = 0xFC;
firstboot = false;

View File

@@ -30,7 +30,7 @@
struct pendingData __xdata pendingDataArr[MAX_PENDING_MACS];
// VERSION GOES HERE!
uint16_t __xdata version = 0x0013;
uint16_t __xdata version = 0x0014;
#define RAW_PKT_PADDING 2
@@ -272,8 +272,8 @@ void processSerial(uint8_t lastchar) {
struct pendingData *pd = (struct pendingData *)serialbuffer;
#if (AP_EMULATE_TAG == 1)
if (memcmp(pd->targetMac, fakeTagMac, 8) == 0) {
fakePendingData(pd);
pr("ACK>\n");
fakePendingData(pd);
} else {
#endif
int8_t slot = findSlotForMac(pd->targetMac);
@@ -301,7 +301,7 @@ void processSerial(uint8_t lastchar) {
if (bytesRemain == 0) {
if (checkCRC(serialbuffer, sizeof(struct pendingData))) {
struct pendingData *pd = (struct pendingData *)serialbuffer;
#if (AP_EMULATE_TAG == 1)
#if (AP_EMULATE_TAG == 1 && HAS_EEPROM == 1)
if (memcmp(pd->targetMac, fakeTagMac, 8) == 0) {
fakeTagTrafficPending = false;
pr("ACK>\n");
@@ -310,7 +310,7 @@ void processSerial(uint8_t lastchar) {
// deleteAllPendingDataForVer((uint8_t *)&pd->availdatainfo.dataVer);
deleteAllPendingDataForMac((uint8_t *)&pd->targetMac);
pr("ACK>\n");
#if (AP_EMULATE_TAG == 1)
#if (AP_EMULATE_TAG == 1 && HAS_EEPROM == 1)
}
#endif
} else {
@@ -416,6 +416,9 @@ void espNotifyAPInfo() {
countSlots();
pr("PEN>%02X\n", curPendingData);
pr("NOP>%02X\n", curNoUpdate);
#if (AP_EMULATE_TAG == 1)
fakeTagCheckIn();
#endif
}
// process data from tag
@@ -660,7 +663,7 @@ void sendPong(void *__xdata buf) {
radioTx(radiotxbuffer);
}
#if (AP_EMULATE_TAG == 1)
#if (AP_EMULATE_TAG == 1 && HAS_EEPROM == 1)
void attemptFakeTagUpdate() {
if (memcmp(fakeTagMac, lastBlockMac, 8) == 0) {
lastBlockRequest = timerGet();
@@ -726,9 +729,6 @@ void main(void) {
pr("RES>\n");
pr("RDY>\n");
#if (AP_EMULATE_TAG == 1)
fakeTagCheckIn();
#endif
housekeepingTimer = timerGet();
@@ -781,8 +781,7 @@ void main(void) {
loopCount--;
if (loopCount == 0) {
#if (HAS_SCREEN == 1)
#if (AP_EMULATE_TAG == 1)
#if (AP_EMULATE_TAG == 1 && HAS_EEPROM == 1)
if (fakeTagTrafficPending) attemptFakeTagUpdate();
#else
countSlots();

View File

@@ -7,7 +7,7 @@
#define HAS_EEPROM 0
#define HAS_SCREEN 1
#define AP_EMULATE_TAG 0
#define AP_EMULATE_TAG 1
#define HW_TYPE SOLUM_SEG_UK