Ejemplo n.º 1
0
void doSwitchMode(Mode mode){
    arduino.connect(ip, port);

    if (mode != currentMode){
        currentMode = mode;

        char data;
        switch (mode){
            case Mode::SolidWhite: data = (char) 0;
                                   break;
            case Mode::Marquee:    data = (char) 1;
                                   break;
            case Mode::ColorCycle: data = (char) 2;
                                   break;
            case Mode::Pew:        data = (char) 3;
                                   break;
            default: break;
        }

        char* dataPointer = &data;
        arduino.send(dataPointer, sizeof(data));
    }

    arduino.disconnect();

}
Ejemplo n.º 2
0
				inline bool connect(sf::IpAddress mIp, unsigned short mPort)
				{
					if(busy) { ssvu::lo("ManagedSocket") << "Error: already connected" << std::endl; return false; }

					for(int i{0}; i < 5; ++i)
					{
						if(!busy && socket.connect(mIp, mPort) == sf::Socket::Done) goto succeed;
						std::this_thread::sleep_for(std::chrono::milliseconds(50));
					}

					return false;

					succeed:
					if(!busy)
					{
						ssvu::lo("ManagedSocket") << "Connecting..." << std::endl;
						busy = true;
						handlerFuture = std::async(std::launch::async, [this]{ while(busy) update(); });
					}
					ssvu::lo("ManagedSocket") << "Connected to " << mIp.toString() << ":" << mPort << std::endl;
					return true;
				}