|
| Author |
Message |
|
Duane
|
Post subject: Binary/BCD clock  Posted: Fri Feb 25, 2011 10:44 pm |
Joined: Mon Feb 21, 2011 10:03 am Posts: 26 Location: San Diego, CA
|
Here's a simple binary/BCD clock. Graphics are embedded in the program, so there's no separate resource upload. Enjoy! /** * * Binary/BCD clock * * Read digits from top to bottom - hours/10, hours%10, mins/10, mins%10, secs/10, secs%10 * * Copyright (C) 2011, Duane Maxwell [email protected] * * Permission to use, copy, modify, and/or distribute this software for * any purpose with or without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS * SOFTWARE. **/
#include <pulse_os.h> #include <pulse_types.h> #include <stdint.h>
#define LED_SIZE 20 #define H_OFFSET 8 #define V_OFFSET 4
static color24_t offColors[] = { {0x00,0x00,0x00,0x00}, {0x11,0x00,0x00,0x00}, {0x11,0x11,0x11,0x00}, {0x22,0x00,0x00,0x00}, {0x22,0x11,0x11,0x00}, {0x33,0x11,0x11,0x00}, {0x22,0x22,0x22,0x00}, {0x33,0x33,0x33,0x00}, {0x44,0x22,0x22,0x00}, {0x55,0x33,0x33,0x00}, {0x77,0x55,0x55,0x00}, {0xBB,0xBB,0xBB,0x00} };
char offMap[] = "AAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAA" "AAAAAACGDBBBAAAAAAAA" "AAAAAALKDDDDDBAAAAAA" "AAAAAHIDDDDDDDAAAAAA" "AAAAAJFDDDDDDDEAAAAA" "AAAAADDDDDDDDDFAAAAA" "AAAAADDDDDDDDDFAAAAA" "AAAAADDDDDDDDDGAAAAA" "AAAAAADDDDDDDFCAAAAA" "AAAAAABDDDDDFEAAAAAA" "AAAAAAABDDFFCAAAAAAA" "AAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAA" "AAAAAAAAAAAAAAAAAAAA";
static color24_t onColors[] = { {0x00,0x00,0x00,0x00}, {0x11,0x00,0x00,0x00}, {0x22,0x00,0x00,0x00}, {0x33,0x00,0x00,0x00}, {0x44,0x00,0x00,0x00}, {0x55,0x00,0x00,0x00}, {0x66,0x00,0x00,0x00}, {0x77,0x00,0x00,0x00}, {0x77,0x11,0x11,0x00}, {0x88,0x00,0x00,0x00}, {0xAA,0x00,0x00,0x00}, {0xBB,0x00,0x00,0x00}, {0x99,0x33,0x33,0x00}, {0xAA,0x22,0x22,0x00}, {0xCC,0x00,0x00,0x00}, {0xDD,0x00,0x00,0x00}, {0xEE,0x00,0x00,0x00}, {0xFF,0x00,0x00,0x00}, {0xFF,0x11,0x11,0x00}, {0xFF,0x22,0x22,0x00}, {0xEE,0x33,0x33,0x00}, {0xFF,0x55,0x55,0x00}, {0xEE,0xBB,0xBB,0x00} };
char onMap[] = "AAAAAAAAAAAAAAAAAAAA" "AAAAAAABBBBBBBAAAAAA" "AAAAABCCDDDDDCCBAAAA" "AAAABCDEEEFEEEDCBAAA" "AAABCDEFGGGGGFEDCBAA" "AABCDEINPPQPKGGEDCBA" "AACDEGWVRRRRROHGEDCA" "ABCEFMTRRRRRRRKGFECA" "ABDEGUSRRRRRRRQHGEDB" "ABDEGRRRRRRRRRRJGEDB" "ABDFGRRRRRRRRRRJGFDB" "ABDEGQRRRRRRRRQJGEDB" "ABDEGKRRRRRRRRLHGEDB" "ABCEFGORRRRRRPJGFECA" "AACDEGHLRRRRLJHGEDBA" "AABCDEGGHJJJHGGEDCAA" "AAABCDEFGGGGGFEDCAAA" "AAAABCDEEEFEEEDCAAAA" "AAAAABCCDDDDDCBAAAAA" "AAAAAAAABBBBBAAAAAAA";
void drawLED(int y,int x,int on) { x = x*LED_SIZE+H_OFFSET; y = y*LED_SIZE+V_OFFSET; pulse_set_draw_window(x,y,x+LED_SIZE-1,y+LED_SIZE-1); char *map = on ? onMap : offMap; color24_t *colors = on ? onColors : offColors; for (int i=0;i<LED_SIZE*LED_SIZE; i++) { pulse_draw_point24(colors[*map++-'A']); } }
int last_sec; int last_min; int last_hour;
void resetLast() { last_sec = -1; last_min = -1; last_hour = -1; }
void handle_button_causing_wakeup();
void main_app_init() { resetLast(); pulse_blank_canvas(); pulse_oled_set_brightness(100); pulse_update_power_down_timer(10000); // sleep in 10 seconds pulse_register_callback(ACTION_WOKE_FROM_BUTTON, &handle_button_causing_wakeup); }
void handle_button_causing_wakeup() { resetLast(); pulse_blank_canvas(); pulse_oled_set_brightness(100); pulse_update_power_down_timer(15000); // sleep again in 15 seconds }
void main_app_handle_button_down() { }
void main_app_handle_button_up() {
}
void main_app_loop() { struct pulse_time_tm tm; pulse_get_time_date(&tm); int sec = tm.tm_sec; if (sec!=last_sec) { last_sec = sec; int sec10 = sec/10; sec %= 10; drawLED(5,3,sec&1); drawLED(5,2,sec&2); drawLED(5,1,sec&4); drawLED(5,0,sec&8); drawLED(4,3,sec10&1); drawLED(4,2,sec10&2); drawLED(4,1,sec10&4); } int min = tm.tm_min; if (min!=last_min) { last_min = min; int min10 = min/10; min %= 10; drawLED(3,3,min&1); drawLED(3,2,min&2); drawLED(3,1,min&4); drawLED(3,0,min&8); drawLED(2,3,min10&1); drawLED(2,2,min10&2); drawLED(2,1,min10&4); } int hour = tm.tm_hour; if (hour!=last_hour) { last_hour = hour; int hour10 = hour/10; hour %= 10; drawLED(1,3,hour&1); drawLED(1,2,hour&2); drawLED(1,1,hour&4); drawLED(1,0,hour&8); drawLED(0,3,hour10&1); drawLED(0,2,hour10&2); } }
void main_app_handle_doz() { for (int i = 100; i >= 0; i-=6) { pulse_oled_set_brightness(i); pulse_mdelay(60); } }
void main_app_handle_hardware_update(enum PulseHardwareEvent event) { }
| Attachments: |
binaryclock.jpg [ 30 KiB | Viewed 468 times ]
|
Last edited by Duane on Fri Mar 04, 2011 12:00 pm, edited 1 time in total.
|
|
|
|
 |
|
Eric
|
Post subject: Re: Binary/BCD clock  Posted: Sun Feb 27, 2011 12:24 am |
Joined: Mon Feb 14, 2011 7:07 pm Posts: 172
|
|
Awesome! Would you mind if we grabbed a quick video of this and threw it on our blog? Attributed to you, naturally.
_________________ ---
Lead designer of inPulse
|
|
|
|
 |
|
Duane
|
Post subject: Re: Binary/BCD clock  Posted: Sun Feb 27, 2011 8:20 am |
Joined: Mon Feb 21, 2011 10:03 am Posts: 26 Location: San Diego, CA
|
|
You're welcome to post anything you want.
I also used the same license as your source code, so you're also welcome to do whatever you want with the code consistent with the license.
|
|
|
|
 |
|
jnjitkoff
|
Post subject: Re: Binary/BCD clock  Posted: Sun Feb 27, 2011 9:40 am |
Joined: Sat Feb 19, 2011 3:34 pm Posts: 5 Location: Mountain View, CA
|
|
How do you generate the code for the inline images? I'd love to do this for some of the smaller ones I'm using.
|
|
|
|
 |
|
Duane
|
Post subject: Re: Binary/BCD clock  Posted: Sun Feb 27, 2011 3:12 pm |
Joined: Mon Feb 21, 2011 10:03 am Posts: 26 Location: San Diego, CA
|
jnjitkoff wrote: How do you generate the code for the inline images? I'd love to do this for some of the smaller ones I'm using. The LEDs were originally done in Flash for this Chumby widget. Since if have the original FLA, I modified it to see what it would look like at inPulse resolution and resized and placed the assets accordingly. I then had Flash export the two LED graphics as PNG. I brought them into Photoshop to "posterize" them to reduce the number of colors since the original range was silly. Of course, these graphics could be done in any drawing program - I just happened to have them already in Flash. I then went to an online image conversion site and converted them to XPM, which basically turns them into C source code. You could use them as-is with a little coding, but for efficiency, I made the color selectors in a contiguous range and rearranged some things a bit for better use with the inPulse SDK. I did that by hand for these (just find/replace and some trivial editing) - if I do it again, I'll probably throw together a simple script. It seems like a lot of steps, but it only took maybe 15 minutes, and could be automated with little effort.
|
|
|
|
 |
|
Eric
|
Post subject: Re: Binary/BCD clock  Posted: Mon Feb 28, 2011 8:40 pm |
Joined: Mon Feb 14, 2011 7:07 pm Posts: 172
|
http://www.youtube.com/watch?v=jPt5SnKrDI8Here's a quick video of your wicked app, Duane! I've been wearing it all day, finally getting the hang of reading it before the timer times out!
_________________ ---
Lead designer of inPulse
|
|
|
|
 |
|
Duane
|
Post subject: Re: Binary/BCD clock  Posted: Mon Feb 28, 2011 9:37 pm |
Joined: Mon Feb 21, 2011 10:03 am Posts: 26 Location: San Diego, CA
|
|
Pretty cool. Glad you like it.
I'm not really sure the LEDs should look that realistic - it makes your nice OLED display and ARM7 look like 3 cents worth of cheap LEDs and a couple of flip flops.
|
|
|
|
 |
|
Eric
|
Post subject: Re: Binary/BCD clock  Posted: Tue Mar 01, 2011 12:48 pm |
Joined: Mon Feb 14, 2011 7:07 pm Posts: 172
|
|
Yes, but with a few tweaks, your binary watch could have notifications zooming to it! That's something pretty special...
_________________ ---
Lead designer of inPulse
|
|
|
|
 |
|
Killer Turtle
|
Post subject: Re: Binary/BCD clock  Posted: Sat Mar 05, 2011 6:15 am |
Joined: Sun Feb 27, 2011 8:32 pm Posts: 138 Location: Where ever the USAF sends me.
|
|
Maybe I'll work on this since I already got the analog watch combined with notification.
_________________ Page ID: KTS
|
|
|
|
 |
|
Johan
|
Post subject: Re: Binary/BCD clock  Posted: Sat Mar 19, 2011 8:25 am |
Joined: Fri Mar 04, 2011 8:54 pm Posts: 82
|
Hey Duane - make sure to post this app on http://www.inpulsewatch.com or I can as well of course  - Sorry can't help but to truly love this app! BTW - does anybody know why this app doesn't display correctly in the simulator? All images are shifted. Is there a fix for this? It does of course run great on my watch.
_________________
 Get the most out of your watch - http://www.inpulsewatch.com
|
|
|
|
 |
|
|