Browse Source

sleep phase updates

save a lot of energy by shutting of the rf part between sending. it is a interval of 2-3 seconds, so it saves
added gui to set program id
added a workaround for a very hard to fix bug when the battery is quite low in power. bug 1 sets it on
removed unused code
fertito
Daniel Poelzleithner 12 years ago
parent
commit
18825f8ddf
  1. 4
      TODO
  2. 1
      ezchronos.c
  3. 2
      logic/menu.c
  4. 94
      logic/phase_clock.c
  5. 14
      logic/phase_clock.h
  6. 21
      logic/rfsimpliciti.c
  7. 1
      logic/rfsimpliciti.h
  8. 20
      simpliciti/Applications/application/End_Device/main_ED_BM.c

4
TODO

@ -7,6 +7,10 @@
* fix the eggtimer. it runs to slow (like 2 seconds per second...)
* merge eggtimer into stopwatch. to much shared code that blow the firmware
== OPEN BUG ==
* very hard to debug: when the battery is quite low, the sleep init mode fails. only way currently working
is to set "bug 1" in the sleep settings and skip the init phase (very bad).
== IN WORKS ==
* autosync before/after flash

1
ezchronos.c

@ -320,6 +320,7 @@ void init_global_variables(void)
// ptrMenu_L2 = &menu_L2_Distance;
// ptrMenu_L2 = &menu_L2_Calories;
// ptrMenu_L2 = &menu_L2_Battery;
// ptrMenu_L2 = &menu_L2_Phase;
// Assign LINE1 and LINE2 display functions
fptr_lcd_function_line1 = ptrMenu_L1->display_function;

2
logic/menu.c

@ -253,7 +253,7 @@ const struct menu menu_L2_Battery =
const struct menu menu_L2_Phase =
{
FUNCTION(sx_phase), // direct function
FUNCTION(dummy), // sub menu function
FUNCTION(mx_phase), // sub menu function
FUNCTION(display_phase_clock), // display function
FUNCTION(update_time), // new display data
&menu_L2_Rf,

94
logic/phase_clock.c

@ -64,6 +64,7 @@
#include "temperature.h"
#include "vti_ps.h"
#include "altitude.h"
#include "user.h"
// *************************************************************************************************
@ -116,22 +117,6 @@ unsigned char phase_clock_reply_count;
extern void (*fptr_lcd_function_line1)(u8 line, u8 update);
// *************************************************************************************************
// @fn reset_rf
// @brief Reset SimpliciTI data.
// @param none
// @return none
// *************************************************************************************************
void reset_sleep(void)
{
// No connection
sPhase.mode = SLEEP_OFF;
// reset rf
reset_rf();
}
// *************************************************************************************************
// @fn sx_sleep
// @brief Start Sleep mode. Button DOWN connects/disconnects to access point.
@ -152,10 +137,71 @@ void sx_phase(u8 line)
if (is_bluerobin()) return;
#endif
// Start SimpliciTI in tx only mode
start_simpliciti_tx_only(SIMPLICITI_PHASE_CLOCK_START);
if(sPhase.bug)
start_simpliciti_tx_only(SIMPLICITI_PHASE_CLOCK);
else
start_simpliciti_tx_only(SIMPLICITI_PHASE_CLOCK_START);
//start_simpliciti_tx_only(SIMPLICITI_PHASE_CLOCK);
}
// *************************************************************************************************
// @fn mx_phase
// @brief Set program number to use
// @param u8 line LINE2
// @return none
// *************************************************************************************************
void mx_phase(u8 line){
s32 prog, bug;
u8 mode = 0;
prog = (s32)sPhase.program;
bug = (s32)sPhase.bug;
// Loop values until all are set or user breaks set
while(1)
{
// Idle timeout: exit without saving
if (sys.flag.idle_timeout) break;
// M2 (short): save, then exit
if (button.flag.num)
{
// Store local variables in global Eggtimer default
//sAlarm.hour = hours;
//sAlarm.minute = minutes;
sPhase.program = (u8)prog;
sPhase.bug = (u8)bug;
display.flag.line2_full_update = 1;
break;
}
if (button.flag.star)
mode = (mode+1)%2;
switch (mode) {
case 0:
//set_value(&prog, 2, 0, 0, 99, SETVALUE_ROLLOVER_VALUE + SETVALUE_DISPLAY_VALUE + SETVALUE_NEXT_VALUE, LCD_SEG_L2_1_0, display_value1);
display_chars(LCD_SEG_L2_5_0, (u8 *)" PR ", SEG_ON);
set_value(&prog, 2, 0, 0, 99, SETVALUE_ROLLOVER_VALUE + SETVALUE_DISPLAY_VALUE + SETVALUE_NEXT_VALUE, LCD_SEG_L2_1_0, display_value1);
break;
case 1:
display_chars(LCD_SEG_L2_5_0, (u8 *)" BUG", SEG_ON);
set_value(&bug, 2, 0, 0, 1, SETVALUE_ROLLOVER_VALUE + SETVALUE_DISPLAY_VALUE + SETVALUE_NEXT_VALUE, LCD_SEG_L2_1_0, display_value1);
break;
}
}
// Clear button flag
button.all_flags = 0;
display_phase_clock(line, DISPLAY_LINE_UPDATE_FULL);
}
u8 diff(u8 x1, u8 x2) {
// *************************************************************************************************
// @fn diff
// @brief calculates the smallest difference between two numbers
// @param none
// @return none
// *************************************************************************************************
static u8 diff(u8 x1, u8 x2) {
u8 b1 = x1 - x2;
if(b1 > 127)
b1 = x2 - x1;
@ -165,7 +211,6 @@ u8 diff(u8 x1, u8 x2) {
return b1;
}
// *************************************************************************************************
// @fn phase_clock_calcpoint
// @brief calculate one data point for the out buffer
@ -208,15 +253,6 @@ void display_phase_clock(u8 line, u8 update)
display_chars(LCD_SEG_L2_5_0, (u8 *)" SLEEP", SEG_ON);
}
}
// *************************************************************************************************
// @fn is_sleep
// @brief Returns TRUE if SimpliciTI receiver is connected.
// @param none
// @return u8
// *************************************************************************************************
u8 is_sleep(void)
{
return (sPhase.mode != SLEEP_OFF);
}
#endif /*CONFIG_PHASE_CLOCK*/

14
logic/phase_clock.h

@ -55,15 +55,7 @@ extern void send_data(void);
extern void display_phase_clock(u8 line, u8 update);
extern void sx_phase(u8 line);
/*extern void sx_rf(u8 line);
extern void sx_ppt(u8 line);
extern void sx_sync(u8 line);
extern void display_rf(u8 line, u8 update);
extern void display_ppt(u8 line, u8 update);
extern void display_sync(u8 line, u8 update);
extern void send_smpl_data(u16 data);
extern u8 is_rf(void);
*/
extern void mx_phase(u8 line);
extern void phase_clock_calcpoint();
@ -116,9 +108,7 @@ typedef enum
// Global Variable section
struct SPhase
{
// SIMPLICITI_OFF, SIMPLICITI_ACCELERATION, SIMPLICITI_BUTTONS
simpliciti_mode_t mode;
u8 bug;
// current session id
u8 session;
// sleep program to start

21
logic/rfsimpliciti.c

@ -75,7 +75,7 @@
void simpliciti_get_data_callback(void);
void start_simpliciti_tx_only(simpliciti_mode_t mode);
void start_simpliciti_sync(void);
int simpliciti_get_rvc_callback(u8 len) __attribute__((noinline));
// *************************************************************************************************
// Defines section
@ -223,10 +223,10 @@ void start_simpliciti_tx_only(simpliciti_mode_t mode)
start_as = 1;
}
#ifdef CONFIG_PHASE_CLOCK
else if (mode == SIMPLICITI_PHASE_CLOCK_START)
else if (mode == SIMPLICITI_PHASE_CLOCK_START || mode == SIMPLICITI_PHASE_CLOCK)
{
simpliciti_data[0] = SIMPLICITI_PHASE_CLOCK_START_EVENTS;
start_as = 1;
if(mode == SIMPLICITI_PHASE_CLOCK)
start_as = 1;
display_symbol(LCD_ICON_RECORD, SEG_ON_BLINK_ON);
}
#endif
@ -414,6 +414,8 @@ WDTCTL = WDTPW + WDTHOLD;
{
/* Initialisation phase. Get a Session id and send the
program wanted */
//display_chars(LCD_SEG_L1_3_2, itoa(packet_counter, 2, ' '), SEG_ON);
if(packet_counter == 30) {
simpliciti_flag |= SIMPLICITI_TRIGGER_STOP;
packet_counter = 0;
@ -426,10 +428,11 @@ WDTCTL = WDTPW + WDTHOLD;
simpliciti_data[0] = SIMPLICITI_PHASE_CLOCK_START_EVENTS;
// put 2 bytes of watch id into the package
WATCH_ID(simpliciti_data, 1);
// FIXME: TODO set program
// FIXME: TODO set program
simpliciti_data[3] = sPhase.program;
simpliciti_flag |= SIMPLICITI_TRIGGER_SEND_DATA | SIMPLICITI_TRIGGER_RECEIVE_DATA;
packet_counter ++;
}
else if (sRFsmpl.mode == SIMPLICITI_PHASE_CLOCK)
{
@ -487,8 +490,13 @@ WDTCTL = WDTPW + WDTHOLD;
display_symbol(LCD_ICON_BEEPER2, SEG_ON_BLINK_ON);
display_symbol(LCD_ICON_BEEPER3, SEG_ON_BLINK_ON);
open_radio();
simpliciti_flag |= SIMPLICITI_TRIGGER_SEND_DATA;
}
} else if (sPhase.out_nr == 0) {
// shutoff radio. no need to let it run for so long
close_radio();
}
sRFsmpl.timeout = SIMPLICITI_TIMEOUT;
@ -556,6 +564,7 @@ int simpliciti_get_rvc_callback(u8 len)
simpliciti_data[0] = 0x00;
simpliciti_data[1] = 0x00;
simpliciti_data[2] = 0x00;
as_start();
return 1;
#endif
}

1
logic/rfsimpliciti.h

@ -112,6 +112,7 @@ extern unsigned char simpliciti_flag;
// Extern section
extern void start_simpliciti_tx_only(simpliciti_mode_t mode);
extern int simpliciti_get_rvc_callback(u8 len) __attribute__((noinline));
#endif /*RFSIMPLICITI_H_*/

20
simpliciti/Applications/application/End_Device/main_ED_BM.c

@ -61,8 +61,9 @@ extern uint8_t sInit_done;
extern void Timer0_A4_Delay(u16 ticks);
extern unsigned char simpliciti_payload_length;
//extern txOpt_t simpliciti_options;
extern int simpliciti_get_rvc_callback(uint8_t len);
//extern int simpliciti_get_rvc_callback(uint8_t len);
// *************************************************************************************************
// Global Variable section
@ -232,10 +233,11 @@ void simpliciti_main_tx_only(void)
// Send data when flag bit SIMPLICITI_TRIGGER_SEND_DATA is set
if (getFlag(simpliciti_flag, SIMPLICITI_TRIGGER_SEND_DATA))
{
SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0);
// Acceleration / button events packets are 4 bytes long
SMPL_SendOpt(sLinkID1, simpliciti_data, simpliciti_payload_length, SMPL_TXOPTION_NONE);
SMPL_SendOpt(sLinkID1, simpliciti_data, simpliciti_payload_length, SMPL_TXOPTION_NONE);
//SMPL_SendOpt(sLinkID1, simpliciti_data, simpliciti_payload_length, simpliciti_options);
// reset options to default
//simpliciti_options = SMPL_TXOPTION_NONE;
clearFlag(simpliciti_flag, SIMPLICITI_TRIGGER_SEND_DATA);
}
// Receive data when flag bit SIMPLICITI_TRIGGER_RECEIVE_DATA is set
@ -252,8 +254,8 @@ void simpliciti_main_tx_only(void)
// generate a ready to receive packet
ed_data[0] = SYNC_ED_TYPE_R2R;
ed_data[1] = 0xCB;
SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, 0);
NWK_DELAY(10);
// we try to receive 9 times by sending a R2R packet
for (i = 0; i < 10; i++) {
@ -276,8 +278,8 @@ void simpliciti_main_tx_only(void)
break;
}
}
Timer0_A4_Delay(CONV_MS_TO_TICKS(50));
}
Timer0_A4_Delay(CONV_MS_TO_TICKS(500));
}
}
@ -329,12 +331,6 @@ void simpliciti_main_sync(void)
// Get radio ready. Radio wakes up in IDLE state.
SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_AWAKE, 0);
// send sync active package
ed_data[0] = SYNC_ED_TYPE_R2R;
ed_data[1] = 0xCB;
SMPL_SendOpt(sLinkID1, ed_data, 2, SMPL_TXOPTION_NONE);
// Send 2 byte long ready-to-receive packet to stimulate host reply
ed_data[0] = SYNC_ED_TYPE_R2R;
ed_data[1] = 0xCB;

Loading…
Cancel
Save