Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
time zone/flashcard watchface
#1
I've created another watchface.  It shows the time and date for your present timezone, plus three other hardwired zones.
       
It also does flashcards for learning Japanese.  It shows a bitmap for a character and then a few seconds later, it shows the pronunciation and meaning.

you need to change the watchface in main to this:
 display_set(watchface_zoneflash);

this is the zoneflash.c file, which goes in the watchfaces folder.
Code:
#include "common.h"
#include "watchfaces/flash.h"

static void drawDate(void);
static void drawFlash(void);
static void drawTimeZones(void);
static display_t draw(void);
static byte secs;
static char extra1,extra2, extra3;
static int newtime1, newtime2, newtime3;

void watchface_zoneflash()
{
 display_setDrawFunc(draw);
 buttons_setFuncs(NULL, menu_select, NULL);
}

static display_t draw()
{
 drawDate();

 draw_string("JP", false, 0, 10);
 draw_string(time_timeStr(), false, 21, 10);
 // Draw battery icon
 drawBattery();

 drawTimeZones();
 drawFlash();

 return DISPLAY_DONE;
}
static void drawTimeZones()
{
 char buff[6];

 //  if (timeDate.time.secs == 0){
   extra1 = ' ';
   newtime1 = timeDate.time.hour-9;
   if (newtime1 < 0){
     newtime1 = 24+newtime1;
     extra1 = '-';
   }
   
   newtime2 = timeDate.time.hour-14;
   extra2 = ' ';
   if (newtime2 < 0){
     newtime2 = 24+newtime2;
     extra2 = '-';
   }
   newtime3 = timeDate.time.hour-17;
   extra3 = ' ';
   if (newtime3 < 0){
     newtime3 = 24+newtime3;
     extra3 = '-';
   }
   //}
 sprintf_P(buff, PSTR("%2s %02hhu%c"), "UK",newtime1,extra1);
 draw_string(buff, false, 0, 20);
 sprintf_P(buff, PSTR("%2s %02hhu%c"), "NY",newtime2,extra2);
 draw_string(buff, false, 0, 30);
 sprintf_P(buff, PSTR("%2s %02hhu%c"), "CA",newtime3,extra3);
 draw_string(buff, false, 0, 40);
}
static void drawFlash()
{
  static byte jinum;
  byte modval = 6;
  if(timeDate.time.secs % modval == 0 && timeDate.time.secs != secs)
  {
     jinum = rand() % NUMLEX;
  }
  if (timeDate.time.secs % modval > 3)
  {
    draw_string(translation[jinum], false, 50, 20);
    draw_string(romanji[jinum], false, 50, 30);
  }
  image_s img = newImage(50,40, &ji[147*jinum], 25*2-1, 24, WHITE, NOINVERT, 0);
  draw_bitmap_set(&img);
  draw_bitmap_s2(&img);
  secs = timeDate.time.secs;
}

static void drawDate()
{
 // Get day string
 char day[BUFFSIZE_STR_DAYS];
 strcpy_P(day, days[timeDate.date.day]);

 // Get month string
 char month[BUFFSIZE_STR_MONTHS];
 strcpy_P(month, months[timeDate.date.month]);

 // Draw date
 char buff[BUFFSIZE_DATE_FORMAT];
 sprintf_P(buff, PSTR(DATE_FORMAT), day, timeDate.date.date, month, timeDate.date.year);
 draw_string(buff,false,12,0);
}

Add this to your common.h file:
#include "watchfaces/zoneflash.h"

create a zoneflash.h file in the include/watchfaces folder.
Code:
#ifndef ZONE_H_
#define ZONE_H_

void watchface_zoneflash(void);

#endif /* ZONE_H_ */

The final bit is the bitmaps for the characters and the pronunciation and English translation.  This goes into includes/watchfaces/flash.h
Code:
// Japanese flash cards
// ji has the bitmaps for the kanji
//

static const byte ji[] PROGMEM ={
0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x70,0xF0,0x90,0x10,0x1C,0x1C,0x10,0x10,0xF0,0xF0,0x30,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,0xFC,0xFC,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xFF,0xFF,0x83,0xE3,0xF3,0x7B,0x7B,0x63,0x63,0x63,0xFB,0xFB,0x63,0x63,0x63,0x63,0x63,0x63,0x03,0x00,0x00,0x00,0x00,0x00,0xC0,0xCF,0x0F,0x0C,0x0C,0x0C,0x0C,0x0C,0xFF,0xFF,0x0C,0x0C,0x0C,0x0C,0x0C,0x0F,0x0F,0xC0,0xC0,0x00,0x00,
0x00,0x00,0x30,0x7F,0x1F,0x00,0x20,0x21,0x20,0x22,0x22,0x22,0x22,0x22,0x3F,0x3F,0x22,0x22,0x22,0x22,0x22,0x20,0x20,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x30,0x30,0x30,0x30,0x30,0x30,0x3F,0x3F,0x30,0x30,0x30,0x30,0x30,0x30,0x38,0x7F,0x7F,0x00,0x00,

0x00,0x00,0x00,0x00,0x80,0xF0,0xFC,0x7C,0x40,0xC0,0xC0,0x00,0x00,0x00,0xF8,0xF8,0x18,0x18,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0xF0,0xF0,0x30,0x10,0x10,0x00,0xF8,0xF8,0x88,0x88,0x98,0xF8,0x98,0x88,0x88,0xF8,0xF8,0x00,0x00,0x00,
0x00,0x00,0x30,0x3C,0x0F,0x1F,0xFE,0xC0,0xE0,0xFF,0x1F,0x00,0xC0,0xF0,0x7F,0x03,0x00,0x00,0xFF,0xFF,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x04,0x04,0xFF,0xFF,0x0E,0x04,0x04,0x00,0x1F,0x1F,0x11,0x11,0x39,0xFF,0xB9,0x11,0x11,0x1F,0x1F,0x00,0x00,0x00,
0x00,0x00,0x20,0x70,0x38,0x1C,0x0E,0x07,0x07,0x0E,0x1C,0x19,0x33,0x31,0x30,0x60,0x60,0x60,0x61,0x63,0x63,0x63,0x63,0x00,0x00,0x00,0x04,0x0E,0x06,0x07,0x07,0x03,0x03,0x23,0x20,0x23,0x23,0x23,0x23,0x33,0x3F,0x33,0x23,0x23,0x23,0x23,0x20,0x00,0x00,

0x00,0x00,0x00,0x0C,0x2C,0x6C,0x4C,0x0C,0x0C,0x8C,0xFC,0xFC,0x00,0x00,0x2C,0x6C,0x4C,0x0C,0x0C,0x8C,0x0C,0xFC,0xF8,0x00,0x00,0x00,0x20,0x60,0x70,0x38,0x1C,0x8C,0x00,0x00,0xF8,0xFC,0x6C,0x4C,0x4C,0x4C,0x4C,0x4C,0x4C,0xFC,0xFC,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x06,0x06,0xE6,0xE3,0xE3,0x61,0x69,0x6F,0x6F,0x70,0x72,0x66,0x62,0x63,0x63,0xE1,0xE1,0xEC,0x0F,0x07,0x00,0x00,0x00,0x20,0x70,0x38,0xFC,0xFF,0x03,0x81,0x90,0x93,0x93,0x93,0x92,0x92,0x92,0x92,0x92,0xF2,0xF3,0xF3,0x90,0x90,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7F,0x7F,0x76,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x76,0x7F,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x7F,0x00,0x00,0x00,0x00,0x06,0x0C,0x0C,0x00,0x00,0x20,0x60,0x7F,0x3F,0x01,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0xC8,0xC8,0x88,0x88,0x88,0xC8,0xC8,0xF8,0x78,0x38,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30,0x00,0x00,0xF8,0x98,0x88,0x88,0xF8,0xF8,0x00,0x00,0xF0,0xF0,0x00,0x00,0xFC,0xFC,0x00,0x00,
0x00,0x00,0x08,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0D,0xFF,0xFF,0x0F,0x0C,0x0C,0x8C,0xCC,0xEC,0x7C,0x3C,0x1C,0x08,0x00,0x00,0x00,0x03,0x06,0x86,0x80,0x00,0x00,0xFF,0x19,0x19,0x19,0xFF,0xFF,0x00,0x00,0xFF,0xFF,0x00,0x00,0xFF,0xFF,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x7F,0x7F,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x3E,0x07,0x01,0x20,0x30,0x1D,0x09,0x01,0x01,0x09,0x39,0x30,0x00,0x01,0x01,0x60,0x60,0x3F,0x1F,0x00,0x00,

0x00,0x00,0x00,0xC0,0xC0,0xC4,0xDC,0xD8,0xC0,0xC0,0xC0,0xCC,0xDC,0xD8,0xC0,0xC0,0xC0,0xF0,0xFC,0xDC,0xC0,0xC0,0xC0,0x00,0x00,0x00,0x00,0x0C,0x2C,0x6C,0x4C,0x0C,0x0C,0x8C,0xFC,0xFC,0x00,0x00,0x2C,0x6C,0x4C,0x0C,0x0C,0x8C,0x0C,0xFC,0xF8,0x00,0x00,
0x00,0x00,0x00,0x87,0x87,0x80,0x84,0x84,0x84,0x84,0x84,0x84,0xE4,0xE4,0xB4,0xBC,0x9C,0x8C,0x8C,0x80,0x80,0x87,0x87,0x00,0x00,0x00,0x00,0x06,0x06,0xE6,0xE3,0xE3,0x61,0x69,0x6F,0x6F,0x70,0x72,0x66,0x62,0x63,0x63,0xE1,0xE1,0xEC,0x0F,0x07,0x00,0x00,
0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x21,0x61,0x61,0x3F,0x3F,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x7F,0x76,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x76,0x7F,0x7F,0x00,0x00,0x00,0x00,
};
#define NUMLEX 5

static char translation[][15] = {"production","processing","acquisition","prediction","learning"};
static char romanji[][15] = {"sanshutsu","shori","shuutoku", "yosoku","gakushuu"};
Reply
#2
Here is a program that I used to convert the Japanese characters into bitmaps for the watch.  Anything that can be drawn on the screen can be converted into a bitmap with this program.  The program runs in Processing, which is java, so it should run on all platforms.  Here is a screenshot showing the original character in the red box and then the 25x50 binary array that is converted into hex for the watch. Hopefully it is useful for someone...

   

Just download processing and copy the code into the editor and press play.
https://processing.org/

Here is the Processing code that converts the stuff in the red box into C code.
Code:
PFont myFont;

float[] square = {
 48, 29, 98, 54
};
boolean first = true;

void setup() {
 size(1000, 700);
 rectMode(CORNERS);
 myFont = createFont("Osaka", 24);
 textFont(myFont);
}
boolean codeout = false;

void draw() {
 background(255);
 fill(255);
 stroke(#FF0F0F);
 rect(square[0], square[1], square[2], square[3]);
 fill(0);
 textSize(24);
 text("学習", 50, 50);  // Japanese character for "learning"
 
 float side = 1;

 float tsize = 12;
 textSize(tsize);
 int hei = int((square[2]-square[0])/side);
 int wid = int((square[3]-square[1])/side);
 text(wid+"x"+hei, 50, 100);
 color base = color(100);
 loadPixels();
 fill(0);
 String b = "";
 int bb = 0;
 String[] prog = new String[5];
 for (int j = 1; j < 5; j++) {
   prog[j] = "";
 }
 int numbytes = 0;
   
 for (int i = 1; i < hei; i++) {
   for (int j = 1; j < wid; j++) {
     int x = 0;
     if (j%8 == 0){
        b = hex(bb).substring(6,8);
       text(b, 150 + 2*i*side*tsize/side, 400 + j*3);
      if (prog[floor(j/8)] == null){
        prog[floor(j/8)] = "";
      }
      prog[floor(j/8)] = prog[floor(j/8)]+"0x"+b+",";
      numbytes++;
        bb=0;
     }
     float bl = 0;
     for (int k = 0; k < side; k++) {
       for (int m = 0; m < side; m++) {
         color c = get(int(i*side+square[0]+k), int(j*side+square[1]+m));
         bl = bl+blue(c);
       }
     }
     if (bl/(side*side) < blue(base)) {
       x = 1;
     }
     bb = bb + (x << (j%8));
     text(x, 150 + i*side*tsize/side, 50 + j*side*tsize/side);
   }
   b = b + "\n";
 }
 
 if (codeout == false){
   prog[0] = "static const byte ji[] PROGMEM ={";
   prog[4] = "};";
   saveStrings("words.h", prog);
   println(prog);    
 }
 codeout = true;
}

void mousePressed() {
 if (mouseX < 200 && mouseY < 200){
 if (first) {
   square[0] = mouseX;
   square[1] = mouseY;
   first = false;
 } else {
   square[2] = mouseX;
   square[3] = mouseY;
   first = true;
   println(square);
 }
 }
}

In the console, you will get something like this, which can be copied into the program that I posted earlier.
Code:
static const byte ji[] PROGMEM ={ 0x00,0x00,0x00,0xC0,0xC0,0xC4,0xDC,0xD8,0xC0,0xC0,0xC0,0xCC,0xDC,0xD8,0xC0,0xC0,0xC0,0xF0,0xFC,0xDC,0xC0,0xC0,0xC0,0x00,0x00,0x00,0x00,0x0C,0x2C,0x6C,0x4C,0x0C,0x0C,0x8C,0xFC,0xFC,0x00,0x00,0x2C,0x6C,0x4C,0x0C,0x0C,0x8C,0x0C,0xFC,0xF8,0x00,0x00, 0x00,0x00,0x00,0x87,0x87,0x80,0x84,0x84,0x84,0x84,0x84,0x84,0xE4,0xE4,0xB4,0xBC,0x9C,0x8C,0x8C,0x80,0x80,0x87,0x87,0x00,0x00,0x00,0x00,0x06,0x06,0xE6,0xE3,0xE3,0x61,0x69,0x6F,0x6F,0x70,0x72,0x66,0x62,0x63,0x63,0xE1,0xE1,0xEC,0x0F,0x07,0x00,0x00, 0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x21,0x61,0x61,0x3F,0x3F,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0x7F,0x76,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x26,0x76,0x7F,0x7F,0x00,0x00,0x00,0x00, };
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)