diff --git a/lambda-test/alert-test.c b/lambda-test/alert-test.c index 8d9c29b..5abdbd1 100644 --- a/lambda-test/alert-test.c +++ b/lambda-test/alert-test.c @@ -21,14 +21,15 @@ beepCount = 0; oscCount = 0; - // alert with two beep2 with a length of 2 - alert(2, 2, "a", "b"); + // alert with two beep2 with a length of 2 and tone 31 + alert(2, 2, 31, "a", "b"); oscillateBeep(); oscillateBeep(); // beep on, alertActive true assertTrue(beepCount == 2); assertTrue(oscCount == 2); + assertTrue(OCR1A = 31); assertTrue(bit_is_set(TCCR1A, COM1A0)); assertTrue(isAlertActive()); @@ -71,11 +72,12 @@ beepLength = 0; oscCount = 0; - beep(1, 2); + beep(1, 2, 31); assertTrue(beepCount == 1); assertTrue(beepLength == 2); assertTrue(oscCount == 0); + assertTrue(OCR1A = 31); return true; } @@ -89,11 +91,12 @@ beepLength = 0; oscCount = 0; - alert(1, 2, "a", "b"); + alert(1, 2, 31, "a", "b"); assertTrue(beepCount == 1); assertTrue(beepLength == 2); assertTrue(oscCount == 0); + assertTrue(OCR1A = 31); assertTrue(isAlertActive()); return true; @@ -108,11 +111,12 @@ beepLength = 0; oscCount = 0; - alert(1, 2, "a", "b"); + alert(1, 2, 31, "a", "b"); assertTrue(beepCount == 1); assertTrue(beepLength == 2); assertTrue(oscCount == 0); + assertTrue(OCR1A = 31); assertTrue(isAlertActive()); cancelAlert(); diff --git a/lambda-test/display-test.c b/lambda-test/display-test.c index bc5b104..b413f3f 100644 --- a/lambda-test/display-test.c +++ b/lambda-test/display-test.c @@ -45,7 +45,7 @@ updatePending = false; - alert(1, 1, "", ""); + alert(1, 1, 31, "", ""); assertTrue(isAlertActive()); cycleDisplay(); @@ -126,7 +126,7 @@ extern bool updatePending; updatePending = true; - alert(1, 1, "", ""); + alert(1, 1, 31, "", ""); assertTrue(isAlertActive()); // update should be skipped if alert is active diff --git a/lambda/alert.c b/lambda/alert.c index 53d1264..2beb6cd 100644 --- a/lambda/alert.c +++ b/lambda/alert.c @@ -11,6 +11,7 @@ #include #include #include +#include "integers.h" #include "alert.h" #include "sensors.h" #include "display.h" @@ -41,14 +42,18 @@ oscCount == beepLength * 2 - 1 ? oscCount = 0 : oscCount++; } -void beep(uint8_t const beeps, uint8_t const length) { +void beep(uint8_t const beeps, uint8_t const length, uint16_t const tone) { + TCNT1 = 0; + OCR1A = tone; oscCount = 0; beepCount = beeps; beepLength = length; } -void alert(uint8_t const beeps, uint8_t const length, +void alert(uint8_t const beeps, uint8_t const length, uint16_t tone, char* const line0, char* const line1) { + TCNT1 = 0; + OCR1A = tone; alertActive = true; oscCount = 0; beepCount = beeps; diff --git a/lambda/alert.h b/lambda/alert.h index e6328e3..0bc8b61 100644 --- a/lambda/alert.h +++ b/lambda/alert.h @@ -14,16 +14,18 @@ void oscillateBeep(void); /** - * Beeps the given number of beeps with the given length. Returns quickly so - * it can be called from an ISR. + * Beeps the given number of beeps with the given length and tone. + * Returns quickly so it can be called from an ISR. */ -void beep(uint8_t beeps, uint8_t length); +void beep(uint8_t beeps, uint8_t length, uint16_t tone); /** - * Beeps the given number of beeps with the given length and displays the - * given two texts on the first and second line of the display, respectively. + * Beeps the given number of beeps with the given length and tone and displays + * the given two texts on the first and second line of the display, + * respectively. */ -void alert(uint8_t beeps, uint8_t length, char* line0, char* line1); +void alert(uint8_t beeps, uint8_t length, uint16_t tone, + char* line0, char* line1); /** * Stops beeping and blocking display updates. diff --git a/lambda/command.c b/lambda/command.c index 43704c7..d463ee4 100644 --- a/lambda/command.c +++ b/lambda/command.c @@ -39,23 +39,23 @@ // simulation enable resetMeas(); simulation = true; - beep(1, 2); + beep(1, 2, 31); } else if (strcmp_P(fields[0], PSTR("sd")) == 0) { // simulation disable resetMeas(); simulation = false; - beep(1, 2); + beep(1, 2, 31); } else if (strcmp_P(fields[0], PSTR("le")) == 0) { // logging enable logging = true; - beep(1, 2); + beep(1, 2, 31); } else if (strcmp_P(fields[0], PSTR("ld")) == 0) { // logging disable logging = false; - beep(1, 2); + beep(1, 2, 31); } else if (strcmp_P(fields[0], PSTR("cm")) == 0) { // cycle menu @@ -65,7 +65,19 @@ // test alert char buf[16]; strcpy_P(buf, PSTR("Beep Beep Beep!")); - alert(3, 10, buf, fields[1]); + alert(3, 10, 15, buf, fields[1]); + } + else if (strcmp_P(fields[0], PSTR("tb")) == 0) { + // test beep + uint8_t length = 2; + if (fields[1] != '\0') { + length = atoi(fields[1]); + } + uint16_t tone = 31; + if (fields[2] != '\0') { + tone = atoi(fields[2]); + } + beep(1, length, tone); } else if (simulation) { Measurement meas = readMeas(fields, fieldCount); diff --git a/lambda/display.c b/lambda/display.c index c35219a..60a39f6 100644 --- a/lambda/display.c +++ b/lambda/display.c @@ -57,7 +57,7 @@ if (position > MENU_MAX_VALUES) { position = MENU_OFF; } - beep(1, 2); + beep(1, 2, 31); } void updateMeas(Measurement const meas) { diff --git a/lambda/lambda.c b/lambda/lambda.c index 1cfac6d..b03a8d1 100644 --- a/lambda/lambda.c +++ b/lambda/lambda.c @@ -44,7 +44,7 @@ initInterrupts(); initTimers(); - alert(1, 2, " Hello! ", ""); + alert(1, 2, 31, " Hello! ", ""); Measurement meas;