Give water to plants if dry amd pla meanwhile music the music vou can define with note length bind and breake also select several instruments for the sound

Dependencies:   mbed

Committer:
helmut
Date:
Wed Sep 19 14:16:56 2012 +0000
Revision:
0:5150b09127e3
plays mostly music that you can do with notes length breakes and bind; Some already defined; Tool is to start a pump for water to give plant is too dry.; Meanwhie plays music the most part of all

Who changed what in which revision?

UserRevisionLine numberNew contents of line
helmut 0:5150b09127e3 1
helmut 0:5150b09127e3 2 /*
helmut 0:5150b09127e3 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
helmut 0:5150b09127e3 4
helmut 0:5150b09127e3 5 Permission is hereby granted, free of charge, to any person obtaining a copy
helmut 0:5150b09127e3 6 of this software and associated documentation files (the "Software"), to deal
helmut 0:5150b09127e3 7 in the Software without restriction, including without limitation the rights
helmut 0:5150b09127e3 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
helmut 0:5150b09127e3 9 copies of the Software, and to permit persons to whom the Software is
helmut 0:5150b09127e3 10 furnished to do so, subject to the following conditions:
helmut 0:5150b09127e3 11
helmut 0:5150b09127e3 12 The above copyright notice and this permission notice shall be included in
helmut 0:5150b09127e3 13 all copies or substantial portions of the Software.
helmut 0:5150b09127e3 14
helmut 0:5150b09127e3 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
helmut 0:5150b09127e3 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
helmut 0:5150b09127e3 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
helmut 0:5150b09127e3 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
helmut 0:5150b09127e3 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
helmut 0:5150b09127e3 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
helmut 0:5150b09127e3 21 THE SOFTWARE.
helmut 0:5150b09127e3 22 */
helmut 0:5150b09127e3 23
helmut 0:5150b09127e3 24 #ifndef NETTCPSOCKET_H
helmut 0:5150b09127e3 25 #define NETTCPSOCKET_H
helmut 0:5150b09127e3 26
helmut 0:5150b09127e3 27 #include "net.h"
helmut 0:5150b09127e3 28 #include "host.h"
helmut 0:5150b09127e3 29
helmut 0:5150b09127e3 30 #include <queue>
helmut 0:5150b09127e3 31 using std::queue;
helmut 0:5150b09127e3 32
helmut 0:5150b09127e3 33 //Implements a Berkeley-like socket if
helmut 0:5150b09127e3 34 //Can be interfaced either to lwip or a Telit module
helmut 0:5150b09127e3 35
helmut 0:5150b09127e3 36 enum NetTcpSocketErr
helmut 0:5150b09127e3 37 {
helmut 0:5150b09127e3 38 __NETTCPSOCKET_MIN = -0xFFFF,
helmut 0:5150b09127e3 39 NETTCPSOCKET_SETUP, //NetTcpSocket not properly configured
helmut 0:5150b09127e3 40 NETTCPSOCKET_TIMEOUT,
helmut 0:5150b09127e3 41 NETTCPSOCKET_IF, //If has problems
helmut 0:5150b09127e3 42 NETTCPSOCKET_MEM, //Not enough mem
helmut 0:5150b09127e3 43 NETTCPSOCKET_INUSE, //If/Port is in use
helmut 0:5150b09127e3 44 NETTCPSOCKET_EMPTY, //Connections queue is empty
helmut 0:5150b09127e3 45 NETTCPSOCKET_RST, // Connection was reset by remote host
helmut 0:5150b09127e3 46 //...
helmut 0:5150b09127e3 47 NETTCPSOCKET_OK = 0
helmut 0:5150b09127e3 48 };
helmut 0:5150b09127e3 49
helmut 0:5150b09127e3 50 enum NetTcpSocketEvent
helmut 0:5150b09127e3 51 {
helmut 0:5150b09127e3 52 NETTCPSOCKET_CONNECTED, //Connected to host, must call accept() if we were listening
helmut 0:5150b09127e3 53 NETTCPSOCKET_ACCEPT, //Connected to client
helmut 0:5150b09127e3 54 NETTCPSOCKET_READABLE, //Data in buf
helmut 0:5150b09127e3 55 NETTCPSOCKET_WRITEABLE, //Can write data to buf
helmut 0:5150b09127e3 56 NETTCPSOCKET_CONTIMEOUT,
helmut 0:5150b09127e3 57 NETTCPSOCKET_CONRST,
helmut 0:5150b09127e3 58 NETTCPSOCKET_CONABRT,
helmut 0:5150b09127e3 59 NETTCPSOCKET_ERROR,
helmut 0:5150b09127e3 60 NETTCPSOCKET_DISCONNECTED
helmut 0:5150b09127e3 61 };
helmut 0:5150b09127e3 62
helmut 0:5150b09127e3 63
helmut 0:5150b09127e3 64 class NetTcpSocket
helmut 0:5150b09127e3 65 {
helmut 0:5150b09127e3 66 public:
helmut 0:5150b09127e3 67 NetTcpSocket();
helmut 0:5150b09127e3 68 virtual ~NetTcpSocket(); //close()
helmut 0:5150b09127e3 69
helmut 0:5150b09127e3 70 virtual NetTcpSocketErr bind(const Host& me) = 0;
helmut 0:5150b09127e3 71 virtual NetTcpSocketErr listen() = 0;
helmut 0:5150b09127e3 72 virtual NetTcpSocketErr connect(const Host& host) = 0;
helmut 0:5150b09127e3 73 virtual NetTcpSocketErr accept(Host* pClient, NetTcpSocket** ppNewNetTcpSocket) = 0;
helmut 0:5150b09127e3 74
helmut 0:5150b09127e3 75 virtual int /*if < 0 : NetTcpSocketErr*/ send(const char* buf, int len) = 0;
helmut 0:5150b09127e3 76 virtual int /*if < 0 : NetTcpSocketErr*/ recv(char* buf, int len) = 0;
helmut 0:5150b09127e3 77
helmut 0:5150b09127e3 78 virtual NetTcpSocketErr close() = 0;
helmut 0:5150b09127e3 79
helmut 0:5150b09127e3 80 virtual NetTcpSocketErr poll() = 0;
helmut 0:5150b09127e3 81
helmut 0:5150b09127e3 82 class CDummy;
helmut 0:5150b09127e3 83 //Callbacks
helmut 0:5150b09127e3 84 template<class T>
helmut 0:5150b09127e3 85 //Linker bug : Must be defined here :(
helmut 0:5150b09127e3 86 void setOnEvent( T* pItem, void (T::*pMethod)(NetTcpSocketEvent) )
helmut 0:5150b09127e3 87 {
helmut 0:5150b09127e3 88 m_pCbItem = (CDummy*) pItem;
helmut 0:5150b09127e3 89 m_pCbMeth = (void (CDummy::*)(NetTcpSocketEvent)) pMethod;
helmut 0:5150b09127e3 90 }
helmut 0:5150b09127e3 91
helmut 0:5150b09127e3 92 void resetOnEvent(); //Disable callback
helmut 0:5150b09127e3 93
helmut 0:5150b09127e3 94 protected:
helmut 0:5150b09127e3 95 void queueEvent(NetTcpSocketEvent e);
helmut 0:5150b09127e3 96 void discardEvents();
helmut 0:5150b09127e3 97 void flushEvents(); //to be called during polling
helmut 0:5150b09127e3 98
helmut 0:5150b09127e3 99 Host m_host;
helmut 0:5150b09127e3 100 Host m_client;
helmut 0:5150b09127e3 101
helmut 0:5150b09127e3 102 friend class Net;
helmut 0:5150b09127e3 103 int m_refs;
helmut 0:5150b09127e3 104
helmut 0:5150b09127e3 105 bool m_closed;
helmut 0:5150b09127e3 106 bool m_removed;
helmut 0:5150b09127e3 107
helmut 0:5150b09127e3 108 private:
helmut 0:5150b09127e3 109 //We do not want to execute user code in interrupt routines, so we queue events until the server is polled
helmut 0:5150b09127e3 110 //If we port this to a multithreaded OS, we could avoid this (however some functions here are not thread-safe, so beware ;) )
helmut 0:5150b09127e3 111 void onEvent(NetTcpSocketEvent e); //To be called on poll
helmut 0:5150b09127e3 112 CDummy* m_pCbItem;
helmut 0:5150b09127e3 113 void (CDummy::*m_pCbMeth)(NetTcpSocketEvent);
helmut 0:5150b09127e3 114 queue<NetTcpSocketEvent> m_events;
helmut 0:5150b09127e3 115
helmut 0:5150b09127e3 116 };
helmut 0:5150b09127e3 117
helmut 0:5150b09127e3 118 #endif