Add TINYGL_TEXT_MODE_ROTATE_STEP

main
Michael Hayes 15 years ago
parent 020a0d55d7
commit ab139beab9

@ -28,7 +28,7 @@
/** Define polling rates in Hz. The tweeter task needs to be the highest
priority since any jitter will make the sound awful. */
enum {TWEETER_TASK_RATE = 20000};
enum {TWEETER_TASK_RATE = 5000};
enum {DISPLAY_TASK_RATE = 300};
enum {TUNE_TASK_RATE = 100};
enum {BUTTON_TASK_RATE = 20};
@ -345,7 +345,6 @@ static void display_task (__unused__ void *data)
tinygl_init (DISPLAY_TASK_RATE);
tinygl_font_set (&font3x5_1);
tinygl_text_mode_set (TINYGL_TEXT_MODE_SCROLL_LEFT);
tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN);
tinygl_text_speed_set (10);

@ -25,7 +25,7 @@
#define BUTTON_TASK_RATE 10
#define DISPLAY_TASK_RATE 400
#define DISPLAY_TASK_RATE 200
/* Define text update rate (characters per 10 s). */
#define MESSAGE_RATE 10
@ -36,6 +36,8 @@
static tweeter_scale_t scale_table[] = TWEETER_SCALE_TABLE (TWEETER_TASK_RATE);
static tweeter_t tweeter;
static tweeter_obj_t tweeter_info;
static char *note_names[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
static uint8_t note = 0;
static void led_flash_task_init (void)
@ -73,11 +75,15 @@ static void button_task_init (void)
}
static void button_task (__unused__ void *data)
static void display_note (void)
{
static uint8_t note = 0;
static char *note_names[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
tinygl_clear ();
tinygl_text (note_names[note]);
}
static void button_task (__unused__ void *data)
{
button_update ();
navswitch_update ();
@ -87,6 +93,7 @@ static void button_task (__unused__ void *data)
note++;
else
note = 0;
display_note ();
}
if (navswitch_push_event_p (NAVSWITCH_SOUTH))
@ -95,15 +102,18 @@ static void button_task (__unused__ void *data)
note--;
else
note = ARRAY_SIZE (note_names) - 1;
display_note ();
}
if (button_push_event_p (BUTTON1))
if (button_push_event_p (BUTTON1)
|| navswitch_push_event_p (NAVSWITCH_PUSH))
{
tinygl_text (note_names[note]);
tweeter_note_play (tweeter, note + MIDI_NOTE_C4, 127);
}
if (button_release_event_p (BUTTON1))
if (button_release_event_p (BUTTON1)
|| navswitch_release_event_p (NAVSWITCH_PUSH))
{
tweeter_note_play (tweeter, 0, 127);
}
@ -116,6 +126,8 @@ static void display_task_init (void)
tinygl_font_set (&font3x5_1);
tinygl_text_speed_set (MESSAGE_RATE);
tinygl_text_mode_set (TINYGL_TEXT_MODE_ROTATE_STEP);
display_note ();
}

@ -16,6 +16,7 @@ static font_t *font;
static tinygl_text_mode_t text_mode = TINYGL_TEXT_MODE_STEP;
static uint8_t message_index;
static uint8_t scroll_pos = 0;
static uint8_t display_pos = 0;
static char message1[32] = "";
@ -144,6 +145,42 @@ static bool tinygl_font_pixel_get (char ch, uint8_t col, uint8_t row)
}
/** Draw character using current font.
@param ch character to draw
@param offset coordinates of top left position
@param rotate non-zero to rotate character. */
void tinygl_draw_char (char ch, tinygl_point_t offset, bool rotate)
{
uint8_t x;
uint8_t y;
if (rotate)
{
for (x = 0; x < font->height; x++)
{
for (y = 0; y < font->width; y++)
{
tinygl_draw_point (tinygl_point (x + offset.x,
TINYGL_HEIGHT - 1 - (y + offset.y)),
tinygl_font_pixel_get (ch, y, x));
}
}
}
else
{
for (x = 0; x < font->width; x++)
{
for (y = 0; y < font->height; y++)
{
tinygl_draw_point (tinygl_point (x + offset.x, y + offset.y),
tinygl_font_pixel_get (ch, x, y));
}
}
}
}
/** Display a character.
@param ch character to display
@return 1 if character fully displayed. */
@ -171,17 +208,17 @@ static bool tinygl_display_char (char ch)
if (scroll_pos != 0)
break;
for (x = 0; x < font->width; x++)
{
for (y = 0; y < font->height; y++)
{
tinygl_draw_point (tinygl_point (x, y),
tinygl_font_pixel_get (ch, x, y));
}
}
tinygl_draw_char (ch, tinygl_point (0, 0), 0);
break;
case TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN:
if ((display_pos + font->width) < TINYGL_WIDTH)
{
tinygl_draw_char (ch, tinygl_point (0, display_pos), 1);
display_pos += font->width + 1;
break;
}
display_scroll_down ();
for (x = 0; x < font->height; x++)
@ -190,6 +227,19 @@ static bool tinygl_display_char (char ch)
tinygl_font_pixel_get (ch, scroll_pos, x));
}
break;
case TINYGL_TEXT_MODE_ROTATE_STEP:
if (scroll_pos != 0)
break;
if ((display_pos + font->width) > TINYGL_HEIGHT)
display_pos = 0;
tinygl_draw_char (ch, tinygl_point (0, display_pos), 1);
display_pos += font->width + 1;
if ((display_pos + font->width) < TINYGL_WIDTH)
return 1;
break;
}
scroll_pos++;
@ -203,7 +253,10 @@ static bool tinygl_display_char (char ch)
static void tinygl_text_advance (void)
{
if (!message1[message_index])
{
message_index = 0;
display_pos = 0;
}
if (message1[message_index])
{
@ -219,6 +272,7 @@ void tinygl_text (const char *string)
{
message_index = 0;
scroll_pos = 0;
display_pos = 0;
strncpy (message1, string, sizeof (message1));
}

@ -108,7 +108,9 @@ typedef enum
/** Scrolling text. */
TINYGL_TEXT_MODE_SCROLL_LEFT,
/** Rotated scrolling text. */
TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN
TINYGL_TEXT_MODE_ROTATE_SCROLL_DOWN,
/* Stepping rotated text. */
TINYGL_TEXT_MODE_ROTATE_STEP
} tinygl_text_mode_t;
@ -144,6 +146,13 @@ void tinygl_text_mode_set (tinygl_text_mode_t mode);
void tinygl_font_set (font_t *pfont);
/** Draw character using current font.
@param ch character to draw
@param offset coordinates of top left position
@param rotate non-zero to rotate character. */
void tinygl_draw_char (char ch, tinygl_point_t offset, bool rotate);
/** Draw point.
@param point coordinates of point
@param pixel_value pixel value to draw point. */

Loading…
Cancel
Save