Saturday, July 21, 2012

Menu and New Function

Counter Function Description

I'd like to add a "Counter" function into the watch.

  1.    Press "Up" key, counter add 1.  
  2.    Long press "*" key, counter reset to zero.
I'd like to add counter function after Time function.

File "counter.h"


#ifndef COUNTER_H_
#define COUNTER_H_

// **************************************************************
// Include section


//***************************************************************
// Prototypes section

// internal functions
extern void reset_counter(void);

// menu functions
extern void mx_counter(u8 line);
extern void sx_counter(u8 line);
extern void display_counter(u8 line, u8 update);


//***************************************************************
// Defines section


//***************************************************************
// Global Variable section
struct counter
{
// MENU_ITEM_NOT_VISIBLE, MENU_ITEM_VISIBLE
menu_t state;
s16 count;
};
extern struct counter sCounter;


#endif /*COUNTER_H_*/

File "counter.c"


// system
#include "project.h"
// driver
#include "counter.h"
#include "ports.h"
#include "display.h"
//#include "adc12.h"
//#include "timer.h"

// logic
#include "user.h"
// Global Variable section
struct counter sCounter;
void reset_counter(void)
{
  sCounter.state = MENU_ITEM_NOT_VISIBLE; 
sCounter.count = 0;
}

void mx_counter(u8 line)
{
sCounter.count = 0;
display.flag.update_counter = 1;
}
void sx_counter(u8 line)
{
sCounter.count ++;
display.flag.update_counter = 1;
}
void display_counter(u8 line, u8 update)
{
u8 * str;

// Redraw line
if (update == DISPLAY_LINE_UPDATE_FULL)
{
// Set battery and V icon
display_symbol(LCD_SYMB_ARROW_UP, SEG_ON);

// Menu item is visible
sCounter.state = MENU_ITEM_VISIBLE; 

// Display result in xxxx format
str = itoa(sCounter.count, 4, 0);

display_chars(LCD_SEG_L1_3_0, str, SEG_ON);
}
else if (update == DISPLAY_LINE_UPDATE_PARTIAL)
{
// Display result in xxxx format
str = itoa(sCounter.count, 4, 0);

display_chars(LCD_SEG_L1_3_0, str, SEG_ON);

display.flag.update_counter = 0;
}
else if (update == DISPLAY_LINE_CLEAR)
{
// Menu item is not visible
sCounter.state = MENU_ITEM_NOT_VISIBLE;
// Clear function-specific symbols
display_symbol(LCD_SYMB_ARROW_UP, SEG_OFF);
}
}

In file "main.c"



// logic
#include "menu.h"
#include "date.h"
#include "alarm.h"
#include "stopwatch.h"
#include "battery.h"
#include "temperature.h"
#include "altitude.h"
#include "battery.h"
#include "acceleration.h"
#include "bluerobin.h"
#include "rfsimpliciti.h"
#include "simpliciti.h"
#include "test.h"
#include "counter.h"
....
void init_global_variables(void)
{
.....
// Read calibration values from info memory
read_calibration_values();
// reset counter
reset_counter();
}

In file "display.h", add another flag "update_counter"

typedef union
{
  struct
  {
  // Line1 + Line2 + Icons
    u16 full_update       : 1;    // 1 = Redraw all content
    u16 partial_update       : 1;    // 1 = Update changes
 
  // Line only
    u16 line1_full_update     : 1;    // 1 = Redraw Line1 content
    u16 line2_full_update     : 1;    // 1 = Redraw Line2 content

// Logic module data update flags
    u16 update_time       : 1;    // 1 = Time was updated 
    u16 update_stopwatch     : 1;    // 1 = Stopwatch was updated
    u16 update_temperature   : 1;    // 1 = Temperature was updated
    u16 update_battery_voltage : 1;    // 1 = Battery voltage was updated
    u16 update_date       : 1;    // 1 = Date was updated
    u16 update_alarm       : 1;    // 1 = Alarm time was updated
    u16 update_acceleration : 1; // 1 = Acceleration data was updated
    u16 update_counter : 1;    // 1 = counter was update
  } flag;
  u16 all_flags;            // Shortcut to all display flags (for reset)
} s_display_flags;


Menu Manipulation 

Add a menu after "Time" function.

File "menu.c"
In file menu.c, add a function first,


u8 update_counter(void)
{
return (display.flag.update_counter);
}

Then add counter menu

// Line 1 - Counter
const struct menu menu_L1_Counter = 
{
   FUNCTION( sx_counter ),
   FUNCTION( mx_counter ),
   FUNCTION( display_counter ),
   FUNCTION( update_counter ),
   &menu_L1_Alarm,
};

Change the Time menu next menu pointer,
// Line1 - Time

const struct menu menu_L1_Time =
{
FUNCTION(sx_time), // direct function
FUNCTION(mx_time), // sub menu function
FUNCTION(display_time), // display function
FUNCTION(update_time), // new display data
// &menu_L1_Alarm,
&menu_L1_Counter,
};

That's it.


Wednesday, July 18, 2012

Start Here

I got this eZ430-Chronos, the TI watch development tool, about 3 years ago (2009).  It was intended to inspire my son Alvin for embedded system development.  Turn out we both don't have time then.

Start ez430 wiki

Installation

   Install the CD for all the drivers and CCS4 development IDE.  After install CCS, run it and got update notification and proceed to update.

Wireless Update ?

Since 2010, ez430-Chronos got the capability for wireless update.  Our kit need update to do that.

Watch Firmware Update

   Get the eZ430-Chronos Firmware Update Tools to update my watch (915Mhz version).  However, to make it work, the RF Access Point also need to update.

RF Access Point Update

We need another tool CC-DEBUGER and connect it to RF board to update.  Since we don't have CC-DEBUGGER, just forget about it for now.

Working Test

Plug in RF board and run Chronos Control Center.
  1. Start Access Point (Chronos Control Center)
  2. Watch # key to Acc mode.  Press down to start (and stop) sending ACC data.  
  3. X Y Z show the wave of data collected.
  4. Watch # key to PPT mode. Press down to start (and stop) ppt mode.
  5. Watch up, #, * key pressed show on Chronos Control Center)

Compile and Debug

  1. Start CCS
  2. Project->Import Existing CCS Eclipse Project (Select existing project from installed folder)
  3. Select ez-430 as active project.  Target (right click select 915 limited).
  4. Select temperature.c
  5. find "display_temperatture() function.  Add first line : sys.flag.use_metric_units = 1
  6. Build 
  7. Debug
  8. Set break point at display_temperature function
  9. Press * to temperature mode and program stop
  10. continue run and all temperature display is using metric_unit (Celcus).
My display is 30.9C now.  It can't be right.  It is not that hot here.  Maybe battery is low or need calibration now. Battery voltage is 29.1V (according to reading from watch).  From multi-meter, battery is 2.96V(without load).