void simpleNickname(void) { int dx=0; int dy=0; static uint32_t ctr=0; ctr++; setExtFont(GLOBAL(nickfont)); dx=DoString(0,0,GLOBAL(nickname)); dx=(RESX-dx)/2; if(dx<0) dx=0; dy=(RESY-getFontHeight())/3; lcdFill(GLOBAL(nickbg)); setTextColor(GLOBAL(nickbg),GLOBAL(nickfg)); DoString(dx,dy,GLOBAL(nickname)); dataLove(); batteryLevel(); lcdDisplay(); getInputWaitTimeout(300); return; }
// **************************************************************************** // *** Main Function ********************************************************** // **************************************************************************** void main(void) { initialization(); sendTextMessage("What Hath God Wrought? Number 1"); while(1){ // sendTextMessage("What Hath God Wrought \r\n"); // int angleForMessage = getHandleAngle(); // char angleMessage[20]; // angleMessage[0]=0; // longToString(angleForMessage, angleMessage); // // concat(angleMessage, "\r \n"); // sendMessage("angle: "); // sendMessage(angleMessage); } waterPrimeTimeOut /= upstrokeInterval; leakRateTimeOut /= upstrokeInterval; //timeBetweenUpstrokes /= upstrokeInterval; // Do all of these values need to be reset each time around the loop? Or at the end of the day? 06-16-2014 int handleMovement = 0; // Either 1 or no 0 if the handle moving upward int timeOutStatus = 0; // Used to keep track of the water prime timeout int hour = 0; // Hour of day float angleCurrent = 0; // Stores the current angle of the pump handle float anglePrevious = 0; // Stores the last recoreded angle of the pump handle float angleDelta = 0; // Stores the difference between the current and previous angles float upStroke = 0; // 0 if there is no upstroke, otherwise stores the delta angle float upStrokePrime = 0; // Stores the sum of the upstrokes for calculating the prime float upStrokeExtract = 0; // Stores the sum of the upstrokes for calculating volume float volumeEvent = 0; // Stores the volume extracted float leakRatePrevious = 0; // Stores the previous Leak Rate incase if someone stats to pump before leakage can be measured //float extractionStartTime = 0; // The time of day (in seconds) when the extraction started //float extractionEndTime = 0; // The time of day (in seconds) when the extraction ended //float extractionDuration = 0; // The difference between the extraction start and end times long leakTimeCounter = 0; // Used to keep track of the leak time timeout float upStrokePrimeMeters = 0; // Stores the upstroke in meters float leakRate = 0; // Rate at which water is leaking from the rising main // float leakTime = 0; // The number of milliseconds from when the user stops pumping until there is no water (min: 0, max: 10 minutes) // long upStrokeDelayCounter = 0; // int currentHour; int currentDay; int currentHourDepthSensor; float deltaAverage; while (1) { //MAIN LOOP; repeats indefinitely //////////////////////////////////////////////////////////// // Idle Handle Monitor Loop // 2 axis of the accelerometer are constantly polled for // motion in the upward direction by comparing angles //////////////////////////////////////////////////////////// // Get the angle of the pump handle to measure against anglePrevious = getHandleAngle(); float previousAverage = 0; // Set the handle movement to 0 (handle is not moving) handleMovement = 0; // Loop until the handle starts moving float angleAccumulated=0; while (handleMovement == 0) { currentDay = getDateI2C(); if ( prevDay != currentDay){ //(prevDay != getDateI2C()){// it's a new day so send midNightMessage(); batteryFloat = batteryLevel(); midnightMessage(); } if (depthSensorInUse == 1){ // if the Depth sensor is present delayMs(1000); int currentDayDepthSensor = BcdToDec(getDateI2C()); delayMs(1000); if ((BcdToDec(getHourI2C() == 12) && (prevDayDepthSensor != currentDayDepthSensor))); midDayDepthRead(); } delayMs(upstrokeInterval); // Delay for a short time float newAngle = getHandleAngle(); float deltaAngle = abs(newAngle - anglePrevious); anglePrevious = newAngle; if (deltaAngle > 2){ // prevents floating accelerometer values when it's not actually moving angleAccumulated += deltaAngle; } // If the angle has changed, set the handleMovement flag if (angleAccumulated > 5) //05-30-14 Test for small delta's used to be angleDeltaThreshold { handleMovement = 1; } } ///////////////////////////////////////////////////////// // Priming Loop // The total amount of upstroke is recorded while the // upper water sensor is checked to determine if the // pump has been primed ///////////////////////////////////////////////////////// timeOutStatus = 0; // prepares timeoutstatus for new event // Get the angle of the pump handle to measure against anglePrevious = getHandleAngle(); upStrokePrime = 0; // gets the variable ready for a new event upStroke = 0; // gets variable ready for new event // averaging angle Code 9/17/2015 initializeQueue(anglePrevious); previousAverage = queueAverage(); // Averaging angle code while ((timeOutStatus < waterPrimeTimeOut) && !readWaterSensor()) { delayMs(upstrokeInterval); // delay a short time (10ms) // averaging angle Code 9/17/2015 pushToQueue(getHandleAngle()); //get Current angle of the pump handle deltaAverage = queueAverage() - previousAverage(); previousAverage = queueAverage(); // end averaging angle Code angleCurrent = getHandleAngle(); // Get the current angle of the pump handle angleDelta = angleCurrent - anglePrevious; // Calculate the change in angle of the pump handle //if(angleDelta > 5){ if (deltaAverage > 5){ // averaging angle code 9/17/2015 upStroke + = deltaAverage; // angle Code 9/17/2015 // upStroke += angleDelta; upStrokePrime += degToRad(upStroke); // Update the upStrokePrime timeOutStatus=0; // upstroke and current angle } else{ timeOutStatus++;} anglePrevious = angleCurrent; // Update the previous angle for the next calculation }