common.dox 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. /**
  2. @defgroup Foundation Foundation
  3. \brief The core of the Pebble SDK
  4. The Pebble SDK consists of different frameworks that are organized by functionality.
  5. Each framework includes an API and provides access to the software libraries supported
  6. natively by Pebble OS. You use these interfaces (APIs) in the C programming
  7. language to write software for the Pebble platform.
  8. Frameworks are grouped hierarchically into Foundation, Graphics, Standard C and User Interface.
  9. The Foundation framework is the core of the Pebble OS.
  10. @defgroup Graphics Graphics
  11. \brief Low-level drawing routines
  12. The Graphics framework defines a set of APIs that can be used to draw paths, primitives and text,
  13. as well as handle the loading of fonts and the setting of graphics contexts for compositing, fill color
  14. and text color.
  15. @defgroup Smartstrap
  16. \brief Communicating with a Smartstrap
  17. Smartstrap APIs allow Pebble watches to communicate with electronics connected to the
  18. watch through the accessory port.
  19. Apps communicate with smartstraps by manipulating the attributes which the smartstrap supports
  20. or by reading and writing raw data using the raw data attribute (see \ref
  21. SMARTSTRAP_RAW_DATA_SERVICE_ID and \ref SMARTSTRAP_RAW_DATA_ATTRIBUTE_ID). A service is a collection of
  22. attributes which may be supported by a smartstrap. Once a smartstrap is connected, the
  23. availability handler will be called (if subscribed) for each service which is supported by the
  24. smartstrap. Then, the app may make read and write requests to attributes within that service on
  25. the smartstrap.
  26. Performing a read request on an attribute will cause the did_read handler to be called for the
  27. attribute when either a valid response is received from the smartstrap, or some error (i.e. a
  28. timeout) occurs.
  29. Performing a write request on an attribute will cause the did_write handler to be called for the
  30. attribute when the write is completed or an error occurs.
  31. When either the first attribute is created (see \ref smartstrap_attribute_create), or an
  32. availability_did_change handler is subscribed (see \ref smartstrap_subscribe), whichever comes
  33. first, power will be applied to the smartstrap, and connection establishment will begin. As part
  34. of the connection establishment, the smartstrap will report the services which it supports, at
  35. which point the smartstrap APIs will report them as being available and allow requests to be
  36. issued. If all created attributes are destroyed (see \ref smartstrap_attribute_destroy) and the
  37. availability_did_change handler is unsubscribed (see \ref smartstrap_unsubscribe), power will no
  38. longer be applied to the smartstrap and the services which it supported will no longer be
  39. available.
  40. Multiple attributes may have a read or write request pending at any given time, but individual
  41. attributes may only have a single request (either read or write) pending at any given time.
  42. Calls made to \ref smartstrap_attribute_create on a platform that does not support smartstraps
  43. will return NULL. Other calls will do nothing, and return SmartstrapResultNotPresent if
  44. possible.
  45. For code samples, a list of available attributes, and technical details of the Smartstrap
  46. protocol, see the
  47. <a href="//developer.getpebble.com/guides/hardware/">Building Smartstraps Guide</a>.
  48. @defgroup UI User Interface
  49. \brief Everything related to user interface
  50. The User Interface framework enables your Pebble watchface or watchapp to handle basic UI components,
  51. like clicks, layers, vibes, windows and window stacks.
  52. @defgroup Fonts Fonts
  53. \brief Custom and system fonts
  54. Pebble OS provides you with a wide range of system fonts that you can use when you need to display and
  55. render text or numbers in your Pebble watchface or watchapp.
  56. If you want to use a system font, you call fonts_get_system_font() and simply pass it the name of the
  57. system font you want.
  58. To use a custom font, call fonts_load_custom_font(). The sample code feature_custom_font shows how you can
  59. do this programmatically, using a font resource to convert a TrueType font into a rasterized version of that
  60. font at a specified font size.
  61. For example:
  62. \code{.c}
  63. GFont custom_font = fonts_load_custom_font
  64. (resource_get_handle(RESOURCE_ID_FONT_OSP_DIN_44));
  65. \endcode
  66. Raster Gothic Condensed is the font used throughout the Pebble system, largely because it is optimized
  67. for monochromatic displays. Pebble selected this font because it allows a relatively large number of
  68. characters to be displayed on a single line, also because the font has an excellent readability vs. size ratio.
  69. Refer to the chapter \htmlinclude UsingResources.html which explains how to work with font resources and embed
  70. a font into your app.
  71. @defgroup Math Math
  72. \brief Math routines.
  73. Below is a code example that uses the trigonometry functions to calculate the coordinate at which
  74. the second hand of a watch ends, using seconds from the system time.
  75. \code{.c}
  76. GPoint secondHand;
  77. GPoint center;
  78. struct tm *tick_time = ...;
  79. int32_t secondHandLength = ...;
  80. ...
  81. int32_t second_angle = TRIG_MAX_ANGLE * tick_time->tm_sec / 60;
  82. secondHand.y = (-cos_lookup(second_angle) * secondHandLength / TRIG_MAX_RATIO) + center.y;
  83. secondHand.x = (sin_lookup(second_angle) * secondHandLength / TRIG_MAX_RATIO) + center.x;
  84. \endcode
  85. @defgroup EventService Event Service
  86. \brief APIs to handle event services
  87. Pebble OS provides you with a set of APIs for handling event services, like accelerometer taps, app focus
  88. for interactivity, battery states, Bluetooth connections, and tick timers to call when a time component has
  89. changed. You use event services to be notified, for example, when something happens on Pebble, like losing
  90. the connection to the phone or when a notification covers the screen and requires your Pebble game to pause.
  91. @defgroup App App
  92. \brief App entry point and event loop.
  93. App is a module that provides you with an event loop for your Pebble app.
  94. All interaction between Pebble apps and the underlying Pebble OS takes place through an event loop.
  95. Before calling the \ref app_event_loop() function, you subscribe to event services and implement event handlers.
  96. Each handler receives specific types of Events dispatched throughout the life of the Pebble watchapp.
  97. The \ref app_event_loop() function takes care of both waiting for new events to become available on the
  98. watchapp event bus and routing new events to the appropriate handler. \ref EventService allows an app to
  99. directly register for different types of events. This function will block until the watchapp is ready
  100. to exit, and should be placed in the app's main() function.
  101. A watchapp typically configures and uses the \ref app_event_loop() as follows:
  102. \code{.c}
  103. int main(void) {
  104. // do set up here
  105. // Enter the main event loop. This will block until the app is ready to exit.
  106. app_event_loop();
  107. // do clean up here
  108. }
  109. \endcode
  110. @defgroup StandardC Standard C
  111. \brief Standard C types, functions, constants, etc.
  112. The standard C functions available here, such as \ref snprintf() and \ref time(), are provided by the firmware. Using these functions will not significantly increase the size of your app beyond what is needed to call the function. You may use other standard C functions not listed here, but be aware that not all will successfully be added to your app, and if they are added, your app's binary size will increase accordingly.
  113. @addtogroup StandardC
  114. @{
  115. @defgroup StandardMath Math
  116. \brief Standard math functions.
  117. @addtogroup StandardMath
  118. @{
  119. \fn int rand()
  120. \brief Generate a pseudo-random integer between 0 and \ref RAND_MAX inclusive. This function can be seeded by \ref srand().
  121. A simple way to change the range to be an integer between 0 and n-1 inclusive is using \% e.g. `rand() % n`.
  122. \return The pseudo-randomly generated number
  123. \fn void srand(unsigned int seed)
  124. \brief Seed the pseudo-random number generator.
  125. When your app starts, the pseudo-random number generator is automatically seeded with a random number that is generated by a high-entropy hardware random number generator.
  126. This function affects subsequent calls to \ref rand() to produce a sequence of numbers for a given seed value. You can use this to either create a different sequence of numbers by always using a different seed or to obtain the same sequence of numbers by reusing the same seed.
  127. \param seed The source number used to generate a sequence of pseudo-random numbers
  128. \def RAND_MAX
  129. \brief The maximum integer value \ref rand() may return.
  130. @}
  131. @defgroup StandardLocale Locale
  132. \brief Standard locale functions.
  133. @addtogroup StandardLocale
  134. @{
  135. \fn char *setlocale(int category, char *locale)
  136. \brief Set the app's locale for a category of routines.
  137. `setlocale` can be used to:
  138. - set the app's locale to a specific locale: `setlocale(LC_ALL, "en_CA")`
  139. - set the app's locale to the system locale: `setlocale(LC_ALL, "")`
  140. - get the app's curent locale: `setlocale(LC_ALL, NULL)`
  141. \param category The category of routines for which to set the locale
  142. \param locale The ISO formatted locale to use, or "" for the system locale
  143. \return the locale after the change is applied, NULL on failure (e.g. unsuported category)
  144. \note Currently, we only support two categories: LC_ALL and LC_TIME
  145. @}
  146. @defgroup StandardMemory Memory
  147. \brief Standard memory functions.
  148. @addtogroup StandardMemory
  149. @{
  150. \fn void *malloc(size_t size)
  151. \brief Allocates a requested amount of memory.
  152. \param size The number of bytes to allocate
  153. \return A pointer to the allocated memory or NULL on error.
  154. \fn void free(void *ptr)
  155. \brief Frees previously allocated memory.
  156. \param ptr The memory buffer to free.
  157. \fn void *calloc(size_t count, size_t size)
  158. \brief Allocates space for count objects that are size bytes and fills the
  159. memory with bytes of value 0
  160. \param count The number of objects to allocate space for
  161. \param size The size of the object type being allocated
  162. \return A pointer to the allocated memory or NULL on error.
  163. \fn void *realloc(void *ptr, size_t size)
  164. \brief Takes the memory allocated at ptr and changes the length of its
  165. allocation to the size specified. Copies the smaller of the length of the
  166. original allocation or the new size into the newly allocated buffer.
  167. \param ptr The memory allocation to be changed
  168. \param size The size to change the ptr allocation to
  169. \return A pointer to the new allocated memory or NULL on error
  170. \fn int memcmp(const void *ptr1, const void *ptr2, size_t n)
  171. \brief Compares the first n bytes of memory regions ptr1 and ptr2
  172. \param ptr1 The pointer to the first memory region to compare
  173. \param ptr2 The pointer to the second memory region to compare
  174. \param n The number of bytes to compare
  175. \return 0 if the first n bytes of ptr1 and ptr 2 match. Otherwise, the sign is determined by the sign of the difference between the first pair of bytes that differ in ptr1 and ptr2.
  176. \fn void *memcpy(void *dest, const void *src, size_t n)
  177. \brief Copies n bytes from src to dest.
  178. \param dest The pointer to the destination memory region
  179. \param src The pointer to the source memory region
  180. \param n The number of bytes to copy
  181. \fn void *memmove(void *dest, const void *src, size_t n);
  182. \brief Copies n bytes from src to dest by first copying to a temporary area first, allowing dest and src to potentially overlap. This can be used to move data to a location that overlaps its previous location.
  183. \param dest The pointer to the destination memory region
  184. \param src The pointer to the source memory region
  185. \param n The number of bytes to copy
  186. \fn void *memset(void *dest, int c, size_t n);
  187. \brief Sets n bytes to c starting at dest. This can be used to clear a memory region for example if c is 0.
  188. \param dest The pointer to the destination memory region
  189. \param c The integer used as an unsigned char to assign to each byte
  190. \param n The number of bytes to set
  191. \typedef size_t
  192. \brief size as an unsigned integer
  193. @}
  194. @defgroup StandardIO Format
  195. \brief Standard formatting. If you're looking for input/output functions, check out the \ref Logging API.
  196. @addtogroup StandardIO
  197. @{
  198. \fn int snprintf(char *str, size_t n, const *fmt, ...);
  199. \brief Format a string into a buffer. The Pebble-supported format specifiers are displayed below.
  200. \param str The string buffer to write the formatted string into
  201. \param n The maximum size of the buffer
  202. \param fmt The C formatting string
  203. \return The number of bytes written
  204. \htmlonly
  205. <style type="text/css">
  206. .tg {border-collapse:collapse;border-spacing:0;}
  207. .tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
  208. .tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
  209. </style>
  210. <table class="tg">
  211. <tr>
  212. <th class="tg-031e">Specifier</th>
  213. <th class="tg-031e">Output</th>
  214. <th class="tg-031e">Example</th>
  215. </tr>
  216. <tr>
  217. <td class="tg-031e">d or i</td>
  218. <td class="tg-031e">Signed decimal integer</td>
  219. <td class="tg-031e">294<br>-294</td>
  220. </tr>
  221. <tr>
  222. <td class="tg-031e">u</td>
  223. <td class="tg-031e">Unsigned decimal integer</td>
  224. <td class="tg-031e">7235</td>
  225. </tr>
  226. <tr>
  227. <td class="tg-031e">o</td>
  228. <td class="tg-031e">Unsigned octal</td>
  229. <td class="tg-031e">610</td>
  230. </tr>
  231. <tr>
  232. <td class="tg-031e">x</td>
  233. <td class="tg-031e">Unsigned hexadecimal integer</td>
  234. <td class="tg-031e">8b2</td>
  235. </tr>
  236. <tr>
  237. <td class="tg-031e">X</td>
  238. <td class="tg-031e">Unsigned hexadecimal integer (uppercase)</td>
  239. <td class="tg-031e">8B2</td>
  240. </tr>
  241. <tr>
  242. <td class="tg-031e">c</td>
  243. <td class="tg-031e">Character</td>
  244. <td class="tg-031e">h</td>
  245. </tr>
  246. <tr>
  247. <td class="tg-031e">s</td>
  248. <td class="tg-031e">Null-terminated string of characters</td>
  249. <td class="tg-031e">pebble</td>
  250. </tr>
  251. <tr>
  252. <td class="tg-031e">p</td>
  253. <td class="tg-031e">Pointer address</td>
  254. <td class="tg-031e">0xb8000000</td>
  255. </tr>
  256. <tr>
  257. <td class="tg-031e">%</td>
  258. <td class="tg-031e">A % followed by another % character will write a single % to the stream.</td>
  259. <td class="tg-031e">%</td>
  260. </tr>
  261. </table>
  262. <br>
  263. \endhtmlonly
  264. \details Length specifiers can also be combined with the format specifiers above:
  265. \htmlonly
  266. <style type="text/css">
  267. .tg {border-collapse:collapse;border-spacing:0;}
  268. .tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
  269. .tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
  270. .tg .tg-s6z2{text-align:center}
  271. </style>
  272. <table class="tg">
  273. <tr>
  274. <th class="tg-031e"></th>
  275. <th class="tg-s6z2">u o x X</th>
  276. <th class="tg-s6z2">c</th>
  277. <th class="tg-s6z2">s</th>
  278. <th class="tg-s6z2">p</th>
  279. <th class="tg-s6z2">n</th>
  280. </tr>
  281. <tr>
  282. <td class="tg-031e">(none)</td>
  283. <td class="tg-031e">unsigned int</td>
  284. <td class="tg-031e">int</td>
  285. <td class="tg-031e">char*</td>
  286. <td class="tg-031e">void*</td>
  287. <td class="tg-031e">int*</td>
  288. </tr>
  289. <tr>
  290. <td class="tg-031e">h</td>
  291. <td class="tg-031e">unsigned short int</td>
  292. <td class="tg-031e"></td>
  293. <td class="tg-031e"></td>
  294. <td class="tg-031e"></td>
  295. <td class="tg-031e">short int*</td>
  296. </tr>
  297. <tr>
  298. <td class="tg-031e">l</td>
  299. <td class="tg-031e">unsigned long int</td>
  300. <td class="tg-031e">wint_t</td>
  301. <td class="tg-031e">wchar_t*</td>
  302. <td class="tg-031e"></td>
  303. <td class="tg-031e">long int*</td>
  304. </tr>
  305. </table>
  306. \endhtmlonly
  307. @}
  308. @defgroup StandardString String
  309. \brief Standard C-string manipulation.
  310. @addtogroup StandardString
  311. @{
  312. \fn int strcmp(const char *str1, const char *str2)
  313. \brief Compares the null terminated strings str1 and str2 to each other.
  314. \param str1 The first C string to compare
  315. \param str2 The second C string to compare
  316. \return The difference of the first differing pair of bytes or 0 if the strings are identical
  317. \fn int strncmp(const char *str1, const char *str2, size_t n)
  318. \brief Compares the null terminated strings str1 and str2 to each other for up to n bytes. Comparison ends when a null is read or when n bytes are read, whichever happens first.
  319. \param str1 The first C string to compare
  320. \param str2 The second C string to compare
  321. \param n The maximum number of bytes to compare
  322. \return The difference of the first differing pair of bytes or the final pair of bytes read or 0 if the portions of the strings read are identical
  323. \fn char *strcpy(char *dest, const char *src)
  324. \brief Copies the string in src into dest and null terminates dest. There should be no overlap of dest and src in memory.
  325. \param dest The destination buffer with enough space for src
  326. \param src The source C string
  327. \return The destination buffer dest
  328. \fn char *strncpy(char *dest, const char *src, size_t n)
  329. \brief Copies up to n bytes from the string in src into dest and null terminates dest. If dest is null terminated before n bytes have been written, null bytes will continue to be written until n bytes total were written. There should be no overlap of dest and src in memory.
  330. \param dest The destination buffer with enough space for n bytes
  331. \param src The source string
  332. \param n The number of bytes to copy
  333. \return The destination buffer dest
  334. \fn char *strcat(char *dest, const char *src)
  335. \brief Concatenates the string in src to the end of the string pointed by dest and null terminates dest. There should be no overlap of dest and src.
  336. \param dest The destination buffer with enough space for src beyond the null character
  337. \param src The source C string
  338. \return The destination buffer dest
  339. \fn char *strncat(char *dest, const char *src, size_t n)
  340. \brief Concatenates up to n bytes from the string in src to the end of the string pointed by dest and null terminates dest. There should be no overlap of dest and src in memeory.
  341. \param dest The destination buffer with enough space for src beyond the null character
  342. \param src The source string
  343. \param n The maximum number of bytes to copy
  344. \return The destination buffer dest
  345. \fn size_t strlen(const char *str)
  346. \brief Calculates the length of a null terminated string.
  347. \param str The C string.
  348. \return The length of the C string str.
  349. @}
  350. @addtogroup StandardTime
  351. @{
  352. \typedef time_t
  353. time in seconds since the epoch, January 1st 1970
  354. @}
  355. \typedef unsigned int uint32_t
  356. \brief 32-bit unsigned integer number
  357. \typedef unsigned int uint16_t
  358. \brief 16-bit unsigned integer number
  359. @}
  360. @defgroup Misc Miscellaneous
  361. \brief Miscellaneous
  362. Useful helper functionality for building your pebble application that doesn't fit in any other category.
  363. */
  364. /* stdio.h */
  365. int snprintf(char *str, size_t n, const *fmt, ...);
  366. /* stdlib.h */
  367. #define RAND_MAX
  368. int rand();
  369. void srand(unsigned int seed);
  370. void *malloc(size_t size);
  371. void *calloc(size_t count, size_t size);
  372. void *realloc(void *ptr, size_t size);
  373. void free(void *ptr);
  374. /* string.h */
  375. typedef unsigned int size_t;
  376. int memcmp(const void *ptr1, const void *ptr2, size_t n);
  377. void *memcpy(void *dest, const void *src, size_t n);
  378. void *memmove(void *dest, const void *src, size_t n);
  379. void *memset(void *dest, int c, size_t n);
  380. int strcmp(const char *str1, const char *str2);
  381. int strncmp(const char *str1, const char *str2, size_t n);
  382. char *strcpy(char *dest, const char *src);
  383. char *strncpy(char *dest, const char *src, size_t n);
  384. char *strcat(char *dest, const char *src);
  385. char *strncat(char *dest, const char *src, size_t n);
  386. size_t strlen(const char *str);
  387. /* locale.h */
  388. char *setlocale(int category, char *locale);
  389. /* time.h */
  390. typedef unsigned int time_t;
  391. /* C99 integer types */
  392. typedef int int8_t;
  393. typedef int uint8_t;
  394. typedef int int16_t;
  395. typedef int uint16_t;
  396. typedef int int32_t;
  397. typedef int uint32_t;
  398. typedef int int64_t;
  399. typedef int uint64_t;