From 12044e3cc2d33d97b5a70318b6910c18267b5b3b Mon Sep 17 00:00:00 2001 From: n2232 Date: Wed, 26 Jan 2011 09:15:26 +0000 Subject: [PATCH] =?UTF-8?q?=E3=83=BB=E6=AD=A9=E6=95=B0=E8=A8=88=E6=96=B0?= =?UTF-8?q?=E4=BB=95=E6=A7=98=E3=80=81=E3=83=90=E3=82=B0=E3=83=90=E3=82=B0?= =?UTF-8?q?=E3=81=A0=E3=81=A3=E3=81=9F=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E3=80=82=E3=83=86=E3=82=B9=E3=83=88=E3=82=82=E4=B8=80=E9=80=9A?= =?UTF-8?q?=E3=82=8A=20=E3=83=BB=E3=83=AD=E3=82=B0=E3=81=84=E3=81=A3?= =?UTF-8?q?=E3=81=B1=E3=81=84=E3=83=95=E3=83=A9=E3=82=B0(HOSU=5FSETTING.4)?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0=20=E3=83=BB=E9=9B=BB=E6=BA=90LED?= =?UTF-8?q?=E3=81=8C=E8=B5=A4=E7=82=B9=E7=81=AF=E3=81=99=E3=82=8B=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6=E3=81=AA=E9=9B=BB=E6=B1=A0=E3=82=92=E6=8E=A5=E7=B6=9A?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=81=A8=E3=81=8D=E3=80=81=E7=9B=B4=E5=BE=8C?= =?UTF-8?q?=E3=81=AE=E4=B8=80=E5=9B=9E=E3=81=A0=E3=81=91=E3=81=8A=E7=9F=A5?= =?UTF-8?q?=E3=82=89=E3=81=9BLED=E3=81=AE=E8=B5=A4=E3=81=8C=E3=81=A4?= =?UTF-8?q?=E3=81=8D=E3=81=A3=E3=81=B1=E3=81=AA=E3=81=97=E3=81=AB=E3=81=AA?= =?UTF-8?q?=E3=82=8B=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3=EF=BC=882?= =?UTF-8?q?=E5=9B=9E=E7=9B=AE=E4=BB=A5=E9=99=8D=E3=81=AE=E9=9B=BB=E6=BA=90?= =?UTF-8?q?=E6=8A=95=E5=85=A5=E3=81=A7=E3=81=AF=E5=A4=A7=E4=B8=88=E5=A4=AB?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- trunk/led.c | 44 ++++++- trunk/pedo_alg_thre_det2.c | 228 ++++++++++++++++++++++--------------- trunk/pedometer.h | 2 - trunk/pm.c | 2 +- trunk/vreg_ctr.c | 7 ++ 5 files changed, 183 insertions(+), 100 deletions(-) diff --git a/trunk/led.c b/trunk/led.c index 7672ec7..ec2f820 100644 --- a/trunk/led.c +++ b/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; // おしまい } - // 青点灯 - 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(); } diff --git a/trunk/pedo_alg_thre_det2.c b/trunk/pedo_alg_thre_det2.c index 3568894..5d98fd7 100644 --- a/trunk/pedo_alg_thre_det2.c +++ b/trunk/pedo_alg_thre_det2.c @@ -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 ); } diff --git a/trunk/pedometer.h b/trunk/pedometer.h index 40caf2a..97ae45f 100644 --- a/trunk/pedometer.h +++ b/trunk/pedometer.h @@ -17,6 +17,4 @@ void pedometer(); // ========================================================= - - #endif diff --git a/trunk/pm.c b/trunk/pm.c index 7725f4d..0862998 100644 --- a/trunk/pm.c +++ b/trunk/pm.c @@ -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 ); diff --git a/trunk/vreg_ctr.c b/trunk/vreg_ctr.c index d6e56a9..ec14457 100644 --- a/trunk/vreg_ctr.c +++ b/trunk/vreg_ctr.c @@ -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_ )