How to measure water in a reservoir

Dependencies:   Cayenne-MQTT-mbed Cayenne-LPP

Committer:
wamae
Date:
Fri Mar 08 11:34:56 2019 +0000
Revision:
0:7bfeb237e600
working code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wamae 0:7bfeb237e600 1 /**
wamae 0:7bfeb237e600 2 * Copyright (c) 2017, Arm Limited and affiliates.
wamae 0:7bfeb237e600 3 * SPDX-License-Identifier: Apache-2.0
wamae 0:7bfeb237e600 4 *
wamae 0:7bfeb237e600 5 * Licensed under the Apache License, Version 2.0 (the "License");
wamae 0:7bfeb237e600 6 * you may not use this file except in compliance with the License.
wamae 0:7bfeb237e600 7 * You may obtain a copy of the License at
wamae 0:7bfeb237e600 8 *
wamae 0:7bfeb237e600 9 * http://www.apache.org/licenses/LICENSE-2.0
wamae 0:7bfeb237e600 10 *
wamae 0:7bfeb237e600 11 * Unless required by applicable law or agreed to in writing, software
wamae 0:7bfeb237e600 12 * distributed under the License is distributed on an "AS IS" BASIS,
wamae 0:7bfeb237e600 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
wamae 0:7bfeb237e600 14 * See the License for the specific language governing permissions and
wamae 0:7bfeb237e600 15 * limitations under the License.
wamae 0:7bfeb237e600 16 */
wamae 0:7bfeb237e600 17
wamae 0:7bfeb237e600 18 #include "drivers/Serial.h"
wamae 0:7bfeb237e600 19
wamae 0:7bfeb237e600 20 /**
wamae 0:7bfeb237e600 21 * Serial object for console tracing
wamae 0:7bfeb237e600 22 */
wamae 0:7bfeb237e600 23 mbed::Serial pc(USBTX, USBRX, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
wamae 0:7bfeb237e600 24
wamae 0:7bfeb237e600 25 /**
wamae 0:7bfeb237e600 26 * If we have tracing library available, we can see traces from within the
wamae 0:7bfeb237e600 27 * stack. The library could be made unavailable by removing FEATURE_COMMON_PAL
wamae 0:7bfeb237e600 28 * from the mbed_app.json to save RAM.
wamae 0:7bfeb237e600 29 */
wamae 0:7bfeb237e600 30 #if defined(FEATURE_COMMON_PAL)
wamae 0:7bfeb237e600 31
wamae 0:7bfeb237e600 32 #include "platform/PlatformMutex.h"
wamae 0:7bfeb237e600 33 #include "mbed_trace.h"
wamae 0:7bfeb237e600 34
wamae 0:7bfeb237e600 35 /**
wamae 0:7bfeb237e600 36 * Local mutex object for synchronization
wamae 0:7bfeb237e600 37 */
wamae 0:7bfeb237e600 38 static PlatformMutex mutex;
wamae 0:7bfeb237e600 39
wamae 0:7bfeb237e600 40 static void serial_lock();
wamae 0:7bfeb237e600 41 static void serial_unlock();
wamae 0:7bfeb237e600 42 static void trace_printer(const char* str);
wamae 0:7bfeb237e600 43
wamae 0:7bfeb237e600 44 /**
wamae 0:7bfeb237e600 45 * Sets up trace for the application
wamae 0:7bfeb237e600 46 * Wouldn't do anything if the FEATURE_COMMON_PAL is not added
wamae 0:7bfeb237e600 47 * or if the trace is disabled using mbed_app.json
wamae 0:7bfeb237e600 48 */
wamae 0:7bfeb237e600 49 void setup_trace()
wamae 0:7bfeb237e600 50 {
wamae 0:7bfeb237e600 51 // setting up Mbed trace.
wamae 0:7bfeb237e600 52 mbed_trace_mutex_wait_function_set(serial_lock);
wamae 0:7bfeb237e600 53 mbed_trace_mutex_release_function_set(serial_unlock);
wamae 0:7bfeb237e600 54 mbed_trace_init();
wamae 0:7bfeb237e600 55 mbed_trace_print_function_set(trace_printer);
wamae 0:7bfeb237e600 56 }
wamae 0:7bfeb237e600 57
wamae 0:7bfeb237e600 58 /**
wamae 0:7bfeb237e600 59 * Lock provided for serial printing used by trace library
wamae 0:7bfeb237e600 60 */
wamae 0:7bfeb237e600 61 static void serial_lock()
wamae 0:7bfeb237e600 62 {
wamae 0:7bfeb237e600 63 mutex.lock();
wamae 0:7bfeb237e600 64 }
wamae 0:7bfeb237e600 65
wamae 0:7bfeb237e600 66 /**
wamae 0:7bfeb237e600 67 * Releasing lock provided for serial printing used by trace library
wamae 0:7bfeb237e600 68 */
wamae 0:7bfeb237e600 69 static void serial_unlock()
wamae 0:7bfeb237e600 70 {
wamae 0:7bfeb237e600 71 mutex.unlock();
wamae 0:7bfeb237e600 72 }
wamae 0:7bfeb237e600 73
wamae 0:7bfeb237e600 74 /**
wamae 0:7bfeb237e600 75 * Prints the Mbed trace, used by trace library.
wamae 0:7bfeb237e600 76 * Not intended for local use.
wamae 0:7bfeb237e600 77 */
wamae 0:7bfeb237e600 78 static void trace_printer(const char* str)
wamae 0:7bfeb237e600 79 {
wamae 0:7bfeb237e600 80 pc.printf("%s\r\n", str);
wamae 0:7bfeb237e600 81 }
wamae 0:7bfeb237e600 82
wamae 0:7bfeb237e600 83 #else
wamae 0:7bfeb237e600 84
wamae 0:7bfeb237e600 85 void setup_trace()
wamae 0:7bfeb237e600 86 {
wamae 0:7bfeb237e600 87 }
wamae 0:7bfeb237e600 88
wamae 0:7bfeb237e600 89 #endif
wamae 0:7bfeb237e600 90