Vanity-Screen.
authorWintermate <wintermute@hannover.ccc.de>
Wed, 23 Oct 2013 00:09:40 +0000 (02:09 +0200)
committerWintermate <wintermute@hannover.ccc.de>
Wed, 23 Oct 2013 00:09:40 +0000 (02:09 +0200)
Makefile
badge/main.c
badge/ui/vanity.c [new file with mode: 0644]
badge/ui/vanity.h [new file with mode: 0644]
vanity/test.png [new file with mode: 0644]
vanity/test.xpm [new file with mode: 0644]
vanity/vanity-convert.cc [new file with mode: 0644]

index 6f4fafb..67c7fb5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -50,7 +50,8 @@ SRCS = \
   badge/ui/event.c \\r
   badge/ui/font.c \\r
   badge/ui/menu.c \\r
-  badge/ui/sprite.c\r
+  badge/ui/sprite.c \\r
+  badge/ui/vanity.c\r
 \r
 SRCS += \\r
   dataflash/iobase.c \\r
index 774649d..54371bc 100644 (file)
@@ -59,6 +59,7 @@
 #include "ui/font.h"
 #include "ui/menu.h"
 #include "ui/sprite.h"
+#include "ui/vanity.h"
 #include "util/util.h"
 #include "jumpnrun/jumpnrun.h"
 
@@ -228,6 +229,10 @@ int main(void)
     scrolltest();
   }
 
+  if(badge_input_raw() & BADGE_EVENT_KEY_LEFT) {
+    badge_vanity_show();
+  }
+
   jumpnrun_play();
   usbmode();
 
diff --git a/badge/ui/vanity.c b/badge/ui/vanity.c
new file mode 100644 (file)
index 0000000..b2bebbd
--- /dev/null
@@ -0,0 +1,31 @@
+#include "vanity.h"
+
+#include "display.h"
+#include "event.h"
+#include <drivers/fatfs/ff.h>
+
+#define VANITY_IMAGE_FILE "/vanity.dat"
+
+void badge_vanity_read_from_fd(FIL *fd, badge_framebuffer *dest) {
+  UINT bytes;
+  f_read(fd, dest, sizeof(*dest), &bytes);
+}
+
+void badge_vanity_show(void) {
+  FIL fd;
+  badge_framebuffer fb;
+
+  if(FR_OK == f_open(&fd, VANITY_IMAGE_FILE, FA_OPEN_EXISTING | FA_READ)) {
+    badge_vanity_read_from_fd(&fd, &fb);
+    f_close(&fd);
+
+    badge_framebuffer_flush(&fb);
+
+    badge_event_t ev;
+    do {
+      ev = badge_event_wait();
+    } while(badge_event_type(ev) != BADGE_EVENT_USER_INPUT);
+
+    for(;;);
+  }
+}
diff --git a/badge/ui/vanity.h b/badge/ui/vanity.h
new file mode 100644 (file)
index 0000000..be1441e
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef INCLUDED_BADGE_UI_VANITY_H
+#define INCLUDED_BADGE_UI_VANITY_H
+
+void badge_vanity_show(void);
+
+#endif
diff --git a/vanity/test.png b/vanity/test.png
new file mode 100644 (file)
index 0000000..732f248
Binary files /dev/null and b/vanity/test.png differ
diff --git a/vanity/test.xpm b/vanity/test.xpm
new file mode 100644 (file)
index 0000000..537b122
--- /dev/null
@@ -0,0 +1,73 @@
+/* XPM */
+static char * test_xpm[] = {
+"96 68 2 1",
+"      g #FFFFFF",
+".     g #000000",
+"                                                                                                ",
+"                                                                                                ",
+"                                                                                                ",
+"                                                                                                ",
+"                                                                    .............               ",
+"                                                    .................            ..             ",
+"                                                  ..             . ..             ........      ",
+"           .....                                ..              .   .            ...     .      ",
+"         ..     ...                           ..              ..  ..            ...             ",
+"         .         .  ..........   ............               .....                             ",
+"        .         ....          .....        ....                                               ",
+"        .        .   .            . ..                                                          ",
+"                 .   .            ....                                                          ",
+"                 ..   .                                                                         ",
+"                   ...                                                                          ",
+"                                                                    .                           ",
+"                                                                    ..                          ",
+"                                                                    ..                          ",
+"                ..............                                      ..                          ",
+"            .....            ..                                     ..                          ",
+"        .....    ..                                                 . .                         ",
+"      ...         .                                                 . .                         ",
+"      .           ..                                                . .                         ",
+"      .            .                                                . .                         ",
+"                   .                                               .. .                         ",
+"                    .                                             .....                         ",
+"                    .                                              . .                          ",
+"                    .                                      .       . .                          ",
+"                    ..                                     ..............       .               ",
+"                     .                                             .  . .........               ",
+"                    .                                              .   .                        ",
+"                     .                                             .   .                        ",
+"                     .                                             .. ..                        ",
+"                     .              .....     .                     .  .                        ",
+"                      .            ..   ..   ...                    .  .                        ",
+"                      .            .     .   . .                    .   .                       ",
+"                      .          ..     ..    . .                  .    .                       ",
+"                      .         .       .     .  ..               .     .                       ",
+"                      .         .     ..     ..    ..             .      .                      ",
+"                      .          .   ..     ..       ..          .       ..                     ",
+"                      .          ....      ..         ..        .         .                     ",
+"                      .           ....     .            .      .           .                    ",
+"               .      .              ......              .   ..             ...                 ",
+"               ..     .                                  ....                 ...               ",
+"                .     .                          .........                                      ",
+"                 ..  .                             ......                                       ",
+"                  ....                                                                          ",
+"                                                                                                ",
+"                                                                                                ",
+"                                                                                                ",
+"                                                                                                ",
+"                                                                                                ",
+"                                                                                                ",
+"                                                                                                ",
+"                                                                                                ",
+"                                                                                                ",
+"                                                                                                ",
+"                                                                                                ",
+"                   ............    ...........................................                  ",
+"             ......            ....          .. ..          ... ..            ....              ",
+"            ..                ..  ..       .......          .     .               .             ",
+"            .               ..      .      .                 .....              ..              ",
+"                            .    ...                                         ...                ",
+"                            .....                                                               ",
+"                                                                                                ",
+"                                                                                                ",
+"                                                                                                ",
+"                                                                                                "};
diff --git a/vanity/vanity-convert.cc b/vanity/vanity-convert.cc
new file mode 100644 (file)
index 0000000..e08b77f
--- /dev/null
@@ -0,0 +1,49 @@
+#include <SFML/Graphics/Image.hpp>
+
+#include <cmath>
+#include <fstream>
+#include <iostream>
+#include <numeric>
+
+#include <badge/ui/display.h>
+
+double square(double x) { return x * x; }
+
+int main(int argc, char *argv[]) {
+  if(argc != 2) {
+    std::cerr << "Usage: " << argv[0] << " [ FILE ]\n";
+    return -1;
+  }
+
+  sf::Image img;
+  if(!img.loadFromFile(argv[1])) {
+    std::cerr << "Could not open file.\n";
+    return -2;
+  }
+
+  if(img.getSize().x != BADGE_DISPLAY_WIDTH ||
+     img.getSize().y != BADGE_DISPLAY_HEIGHT) {
+    std::cerr << "Image must be " << BADGE_DISPLAY_WIDTH << "x" << BADGE_DISPLAY_HEIGHT << " pixels.\n";
+    return -3;
+  }
+
+  badge_framebuffer fb = { { { 0 } } };
+
+  for(unsigned x = 0; x < BADGE_DISPLAY_WIDTH; ++x) {
+    for(unsigned y = 0; y < BADGE_DISPLAY_HEIGHT; ++y) {
+      sf::Color c = img.getPixel(x, y);
+
+      if(std::sqrt(0.241 * square(c.r / 255.) + 0.691 * square(c.g / 255.) + 0.068 * square(c.b / 255.)) < 0.5) {
+        badge_framebuffer_pixel_on(&fb, x, y);
+      }
+    }
+  }
+
+  std::ofstream out("vanity.dat", std::ios::out | std::ios::binary);
+
+  if(out) {
+    out.write(static_cast<char const *>(static_cast<void const *>(&fb)), sizeof(fb));
+  }
+
+  return 0;
+}
This page took 0.039994 seconds and 4 git commands to generate.