mirror of
https://github.com/rvtr/ctr_mcu.git
synced 2025-10-31 13:51:10 -04:00
・歩数計新仕様、バグバグだったのを修正。テストも一通り
・ログいっぱいフラグ(HOSU_SETTING.4)を追加 ・電源LEDが赤点灯する条件な電池を接続したとき、直後の一回だけお知らせLEDの赤がつきっぱなしになるのを修正(2回目以降の電源投入では大丈夫) git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_mcu@305 013db118-44a6-b54f-8bf7-843cb86687b1
This commit is contained in:
parent
c8ed4d66e3
commit
12044e3cc2
44
trunk/led.c
44
trunk/led.c
@ -187,6 +187,7 @@ void LED_init( )
|
||||
LED_duty_notify_grn = 0;
|
||||
LED_pow_red = 0;
|
||||
LED_CAM = 0;
|
||||
LED_old_pow_red = 0;
|
||||
|
||||
if( system_status.reboot )
|
||||
{
|
||||
@ -236,6 +237,7 @@ enum LED_ILUM_MODE{
|
||||
void tsk_led_pow( )
|
||||
{
|
||||
info_led_override = false;
|
||||
|
||||
switch ( vreg_ctr[VREG_C_LED_POW] )
|
||||
{
|
||||
case ( LED_POW_ILM_AUTO ):
|
||||
@ -272,6 +274,12 @@ void tsk_led_pow( )
|
||||
break;
|
||||
}
|
||||
|
||||
if( system_status.pwr_state == OFF || system_status.pwr_state == ON_CHECK )
|
||||
{
|
||||
LED_pow_red_Mirror = 0;
|
||||
info_led_override = false;
|
||||
}
|
||||
|
||||
// 実際にLEDの更新
|
||||
if( system_status.info_fullcolor )
|
||||
{
|
||||
@ -308,14 +316,14 @@ static void led_pow_normal( )
|
||||
frame_sleep = 0;
|
||||
LED_dim_status_sleep.now = (sx16)LED_duty_pow_blu * 128;
|
||||
|
||||
if( led_pow_batt_low() != 0 )
|
||||
if( led_pow_batt_low() != 0 ) // 赤の点灯も←でやっています
|
||||
{
|
||||
return;
|
||||
// おしまい
|
||||
}
|
||||
|
||||
// <20>“_“”
|
||||
led_fade_to( LED_duty_pow_blu, vreg_ctr[VREG_C_LED_BRIGHT] );
|
||||
// 青点灯
|
||||
led_fade_to( LED_duty_pow_blu, vreg_ctr[VREG_C_LED_BRIGHT] );
|
||||
}
|
||||
|
||||
|
||||
@ -326,7 +334,7 @@ static void led_pow_normal( )
|
||||
======================================================== */
|
||||
static void led_pow_sleep( )
|
||||
{
|
||||
if( led_pow_batt_low() != 0 )
|
||||
if( led_pow_batt_low() != 0 ) // 赤の点灯も←でやっています
|
||||
{
|
||||
time_to_next_frame_sleep = LED_SLEEP_FRAME_LEN;
|
||||
frame_sleep = 0;
|
||||
@ -362,8 +370,11 @@ static void led_pow_sleep( )
|
||||
返値: 0 電池が少なくなかった
|
||||
1 少なかったので共通パターンにした
|
||||
======================================================== */
|
||||
//#define LED_RED_SLEEP_DIM 3
|
||||
static u8 led_pow_batt_low()
|
||||
{
|
||||
// static u8 led_red_dim_count;
|
||||
|
||||
if( vreg_ctr[VREG_C_BT_REMAIN] > BATT_TH_LO )
|
||||
{
|
||||
LED_pow_red_Mirror = 0;
|
||||
@ -375,9 +386,30 @@ static u8 led_pow_batt_low()
|
||||
{
|
||||
// 赤点灯
|
||||
led_fade_to( LED_duty_pow_blu, 0 );
|
||||
LED_pow_red_Mirror = 1;
|
||||
|
||||
/*
|
||||
減光を試してみたが、このようなお手軽実装ではちらついてしまってだめだ
|
||||
if( vreg_ctr[VREG_C_LED_POW] == LED_POW_ILM_SLEEP )
|
||||
{
|
||||
if( led_red_dim_count == 0 )
|
||||
{
|
||||
LED_pow_red_Mirror = 1;
|
||||
led_red_dim_count = LED_RED_SLEEP_DIM;
|
||||
}
|
||||
else
|
||||
{
|
||||
LED_pow_red_Mirror = 0;
|
||||
led_red_dim_count -= 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
*/
|
||||
{
|
||||
LED_pow_red_Mirror = 1;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
else // 電池が5%未満 かつ アダプタなし
|
||||
{
|
||||
led_pow_bt_empty();
|
||||
}
|
||||
|
||||
@ -23,9 +23,11 @@ static void hosu_increment();
|
||||
|
||||
// ========================================================
|
||||
u16 get_long_hour();
|
||||
extern uni_pool pool;
|
||||
|
||||
|
||||
extern uni_pool pool;
|
||||
bit pedolog_overflow;
|
||||
|
||||
|
||||
// ========================================================
|
||||
#define _use_my_sqrt_
|
||||
@ -120,7 +122,7 @@ void pedometer()
|
||||
// 谷を挟んでいる
|
||||
{
|
||||
if( acc_norm[0] - peak_l > 4200 ){
|
||||
// 一歩増えました
|
||||
// ■一歩増えました
|
||||
hosu_increment();
|
||||
}
|
||||
}
|
||||
@ -187,14 +189,26 @@ void pedometer()
|
||||
仕様変更 ログがいっぱいになったらそこで止める
|
||||
========================================================*/
|
||||
u8 p_record;
|
||||
u8 last_hour = 0x23; // 履歴の最新は何時?
|
||||
u8 last_day = 0x30;
|
||||
u8 last_month = 0x12;
|
||||
u8 last_year = 0x99;
|
||||
u8 now_min;
|
||||
u8 now_sec;
|
||||
u8 log_year;
|
||||
|
||||
u8 pedo_log_latest[ 6 ];
|
||||
enum {
|
||||
LEDO_LOG_LATEST_HOUR,
|
||||
LEDO_LOG_LATEST_DAY,
|
||||
LEDO_LOG_LATEST_MONTH,
|
||||
LEDO_LOG_LATEST_YEAR,
|
||||
LEDO_LOG_LATEST_MIN,
|
||||
LEDO_LOG_LATEST_SEC
|
||||
};
|
||||
|
||||
/*
|
||||
u8 last_hour; // 履歴の最新は何時?
|
||||
u8 last_day;
|
||||
u8 last_month;
|
||||
u8 pedo_log_latest[ LEDO_LOG_LATEST_YEAR ];
|
||||
u8 last_min;
|
||||
u8 last_sec;
|
||||
*/
|
||||
|
||||
#define HOSU_NODATA 0xFFFF
|
||||
#define HOSU_MAX 0xFFFE
|
||||
@ -203,12 +217,82 @@ static void hosu_increment()
|
||||
{
|
||||
static u16 last_hour_fny; // from new year
|
||||
|
||||
if( p_record >= PEDOMETER_LOG_SIZE )
|
||||
// 空白の時間を考慮する。1時間以上放置されたなど。
|
||||
u16 now_longhour;
|
||||
u8 now_year;
|
||||
|
||||
u8 temp_year, temp_hour, temp_day, temp_month, temp_min, temp_sec, log_year_temp;
|
||||
|
||||
// 時計を止める必要が有るので↓は一気に行って下さい
|
||||
DI();
|
||||
RWAIT = 1;
|
||||
while( !RWST ){;}
|
||||
log_year_temp = temp_year = bcdtob( YEAR );
|
||||
|
||||
// 履歴読み出し時に使用。BCDのままでよい
|
||||
temp_hour = HOUR;
|
||||
temp_day = DAY;
|
||||
temp_month = MONTH;
|
||||
temp_min = MIN;
|
||||
temp_sec = SEC;
|
||||
now_longhour = get_long_hour();
|
||||
|
||||
// RWAIT = 0; ↑で行っています
|
||||
// EI(); 〃
|
||||
|
||||
// 元旦零時台で昨日扱いになった場合の帳尻合わせ
|
||||
if( now_longhour == 65535 )
|
||||
{
|
||||
return;
|
||||
now_longhour = ( ( 365 + (( temp_year & 0x03 ) == 1 ? 1: 0 )) * 24 ) -1; // 閏年を考慮
|
||||
temp_year -= 1;
|
||||
}
|
||||
|
||||
// 累積の更新 //
|
||||
// 書き込みポインタの更新
|
||||
if(( vreg_ctr[ VREG_C_ACC_HOSU_L ] | vreg_ctr[ VREG_C_ACC_HOSU_M ] | vreg_ctr[ VREG_C_ACC_HOSU_H ] ) != 0 )
|
||||
{
|
||||
// 歩数計が止まっていた時間を考慮して必要なら進める
|
||||
if( pedo_log_latest[ LEDO_LOG_LATEST_YEAR ] == temp_year )
|
||||
{
|
||||
if( now_longhour > last_hour_fny )
|
||||
{
|
||||
fill_hosu_hist_hours( now_longhour - last_hour_fny );
|
||||
}
|
||||
}
|
||||
else if( pedo_log_latest[ LEDO_LOG_LATEST_YEAR ] == ( temp_year -1 ) )
|
||||
{
|
||||
// 年をまたいでいるとき
|
||||
fill_hosu_hist_hours( ( ( 365 + (( temp_year & 0x03 ) == 1 ? 1: 0 )) * 24 ) - last_hour_fny + now_longhour );
|
||||
}
|
||||
else if( pedo_log_latest[ LEDO_LOG_LATEST_YEAR ] < temp_year )
|
||||
{
|
||||
// 数年放置
|
||||
fill_hosu_hist_hours( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// カレンダーが巻き戻るなど
|
||||
// ノーケアでよい
|
||||
}
|
||||
|
||||
// ログあふれで記録停止?
|
||||
if( pedolog_overflow )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// インクリメントして良い
|
||||
pedo_log_latest[ LEDO_LOG_LATEST_HOUR ] = temp_hour;
|
||||
pedo_log_latest[ LEDO_LOG_LATEST_DAY ] = temp_day;
|
||||
pedo_log_latest[ LEDO_LOG_LATEST_MONTH ] = temp_month;
|
||||
pedo_log_latest[ LEDO_LOG_LATEST_YEAR ] = temp_year;
|
||||
pedo_log_latest[ LEDO_LOG_LATEST_MIN ] = temp_min;
|
||||
pedo_log_latest[ LEDO_LOG_LATEST_SEC ] = temp_sec;
|
||||
|
||||
last_hour_fny = now_longhour;
|
||||
log_year = log_year_temp;
|
||||
|
||||
// 累積の更新 //
|
||||
// いろいろ失敗した...
|
||||
if( ++vreg_ctr[ VREG_C_ACC_HOSU_L ] == 0 )
|
||||
{
|
||||
@ -221,74 +305,17 @@ static void hosu_increment()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 毎時ログインクリメント
|
||||
if( pool.vreg_c_ext.pedo_log[ p_record ] == HOSU_NODATA )
|
||||
{
|
||||
// 毎時履歴の更新 /////////////////////////////
|
||||
// 空白の時間を考慮する。1時間以上放置されたなど。
|
||||
u16 now_longhour;
|
||||
u8 now_year;
|
||||
|
||||
// 時計を止める必要が有るので↓は一気に行って下さい
|
||||
DI();
|
||||
RWAIT = 1;
|
||||
while( !RWST ){;}
|
||||
log_year = now_year = bcdtob( YEAR );
|
||||
|
||||
// 履歴読み出し時に使用。BCDのままでよい
|
||||
last_hour = HOUR;
|
||||
last_day = DAY;
|
||||
last_month = MONTH;
|
||||
now_min = MIN;
|
||||
now_sec = SEC;
|
||||
now_longhour = get_long_hour();
|
||||
|
||||
// RWAIT = 0; ↑で行っています
|
||||
// EI(); 〃
|
||||
|
||||
// 元旦零時台で昨日扱いになった場合の帳尻合わせ
|
||||
if( now_longhour == 65535 )
|
||||
{
|
||||
now_longhour = ( ( 365 + (( now_year & 0x03 ) == 1 ? 1: 0 )) * 24 ) -1; // 閏年を考慮
|
||||
now_year -= 1;
|
||||
}
|
||||
|
||||
// 書き込みポインタの更新
|
||||
// 歩数計が止まっていた時間を考慮して必要なら進める
|
||||
if( last_year == now_year )
|
||||
{
|
||||
if( now_longhour > last_hour_fny )
|
||||
{
|
||||
fill_hosu_hist_hours( now_longhour - last_hour_fny );
|
||||
}
|
||||
}
|
||||
else if( last_year == ( now_year -1 ) )
|
||||
{
|
||||
// 年をまたいでいるとき
|
||||
fill_hosu_hist_hours( ( ( 365 + (( now_year & 0x03 ) == 1 ? 1: 0 )) * 24 ) - last_hour_fny + now_longhour );
|
||||
}
|
||||
else if( last_year < now_year )
|
||||
{
|
||||
// 数年放置
|
||||
fill_hosu_hist_hours( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// カレンダーが巻き戻るなど
|
||||
// ノーケアでよい
|
||||
}
|
||||
last_year = now_year;
|
||||
last_hour_fny = now_longhour;
|
||||
|
||||
// 実際にインクリメント
|
||||
if( pool.vreg_c_ext.pedo_log[ p_record ] == HOSU_NODATA ) //※ 読みにくい…
|
||||
{
|
||||
pool.vreg_c_ext.pedo_log[ p_record ] = 1;
|
||||
}
|
||||
else if( pool.vreg_c_ext.pedo_log[ p_record ] != HOSU_MAX )
|
||||
{
|
||||
pool.vreg_c_ext.pedo_log[ p_record ] += 1;
|
||||
}
|
||||
pool.vreg_c_ext.pedo_log[ p_record ] = 1;
|
||||
}
|
||||
else if( pool.vreg_c_ext.pedo_log[ p_record ] != HOSU_MAX )
|
||||
{
|
||||
pool.vreg_c_ext.pedo_log[ p_record ] += 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -299,23 +326,43 @@ static void hosu_increment()
|
||||
======================================================== */
|
||||
void fill_hosu_hist_hours( u16 hours )
|
||||
{
|
||||
// ログ最大容量以上放置された?
|
||||
if( hours > PEDOMETER_LOG_SIZE )
|
||||
{
|
||||
hours = PEDOMETER_LOG_SIZE;
|
||||
hours = PEDOMETER_LOG_SIZE;
|
||||
}
|
||||
|
||||
// 空白の数時間の設定
|
||||
if( p_record >= PEDOMETER_LOG_SIZE )
|
||||
{
|
||||
pedolog_overflow = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if( p_record + hours >= PEDOMETER_LOG_SIZE )
|
||||
{
|
||||
pedolog_overflow = true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 空白の数時間の設定
|
||||
do
|
||||
{
|
||||
p_record += 1;
|
||||
// 新仕様 いっぱいで停止
|
||||
p_record += 1;
|
||||
if( p_record >= PEDOMETER_LOG_SIZE )
|
||||
{
|
||||
p_record = 0;
|
||||
}
|
||||
pool.vreg_c_ext.pedo_log[ p_record ] = 0;
|
||||
pedolog_overflow = true;
|
||||
NOP(); // ここに来るようだとバグ
|
||||
break;
|
||||
}else{
|
||||
pool.vreg_c_ext.pedo_log[ p_record ] = 0;
|
||||
}
|
||||
hours -= 1;
|
||||
}
|
||||
while( hours != 0 );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -337,6 +384,7 @@ void clear_hosu_hist()
|
||||
vreg_ctr[ VREG_C_ACC_HOSU_M ] = 0;
|
||||
vreg_ctr[ VREG_C_ACC_HOSU_H ] = 0;
|
||||
p_record = 0;
|
||||
pedolog_overflow = false;
|
||||
}
|
||||
|
||||
|
||||
@ -365,18 +413,16 @@ u8 hosu_read( )
|
||||
|
||||
if( iic_burst_state == 0 )
|
||||
{
|
||||
p_record_buffer = p_record;
|
||||
dat_temp[0] = last_hour;
|
||||
dat_temp[1] = last_day;
|
||||
dat_temp[2] = last_month;
|
||||
dat_temp[3] = btobcd( log_year );
|
||||
dat_temp[4] = now_min;
|
||||
dat_temp[5] = now_sec;
|
||||
p_record_buffer = p_record;
|
||||
}
|
||||
|
||||
if( iic_burst_state <= 5 )
|
||||
{
|
||||
rv = dat_temp[ iic_burst_state ];
|
||||
rv = pedo_log_latest[ iic_burst_state ];
|
||||
if( iic_burst_state == LEDO_LOG_LATEST_YEAR ) // BCDに直さなきゃという失態
|
||||
{
|
||||
rv = btobcd( rv );
|
||||
}
|
||||
iic_burst_state += 1;
|
||||
return( rv );
|
||||
}
|
||||
|
||||
@ -17,6 +17,4 @@ void pedometer();
|
||||
|
||||
|
||||
// =========================================================
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@ -287,7 +287,7 @@ void BT_model_detect()
|
||||
|
||||
BT_DET_P = 1;
|
||||
BT_TEMP_P = 1;
|
||||
wait_ms(1); // 電圧が上がるのに時間が掛かる
|
||||
wait_ms(2); // 電圧が上がるのに時間が掛かる
|
||||
|
||||
raw_adc_temperature = get_adc( ADC_SEL_BATT_TEMP );
|
||||
temp = get_adc( ADC_SEL_BATT_DET );
|
||||
|
||||
@ -20,6 +20,9 @@ extern u8 extinfo_read(); // task_misc.c
|
||||
extern u8 iic_burst_state; // 特殊バーストアクセスする時のカウンタ
|
||||
extern bit info_led_pattern_updated; // お知らせLEDのパターンを先頭に戻す
|
||||
|
||||
extern bit pedolog_overflow;
|
||||
|
||||
|
||||
|
||||
// ********************************************************
|
||||
#ifdef _DBG_PEDO_AUTO_ENABLE_
|
||||
@ -437,6 +440,10 @@ u8 vreg_ctr_read( u8 adrs )
|
||||
{
|
||||
return( extinfo_read() );
|
||||
}
|
||||
else if( adrs == VREG_C_ACC_HOSU_SETTING )
|
||||
{
|
||||
return( pedolog_overflow? 0x10: 0 );
|
||||
}
|
||||
|
||||
#if 0
|
||||
if( adrs >= VREG_C_ENDMARK_ )
|
||||
|
||||
Loading…
Reference in New Issue
Block a user