It is currently Wed Jul 06, 2011 7:19 pm

All times are UTC - 8 hours




 Page 1 of 1 [ 20 posts ] 
Author Message
 Post subject: Making first app, have a question
PostPosted: Sat Apr 09, 2011 5:28 pm 

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.

Here is what I've got so far
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
Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: 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.


Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: 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

void drawMinute(int min, color24_t color) {
   for (int c = 0; c < (180); c++) {
   
      pulse_set_draw_window(sin(c)*25 + 41, cos(c)*25 + 64, sin(c)*25 + 44, cos(c)*25 + 67);
          // Draw pixels onto that canvas
          for (int i = 0; i < 4 * 4; i++) {
              pulse_draw_point24(color);
          }   

   }
}


This code though produces a full circle, when it should produce a half circle



_________________
Page ID: KTS
Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: Sat Apr 09, 2011 6:47 pm 

Joined: Wed Apr 06, 2011 8:53 pm
Posts: 32
That's because sin() takes input in radians.

Here's code that works:

    for (c = 0; c < (180); c++){
        x=(int)(sin(c*3.1415/180.0)*15) + 41;
        y=(int)(cos(c*3.1415/180.0)*15) + 64;
        pulse_set_draw_window(x, y, x+3, y+3);
        pulse_draw_point24(hand_color);
    }


Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: Sat Apr 09, 2011 8:25 pm 

Joined: Wed Apr 06, 2011 8:53 pm
Posts: 32
actually, http://www.nycresistor.com/2011/03/07/h ... come-true/ says that the inPulse can't do floating point... you may have to use his sin/cos code.


Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: 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.


Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: 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
Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: 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
Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: 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.


Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: 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
Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: 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);
}


Using hudson:
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
Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: 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.

Quote:
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);
}


Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: 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.
for (int c = -((sec)*6)-180; c < -178; c++){


Next step is to incorporate into the notification app



_________________
Page ID: KTS
Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: 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.


Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: 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
Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: 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
Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: 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.
**/

#include <pulse_os.h>
#include <pulse_types.h>
#include <app_resources.h>
#include "sin_table.h"
#include <stddef.h>


// Time required to be considered a hold in ms
#define BUTTON_HOLD_TIME 500

// Processor will go to sleep in 15 sec if no activity on the clock screen
#define TIME_BEFORE_SLEEP 15000

const int cx = 48;
const int cy = 63;
static const uint8_t sin_table[] = {
        0,
        25,
        50,
        74,
        98,
        121,
        142,
        162,
        181,
        198,
        213,
        226,
        237,
        245,
        251,
        255,
        255 // duplicate to avoid extra code for handling last case
};

int8_t
sin_lookup(
        uint8_t theta
)
{
        int sign = 1;

        if (theta < 64)
        {
                // q1, upward slope, normal theta, positive sign
        } else
        if (theta < 128)
        {
                theta = 128 - theta; // downward slope, still positive
        } else
        if (theta < 192)
        {
                // q3, downward slope, negative side
                theta = theta - 128;
                sign = -1;
        } else
        {
                // q4, upward slope, negative side
                theta = 256 - theta;
                sign = -1;
        }

        int16_t s1 = sin_table[(theta >> 2) + 0];
        int16_t s2 = sin_table[(theta >> 2) + 1];
        int8_t result = (s1 + ((s2 - s1) * (theta & 0x3)) / 4) / 2;

        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;

// Types of screens
typedef enum Screen
{
    SCREEN_CLOCK,
    SCREEN_NOTIFICATION_LIST,
    SCREEN_NOTIFICATION_READ
} Screen;

// Current screen being displayed
Screen current_screen;

void print_time_into_text_buffer()
{
    uint32_t hour = current_time.tm_hour;
    if(hour > 12)
        hour -= 12;
    else if(hour == 0)
        hour = 12;
    sprintf(text_buffer, "%d:%02d", hour, current_time.tm_min);

}

// 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;

    // Render and draw header
    pulse_draw_image(IMAGE_FULLSCREEN_EMAIL, 0, 0);
    text_box.top = 5;
    text_box.right = SCREEN_WIDTH;
    text_box.left = 28;
    text_box.bottom = 20;
    enum PWTextStyle style = PWTS_TRUNCATE;
    pulse_init_dynamic_text_widget(&text_widget, text_buffer, FONT_GEORGIA_10, COLOR_WHITE24, style);
    sprintf(text_buffer, "%s", notification->sender);
    pulse_render_text(&text_box, &text_widget);

    // Render and draw body
    text_box.top = 28;
    text_box.right = SCREEN_WIDTH;
    text_box.left = 0;
    text_box.bottom = SCREEN_HEIGHT;
    style = PWTS_WRAP_AT_SPACE;
    pulse_init_dynamic_text_widget(&text_widget, body_text, FONT_GEORGIA_10, COLOR_WHITE24, style);
    sprintf(body_text, "%s", notification->body);
    pulse_render_text(&text_box, &text_widget);
}

// 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);
                }
               
                // Print item sender
                draw_notification_list_item_header(i, list_item->sender);
            }
        }
        else
        {
            // Only redraw current selected and previously selected notifications
            if(notification_list_size > 1)
            {
                struct PulseNotification * list_item;
                uint8_t notification_previously_selected = notification_selected - 1;
                if(notification_previously_selected == 0xFF)
                {
                    notification_previously_selected = notification_list_size - 1;
                }

                // Highlight and redraw new selected item
                list_item = pulse_get_notification(latest_notifications[notification_selected]);
                pulse_draw_image(IMAGE_MSGLIST_EMAIL_GLOW, 0, notification_selected * 16);
                draw_notification_list_item_header(notification_selected, list_item->sender);
                notification_id = latest_notifications[notification_selected];

                // Unhighlight and redraw previously selected item
                list_item = pulse_get_notification(latest_notifications[notification_previously_selected]);
                pulse_draw_image(IMAGE_MSGLIST_EMAIL_NOGLOW, 0, notification_previously_selected * 16);
                draw_notification_list_item_header(notification_previously_selected, list_item->sender);
            }
        }
    }
    else
    {
        pulse_blank_canvas();
        printf("No notifications");
    }
}

// Prints the sender of a notification list item
void draw_notification_list_item_header(uint8_t index, char item_header[])
{
    text_box.top = index * 16 + 3;
    text_box.right = SCREEN_WIDTH;
    text_box.left = 18;
    text_box.bottom = (index + 1) * 16;
    enum PWTextStyle style = PWTS_TRUNCATE;
    pulse_init_dynamic_text_widget(&text_widget, text_buffer, FONT_GEORGIA_10, COLOR_WHITE24, style);
    sprintf(text_buffer, "%s", item_header);
    pulse_render_text(&text_box, &text_widget);
}

// Redraw bluetooth icon
void update_bluetooth_icon(bool connected)
{
    if(connected)
    {
        pulse_set_draw_window(0, 0, 19, 19);
        for(int i = 0; i < 400; i++)
        {
            pulse_draw_point24(COLOR_BLACK24);
        }
    }
    else
    {
        pulse_draw_image(IMAGE_BLUETOOTH_NO, 0, 0);
    }
}

void return_to_clock_screen()
{
    pulse_blank_canvas();
    current_screen = SCREEN_CLOCK;

    // Draw clock
    render_clock();

    // 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);
}

void main_app_handle_button_down()
{
    if(current_screen == SCREEN_CLOCK)
    {
        current_screen = SCREEN_NOTIFICATION_LIST;
        cancel_sleep();
        notification_list_first_draw = true;
        notification_selected = 0xFF;
    }
    else if(current_screen == SCREEN_NOTIFICATION_LIST)
    {
        if(notification_list_size == 0)
        {
            return_to_clock_screen();
        }
        else
        {           
            // Set timer for button hold
            button_timer_id = pulse_register_timer(BUTTON_HOLD_TIME, &handle_pulse_protocol_notification,
                                            notification_id);
        }
    }
    else
    {
        return_to_clock_screen();
    }
}

void main_app_handle_button_up()
{
    if(current_screen == SCREEN_NOTIFICATION_LIST)
    {
        // Button was not a hold
        pulse_cancel_timer(&button_timer_id);

        // Select next message in list
        notification_selected++;
        if(notification_selected == notification_list_size)
        {
            notification_selected = 0;
        }

        // Update screen
        latest_notifications_screen(notification_selected);
    }
}

// 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) {

        setMinute(current_hour, current_min);
        current_min = current_time.tm_min;
    }
   
    //if the hours have changed, then redraw
    if (current_hour != current_time.tm_hour) {

        setHour(current_hour, current_min);
        current_hour = current_time.tm_hour;
    }

    }
}

// 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()
{

}

void main_app_handle_hardware_update(enum PulseHardwareEvent event)
{
    switch(event) {
        case BLUETOOTH_CONNECTED:
            bt_connected = true;
            break;
        case BLUETOOTH_DISCONNECTED:
            bt_connected = false;
            break;       
    }
    if(current_screen == SCREEN_CLOCK)
    {
        update_bluetooth_icon(bt_connected);
    }
}
void watch_background() {

}
void drawMinute(int min) {
color24_t color = { 0x44, 0x99, 0x11, 0x00 };
if (min == 0 ) {
       for (int c = -540; c < -((min)*6)-180; c++){
           int x=(sin_lookup((c*256)/360)*40)/128 + cx;
           int y=(cos_lookup((c*256)/360)*40)/128 + cy;
           pulse_set_draw_window(x, y, x, y);
           pulse_draw_point24(COLOR_BLACK24);
      x=(sin_lookup((c*256)/360)*39)/128 + cx;
           y=(cos_lookup((c*256)/360)*39)/128 + cy;
           pulse_set_draw_window(x, y, x, y);
           pulse_draw_point24(COLOR_BLACK24);
       }
   }
    for (int c = -(min*6)-180; c < -178; c++){
        int x=(sin_lookup((c*256)/360)*40)/128 + cx;
        int y=(cos_lookup((c*256)/360)*40)/128 + cy;
        pulse_set_draw_window(x, y, x, y);
        pulse_draw_point24(color);
   x=(sin_lookup((c*256)/360)*39)/128 + cx;
        y=(cos_lookup((c*256)/360)*39)/128 + cy;
        pulse_set_draw_window(x, y, x, y);
        pulse_draw_point24(color);
    }

}

void drawSecond(int sec) {
color24_t sec_color = { 255,255,0,0 };



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);
    }

}
void setMinute(int hrs, int min) {

    //eraseMinute(min);
    //watch_background();
    drawMinute(min);
    drawHour(hrs);
}
void setSecond(int sec) {

    //eraseMinute(min);
    //watch_background();
    drawSecond(sec);
    //drawHour(hrs);
}
void setHour(int hrs, int min) {


    //eraseHour(hrs);
    //watch_background();
    drawMinute(min);
    drawHour(hrs);
}



_________________
Page ID: KTS
Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: Tue Apr 12, 2011 1:28 pm 
User avatar

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
Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: 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
Offline
 Profile  
 
 Post subject: Re: Making first app, have a question
PostPosted: 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.

Thanks everyone, especially Ryan, number3, Hudson



_________________
Page ID: KTS
Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 20 posts ] 

All times are UTC - 8 hours


Who is online

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

Search for:
Jump to: