save loops

Dependencies:   mbed

Committer:
mbedalvaro
Date:
Tue Dec 02 04:39:15 2014 +0000
Revision:
0:df6fdd9b99f0
this new version of skinGames will have a function that stops scanning as the laser reaches the same position (i.e., loops) with a certain precision. It is for extracting contours for Takashita project. It can then save on a file or send on osc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 0:df6fdd9b99f0 1
mbedalvaro 0:df6fdd9b99f0 2 /*
mbedalvaro 0:df6fdd9b99f0 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
mbedalvaro 0:df6fdd9b99f0 4
mbedalvaro 0:df6fdd9b99f0 5 Permission is hereby granted, free of charge, to any person obtaining a copy
mbedalvaro 0:df6fdd9b99f0 6 of this software and associated documentation files (the "Software"), to deal
mbedalvaro 0:df6fdd9b99f0 7 in the Software without restriction, including without limitation the rights
mbedalvaro 0:df6fdd9b99f0 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
mbedalvaro 0:df6fdd9b99f0 9 copies of the Software, and to permit persons to whom the Software is
mbedalvaro 0:df6fdd9b99f0 10 furnished to do so, subject to the following conditions:
mbedalvaro 0:df6fdd9b99f0 11
mbedalvaro 0:df6fdd9b99f0 12 The above copyright notice and this permission notice shall be included in
mbedalvaro 0:df6fdd9b99f0 13 all copies or substantial portions of the Software.
mbedalvaro 0:df6fdd9b99f0 14
mbedalvaro 0:df6fdd9b99f0 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
mbedalvaro 0:df6fdd9b99f0 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
mbedalvaro 0:df6fdd9b99f0 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
mbedalvaro 0:df6fdd9b99f0 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
mbedalvaro 0:df6fdd9b99f0 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mbedalvaro 0:df6fdd9b99f0 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
mbedalvaro 0:df6fdd9b99f0 21 THE SOFTWARE.
mbedalvaro 0:df6fdd9b99f0 22 */
mbedalvaro 0:df6fdd9b99f0 23
mbedalvaro 0:df6fdd9b99f0 24 #ifndef NETUDPSOCKET_H
mbedalvaro 0:df6fdd9b99f0 25 #define NETUDPSOCKET_H
mbedalvaro 0:df6fdd9b99f0 26
mbedalvaro 0:df6fdd9b99f0 27 #include "net.h"
mbedalvaro 0:df6fdd9b99f0 28 #include "host.h"
mbedalvaro 0:df6fdd9b99f0 29
mbedalvaro 0:df6fdd9b99f0 30 #include <queue>
mbedalvaro 0:df6fdd9b99f0 31 using std::queue;
mbedalvaro 0:df6fdd9b99f0 32
mbedalvaro 0:df6fdd9b99f0 33 //Implements a Berkeley-like socket if
mbedalvaro 0:df6fdd9b99f0 34 //Can be interfaced either to lwip or a Telit module
mbedalvaro 0:df6fdd9b99f0 35
mbedalvaro 0:df6fdd9b99f0 36 enum NetUdpSocketErr
mbedalvaro 0:df6fdd9b99f0 37 {
mbedalvaro 0:df6fdd9b99f0 38 __NETUDPSOCKET_MIN = -0xFFFF,
mbedalvaro 0:df6fdd9b99f0 39 NETUDPSOCKET_SETUP, //NetUdpSocket not properly configured
mbedalvaro 0:df6fdd9b99f0 40 NETUDPSOCKET_IF, //If has problems
mbedalvaro 0:df6fdd9b99f0 41 NETUDPSOCKET_MEM, //Not enough mem
mbedalvaro 0:df6fdd9b99f0 42 NETUDPSOCKET_INUSE, //If/Port is in use
mbedalvaro 0:df6fdd9b99f0 43 //...
mbedalvaro 0:df6fdd9b99f0 44 NETUDPSOCKET_OK = 0
mbedalvaro 0:df6fdd9b99f0 45 };
mbedalvaro 0:df6fdd9b99f0 46
mbedalvaro 0:df6fdd9b99f0 47 enum NetUdpSocketEvent //Only one lonely event here... but who knows, maybe some day there'll be another one!
mbedalvaro 0:df6fdd9b99f0 48 {
mbedalvaro 0:df6fdd9b99f0 49 NETUDPSOCKET_READABLE, //Data in buf
mbedalvaro 0:df6fdd9b99f0 50 };
mbedalvaro 0:df6fdd9b99f0 51
mbedalvaro 0:df6fdd9b99f0 52
mbedalvaro 0:df6fdd9b99f0 53 class NetUdpSocket
mbedalvaro 0:df6fdd9b99f0 54 {
mbedalvaro 0:df6fdd9b99f0 55 public:
mbedalvaro 0:df6fdd9b99f0 56 NetUdpSocket();
mbedalvaro 0:df6fdd9b99f0 57 virtual ~NetUdpSocket(); //close()
mbedalvaro 0:df6fdd9b99f0 58
mbedalvaro 0:df6fdd9b99f0 59 virtual NetUdpSocketErr bind(const Host& me) = 0;
mbedalvaro 0:df6fdd9b99f0 60
mbedalvaro 0:df6fdd9b99f0 61 virtual int /*if < 0 : NetUdpSocketErr*/ sendto(const char* buf, int len, Host* pHost) = 0;
mbedalvaro 0:df6fdd9b99f0 62 virtual int /*if < 0 : NetUdpSocketErr*/ recvfrom(char* buf, int len, Host* pHost) = 0;
mbedalvaro 0:df6fdd9b99f0 63
mbedalvaro 0:df6fdd9b99f0 64 /* TODO NTH : printf / scanf helpers that call send/recv */
mbedalvaro 0:df6fdd9b99f0 65
mbedalvaro 0:df6fdd9b99f0 66 virtual NetUdpSocketErr close() = 0;
mbedalvaro 0:df6fdd9b99f0 67
mbedalvaro 0:df6fdd9b99f0 68 virtual NetUdpSocketErr poll() = 0;
mbedalvaro 0:df6fdd9b99f0 69
mbedalvaro 0:df6fdd9b99f0 70 class CDummy;
mbedalvaro 0:df6fdd9b99f0 71 //Callbacks
mbedalvaro 0:df6fdd9b99f0 72 template<class T>
mbedalvaro 0:df6fdd9b99f0 73 //Linker bug : Must be defined here :(
mbedalvaro 0:df6fdd9b99f0 74 void setOnEvent( T* pItem, void (T::*pMethod)(NetUdpSocketEvent) )
mbedalvaro 0:df6fdd9b99f0 75 {
mbedalvaro 0:df6fdd9b99f0 76 m_pCbItem = (CDummy*) pItem;
mbedalvaro 0:df6fdd9b99f0 77 m_pCbMeth = (void (CDummy::*)(NetUdpSocketEvent)) pMethod;
mbedalvaro 0:df6fdd9b99f0 78 }
mbedalvaro 0:df6fdd9b99f0 79
mbedalvaro 0:df6fdd9b99f0 80 void resetOnEvent(); //Disable callback
mbedalvaro 0:df6fdd9b99f0 81
mbedalvaro 0:df6fdd9b99f0 82 protected:
mbedalvaro 0:df6fdd9b99f0 83 void queueEvent(NetUdpSocketEvent e);
mbedalvaro 0:df6fdd9b99f0 84 void discardEvents();
mbedalvaro 0:df6fdd9b99f0 85 void flushEvents(); //to be called during polling
mbedalvaro 0:df6fdd9b99f0 86
mbedalvaro 0:df6fdd9b99f0 87 Host m_host;
mbedalvaro 0:df6fdd9b99f0 88 Host m_client;
mbedalvaro 0:df6fdd9b99f0 89
mbedalvaro 0:df6fdd9b99f0 90 friend class Net;
mbedalvaro 0:df6fdd9b99f0 91 int m_refs;
mbedalvaro 0:df6fdd9b99f0 92
mbedalvaro 0:df6fdd9b99f0 93 bool m_closed;
mbedalvaro 0:df6fdd9b99f0 94 bool m_removed;
mbedalvaro 0:df6fdd9b99f0 95
mbedalvaro 0:df6fdd9b99f0 96 private:
mbedalvaro 0:df6fdd9b99f0 97 //We do not want to execute user code in interrupt routines, so we queue events until the server is polled
mbedalvaro 0:df6fdd9b99f0 98 //If we port this to a multithreaded OS, we could avoid this (however some functions here are not thread-safe, so beware ;) )
mbedalvaro 0:df6fdd9b99f0 99 void onEvent(NetUdpSocketEvent e); //To be called on poll
mbedalvaro 0:df6fdd9b99f0 100 CDummy* m_pCbItem;
mbedalvaro 0:df6fdd9b99f0 101 void (CDummy::*m_pCbMeth)(NetUdpSocketEvent);
mbedalvaro 0:df6fdd9b99f0 102 queue<NetUdpSocketEvent> m_events;
mbedalvaro 0:df6fdd9b99f0 103
mbedalvaro 0:df6fdd9b99f0 104 };
mbedalvaro 0:df6fdd9b99f0 105
mbedalvaro 0:df6fdd9b99f0 106 #endif