Joined: Sun Feb 27, 2011 8:32 pm Posts: 139 Location: Where ever the USAF sends me.
Ok, So i figured out what I am going to do as my first app.
But I am trying to figure out how to draw an arc from point a(top of screen) to point b(bottom of screen) I want the arc to be 15 pixels in radius, and 2 pixels wide.
For (int c = 0; i < (180), i++){ pulse_draw_point24(sin(c)*15 + 41, cos(c)*15 + 64); }
Is this good or not? I'm a Visual basic programmer, so I'm trying to learn C.
Also, I get all kinds of warnings and a few errors when I try to compile, is this normal?
_________________ Page ID: KTS
number3
Post subject: Re: Making first app, have a question
Posted: Sat Apr 09, 2011 5:48 pm
Joined: Wed Apr 06, 2011 8:53 pm Posts: 32
I get warnings too when I compile.
Your code looks like it's about right, except that I'm pretty sure that sin() takes its arguments in radians, not in degrees. There are 2*PI radians in a circle, so 3.14 is about 180 degrees.
Killer Turtle
Post subject: Re: Making first app, have a question
Posted: Sat Apr 09, 2011 6:21 pm
Joined: Sun Feb 27, 2011 8:32 pm Posts: 139 Location: Where ever the USAF sends me.
ok So I've done some changing of the code here is what I have now
Post subject: Re: Making first app, have a question
Posted: Sat Apr 09, 2011 8:34 pm
Joined: Tue Feb 15, 2011 10:35 pm Posts: 42
@number3 The watch can actually do floating point arithmetic but since it is much more intensive than integer arithmetic it would eat up a lot of code space and therefore isn't practical.
@Killer Turtle The code is inefficient because you're drawing over some points multiple times. For drawing the arc I would suggest adapting the midpoint circle algorithm and if you're interested in antialiasing the arc take a look at Xiaolin Wu's adaptation of the algorithm.
Killer Turtle
Post subject: Re: Making first app, have a question
Posted: Sun Apr 10, 2011 6:30 am
Joined: Sun Feb 27, 2011 8:32 pm Posts: 139 Location: Where ever the USAF sends me.
Thanks guys for the help. I now the watch is limited on space, but the program I've got is going to be real small anyways.
Once I get it working I'll do so more work and get it efficient.
_________________ Page ID: KTS
Killer Turtle
Post subject: Re: Making first app, have a question
Posted: Sun Apr 10, 2011 8:23 pm
Joined: Sun Feb 27, 2011 8:32 pm Posts: 139 Location: Where ever the USAF sends me.
So if I am understanding right, sin and cos won't work on the watch, but do work in the Sim? (I've got it working in the Sim, is why I ask)
I've got my app all working in the sim, so now I just have to use hudson's code to get it to work on the watch.
Could I just store all the sin/cos values in arrays instead, it would only be 2 360 spot arrays, or just 2 90 spots, 1 for x and 1 for y and use quadrants?
_________________ Page ID: KTS
Ryan
Post subject: Re: Making first app, have a question
Posted: Mon Apr 11, 2011 3:03 pm
Joined: Tue Feb 15, 2011 10:35 pm Posts: 42
Killer Turtle wrote:
So if I am understanding right, sin and cos won't work on the watch, but do work in the Sim?
Yes the simulator uses other resources (such as a math library) which is why you can use sin() and cos(), but this is not the case on the actual watch. It wouldn't be feasible to use these implementations on the watch because of the resources required to perform floating point arithmetic.
Killer Turtle wrote:
Could I just store all the sin/cos values in arrays instead, it would only be 2 360 spot arrays, or just 2 90 spots, 1 for x and 1 for y and use quadrants?
This is the lookup table method which is actually what hudson uses in his code to compute sin() and cos(). You could just use the one he implemented, but if you want to make your own lookup table you really only need 1 for the first quadrant of sin() as cos(x) = sin(x + 90). Your "x" value is really the index to the lookup table, so it is not necessary to have a second table for x values.
Killer Turtle
Post subject: Re: Making first app, have a question
Posted: Mon Apr 11, 2011 6:54 pm
Joined: Sun Feb 27, 2011 8:32 pm Posts: 139 Location: Where ever the USAF sends me.
ryan thanks for the help.
I will see what I can get working. As this is my first ever program in C, I'm learning how to do everything new. Hopefully within the next couple days I'll get it working on the watch.
I was looking at hudson's code, and just need to figure out how to use it.
I know I've been not saying what I'm working on, but I guess it would help in getting help if I said what it is.
I'm working on a "Arcs of Time" watch display, saw one in a SkyMall magazine and thought it was cool. It uses different Arcs for the Hours/Minutes/second. The arcs length is set by the time, so if it's 6:00 then the hours arc is 180 degree, if it's 9 it's 270. I've got it working on the sim, and just need to get it working with hudson's code on the watch. I'm also planning on having the date (Month, Day) in the middle of the Arc.
If I can get the code small enough, I'm going to change the notification apps watch to this as well.
Attachment:
Screenshot1.jpg [ 10.09 KiB | Viewed 358 times ]
_________________ Page ID: KTS
Killer Turtle
Post subject: Re: Making first app, have a question
Posted: Mon Apr 11, 2011 7:24 pm
Joined: Sun Feb 27, 2011 8:32 pm Posts: 139 Location: Where ever the USAF sends me.
So looking at Hudson's code. I know I need to add the Sin_lookup.h to my libs, and add it to my code as well, but I'm having a hard time figuring out how to get the values for sin & cos out of it. I'm use to Basic, so everything looks a little foreign to me.
First it looks like he uses 256 for a circle and theta is my point I want to find i.e. the current hour
So would I use this in my code to get the sin value: current:
for (int c = -((sec)*6)-180; c < -178; c++){ int x=(int)(sin(c*3.1415/180.0)*43) + 48; int y=(int)(cos(c*3.1415/180.0)*43) + 63; pulse_set_draw_window(x, y, x+5, y+5); pulse_draw_point24(sec_color); }
for (int c = -((sec)*6)-180; c < -178; c++){ int x=(int)(sin_lookup(c)*43) + 48; int y=(int)(cos_lookup(c)*43) + 63; pulse_set_draw_window(x, y, x+5, y+5); pulse_draw_point24(sec_color);
_________________ Page ID: KTS
hudson
Post subject: Re: Making first app, have a question
Posted: Tue Apr 12, 2011 2:47 am
Joined: Sun Feb 27, 2011 11:32 am Posts: 71
Killer Turtle wrote:
First it looks like he uses 256 for a circle and theta is my point I want to find i.e. the current hour
It is a fixed point representation where the scale factor for the input is unsigned 2 Pi / 256 and the scale for the output is signed 1 / 128.
for (int c = -((sec)*6)-180; c < -178; c++){ int x=(int)(sin(c*3.1415/180.0)*43) + 48; int y=(int)(cos(c*3.1415/180.0)*43) + 63; pulse_set_draw_window(x, y, x+5, y+5); pulse_draw_point24(sec_color); }
I would suggest something like this to do the scaling (untested, might need casts to sign extend values):
const int32_t r = 43; const int cx = 48; const int cy = 63;
for (int c = 0 ; c < sec * 6 ; c++) { int x = (sin_lookup((c * 256) / 360)*r) / 128 + cx; int y = (cos_lookup((c * 256) / 360)*r) / 128 + cy; pulse_set_draw_window(x, y, x, y); pulse_draw_point24(sec_color); }
Killer Turtle
Post subject: Re: Making first app, have a question
Posted: Tue Apr 12, 2011 5:12 am
Joined: Sun Feb 27, 2011 8:32 pm Posts: 139 Location: Where ever the USAF sends me.
Hudson,
Thanks so much for that help, it works perfectly. I will be posting a video soon. Just so everyone knows, the reason I did the for statement like this is becuase the watch starts drawing at the bottom of the screen, and draws counter-clockwise, so I had to reverse it.
Next step is to incorporate into the notification app
_________________ Page ID: KTS
hudson
Post subject: Re: Making first app, have a question
Posted: Tue Apr 12, 2011 5:30 am
Joined: Sun Feb 27, 2011 11:32 am Posts: 71
Killer Turtle wrote:
Just so everyone knows, the reason I did the for statement like this is becuase the watch starts drawing at the bottom of the screen, and draws counter-clockwise, so I had to reverse it.
Glad to hear that it worked for you. You can also reverse the direction by changing it to y = cy - cos_lookup(...) since the bitmap display uses a left-hand coordinate system.
Killer Turtle
Post subject: Re: Making first app, have a question
Posted: Tue Apr 12, 2011 5:42 am
Joined: Sun Feb 27, 2011 8:32 pm Posts: 139 Location: Where ever the USAF sends me.
hudson wrote:
Glad to hear that it worked for you. You can also reverse the direction by changing it to y = cy - cos_lookup(...) since the bitmap display uses a left-hand coordinate system.
Cool, thanks for that info, I'll look into it when I got to add the nitification app, incase I run into resource restraints.
I'll post the source code after work too. Here's the video of the app running on my watch.
_________________ Page ID: KTS
Killer Turtle
Post subject: Re: Making first app, have a question
Posted: Tue Apr 12, 2011 12:14 pm
Joined: Sun Feb 27, 2011 8:32 pm Posts: 139 Location: Where ever the USAF sends me.
Ok so I got it incorporated into the Notification App, and it works great on the Simulator.
But when I try to run it on the watch, all I get is the Arc Of Time dispaly.. It vibrates to say a message was received, but I don't get any visual indication of it, and nothing happens when I click a button. Also, on the Simulator the Bluetooth icon works, but on the watch it doesn't. Source code in next post
_________________ Page ID: KTS
Killer Turtle
Post subject: Re: Making first app, have a question
Posted: Tue Apr 12, 2011 12:16 pm
Joined: Sun Feb 27, 2011 8:32 pm Posts: 139 Location: Where ever the USAF sends me.
/** * Notifications App * * Description: * This app demonstrates notification management via 3 screens: a main clock screen, * a screen listing the most recent notifications and screen displaying a new or * selected notification. Also featured is button management to toggle between screens * and power management using sleep mode. * * Copyright (C) 2011, Allerta Inc. * Author: Ryan Young ([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. **/
if (sign == -1) return -result; else return result; }
// This is a text box widget that will define the bounds of where to render the text struct PWTextBox text_box;
// Text widget that stores required information about rendering the text // It must be initialized before it can be used struct PWidgetTextDynamic text_widget;
// Text buffer to store text to be rendered char text_buffer[16];
// Timer used to put processor to sleep int32_t sleep_timer_id;
// Timer used to determine button holds int32_t button_timer_id;
// Clock font color color24_t clock_color = {199, 125, 243, 0}; color24_t background_color = {255, 255, 255, 0}; // Current system minute uint8_t current_min; uint8_t current_second; uint8_t current_hour; // Current system time struct pulse_time_tm current_time;
// If bluetooth is connected bool bt_connected;
// Index of selected item uint8_t notification_selected;
// Number of notifications in list uint8_t notification_list_size;
// Draws all notifications when screen is initialized bool notification_list_first_draw;
//ID of selected notification in list PulseNotificationId notification_id;
// Render clock text and draw to screen void render_clock() { //Erases the screen pulse_blank_canvas();
//Gets current time pulse_get_time_date(¤t_time); current_second = current_time.tm_sec; current_min = current_time.tm_min; current_hour = current_time.tm_hour; // Random color. Looks sort of green.
//Prints background watch_background(); drawSecond(current_second); //Draws minute hand drawMinute(current_time.tm_min); //Draws Hour hand drawHour(current_time.tm_hour);
// Set the screen brightness to full pulse_oled_set_brightness(100);
// Schedule the processor to go to sleep in 15 seconds pulse_update_power_down_timer(15000); }
// Gets the notification based on the id and prints the messages to the screen void handle_pulse_protocol_notification(PulseNotificationId id) { current_screen = SCREEN_NOTIFICATION_READ; cancel_sleep(); pulse_blank_canvas(); struct PulseNotification *notification = pulse_get_notification(id); char body_text[150];
// Set font and color text_widget.font.resource_id = FONT_GEORGIA_10; text_widget.font.color = COLOR_WHITE24;
// Shows the most recent notifications void latest_notifications_screen(uint8_t index) { // Create an array to hold the PulseNotificationIds PulseNotificationId latest_notifications[MAX_NOTIFICATIONS_PER_LIST];
// Call a function to populate the array pulse_get_notification_list_by_type(PNT_ALL, latest_notifications);
// Get size of the list for(int i = 0; i < MAX_NOTIFICATIONS_PER_LIST; i++) { if (latest_notifications[i] == NULL) { break; } notification_list_size = i + 1; }
// Draw screen if(notification_list_size != 0) { // Screen initialized for first time if(notification_list_first_draw) { pulse_blank_canvas(); notification_list_first_draw = false; for(int i = 0; i < notification_list_size; i++) { struct PulseNotification * list_item = pulse_get_notification(latest_notifications[i]); // Draw item icon if(i == index) { pulse_draw_image(IMAGE_MSGLIST_EMAIL_GLOW, 0, i * 16); notification_id = latest_notifications[i]; } else { pulse_draw_image(IMAGE_MSGLIST_EMAIL_NOGLOW, 0, i * 16); }
// Draw bluetooth status icon update_bluetooth_icon(bt_connected); prepare_to_sleep(); }
// Will put processor to sleep in predetermined number of ms void prepare_to_sleep() { sleep_timer_id = pulse_register_timer(TIME_BEFORE_SLEEP, &pulse_update_power_down_timer, 0); }
// Cancel call to put processor to sleep void cancel_sleep() { pulse_cancel_timer(&sleep_timer_id); }
// This function is called once after the watch has booted up // and the OS has loaded void main_app_init() { bt_connected = false; notification_list_size = 0;
return_to_clock_screen();
// Callback to handles new notifications pulse_register_callback(ACTION_NEW_PULSE_PROTOCOL_NOTIFICATION, &handle_pulse_protocol_notification);
// Callback to handle button waking up processor pulse_register_callback(ACTION_WOKE_FROM_BUTTON, &return_to_clock_screen); }
// Main loop. This function is called frequently. // No blocking calls are allowed in this function or else the watch will reset. // The inPulse watchdog timer will kick in after 5 seconds if a blocking // call is made. void main_app_loop() { pulse_get_time_date(¤t_time); if(current_screen == SCREEN_CLOCK) {
if (current_second != current_time.tm_sec) {
setSecond(current_second); current_second = current_time.tm_sec; } //if the minutes have changed, then redraw if (current_min != current_time.tm_min) {
// This function is called whenever the processor is about to sleep (to conserve power) // The sleep functionality is scheduled with pulse_update_power_down_timer(uint32_t) void main_app_handle_doz() {
if (sec == 0 ) { for (int c = -540; c < -((sec)*6)-180; c++){ int x=(sin_lookup((c*256)/360)*43)/128 + cx; int y=(cos_lookup((c*256)/360)*43)/128 + cy; pulse_set_draw_window(x, y, x, y); pulse_draw_point24(COLOR_BLACK24); x=(sin_lookup((c*256)/360)*44)/128 + cx; y=(cos_lookup((c*256)/360)*44)/128 + cy; pulse_set_draw_window(x, y, x, y); pulse_draw_point24(COLOR_BLACK24); } } for (int c = -(sec*6)-180; c < -178; c++){ int x=(sin_lookup((c*256)/360)*43)/128 + cx; int y=(cos_lookup((c*256)/360)*43)/128 + cy; pulse_set_draw_window(x, y, x, y); pulse_draw_point24(sec_color); x= (sin_lookup((c*256)/360)*44)/128 + cx; y= (cos_lookup((c*256)/360)*44)/128 + cy; pulse_set_draw_window(x, y, x, y); pulse_draw_point24(sec_color); }
}
//Sends the proper paramter to the draw hand function. the offset is due to //the ordering of the images in the pulse_types.h file void drawHour(int hrs) { color24_t hrs_color = { 255, 0, 0, 0 }; if (hrs > 12) { hrs = hrs -12; } if (hrs == 1 ) { for (int c = -540; c < -((hrs)*30)-180; c++){ int x=(sin_lookup((c*256)/360)*20)/128 + cx; int y=(cos_lookup((c*256)/360)*20)/128 + cy; pulse_set_draw_window(x, y, x, y); pulse_draw_point24(COLOR_BLACK24); x=(sin_lookup((c*256)/360)*19)/128 + cx; y=(cos_lookup((c*256)/360)*19)/128 + cy; pulse_set_draw_window(x, y, x, y); pulse_draw_point24(COLOR_BLACK24); } } for (int c = -(hrs*30)-180; c < -178; c++){ int x=(sin_lookup((c*256)/360)*20)/128 + cx; int y=(cos_lookup((c*256)/360)*20)/128 + cy; pulse_set_draw_window(x, y, x, y); pulse_draw_point24(hrs_color); x=(sin_lookup((c*256)/360)*19)/128 + cx; y=(cos_lookup((c*256)/360)*19)/128 + cy; pulse_set_draw_window(x, y, x, y); pulse_draw_point24(hrs_color); }
Post subject: Re: Making first app, have a question
Posted: Tue Apr 12, 2011 1:28 pm
Joined: Mon Feb 14, 2011 7:07 pm Posts: 172
Thanks for posting that video, it looks phenomenal! We'll take a look at the source and see if we can help out...
_________________ ---
Lead designer of inPulse
Killer Turtle
Post subject: Re: Making first app, have a question
Posted: Tue Apr 12, 2011 4:25 pm
Joined: Sun Feb 27, 2011 8:32 pm Posts: 139 Location: Where ever the USAF sends me.
Ok, so I think i know what what is going on. When I use the compileandload.py -d it doesn't compile the source code, just load the old source codes bin file.
When I try the -c I get errors saying it can't find the resource file
_________________ Page ID: KTS
Killer Turtle
Post subject: Re: Making first app, have a question
Posted: Tue Apr 12, 2011 5:08 pm
Joined: Sun Feb 27, 2011 8:32 pm Posts: 139 Location: Where ever the USAF sends me.
WOOHOO I got it working, I didn't realize i had to compile the resource file using resource_packer.py, I had just copied the resource folder from the simulator to the sdk. Once I packed the resources it worked correctly.
Now I just need to make the hour arc larger and put the date in the center.
Users browsing this forum: No registered users and 1 guest
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum