Attempting to publish a tree

Dependencies:   BLE_API mbed-dev-bin nRF51822

Fork of microbit-dal by Lancaster University

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MicroBitCompat.h Source File

MicroBitCompat.h

00001 /*
00002 The MIT License (MIT)
00003 
00004 Copyright (c) 2016 British Broadcasting Corporation.
00005 This software is provided by Lancaster University by arrangement with the BBC.
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a
00008 copy of this software and associated documentation files (the "Software"),
00009 to deal in the Software without restriction, including without limitation
00010 the rights to use, copy, modify, merge, publish, distribute, sublicense,
00011 and/or sell copies of the Software, and to permit persons to whom the
00012 Software is furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00020 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00022 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00023 DEALINGS IN THE SOFTWARE.
00024 */
00025 
00026 /**
00027   * This file contains functions used to maintain compatability and portability.
00028   * It also contains constants that are used elsewhere in the DAL.
00029   */
00030 
00031 #ifndef MICROBIT_COMPAT_H
00032 #define MICROBIT_COMPAT_H
00033 
00034 #include "mbed.h"
00035 #include "MicroBitConfig.h"
00036 
00037 #define PI 3.14159265359
00038 
00039 /**
00040   * Determines the smallest of the two numbers
00041   *
00042   * @param a the first number
00043   *
00044   * @param b the second number
00045   *
00046   * @return The smallest of the two given values.
00047   */
00048 inline int min(int a, int b)
00049 {
00050     return (a < b ? a : b);
00051 }
00052 
00053 /**
00054   * Determines the largest of the two numbers
00055   *
00056   * @param a the first number
00057   *
00058   * @param b the second number
00059   *
00060   * @return The larger of the two given values.
00061   */
00062 inline int max(int a, int b)
00063 {
00064     return (a > b ? a : b);
00065 }
00066 
00067 /**
00068   * Sets a given area of memory to zero.
00069   *
00070   * @param a the pointer to the beginning of the memory to clear
00071   *
00072   * @param b the number of bytes to clear.
00073   */
00074 inline void *memclr(void *a, size_t b)
00075 {
00076     return memset(a,0,b);
00077 }
00078 
00079 /**
00080   * Determines if the given character is a printable ASCII/UTF8 decimal digit (0..9).
00081   *
00082   * @param c the character to check
00083   *
00084   * @return true if the character is a digit, false otherwise.
00085   */
00086 inline bool isdigit(char c)
00087 {
00088     return (c > 47 && c < 58);
00089 }
00090 
00091 /**
00092   * Performs an in buffer reverse of a given char array.
00093   *
00094   * @param s the string to reverse.
00095   *
00096   * @return MICROBIT_OK, or MICROBIT_INVALID_PARAMETER.
00097   */
00098 int string_reverse(char *s);
00099 
00100 /**
00101   * Converts a given integer into a string representation.
00102   *
00103   * @param n The number to convert.
00104   *
00105   * @param s A pointer to the buffer where the resulting string will be stored.
00106   *
00107   * @return MICROBIT_OK, or MICROBIT_INVALID_PARAMETER.
00108   */
00109 int itoa(int n, char *s);
00110 
00111 #endif