Michael Koster / Mbed 2 deprecated ipso_interop_mbed1

Dependencies:   Chainable_RGB_LED DHT LED_Bar mbed mbedConnectorInterface mbedEndpointNetwork_mjk_regfix

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BuzzerResource.h Source File

BuzzerResource.h

Go to the documentation of this file.
00001 /**
00002  * @file    BuzzerResource.h
00003  * @brief   mbed CoAP Endpoint
00004  * @author  Doug Anson, Michael Koster
00005  * @version 1.0
00006  * @see
00007  *
00008  * Copyright (c) 2014
00009  *
00010  * Licensed under the Apache License, Version 2.0 (the "License");
00011  * you may not use this file except in compliance with the License.
00012  * You may obtain a copy of the License at
00013  *
00014  *     http://www.apache.org/licenses/LICENSE-2.0
00015  *
00016  * Unless required by applicable law or agreed to in writing, software
00017  * distributed under the License is distributed on an "AS IS" BASIS,
00018  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00019  * See the License for the specific language governing permissions and
00020  * limitations under the License.
00021  */
00022 
00023 #ifndef __BUZZER_RESOURCE_H__
00024 #define __BUZZER_RESOURCE_H__
00025 
00026 
00027 // Base class
00028 #include "DynamicResource.h"
00029 
00030 // our buzzer
00031 DigitalOut buzzer_out(D4);
00032 
00033 bool buzzing = 0;
00034 
00035 /** BuzzerResource class
00036  */
00037 class BuzzerResource : public DynamicResource
00038 {
00039 
00040 public:
00041     /**
00042     Default constructor
00043     @param logger input logger instance for this resource
00044     @param name input the Light resource name
00045     @param observable input the resource is Observable (default: FALSE)
00046     */
00047     BuzzerResource(const Logger *logger,const char *name,const bool observable = false) : 
00048     DynamicResource(logger,name,"urn:X-IPSO:digital-output",SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED,observable) {
00049     }
00050     /**
00051     Get the on/off value of buzzer
00052     @returns string containing the last setting
00053     */
00054     virtual string get() {
00055         if(buzzing) return ("1");
00056         else return ("0");
00057     }
00058 
00059     /**
00060     Set the value of the buzzer
00061     @param string input 0 for quiet, 1 for buzz
00062     */
00063     virtual void put(const string value) {
00064         if (value == "1") {
00065             buzzing = 1;
00066             buzzer_out = 1;
00067         }
00068         else if (value == "0"){
00069             buzzing = 0;
00070             buzzer_out = 0;
00071         }
00072     }
00073 };
00074 
00075 #endif // __BUZZER_RESOURCE_H__