int16_t SpeedSense::readInputValue(uint32_t now) { uint16_t rpm = 0; uint32_t last_interrupt_millis = 0; int16_t current_rpms = -1; if(runMode == Task::RunMode::production) { noInterrupts(); last_interrupt_millis = v_last_rpm_pulse_millis; rpm = v_current_rpm; interrupts(); } else if(runMode == Task::RunMode::test) { // // Storing the test values in PROGMEM saves some space // but makes you have to pull the values out by hand // rather than just accessing them like normal // // This speed test deck is setup so that the last known // RPM / MPH will stick - i.e. it won't go down when the // test data runs out. // static const PROGMEM uint32_t test_data[][2] = { {1,0}, {10000,34}, {20000,70}, {30000,80}, {40000,100}, {45000,120}, {50000,140}, {55000,160}, {60000,170}, {65000,180}, {70000,180}, {75000,180}, {85000,180} }; for(int i = 0;i < sizeof(test_data) / sizeof(test_data[0]);i++) { uint32_t test_time = pgm_read_dword_near((uint16_t)&test_data[i][0]); uint32_t test_value = pgm_read_dword_near((uint16_t)&test_data[i][1]); if((m_last_input_time < test_time) && (now >= test_time)) { last_interrupt_millis = now; rpm = test_value; break; } } } if((now > last_interrupt_millis) && ((now - last_interrupt_millis) > MAX_PULSE_AGE_MILLIS)) { rpm = 0; } m_last_input_time = now; return rpm; }
void moveF(void) { uint32_t F=M.AWGdesiredF; uint8_t i=6; do { // Find range if(F>=pgm_read_dword_near(Powersof10+i)) break; } while(i--); uint32_t add=pgm_read_dword_near(Powersof10+i-2); if(testbit(Misc,negative)) F-=add; else if(testbit(Misc, bigfont)) F+=add; else { // Shortcuts if(i==2) i=7; F=pgm_read_dword_near(Powersof10+i-1); } M.AWGdesiredF = F; }
// currentTide calculation function, takes a DateTime object from real time clock float TideCalc::currentTide(DateTime now) { // Calculate difference between current year and starting year. YearIndx = now.year() - startYear; // Calculate hours since start of current year. Hours = seconds / 3600 currHours = (now.unixtime() - pgm_read_dword_near(&startSecs[YearIndx])) / float(3600); // Shift currHours to Greenwich Mean Time currHours = currHours + adjustGMT; // *****************Calculate current tide height************* tideHeight = Datum; // initialize results variable, units of feet. for (int harms = 0; harms < 37; harms++) { // Step through each harmonic constituent, extract the relevant // values of Nodefactor, Amplitude, Equilibrium argument, Kappa // and Speed. currNodefactor = pgm_read_float_near(&Nodefactor[YearIndx][harms]); currAmp = pgm_read_float_near(&Amp[harms]); currEquilarg = pgm_read_float_near(&Equilarg[YearIndx][harms]); currKappa = pgm_read_float_near(&Kappa[harms]); currSpeed = pgm_read_float_near(&Speed[harms]); // Calculate each component of the overall tide equation // The currHours value is assumed to be in hours from the start of the // year, in the Greenwich Mean Time zone, not the local time zone. tideHeight = tideHeight + (currNodefactor * currAmp * cos( (currSpeed * currHours + currEquilarg - currKappa) * DEG_TO_RAD)); } //******************End of Tide Height calculation************* return tideHeight; // Output of tideCalc is the tide height, units of feet }
uint32_t ledLarsonOpposite(uint8_t *animationFrameNumber) { uint32_t frame; uint8_t actualFrameNumber; actualFrameNumber = (*animationFrameNumber); frame = pgm_read_dword_near(oppositeLarsonPattern + actualFrameNumber); (*animationFrameNumber)++; (*animationFrameNumber) %= (OPPOSITE_LARSON_STEPS); // rollover at 40 updates return frame; }
uint32_t ledLarsonTogether(uint8_t *animationFrameNumber) { uint32_t frame; uint8_t actualFrameNumber; actualFrameNumber = (*animationFrameNumber); frame = pgm_read_dword_near(larsonPattern + actualFrameNumber); (*animationFrameNumber)++; (*animationFrameNumber) %= (LARSON_STEPS); // rollover at 40 updates return frame; }
byte Beak::chirp(const char *chirpStr, int16_t nFrames, SynthFrame *frames) { static const uint32_t hPhaseStep = pgm_read_dword_near(phaseSteps + 17); static const uint32_t jPhaseStep = pgm_read_dword_near(phaseSteps + 19); uint32_t phaseStep = jPhaseStep; // check length and return warning if incorrect const char *cs = chirpStr; byte count = CHIRP_STRING_LENGTH; while(*cs++ && --count) { } if(count || *cs) { return CHIRP_STRING_LENGTH_WARNING; } TheSynth.beginFrameSequence(nFrames, frames); head(hPhaseStep); // all chirps start with these two tones append(hPhaseStep); append(jPhaseStep); while(const char code = *chirpStr++) { // assignment, not comparison phaseStep = phaseStepForCharCode(code); if(phaseStep) { append(phaseStep); } else { return BAD_CHIRP_CODE_WARNING; } } tail(phaseStep); TheSynth.endFrameSequence(); return TheSynth.play(); }
uint32_t Beak::phaseStepForCharCode(const char charCode) { byte index; if(charCode >= 'a' && charCode <= 'v') { index = charCode - 'a' + 10; } else if(charCode >= '0' && charCode <= '9') { index = charCode - '0'; } else { // BAD_CHIRP_CODE_WARNING; return 0L; } return pgm_read_dword_near(phaseSteps + index); }
void SendInt(uint32_t val, uint8_t digits){ uint32_t num = val; for(uint8_t idx = 0; idx < 10 ; idx++) { uint8_t outNum = 0; uint32_t CmpNum = pgm_read_dword_near(num10s + idx); for(uint8_t i = 0; i < 10 ; i++) { if(num>=CmpNum) { num -= CmpNum; outNum++; } else { break; } } if(10-idx<=digits){ SerialSend('0' + outNum);\ } } }
uint32_t ArduinoProgramMemory::readDwordNear(const void* addr) { return pgm_read_dword_near(addr); }
int16_t ThrottleSense::readInputValue(uint32_t now) { int16_t input_level = m_input_level; if(runMode == Task::RunMode::production) { uint32_t input_level_average = 0; int val = analogRead(0); // Serial1.println(val); input_level = map(val,0,819,0,100); /// seems to work if (input_level > 100) { input_level = 100; } // Serial.print("throttle:"); // Serial.println(val); } else if(runMode == Task::RunMode::test) { static const PROGMEM uint32_t test_data[][2] = { {0,0}, {6000,1}, {10000,1}, {11000,1}, {16000,1}, {20000,1}, {21000,20}, {23000,20}, {25000,20}, {27000,91}, {29000,91}, {31000,91}, {33000,91}, {35000,91}, {37000,91}, {39000,91}, {41000,91}, {43000,91}, {45000,91}, {47000,91}, {49000,91}, {51000,40}, {53000,40}, {55000,91}, {57000,20}, {59000,10}, {61000,0} }; for(int i = 0;i < sizeof(test_data) / sizeof(test_data[0]);i++) { uint32_t test_time = pgm_read_dword_near((uint16_t)&test_data[i][0]); uint32_t test_value = pgm_read_dword_near((uint16_t)&test_data[i][1]); if(m_last_input_time <= test_time && now >= test_time) { input_level = test_value; break; } } } m_last_input_time = now; return (input_level); }