void fillLine(void) { char i = 16-charactersSinceFill-1; if (charactersSinceFill >= 16) return fill(); while(i-- >= 0) { sendLiteralBytes(" "); charactersSinceFill ++; } }
void fill(void) { char i = 16*2-charactersSinceFill-1; //sendDec(i); while(i-- >= 0) { sendLiteralBytes(" "); } charactersSinceFill = 0; }
void displayStatus(char status) { sendLiteralBytes("stat:"); sendBinPad(status); sendLiteralBytes("\n"); if (status & 0b1000000) sendLiteralBytes("DR "); if (status & 0b100000) sendLiteralBytes("DS "); if (status & 0b10000) sendLiteralBytes("RT "); if (status & 0b1) sendLiteralBytes("TXF "); sendLiteralBytes("\n"); }
void displayStatus(char status) { setPosition(0,0); sendLiteralBytes("stat:"); sendBinPad(status); fillLine(); if (runFlag == 0) { setPosition(0,15); sendLiteralBytes("_"); } runFlag = !runFlag; setPosition(1,0); if (status & 0b1000000) sendLiteralBytes("DR "); if (status & 0b100000) sendLiteralBytes("DS "); if (status & 0b10000) sendLiteralBytes("RT "); if (status & 0b1) sendLiteralBytes("TXF "); fill(); }
void sendBinPad(unsigned char num) { sendLiteralBytes("0b"); sendCharAsBase(num,2,1); }
void sendHex(unsigned char num) { sendLiteralBytes("0x"); sendCharAsBase(num,16,0); }
void masterMain() { //master short i; short l; short nextSlot; int clients[MAX_CLIENTS]; int clientInfo[MAX_CLIENTS]; nrf_init(); delay(); nrf_txmode(); delay(); nextSlot = 0; for (i=0; i<MAX_CLIENTS; i++) { clients[i] = 0; } sendLiteralBytes("\nLoop Start\n"); LED_RED = 0; LED_GREEN = 0; // while(1) { // LED_RED = !LED_RED; // LED_GREEN = nrf_send(&tx_buf,&rx_buf); // delay(); // } while(1) { LED_RED = !LED_RED; delay(); sendIntArray(&clients,MAX_CLIENTS); sendLiteralBytes("\n"); nrf_setTxAddr(0); //master channel nrf_setRxAddr(0,0); //master channel tx_buf[0] = 0x42; tx_buf[1] = nextSlot+1; //sendLiteralBytes("Attempt Send\n"); //displayStatus(nrf_getStatus()); if (nrf_send(&tx_buf,&rx_buf)) { sendLiteralBytes("\nClient Connected!\n"); clients[nextSlot] = 1; //find the next available slot nextSlot = -1; for (i=0; i<MAX_CLIENTS; i++) { if (clients[i] == 0) { nextSlot = i; break; } } } for (i=0; i<MAX_CLIENTS; i++) { if (clients[i] != 0) { nrf_setTxAddr(i+1); //slave channel nrf_setRxAddr(0,i+1); //slave channel if (nrf_send(&tx_buf,&rx_buf)) { clients[i] = 1; clientInfo[i] = 1; } else { clients[i]++; if (clients[i] > 3) { sendLiteralBytes("Client Disconnected!\n"); clients[i] = 0; clientInfo[i] = 0; } for (l=0; l<MAX_CLIENTS; l++) { if (clients[l] == 0) { nextSlot = l; break; } } } } } } }