bluetooth control motor
Dependents: BLE_LED_IDB0XA1_demo MOTOR_BLE_V2 Motor_Ble_v1 Motor_Ble_v10223 ... more
Fork of X_NUCLEO_IDB0XA1 by
source/utils/Utils.cpp@132:51056160fa4a, 2015-10-07 (annotated)
- Committer:
- Wolfgang Betz
- Date:
- Wed Oct 07 08:39:04 2015 +0200
- Revision:
- 132:51056160fa4a
- Child:
- 226:be2f4e1d0515
Andrea's version as of mail from 10/06/2015 05:56 PM
From: Andrea PALMIERI <andrea.palmieri@st.com>
To: Wolfgang BETZ <wolfgang.betz@st.com>, Rohit Grover <rohit.grover@arm.com>,
Antonio VILEI <antonio.vilei@st.com>, Mihail Stoyanov
<Mihail.Stoyanov@arm.com>
CC: Nicola CAPOVILLA <nicola.capovilla@st.com>, Silvio Lucio OLIVA
<silvio.oliva@st.com>, "jonathan.austin@arm.com" <jonathan.austin@arm.com>
Content-Class: urn:content-classes:message
Date: Tue, 6 Oct 2015 17:56:34 +0200
Subject: RE: Arduino Compatibility of X-NUCLEO-IDB04A1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wolfgang Betz |
132:51056160fa4a | 1 | /* mbed Microcontroller Library |
Wolfgang Betz |
132:51056160fa4a | 2 | * Copyright (c) 2006-2013 ARM Limited |
Wolfgang Betz |
132:51056160fa4a | 3 | * |
Wolfgang Betz |
132:51056160fa4a | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Wolfgang Betz |
132:51056160fa4a | 5 | * you may not use this file except in compliance with the License. |
Wolfgang Betz |
132:51056160fa4a | 6 | * You may obtain a copy of the License at |
Wolfgang Betz |
132:51056160fa4a | 7 | * |
Wolfgang Betz |
132:51056160fa4a | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Wolfgang Betz |
132:51056160fa4a | 9 | * |
Wolfgang Betz |
132:51056160fa4a | 10 | * Unless required by applicable law or agreed to in writing, software |
Wolfgang Betz |
132:51056160fa4a | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Wolfgang Betz |
132:51056160fa4a | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Wolfgang Betz |
132:51056160fa4a | 13 | * See the License for the specific language governing permissions and |
Wolfgang Betz |
132:51056160fa4a | 14 | * limitations under the License. |
Wolfgang Betz |
132:51056160fa4a | 15 | */ |
Wolfgang Betz |
132:51056160fa4a | 16 | |
Wolfgang Betz |
132:51056160fa4a | 17 | #include "Utils.h" |
Wolfgang Betz |
132:51056160fa4a | 18 | |
Wolfgang Betz |
132:51056160fa4a | 19 | /**************************************************************************/ |
Wolfgang Betz |
132:51056160fa4a | 20 | /*! |
Wolfgang Betz |
132:51056160fa4a | 21 | @brief sets values of EN_HIGH_POWER and PA_LEVEL corresponding to dBMLevel of tx power |
Wolfgang Betz |
132:51056160fa4a | 22 | |
Wolfgang Betz |
132:51056160fa4a | 23 | @returns value of tx power in dbm actually set |
Wolfgang Betz |
132:51056160fa4a | 24 | |
Wolfgang Betz |
132:51056160fa4a | 25 | @params[in] dBMLevel |
Wolfgang Betz |
132:51056160fa4a | 26 | dBMLevel of tx power to be set |
Wolfgang Betz |
132:51056160fa4a | 27 | |
Wolfgang Betz |
132:51056160fa4a | 28 | @params[in] dBMLevel |
Wolfgang Betz |
132:51056160fa4a | 29 | dBMLevel of tx power to be set |
Wolfgang Betz |
132:51056160fa4a | 30 | |
Wolfgang Betz |
132:51056160fa4a | 31 | @endcode |
Wolfgang Betz |
132:51056160fa4a | 32 | */ |
Wolfgang Betz |
132:51056160fa4a | 33 | /**************************************************************************/ |
Wolfgang Betz |
132:51056160fa4a | 34 | double getHighPowerAndPALevelValue(int8_t dBMLevel, int8_t& EN_HIGH_POWER, int8_t& PA_LEVEL) { |
Wolfgang Betz |
132:51056160fa4a | 35 | double dbm = (double) dBMLevel; |
Wolfgang Betz |
132:51056160fa4a | 36 | if(dbm<-18.0) { |
Wolfgang Betz |
132:51056160fa4a | 37 | dbm = -18; |
Wolfgang Betz |
132:51056160fa4a | 38 | EN_HIGH_POWER = 0; |
Wolfgang Betz |
132:51056160fa4a | 39 | PA_LEVEL = 0; |
Wolfgang Betz |
132:51056160fa4a | 40 | } |
Wolfgang Betz |
132:51056160fa4a | 41 | else if(dbm>8.0) { |
Wolfgang Betz |
132:51056160fa4a | 42 | dbm = 8; |
Wolfgang Betz |
132:51056160fa4a | 43 | EN_HIGH_POWER = 1; |
Wolfgang Betz |
132:51056160fa4a | 44 | PA_LEVEL = 7; |
Wolfgang Betz |
132:51056160fa4a | 45 | } |
Wolfgang Betz |
132:51056160fa4a | 46 | |
Wolfgang Betz |
132:51056160fa4a | 47 | // As a policy we are setting tx power level to the higher side |
Wolfgang Betz |
132:51056160fa4a | 48 | if((dbm>-18.0) && (dbm<=-15)) { |
Wolfgang Betz |
132:51056160fa4a | 49 | // set tx power to -15dBM |
Wolfgang Betz |
132:51056160fa4a | 50 | EN_HIGH_POWER = 0; |
Wolfgang Betz |
132:51056160fa4a | 51 | PA_LEVEL = 0; |
Wolfgang Betz |
132:51056160fa4a | 52 | } |
Wolfgang Betz |
132:51056160fa4a | 53 | else if((dbm>-15) && (dbm<=-14.7)) { |
Wolfgang Betz |
132:51056160fa4a | 54 | // set tx power to -14.7dBM |
Wolfgang Betz |
132:51056160fa4a | 55 | EN_HIGH_POWER = 0; |
Wolfgang Betz |
132:51056160fa4a | 56 | PA_LEVEL = 1; |
Wolfgang Betz |
132:51056160fa4a | 57 | } |
Wolfgang Betz |
132:51056160fa4a | 58 | else if((dbm>-14.7) && (dbm<=-11.7)) { |
Wolfgang Betz |
132:51056160fa4a | 59 | // set tx power to -11.7dBM |
Wolfgang Betz |
132:51056160fa4a | 60 | EN_HIGH_POWER = 1; |
Wolfgang Betz |
132:51056160fa4a | 61 | PA_LEVEL = 1; |
Wolfgang Betz |
132:51056160fa4a | 62 | } |
Wolfgang Betz |
132:51056160fa4a | 63 | else if((dbm>-11.7) && (dbm<=-11.4)) { |
Wolfgang Betz |
132:51056160fa4a | 64 | // set tx power to -11.4dBM |
Wolfgang Betz |
132:51056160fa4a | 65 | EN_HIGH_POWER = 0; |
Wolfgang Betz |
132:51056160fa4a | 66 | PA_LEVEL = 2; |
Wolfgang Betz |
132:51056160fa4a | 67 | } |
Wolfgang Betz |
132:51056160fa4a | 68 | else if((dbm>-11.4) && (dbm<=-8.4)) { |
Wolfgang Betz |
132:51056160fa4a | 69 | // set tx power to -8.4dBM |
Wolfgang Betz |
132:51056160fa4a | 70 | EN_HIGH_POWER = 1; |
Wolfgang Betz |
132:51056160fa4a | 71 | PA_LEVEL = 2; |
Wolfgang Betz |
132:51056160fa4a | 72 | } |
Wolfgang Betz |
132:51056160fa4a | 73 | else if((dbm>-8.4) && (dbm<=-8.1)) { |
Wolfgang Betz |
132:51056160fa4a | 74 | // set tx power to -8.1dBM |
Wolfgang Betz |
132:51056160fa4a | 75 | EN_HIGH_POWER = 0; |
Wolfgang Betz |
132:51056160fa4a | 76 | PA_LEVEL = 3; |
Wolfgang Betz |
132:51056160fa4a | 77 | } |
Wolfgang Betz |
132:51056160fa4a | 78 | else if((dbm>-8.1) && (dbm<=-5.1)) { |
Wolfgang Betz |
132:51056160fa4a | 79 | // set tx power to -5.1dBM |
Wolfgang Betz |
132:51056160fa4a | 80 | EN_HIGH_POWER = 1; |
Wolfgang Betz |
132:51056160fa4a | 81 | PA_LEVEL = 3; |
Wolfgang Betz |
132:51056160fa4a | 82 | } |
Wolfgang Betz |
132:51056160fa4a | 83 | else if((dbm>-5.1) && (dbm<=-4.9)) { |
Wolfgang Betz |
132:51056160fa4a | 84 | // set tx power to -4.9dBM |
Wolfgang Betz |
132:51056160fa4a | 85 | EN_HIGH_POWER = 0; |
Wolfgang Betz |
132:51056160fa4a | 86 | PA_LEVEL = 4; |
Wolfgang Betz |
132:51056160fa4a | 87 | } |
Wolfgang Betz |
132:51056160fa4a | 88 | else if((dbm>-4.9) && (dbm<=-2.1)) { |
Wolfgang Betz |
132:51056160fa4a | 89 | // set tx power to -2.1dBM |
Wolfgang Betz |
132:51056160fa4a | 90 | EN_HIGH_POWER = 1; |
Wolfgang Betz |
132:51056160fa4a | 91 | PA_LEVEL = 4; |
Wolfgang Betz |
132:51056160fa4a | 92 | } |
Wolfgang Betz |
132:51056160fa4a | 93 | else if((dbm>-2.1) && (dbm<=-1.6)) { |
Wolfgang Betz |
132:51056160fa4a | 94 | // set tx power to -1.6dBM |
Wolfgang Betz |
132:51056160fa4a | 95 | EN_HIGH_POWER = 0; |
Wolfgang Betz |
132:51056160fa4a | 96 | PA_LEVEL = 5; |
Wolfgang Betz |
132:51056160fa4a | 97 | } |
Wolfgang Betz |
132:51056160fa4a | 98 | else if((dbm>-1.6) && (dbm<=1.4)) { |
Wolfgang Betz |
132:51056160fa4a | 99 | // set tx power to -1.6dBM |
Wolfgang Betz |
132:51056160fa4a | 100 | EN_HIGH_POWER = 1; |
Wolfgang Betz |
132:51056160fa4a | 101 | PA_LEVEL = 5; |
Wolfgang Betz |
132:51056160fa4a | 102 | } |
Wolfgang Betz |
132:51056160fa4a | 103 | else if((dbm>1.4) && (dbm<=1.7)) { |
Wolfgang Betz |
132:51056160fa4a | 104 | // set tx power to 1.7dBM |
Wolfgang Betz |
132:51056160fa4a | 105 | EN_HIGH_POWER = 0; |
Wolfgang Betz |
132:51056160fa4a | 106 | PA_LEVEL = 6; |
Wolfgang Betz |
132:51056160fa4a | 107 | } |
Wolfgang Betz |
132:51056160fa4a | 108 | else if((dbm>1.7) && (dbm<=4.7)) { |
Wolfgang Betz |
132:51056160fa4a | 109 | // set tx power to 4.7dBM |
Wolfgang Betz |
132:51056160fa4a | 110 | EN_HIGH_POWER = 1; |
Wolfgang Betz |
132:51056160fa4a | 111 | PA_LEVEL = 6; |
Wolfgang Betz |
132:51056160fa4a | 112 | } |
Wolfgang Betz |
132:51056160fa4a | 113 | else if((dbm>4.7) && (dbm<=5.0)) { |
Wolfgang Betz |
132:51056160fa4a | 114 | // set tx power to 5.0dBM |
Wolfgang Betz |
132:51056160fa4a | 115 | EN_HIGH_POWER = 0; |
Wolfgang Betz |
132:51056160fa4a | 116 | PA_LEVEL = 7; |
Wolfgang Betz |
132:51056160fa4a | 117 | } |
Wolfgang Betz |
132:51056160fa4a | 118 | else if((dbm>5.0) && (dbm<=8)) { |
Wolfgang Betz |
132:51056160fa4a | 119 | // set tx power to 8.0dBM |
Wolfgang Betz |
132:51056160fa4a | 120 | EN_HIGH_POWER = 1; |
Wolfgang Betz |
132:51056160fa4a | 121 | PA_LEVEL = 7; |
Wolfgang Betz |
132:51056160fa4a | 122 | } |
Wolfgang Betz |
132:51056160fa4a | 123 | |
Wolfgang Betz |
132:51056160fa4a | 124 | return dbm; |
Wolfgang Betz |
132:51056160fa4a | 125 | } |