Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add real lessons specification, do not zero morse chars after playing…

… them, debounce will use WDT timer
  • Loading branch information...
commit 33a220c78f969c92c7f62e30593045a0553f61f6 1 parent 1e0518f
Martin Sivak authored
View
4 firmware/audio.c
@@ -101,10 +101,6 @@ void sample_morse(void)
/* last didah, send defined space */
l.space = buffer_data[buffer_ctrl.first] >> 4;
- /* zero data */
- buffer_data[buffer_ctrl.first] = 0;
- buffer_data[bitmask_id] = 0;
-
/* shift buffer pointer to the next char */
buffer_ctrl.first = (buffer_ctrl.first + 2) % AUDIO_BUFFER_SIZE;
}
View
97 firmware/lesson.c
@@ -2,19 +2,108 @@
#include "lesson.h"
#include "morse.h"
-#define RAND(N) (rand() / (RAND_MAX / N))
+#define R(N) (rand() / (RAND_MAX / N))
-uint8_t lesson_new(uint8_t chars, uint8_t length, uint8_t group_min, uint8_t group_max, uint8_t *buffer)
+#define LESSON_TABLE(name) lesson_entry name[]
+#define LESSON_ENTRY_LEN 2
+
+struct _lesson_e1 {
+ uint8_t startchar:6;
+ uint8_t endchar:6;
+ uint8_t groupmax:4;
+};
+
+struct _lesson_e2 {
+ uint8_t groupmin:4;
+ uint8_t effective_speed:4;
+ uint8_t speed:4;
+ uint8_t _reserved:4;
+};
+
+typedef union _lesson_e {
+ struct _lesson_e1 e1;
+ struct _lesson_e2 e2;
+ uint16_t storage;
+} lesson_entry;
+
+#define LESSON(xstartchar, xendchar, xgroupmin, xgroupmax, xspeed, xeffective_speed) {.e1 = {.startchar = xstartchar, .endchar = xendchar, .groupmax = xgroupmax - 10}},\
+ {.e2 = {.groupmin = xgroupmin, .effective_speed = xeffective_speed - 10, .speed = xspeed - xeffective_speed}}
+
+#define LESSON_COUNT(name) sizeof(name)
+
+#define T(table, id, sub) (eeprom_read_word((const uint16_t *)table + LESSON_ENTRY_LEN*id + sub))
+
+#define LESSON_STARTCHAR(v) ((v).e1.startchar)
+#define LESSON_ENDCHAR(v) ((v).e1.endchar)
+
+#define LESSON_EFFECTIVE(v) (10 + (v).e2.effective_speed)
+#define LESSON_SPEED(v) ((v).e2.speed + LESSON_EFFECTIVE(v))
+
+#define LESSON_GROUPMIN(v) ((v).e2.groupmin)
+#define LESSON_GROUPMAX(v) ((v).e1.groupmax)
+
+LESSON_TABLE(lessons) EEMEM = {
+ LESSON(0, 2, 5, 5, 18, 13),
+ LESSON(3, 5, 5, 5, 18, 13),
+ LESSON(0, 5, 5, 5, 18, 13),
+ LESSON(6, 8, 5, 5, 19, 14),
+ LESSON(0, 8, 5, 5, 19, 14),
+ LESSON(9, 11, 5, 5, 19, 14),
+ LESSON(0, 11, 5, 5, 20, 15),
+ LESSON(12, 14, 5, 5, 20, 15),
+ LESSON(0, 14, 5, 5, 20, 15),
+ LESSON(15, 17, 5, 5, 20, 16),
+ LESSON(0, 17, 5, 5, 20, 16),
+ LESSON(18, 20, 5, 5, 20, 16),
+ LESSON(0, 20, 5, 5, 20, 17),
+ LESSON(21, 23, 5, 5, 20, 17),
+ LESSON(0, 23, 5, 5, 20, 17),
+ LESSON(24, 27, 5, 5, 20, 18),
+ LESSON(0, 27, 5, 5, 20, 18), // alpha, +, =
+ LESSON(28, 32, 5, 5, 20, 18), // 1 - 5
+ LESSON(33, 37, 5, 5, 20, 19), // 6 - 0
+ LESSON(20, 37, 5, 5, 20, 19),
+ LESSON(38, 42, 5, 5, 20, 20),
+ LESSON(15, 42, 5, 5, 20, 20),
+ LESSON(0, 42, 5, 5, 20, 20)
+};
+
+uint8_t lesson_get(lesson_entry *table, uint8_t id,
+ uint8_t *startchar, uint8_t *endchar,
+ uint8_t *groupmin, uint8_t *groupmax,
+ uint8_t *speed, uint8_t *effective_speed)
+{
+ if (id>=LESSON_COUNT(table)) return 0;
+
+ lesson_entry e1 = {.storage = T(table, id, 0)};
+ lesson_entry e2 = {.storage = T(table, id, 1)};
+
+ *startchar = LESSON_STARTCHAR(e1);
+ *endchar = LESSON_ENDCHAR(e1);
+ *groupmin = LESSON_GROUPMIN(e2);
+ *groupmax = LESSON_GROUPMAX(e1);
+ *speed = LESSON_SPEED(e2);
+ *effective_speed = LESSON_EFFECTIVE(e2);
+
+ return 1;
+}
+
+uint8_t lesson_new(uint8_t id, uint8_t length, uint8_t *speed, uint8_t *effective_speed, uint8_t *buffer)
{
uint8_t idx = 0;
+
+ uint8_t group_min, group_max, char_min, char_max;
+
+ if (!lesson_get(lessons, id, &char_min, &char_max, &group_min, &group_max, speed, effective_speed)) return 0;
+
uint8_t group;
while (length>0 && length>group_min) {
if (group_min == group_max) group = group_min;
- else group = group_min + RAND(group_max - group_min);
+ else group = group_min + R(1 + group_max - group_min);
while (length>0 && group>0) {
- buffer[idx++] = MORSE_ID(RAND(chars));
+ buffer[idx++] = MORSE_ID(char_min + R(1 + char_max - char_min));
length--;
group--;
}
View
4 firmware/lesson.h
@@ -2,7 +2,9 @@
#define __MT_lesson_20120321_ms__
#include <stdint.h>
+#include <avr/eeprom.h>
-uint8_t lesson_new(uint8_t chars, uint8_t length, uint8_t group_min, uint8_t group_max, uint8_t *buffer);
+
+uint8_t lesson_new(uint8_t id, uint8_t length, uint8_t *speed, uint8_t *effective_speed, uint8_t *buffer);
#endif
View
43 firmware/main.c
@@ -13,7 +13,27 @@
#include "leds.h"
#include "lesson.h"
-uint8_t teaching_chars EEMEM = 3;
+uint8_t teaching_lesson EEMEM = 0;
+uint8_t randomizer EEMEM = 0;
+
+/* use watchdog interrupt for software debounce */
+ISR(WDT_vect)
+{
+ /* disable WD */
+ WDTCR |= _BV(WDCE);
+ WDTCR &= ~_BV(WDE);
+
+ /* enable input interrupts */
+}
+
+void debounce(void)
+{
+ /* disable input interrupts */
+
+ /* reset WDT timer */
+ WDTCR |= _BV(WDIE); /* interrupt has to be enabled, we need it and it prevents reboot */
+ WDTCR |= _BV(WDE);
+}
void setup(void)
{
@@ -41,8 +61,10 @@ void setup(void)
flash_init();
leds_init();
- /* initialize random */
-
+ /* initialize random and change seed for next boot */
+ uint8_t srand = eeprom_read_byte(&randomizer);
+ srandom(srand);
+ eeprom_write_byte(&randomizer, srand+1);
}
typedef uint8_t (*getchar_f)(uint8_t *);
@@ -182,7 +204,7 @@ uint8_t play_morse(uint8_t *chs, getchar_f get)
return v_id;
}
-static uint8_t buffer[23];
+static uint8_t buffer[31];
int main(void)
{
@@ -201,22 +223,23 @@ int main(void)
play_characters(s_welcome, getchar_eep);
// init morse
- audio_morse_init(500, 20, 12);
+ audio_morse_init(500, 20, 20);
play_morse(s_welcome_morse, getchar_eep);
_delay_ms(1500);
while(1) {
- uint8_t lesson = eeprom_read_byte(&teaching_chars);
+ uint8_t lesson = eeprom_read_byte(&teaching_lesson);
play_characters(s_lesson, getchar_eep);
- buffer[0] = (lesson / 10) + '0';
- buffer[1] = (lesson % 10) + '0';
+ buffer[0] = ((lesson+1) / 10) + '0';
+ buffer[1] = ((lesson+1) % 10) + '0';
buffer[2] = 0;
play_characters(buffer, getchar_str);
- lesson_new(lesson, 20, 3, 6, buffer);
+ uint8_t speed, effective_speed;
+ lesson_new(lesson, 30, &speed, &effective_speed, buffer);
audio_wait_init();
audio_play();
@@ -225,7 +248,7 @@ int main(void)
_delay_ms(1000);
- audio_morse_init(500, 20, 12);
+ audio_morse_init(500, speed, effective_speed);
play_morse(buffer, getchar_str);
_delay_ms(2000);
Please sign in to comment.
Something went wrong with that request. Please try again.