no longer crashes the mc
This commit is contained in:
		
							parent
							
								
									b56272cfc6
								
							
						
					
					
						commit
						d52dc0263c
					
				@ -197,19 +197,13 @@ void loop() {
 | 
				
			|||||||
        TickSecond();
 | 
					        TickSecond();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    yield();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if(bitReadyForRead) {
 | 
					    if(bitReadyForRead) {
 | 
				
			||||||
        bitReadyForRead = 0;
 | 
					        bitReadyForRead = 0;
 | 
				
			||||||
        readBit();
 | 
					        readBit();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    yield();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    PPSLowIfRequired();
 | 
					    PPSLowIfRequired();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    yield();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (displayUpdateRequired) {
 | 
					    if (displayUpdateRequired) {
 | 
				
			||||||
        updateDisplay();
 | 
					        updateDisplay();
 | 
				
			||||||
        displayUpdateRequired = 0;
 | 
					        displayUpdateRequired = 0;
 | 
				
			||||||
@ -244,46 +238,34 @@ void TickSecond() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void readBit() {
 | 
					void readBit() {
 | 
				
			||||||
    char buf[255];
 | 
					    //char buf[255];
 | 
				
			||||||
    unsigned int ms = lastBitHighMS;
 | 
					    //sprintf(buf, "*** carrier was high for %sms befor \n", lastBitHighMS);
 | 
				
			||||||
    sprintf(buf, "*** carrier was high for %sms befor \n", ms);
 | 
					    //Serial.print(buf);
 | 
				
			||||||
    Serial.print(buf);
 | 
					 | 
				
			||||||
    displayUpdateRequired++;
 | 
					    displayUpdateRequired++;
 | 
				
			||||||
    registerBit(convertBit(ms));
 | 
					    registerBit(convertBit(lastBitHighMS));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int convertBit(unsigned int ms) {
 | 
					int convertBit(unsigned int ms) {
 | 
				
			||||||
    char buf[255];
 | 
					    char buf[255];
 | 
				
			||||||
    /*
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
       20% - marker
 | 
					 | 
				
			||||||
       50% - one bit
 | 
					 | 
				
			||||||
       80% - zero bit
 | 
					 | 
				
			||||||
       our cutoff points will be 50% and 80%
 | 
					 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
    char bitbuf[20];
 | 
					    char bitbuf[20];
 | 
				
			||||||
 | 
					 | 
				
			||||||
    int output = 0;
 | 
					    int output = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    output = ZEROBIT;
 | 
					    output = ZEROBIT;
 | 
				
			||||||
    sprintf(bitbuf, "ZERO");
 | 
					    sprintf(bitbuf, "ZERO");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return output;
 | 
					   if (ms < 800) {
 | 
				
			||||||
    /*
 | 
					 | 
				
			||||||
       if (rawVal < 800) {
 | 
					 | 
				
			||||||
       output = ONEBIT;
 | 
					       output = ONEBIT;
 | 
				
			||||||
       sprintf(bitbuf, "ONE");
 | 
					       sprintf(bitbuf, "ONE");
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
       if (rawVal < 680) {
 | 
					   if (ms < 400) {
 | 
				
			||||||
       output = MARKBIT;
 | 
					       output = MARKBIT;
 | 
				
			||||||
       sprintf(bitbuf, "MARK");
 | 
					       sprintf(bitbuf, "MARK");
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
       sprintf(buf, "frame rawVal=%d, bit=%s\n", rawVal, bitbuf);
 | 
					   sprintf(buf, "frame prevHighMs=%s, bit=%s\n", ms, bitbuf);
 | 
				
			||||||
   Serial.print(buf);
 | 
					   Serial.print(buf);
 | 
				
			||||||
   return output;
 | 
					   return output;
 | 
				
			||||||
     */
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void registerBit(int doot) {
 | 
					void registerBit(int doot) {
 | 
				
			||||||
@ -291,6 +273,7 @@ void registerBit(int doot) {
 | 
				
			|||||||
        frameCounter++;
 | 
					        frameCounter++;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (doot == MARKBIT) {
 | 
					    if (doot == MARKBIT) {
 | 
				
			||||||
        if (lastBitReceived == MARKBIT) {
 | 
					        if (lastBitReceived == MARKBIT) {
 | 
				
			||||||
            // two mark bits in a row means we are in the first second of the minute
 | 
					            // two mark bits in a row means we are in the first second of the minute
 | 
				
			||||||
@ -363,11 +346,10 @@ void updateDisplay() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if (lossOfSignal) {
 | 
					    if (lossOfSignal) {
 | 
				
			||||||
        sprintf(statusString, "LOS");
 | 
					        sprintf(statusString, "LOS");
 | 
				
			||||||
    }
 | 
					    } else {
 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (millisSinceBoot - frameStartTime < 10000) {
 | 
					 | 
				
			||||||
        sprintf(statusString, "RX(syncing)");
 | 
					        sprintf(statusString, "RX(syncing)");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (minuteSync) {
 | 
					    if (minuteSync) {
 | 
				
			||||||
        sprintf(statusString, "RX(bit %d)", frameCounter);
 | 
					        sprintf(statusString, "RX(bit %d)", frameCounter);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user