Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hardware beep is disabled for KH270 #122

Closed
t0mpr1c3 opened this issue Sep 6, 2023 · 1 comment · Fixed by #143
Closed

Hardware beep is disabled for KH270 #122

t0mpr1c3 opened this issue Sep 6, 2023 · 1 comment · Fixed by #143
Assignees
Milestone

Comments

@t0mpr1c3
Copy link
Contributor

t0mpr1c3 commented Sep 6, 2023

The hardware beeper is disabled for the KH270 because the delay() function interferes with setting the solenoids.

@jpcornil-git suggests a solution without timers by calling a procedure Beep:schedule() from the main loop and refactor the code to something like this (not compiled/tested):

void Beeper::beep(uint8_t length) {
  duration = length;
  currentState = s_beep_on;
}

void Beeper::schedule() { // scheduled from loop()
  switch (currentState) {
    case s_beep_on:
      analogWrite(PIEZO_PIN, BEEP_ON_DUTY);
      currentState = s_beep_wait;
      nextState = s_beep_off;
      nextTime = millis() + BEEP_DELAY;
      break;
    case s_beep_off:
      analogWrite(PIEZO_PIN, BEEP_OFF_DUTY);
      currentState = s_wait;
      nextState = s_beep_on;
      nextTime = millis() + BEEP_DELAY;
      duration--;
      break;
    case s_beep_wait:
      if (millis() > nextTime) {
        currentState = nextState; 
        if (duration <= 0) {
          analogWrite(PIEZO_PIN, BEEP_NO_DUTY);
          currentState = s_beep_idle; // default
        }
      }
      break;
    default:
      break;
  }
}

Something similar can be done for LED/alive indication.

@t0mpr1c3 t0mpr1c3 added the bug label Sep 7, 2023
@t0mpr1c3 t0mpr1c3 linked a pull request Sep 12, 2023 that will close this issue
2 tasks
@t0mpr1c3 t0mpr1c3 self-assigned this Oct 18, 2023
@X-sam X-sam assigned clholgat and unassigned t0mpr1c3 Mar 30, 2024
@X-sam X-sam added this to the v1.0 milestone Mar 30, 2024
@X-sam X-sam moved this to Needs Testing in AYAB 1.0.0 Release Tracking Mar 30, 2024
@clholgat
Copy link
Contributor

The 270 is beeping again.

@github-project-automation github-project-automation bot moved this from Needs Testing to Done in AYAB 1.0.0 Release Tracking Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

3 participants