1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     pl_PedometerApi.h
4 
5   Copyright (C)2010 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 31469 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_PL_CTR_PL_PEDOMETER_API_H_
17 #define NN_PL_CTR_PL_PEDOMETER_API_H_
18 
19 #include <nn/Result.h>
20 #include <nn/types.h>
21 #include <nn/fnd.h>
22 
23 #ifdef __cplusplus
24 
25 namespace nn {
26 namespace pl {
27 namespace CTR {
28 
29 namespace detail{
30     typedef enum _IPCPortType
31     {
32         PORT_PEDOMETER = 0,
33         PORT_PEDOMETER_HID,
34         PORT_PEDOMETER_SYS,
35         NUM_OF_IPC_PORTS
36     } IPCPortType;
37 
38 }
39 
40 const char  PORT_NAME_PEDOMETER[] = "ptm:pdm";
41 const char  PORT_NAME_PEDOMETER_HID[] = "ptm:pdmh";
42 const char  PORT_NAME_PEDOMETER_SYS[] = "ptm:pdms";
43 
44 
45 /*!
46   @name   歩数ライブラリ
47   @{
48 */
49 
50 const s32 MAX_MONTHDAYS = 31; //!< 一ヶ月分のエントリに保存される日数
51 const s32 DAYHOURS = 24; //!< 一日分のエントリに保存される時間数
52 const s32 NUM_FREESPACE = 2; //!< 内部用のエントリ数
53 const s32 NUM_MONTHHISTORIES = 12 * 10; //!< 歩数ライブラリが保持する月ごとのエントリ数の最大値
54 const s32 MAX_MONTHHISTORIES = NUM_MONTHHISTORIES + NUM_FREESPACE; //!< 月ごとのエントリ数の内部での保存値
55 const s32 NUM_MONTHHISTORYENTRIES = MAX_MONTHDAYS * DAYHOURS; //!< 1ヶ月分の保存データ数
56 const u16 INVALID_COUNTER = 0xffff; //!< 無効なエントリを意味する値
57 
58 /*!
59    @brief  歩数エントリの記録年月を保持する構造体です。
60 
61            @ref GetStepHistoryAll で取得した歩数エントリに対応しています。
62 */
63 struct PedometerMonthHeader
64 {
65     u16 unusedCounter; //!< 値が @ref INVALID_COUNTER であれば、このエントリが未使用であることを示します。
66     s16 year;          //!< このエントリの年です。
67     s16 month;         //!< このエントリの月です。
68 };
69 
70 /*!
71    @brief  歩数データのヘッダ情報を意味する構造体です。
72 
73            @ref GetStepHistoryAll で取得できますが、totalStepCount, monthInfo 以外は使う必要はありません。
74 */
75 struct PedometerHistoryHeader
76 {
77     s32 version;                                        //!< バージョン情報です。
78     u32 totalStepCount;                                 //!< トータル歩数です。@ref GetTotalStepCount で取得できる値を同じです。
79     nn::fnd::DateTime startRecordTime;                  //!< 前回の記録時刻です。
80     PedometerMonthHeader monthInfo[MAX_MONTHHISTORIES]; //!< 歩数エントリの記録年月の情報です。
81     NN_PADDING4;
82 };
83 
84 /*!
85    @brief  一ヶ月分の歩数を保持する型です。
86 */
87 typedef u16 PedometerMonthData[NUM_MONTHHISTORYENTRIES];
88 
89 /*!
90    @brief  歩数ライブラリが保持する全歩数データ(10年分)を保持する型です。
91 */
92 typedef PedometerMonthData PedometerHistoryData[MAX_MONTHHISTORIES];
93 
94 /*
95     @brief Result コードの詳細
96 */
97 enum Description
98 {
99     DESCRIPTION_PEDOMETER_IS_WRITING = 1 //!< 歩数データの書き出し処理中であるため、取得できませんでした。
100 };
101 
102 /*!
103     @class nn::pl::CTR::ResultIsWriting
104     @brief @ref 歩数データの書き出し処理が実行中であることを示します。時間をおいてリトライするようにしてください。
105 */
106     NN_DEFINE_RESULT_CONST(
107         ResultIsWriting,
108         Result::LEVEL_STATUS, Result::SUMMARY_NOTHING_HAPPENED, Result::MODULE_NN_PTM, DESCRIPTION_PEDOMETER_IS_WRITING
109     );
110 
111 
112 
113 /*!
114   @brief    歩数の記録されている年月を表すエントリの構造体です。
115 */
116 struct PedometerEntry
117 {
118   s16 year;
119   s16 month;
120 };
121 
122 /*!
123     @brief      歩数計の状態を返します。
124 
125     @return     歩数計が歩数をカウントしているなら true を返し、カウントしていないなら false を返します。
126 */
127 bool GetPedometerState();
128 
129 /*!
130     @brief      ライブラリが記録している歩数のエントリ情報を取得します。
131 
132     @return     エントリ情報の個数を返します。
133 */
134 s8 GetStepHistoryEntry(PedometerEntry* pEntry);
135 
136 /*!
137     @brief 時間ごとに記録された歩数を取得します。
138 
139     @param[out] pStepCounts     取得した歩数を格納します。
140     @param[in]  numHours        取得する時間を指定します。
141     @param[in]  start           取得する期間の開始日時を指定します。
142 */
143 void GetStepHistory( u16 pStepCounts[], s32 numHours, nn::fnd::DateTime start );
144 
145 /*!
146     @brief  累計歩数を取得します。
147 
148     @return 累積歩数を返します。
149 */
150 u32 GetTotalStepCount();
151 
152 /*!
153     @brief ライブラリが保持する全歩数データを取得します。
154 
155     取得した header の monthInfo に記録されているエントリ情報は、data の PedometerMonthData の並びに対応しています。
156 
157     @param[out] header     取得した歩数エントリのヘッダ情報を格納します。
158     @param[out] data       取得した歩数エントリの情報を格納します。
159     @return     関数の実行結果を返します。以下に挙げる Result を返します。
160     @retval     ResultIsWriting             歩数のマージ処理が実行中です。時間をおいてリトライしてください。
161 */
162 nn::Result GetStepHistoryAll( PedometerHistoryHeader& header, PedometerHistoryData& data );
163 
164 /*!
165     @}
166  */
167 
168 } // namespace CTR {
169 } // namespace pl {
170 } // namespace nn {
171 
172 #endif
173 
174 #endif //   #ifndef NN_PL_CTR_PL_PEDOMETER_API_H_
175