mirror of
https://github.com/workinghard/Cube4Fun.git
synced 2025-12-13 20:32:09 +00:00
Added admin key to control the cube
This commit is contained in:
@@ -1,813 +0,0 @@
|
||||
//
|
||||
// Webserver4Rainbow
|
||||
// Cube4Fun
|
||||
//
|
||||
// Created by Nikolai Rinas on 27.03.15.
|
||||
// Copyright (c) 2015 Nikolai Rinas. All rights reserved.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
#define DEBUG
|
||||
|
||||
#include <Wire.h>
|
||||
#include <SD.h>
|
||||
#include <SPI.h>
|
||||
#include <Ethernet.h>
|
||||
//#include <MemoryFree.h>
|
||||
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DEBUG_PRINTLN(x) Serial.println (x)
|
||||
#define DEBUG_PRINT(x) Serial.print (x)
|
||||
#define DEBUG_PRINT2(x,y) Serial.print (x,y)
|
||||
#define DEBUG_PRINTLN_TXT(x) Serial.println (F(x))
|
||||
#define DEBUG_PRINT_TXT(x) Serial.print (F(x))
|
||||
#else
|
||||
#define DEBUG_PRINTLN(x)
|
||||
#define DEBUG_PRINT(x)
|
||||
#define DEBUG_PRINT2(x,y)
|
||||
#define DEBUG_PRINTLN_TXT(x)
|
||||
#define DEBUG_PRINT_TXT(x)
|
||||
#endif
|
||||
|
||||
#define INBUFFER 65
|
||||
#define MY_CUBE_ADDR 2
|
||||
#define MAX_SEND_RETRY 10
|
||||
#define SERVER_PORT 8081
|
||||
#define ANIM_FILE_NAME "ANIMS.FRM"
|
||||
#define MAX_ANIMKEY_LENGTH 12
|
||||
#define MY_STREAM_KEEPALIVE_TIME 2000 // Send at least every 2 seconds one frame
|
||||
//#define MY_STREAM_TIMEOUT 30000 // Reset broken connection
|
||||
|
||||
unsigned char myReadBuffer[INBUFFER]; // string for fetching data from address
|
||||
unsigned char myReadBufferCount = 0;
|
||||
|
||||
//int getState = 0;
|
||||
// Enter a MAC address for your controller below.
|
||||
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
|
||||
byte mac[] = {
|
||||
0x90, 0xA2, 0xDA, 0x06, 0x00, 0x2A
|
||||
};
|
||||
// Fallback defaults
|
||||
IPAddress ip(192,168,1,79);
|
||||
IPAddress gateway(192,168,1, 1);
|
||||
IPAddress subnet(255, 255, 255, 0);
|
||||
//unsigned char x,y,z;
|
||||
unsigned char mySendBuffer[32];
|
||||
unsigned char myReceiveBuffer[64];
|
||||
|
||||
unsigned char serverMode = 0; // Default waiting for commands/requests
|
||||
|
||||
unsigned char myAnimationCount = 0;
|
||||
unsigned int _animationSpeed = 0;
|
||||
unsigned long _animationLength = 0;
|
||||
unsigned long _animationStartPos = 0;
|
||||
unsigned long _animationEndPos = 0;
|
||||
unsigned int _animationActFrame = 0;
|
||||
unsigned long _previousMillis = 0; // will store last time animation frame was sent
|
||||
|
||||
unsigned long _lastTimeFrameSent = 0; // general check when last frame was sent, use for timeout
|
||||
|
||||
// often used chars
|
||||
unsigned const char lc_b = 'b';
|
||||
unsigned const char lc_g = 'g';
|
||||
unsigned const char lc_r = 'r';
|
||||
unsigned const char lc_n = 'n';
|
||||
unsigned const char lc_f = 'f';
|
||||
unsigned const char lc_F = 'F';
|
||||
unsigned const char lc_s = 's';
|
||||
unsigned const char lc_S = 'S';
|
||||
unsigned const char lc_G = 'G';
|
||||
unsigned const char lc_E = 'E';
|
||||
unsigned const char lc_T = 'T';
|
||||
unsigned const char lc_coma = ',';
|
||||
unsigned const char lc_space = ' ';
|
||||
unsigned const char lc_slash = '/';
|
||||
unsigned const char lc_question = '?';
|
||||
unsigned const char lc_newline = '\n';
|
||||
unsigned const char lc_return = '\r';
|
||||
|
||||
|
||||
// Initialize the Ethernet client library
|
||||
// with the IP address and port of the server
|
||||
// that you want to connect to (port 80 is default for HTTP):
|
||||
//EthernetClient client;
|
||||
|
||||
// Initialize the Ethernet server library
|
||||
// with the IP address and port you want to use
|
||||
EthernetServer server(SERVER_PORT);
|
||||
|
||||
|
||||
// --- FUNCTIONS --- //
|
||||
// String functions START
|
||||
void appendChar2readBuffer(unsigned char c) {
|
||||
myReadBuffer[myReadBufferCount] = c;
|
||||
myReadBufferCount++;
|
||||
}
|
||||
int readBufferCompare2(const char* c, int count) {
|
||||
int result = 0 - count;
|
||||
for (unsigned char x=0;x<count;x++) {
|
||||
if (myReadBuffer[x] == c[x]) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
//--String functions END
|
||||
|
||||
void clearSavedAnimation() {
|
||||
DEBUG_PRINTLN("Anim reset");
|
||||
// Reset the animation
|
||||
_animationLength = 0;
|
||||
_animationStartPos = 0;
|
||||
_animationEndPos = 0;
|
||||
_animationActFrame = 0;
|
||||
_animationSpeed = 0;
|
||||
}
|
||||
|
||||
void clearBufferedFrame() {
|
||||
for (unsigned char x=0;x<64;x++) {
|
||||
mySendBuffer[x] = myReceiveBuffer[255];
|
||||
}
|
||||
}
|
||||
|
||||
void sendStartFrameStream() {
|
||||
mySendBuffer[0] = lc_s;
|
||||
wireSendBytes(mySendBuffer, 1);
|
||||
DEBUG_PRINTLN_TXT("Frm strmmd started");
|
||||
}
|
||||
|
||||
void sendEndFrameStream() {
|
||||
sendEmptyFrame(); // Send last frame
|
||||
mySendBuffer[0] = lc_S;
|
||||
wireSendBytes(mySendBuffer, 1);
|
||||
DEBUG_PRINTLN_TXT("Frm strmmd ended");
|
||||
}
|
||||
|
||||
// We need this function to change properly between different modes
|
||||
void setServerMode(unsigned char newMode) {
|
||||
if ( serverMode != newMode ) {
|
||||
DEBUG_PRINT(serverMode);
|
||||
DEBUG_PRINT_TXT(" -> ");
|
||||
DEBUG_PRINTLN(newMode);
|
||||
// Transition from 0 -> 1
|
||||
if ( serverMode == 0 && newMode == 1 ) {
|
||||
clearBufferedFrame();
|
||||
sendStartFrameStream();
|
||||
// Transition from 0 -> 2
|
||||
}else if ( serverMode == 0 && newMode == 2 ) {
|
||||
clearBufferedFrame();
|
||||
sendStartFrameStream();
|
||||
// Transition from 1 -> 0
|
||||
}else if ( serverMode == 1 && newMode == 0 ) {
|
||||
sendEndFrameStream();
|
||||
// Transition from 2 -> 0
|
||||
}else if ( serverMode == 2 && newMode == 0 ) {
|
||||
sendEndFrameStream();
|
||||
clearSavedAnimation();
|
||||
// Transition from 2 -> 1
|
||||
}else if ( serverMode == 2 && newMode == 1 ) {
|
||||
// Don't display saved animation again
|
||||
// this behaviour may be changed if prefered
|
||||
clearBufferedFrame();
|
||||
clearSavedAnimation();
|
||||
}
|
||||
// Transition from 1 -> 2
|
||||
// nothing special to do
|
||||
|
||||
serverMode = newMode;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char checkRequest(unsigned char c, unsigned char readState) {
|
||||
// Check for GET request and safe the data
|
||||
switch (readState) {
|
||||
case 0:
|
||||
if ( c == lc_G ) { readState = 1; }; break;
|
||||
case 1:
|
||||
if ( c == lc_E ) { readState = 2; }else{ readState = 0; }; break;
|
||||
case 2:
|
||||
if ( c == lc_T ) { readState = 3; }else{ readState = 0; }; break;
|
||||
case 3:
|
||||
if ( c == lc_space ) { readState = 4; }else{ readState = 0; }; break;
|
||||
case 4:
|
||||
if ( c == lc_slash ) { readState = 5; }else{ readState = 0; }; break;
|
||||
case 5:
|
||||
if ( c == lc_question ) { readState = 6; }else{ readState = 0; }; break;
|
||||
case 6:
|
||||
// Falls der Buffer noch nicht voll
|
||||
if ( myReadBufferCount < INBUFFER ) {
|
||||
if ( c == lc_space || c == lc_return || c == lc_newline ) {
|
||||
// Less data than buffersize
|
||||
readState = 7;
|
||||
}else{
|
||||
// Fille the buffer
|
||||
appendChar2readBuffer(c);
|
||||
}
|
||||
}else{
|
||||
// More data than buffersize
|
||||
readState = 7;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Reset the state for unknown data
|
||||
readState = 0;
|
||||
}
|
||||
return readState;
|
||||
}
|
||||
|
||||
void processRequest(EthernetClient client) {
|
||||
boolean debugFunc = false;
|
||||
#ifdef DEBUG
|
||||
// check the form
|
||||
if(readBufferCompare2("2=red", 5) > -1) {
|
||||
sentBlink(lc_r);
|
||||
DEBUG_PRINTLN_TXT("Red blink sent");
|
||||
debugFunc = true;
|
||||
}else if(readBufferCompare2("3=blue", 6) > -1) {
|
||||
sentBlink(lc_b);
|
||||
DEBUG_PRINTLN_TXT("Blue blink sent");
|
||||
debugFunc = true;
|
||||
}else if(readBufferCompare2("4=green", 7) > -1) {
|
||||
sentBlink(lc_g);
|
||||
DEBUG_PRINTLN_TXT("Green blink sent");
|
||||
debugFunc = true;
|
||||
}else if(readBufferCompare2("5=send", 6) > -1) {
|
||||
setFrame();
|
||||
DEBUG_PRINTLN_TXT("Frametest started");
|
||||
debugFunc = true;
|
||||
}else if(readBufferCompare2("6=start", 7) > -1) {
|
||||
sendStream();
|
||||
DEBUG_PRINTLN_TXT("Streamtest started");
|
||||
debugFunc = true;
|
||||
}else if(readBufferCompare2("7=file", 6) > -1) {
|
||||
printFileContent();
|
||||
DEBUG_PRINTLN_TXT("File content");
|
||||
debugFunc = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( debugFunc == false ) {
|
||||
if (readBufferCompare2("Ss", 2) > -1) { // Streammode, expect frames
|
||||
DEBUG_PRINTLN_TXT("Set mode to 1");
|
||||
setServerMode(1);
|
||||
}else if(readBufferCompare2("Ww", 2) > -1 ) { // Stream write mode
|
||||
writeAnimationSDCard(client); // blocking mode !!
|
||||
}else{
|
||||
checkAnimationSDCard(); // Check if we have animations on the SD card
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wireSendBytes(const uint8_t *data, size_t quantity) {
|
||||
boolean try_again = true;
|
||||
uint8_t error;
|
||||
unsigned char send_retries = 0;
|
||||
while ( try_again == true ) {
|
||||
Wire.beginTransmission(MY_CUBE_ADDR);
|
||||
if ( quantity == 1 ) {
|
||||
Wire.write(data[0]);
|
||||
}else{
|
||||
Wire.write(data, quantity);
|
||||
}
|
||||
error = Wire.endTransmission();
|
||||
if ( error == 0 || send_retries > MAX_SEND_RETRY ) {
|
||||
// everything went well or timeout
|
||||
try_again = false;
|
||||
}else{
|
||||
// Something went wrong
|
||||
DEBUG_PRINTLN_TXT("Send failed");
|
||||
}
|
||||
delayMicroseconds(10);
|
||||
}
|
||||
send_retries++;
|
||||
}
|
||||
|
||||
|
||||
void sentBlink(unsigned char color) {
|
||||
mySendBuffer[0] = lc_b;
|
||||
mySendBuffer[1] = color;
|
||||
wireSendBytes(mySendBuffer, 2);
|
||||
}
|
||||
|
||||
void setFrame() {
|
||||
int color = 0;
|
||||
int pos = random(0,64);
|
||||
mySendBuffer[0] = lc_f;
|
||||
wireSendBytes(mySendBuffer, 1);
|
||||
for (unsigned char x=0;x<32;x++) {
|
||||
if ( x == pos ) { color = random(0,64);}
|
||||
mySendBuffer[x] = color;
|
||||
color = 0;
|
||||
}
|
||||
wireSendBytes(mySendBuffer, 32);
|
||||
for (unsigned char x=0;x<32;x++) {
|
||||
if ( x+32 == pos ) { color = random(0,64);}
|
||||
mySendBuffer[x] = color;
|
||||
color = 0;
|
||||
}
|
||||
wireSendBytes(mySendBuffer, 32);
|
||||
mySendBuffer[0] = lc_F;
|
||||
mySendBuffer[1] = 50; // Show for two seconds
|
||||
wireSendBytes(mySendBuffer, 2);
|
||||
}
|
||||
|
||||
void sendStream() {
|
||||
unsigned char pos;
|
||||
|
||||
// Set to the stream mode
|
||||
mySendBuffer[0] = lc_s;
|
||||
wireSendBytes(mySendBuffer,1);
|
||||
// Begin data transmission
|
||||
for ( pos=0;pos<64;pos++ ) {
|
||||
//DEBUG_PRINT_TXT("Sende frame: ");
|
||||
//DEBUG_PRINTLN(pos);
|
||||
// Send walking led
|
||||
int color = 0;
|
||||
for (unsigned char x=0;x<32;x++) { // First half frame
|
||||
if ( x == pos ) { color = 128;}
|
||||
mySendBuffer[x] = color;
|
||||
color = 0;
|
||||
}
|
||||
wireSendBytes(mySendBuffer, 32);
|
||||
|
||||
for (unsigned char x=0;x<32;x++) {
|
||||
if ( x+32 == pos ) { color = 128;}
|
||||
mySendBuffer[x] = color;
|
||||
color = 0;
|
||||
}
|
||||
wireSendBytes(mySendBuffer, 32);
|
||||
|
||||
// call for new frame
|
||||
if ( pos<63 ) {
|
||||
mySendBuffer[0] = lc_n;
|
||||
wireSendBytes(mySendBuffer, 1);
|
||||
}
|
||||
|
||||
// Delay for 200ms
|
||||
delay(50);
|
||||
}
|
||||
// End the stream mode
|
||||
mySendBuffer[0] = lc_S;
|
||||
wireSendBytes(mySendBuffer, 1);
|
||||
|
||||
}
|
||||
|
||||
void sendBufferedFrame() {
|
||||
// Split the received Buffer in two parts and send them to the LED shield
|
||||
|
||||
for (unsigned char x=0;x<32;x++) { // First half frame
|
||||
mySendBuffer[x] = myReceiveBuffer[x];
|
||||
}
|
||||
wireSendBytes(mySendBuffer, 32);
|
||||
for (unsigned char x=0;x<32;x++) { // Second half frame
|
||||
mySendBuffer[x] = myReceiveBuffer[x+32];
|
||||
}
|
||||
wireSendBytes(mySendBuffer, 32);
|
||||
|
||||
mySendBuffer[0] = lc_n;
|
||||
wireSendBytes(mySendBuffer, 1);
|
||||
|
||||
// Remember when the frame was sent las time
|
||||
_lastTimeFrameSent = millis();
|
||||
}
|
||||
|
||||
void sendEmptyFrame() { // Because we need last frame for the LED shield
|
||||
for (unsigned char x=0;x<32;x++) { // First half frame
|
||||
mySendBuffer[x] = 0;
|
||||
}
|
||||
wireSendBytes(mySendBuffer, 32);
|
||||
wireSendBytes(mySendBuffer, 32);
|
||||
}
|
||||
|
||||
int sendFrameCached(unsigned char c, int bufferSize) {
|
||||
myReceiveBuffer[bufferSize] = c;
|
||||
if ( bufferSize<63 ) {
|
||||
bufferSize++;
|
||||
}else{
|
||||
// send the buffer
|
||||
sendBufferedFrame();
|
||||
bufferSize=0;
|
||||
}
|
||||
return bufferSize;
|
||||
}
|
||||
|
||||
void printFileContent() {
|
||||
File myProjectFile = SD.open(ANIM_FILE_NAME, FILE_READ);
|
||||
if (myProjectFile) {
|
||||
while (myProjectFile.available()) {
|
||||
unsigned char myC = myProjectFile.read();
|
||||
DEBUG_PRINTLN(myC);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void checkAnimationSDCard() {
|
||||
// Open File for read
|
||||
File myProjectFile = SD.open(ANIM_FILE_NAME, FILE_READ);
|
||||
if (myProjectFile) {
|
||||
DEBUG_PRINTLN_TXT("Reading keys");
|
||||
|
||||
unsigned char myReadStatus = 0; // 0 = expect key
|
||||
unsigned char myC = 0;
|
||||
unsigned char myKeyBuffer[MAX_ANIMKEY_LENGTH]; // maximum length for the key
|
||||
unsigned char myKeyLength = 0;
|
||||
unsigned char myIntBuffer[2]; // Byte to int
|
||||
unsigned char myIntBufferLength = 0;
|
||||
|
||||
while (myProjectFile.available() && myReadStatus < 20) {
|
||||
myC = myProjectFile.read();
|
||||
|
||||
switch (myReadStatus) {
|
||||
case 0: // expect key
|
||||
if ( myC == lc_coma ) {
|
||||
myReadStatus = 1; // Startkey found
|
||||
}
|
||||
break;
|
||||
case 1: // expect keyline confirmation
|
||||
if ( myC == lc_F ) {
|
||||
myReadStatus = 2; // Key-line confirmed
|
||||
}else{
|
||||
myReadStatus = 0; // Reset
|
||||
}
|
||||
break;
|
||||
case 2: // Reading animation key
|
||||
if ( myC == lc_coma ) {
|
||||
myReadStatus = 3; // change to read next element
|
||||
}else if ( myKeyLength < MAX_ANIMKEY_LENGTH ) { // Fill till max buffer
|
||||
myKeyBuffer[myKeyLength] = myC;
|
||||
myKeyLength++;
|
||||
}
|
||||
break;
|
||||
case 3: // Save playtime
|
||||
if ( myIntBufferLength < 2 ) { // Save playtime value
|
||||
myIntBuffer[myIntBufferLength] = myC;
|
||||
myIntBufferLength++;
|
||||
}
|
||||
if ( myIntBufferLength == 2 ) { // Buffer is full, set values
|
||||
unsigned int animationLength = word(myIntBuffer[1], myIntBuffer[0]);
|
||||
// Save the time the animation will end
|
||||
_animationLength = animationLength * 1000 + millis();
|
||||
// clear buffer
|
||||
myIntBufferLength = 0;
|
||||
// expect next value
|
||||
myReadStatus = 4;
|
||||
}
|
||||
break;
|
||||
case 4: // Save speed
|
||||
if ( myIntBufferLength < 2 ) { // Save speed value
|
||||
myIntBuffer[myIntBufferLength] = myC;
|
||||
myIntBufferLength++;
|
||||
}
|
||||
if ( myIntBufferLength == 2 ) { // Buffer is full, set values
|
||||
_animationSpeed = word(myIntBuffer[1], myIntBuffer[0]);
|
||||
// clear buffer
|
||||
myIntBufferLength = 0;
|
||||
// expect next value
|
||||
myReadStatus = 5;
|
||||
}
|
||||
break;
|
||||
case 5: // Save frames
|
||||
if ( myIntBufferLength < 2 ) { // Save speed value
|
||||
myIntBuffer[myIntBufferLength] = myC;
|
||||
myIntBufferLength++;
|
||||
}
|
||||
if ( myIntBufferLength == 2 ) { // Buffer is full, set values
|
||||
// set to complete read
|
||||
myReadStatus = 6;
|
||||
unsigned int animationFrames = word(myIntBuffer[1], myIntBuffer[0]);
|
||||
// Calculate start and end position
|
||||
_animationStartPos = myProjectFile.position() + 1;
|
||||
_animationEndPos = _animationStartPos + 65 * animationFrames;
|
||||
// Check if the key matches
|
||||
if(readBufferCompare2(reinterpret_cast<const char*>(myKeyBuffer), myKeyLength) > -1) {
|
||||
// We found animation
|
||||
DEBUG_PRINTLN_TXT("Found animation");
|
||||
myReadStatus = 20; // End search, we found our animation
|
||||
}else{
|
||||
DEBUG_PRINTLN_TXT("No animation found");
|
||||
if (_animationEndPos > _animationStartPos ) {
|
||||
// Goto next frame
|
||||
myProjectFile.seek(_animationEndPos);
|
||||
myReadStatus = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// clear buffer
|
||||
myIntBufferLength = 0;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if( myC == lc_newline ) { // uncomplete keyline or no animation found
|
||||
// check for values
|
||||
if ( _animationEndPos > 0 && _animationStartPos > 0 && _animationSpeed > 0 ) {
|
||||
DEBUG_PRINTLN_TXT("Anim key found");
|
||||
}else{
|
||||
DEBUG_PRINTLN_TXT("--keyline failed--");
|
||||
// Reset everything
|
||||
myReadStatus = 0;
|
||||
myKeyLength = 0;
|
||||
myIntBufferLength = 0;
|
||||
clearSavedAnimation();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
myProjectFile.close();
|
||||
}
|
||||
|
||||
boolean readAnimationSD() {
|
||||
unsigned char myC;
|
||||
unsigned char myBytes = 0;
|
||||
// Read SD Card
|
||||
File myProjectFile = SD.open(ANIM_FILE_NAME, FILE_READ);
|
||||
// Goto start position
|
||||
if ( myProjectFile.available() ) {
|
||||
unsigned long _animationPos = _animationStartPos + _animationActFrame * 65; // startPos + offset
|
||||
if ( _animationPos < _animationEndPos ) {
|
||||
myProjectFile.seek(_animationPos);
|
||||
}else{
|
||||
_animationActFrame = 0; // Start at the first frame again
|
||||
myProjectFile.seek(_animationStartPos);
|
||||
}
|
||||
}
|
||||
// Read one frame
|
||||
while ( myProjectFile.available() && myBytes < 64 ) {
|
||||
myC = myProjectFile.read();
|
||||
myReceiveBuffer[myBytes] = myC;
|
||||
myBytes++;
|
||||
}
|
||||
|
||||
// close the file:
|
||||
myProjectFile.close();
|
||||
|
||||
// If we have complete frame, return true
|
||||
if ( myBytes > 63 ) {
|
||||
// read successfull
|
||||
_animationActFrame++;
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long byte2Long(unsigned char* byteArray) {
|
||||
// little endian conversion
|
||||
unsigned long retval;
|
||||
retval = (unsigned long) byteArray[3] << 24 | (unsigned long) byteArray[2] << 16;
|
||||
retval |= (unsigned long) byteArray[1] << 8 | byteArray[0];
|
||||
return retval;
|
||||
}
|
||||
void writeAnimationSDCard(EthernetClient client) {
|
||||
// Send answer
|
||||
unsigned char readBuffer[4];
|
||||
readBuffer[0] = myReadBuffer[2];
|
||||
readBuffer[1] = myReadBuffer[3];
|
||||
readBuffer[2] = myReadBuffer[4];
|
||||
readBuffer[3] = myReadBuffer[5];
|
||||
unsigned long fileSize = byte2Long(readBuffer);
|
||||
|
||||
// DEBUG_PRINT_TXT("fileSizeBuffer: ");
|
||||
for (unsigned char i=0; i<4; i++ ) {
|
||||
client.write(readBuffer[i]);
|
||||
// DEBUG_PRINT(readBuffer[i]);
|
||||
}
|
||||
client.write(lc_return);
|
||||
client.write(lc_newline);
|
||||
// DEBUG_PRINTLN_TXT(" ");
|
||||
|
||||
|
||||
|
||||
// DEBUG_PRINT_TXT("Filesize expected:");
|
||||
// DEBUG_PRINTLN(fileSize);
|
||||
|
||||
// Blocking mode to write receiving data to file
|
||||
if (client) {
|
||||
// Remove file if exists
|
||||
if ( SD.exists(ANIM_FILE_NAME) ) {
|
||||
SD.remove(ANIM_FILE_NAME);
|
||||
}
|
||||
|
||||
File myProjectFile = SD.open(ANIM_FILE_NAME, FILE_WRITE);
|
||||
unsigned long receivedBytes = 0;
|
||||
|
||||
if (myProjectFile) {
|
||||
while (client.connected() && receivedBytes < fileSize) {
|
||||
if (client.available()) {
|
||||
unsigned char c = client.read();
|
||||
//writing bytes
|
||||
myProjectFile.write(c);
|
||||
receivedBytes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
if ( receivedBytes == fileSize ) {
|
||||
DEBUG_PRINTLN_TXT("Complete data received\n");
|
||||
}else{
|
||||
DEBUG_PRINTLN_TXT("Data incomplete\n");
|
||||
}
|
||||
DEBUG_PRINT_TXT("Expected:");
|
||||
DEBUG_PRINTLN(fileSize);
|
||||
DEBUG_PRINT_TXT("Received:");
|
||||
DEBUG_PRINTLN(receivedBytes);
|
||||
*/
|
||||
myProjectFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
void displaySavedAnimation() {
|
||||
if ( _animationLength > 0 ) { // Animation was set
|
||||
unsigned long currentMillis = millis();
|
||||
// Display animation set over the network
|
||||
if ( currentMillis < _animationLength ) { // __animationLength = startTime + animLengthTime
|
||||
if ( _animationStartPos > 0 && _animationEndPos > 0 && _animationSpeed > 0){ // validity check
|
||||
if ( _animationEndPos > _animationStartPos ) {
|
||||
//DEBUG_PRINTLN_TXT("Setting mode to 2");
|
||||
setServerMode(2); // Switch the server mode
|
||||
if ( currentMillis - _previousMillis >= _animationSpeed ) { // Sent data with the set speed
|
||||
// save the last time you sent frame
|
||||
_previousMillis = currentMillis;
|
||||
// Fill Buffer
|
||||
if ( true == readAnimationSD() ) {
|
||||
// Send buffered frame
|
||||
sendBufferedFrame();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
// End the stream mode
|
||||
setServerMode(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void keepAliveFrame() {
|
||||
// Check if we need to send a keep alive frame
|
||||
if ( millis() - _lastTimeFrameSent > MY_STREAM_KEEPALIVE_TIME ) {
|
||||
// Send buffered frame
|
||||
sendBufferedFrame();
|
||||
}
|
||||
}
|
||||
|
||||
// --------- MAIN ---------- //
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Wire.begin();
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.begin(9600);
|
||||
#endif
|
||||
DEBUG_PRINTLN_TXT("Sender1");
|
||||
|
||||
DEBUG_PRINTLN_TXT("Init SD card...");
|
||||
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
|
||||
// Note that even if it's not used as the CS pin, the hardware SS pin
|
||||
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
|
||||
// or the SD library functions will not work.
|
||||
// disable w5100 SPI
|
||||
pinMode(10, OUTPUT);
|
||||
//digitalWrite(10,HIGH);
|
||||
|
||||
if (!SD.begin(4)) {
|
||||
DEBUG_PRINTLN_TXT("init failed!");
|
||||
// TODO: deny some functions
|
||||
}else{
|
||||
DEBUG_PRINTLN_TXT("init done.");
|
||||
}
|
||||
|
||||
// start the Ethernet connection:
|
||||
Ethernet.begin(mac, ip, gateway, subnet);
|
||||
|
||||
// ----------------------
|
||||
/* Sorry, but had to drop DHCP support due to missing memory
|
||||
// If you have a MEGA, feel free to use it
|
||||
if (Ethernet.begin(mac) == 0) {
|
||||
DEBUG_PRINTLN_TXT("Failed to configure Ethernet using DHCP");
|
||||
DEBUG_PRINTLN_TXT("Using defaults 192.168.1.79");
|
||||
// initialize the ethernet device not using DHCP:
|
||||
Ethernet.begin(mac, ip, gateway, subnet);
|
||||
}
|
||||
*/
|
||||
// -----------------------
|
||||
|
||||
#ifdef DEBUG
|
||||
// print your local IP address:
|
||||
DEBUG_PRINTLN_TXT("My IP: ");
|
||||
for (byte thisByte = 0; thisByte < 4; thisByte++) {
|
||||
// print the value of each byte of the IP address:
|
||||
DEBUG_PRINT2(Ethernet.localIP()[thisByte], DEC);
|
||||
DEBUG_PRINT(".");
|
||||
}
|
||||
DEBUG_PRINTLN_TXT("");
|
||||
#endif
|
||||
|
||||
// Print free memory
|
||||
//DEBUG_PRINT("freeMemory()=");
|
||||
//DEBUG_PRINTLN(freeMemory());
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// Process Server requests
|
||||
// listen for incoming clients
|
||||
EthernetClient client = server.available();
|
||||
|
||||
if (client) { // Client connected and sending data
|
||||
DEBUG_PRINTLN_TXT("Client attached");
|
||||
// Init status
|
||||
unsigned char readState = 0;
|
||||
unsigned char lastChar = 0; // Make sure you never check for 0-value !!!
|
||||
int bufferSize = 0;
|
||||
// If we receive data, interrupt other states
|
||||
setServerMode(0);
|
||||
|
||||
// Read incoming data
|
||||
while (client.connected()) {
|
||||
if (client.available()) {
|
||||
// get incoming byte
|
||||
unsigned char c = client.read();
|
||||
|
||||
// check for server mode
|
||||
switch (serverMode) {
|
||||
case 0:
|
||||
// Checking incoming requests
|
||||
readState = checkRequest(c, readState);
|
||||
|
||||
// Processing if request is recognized
|
||||
if ( readState == 7 ) { // HTTP GET recognized
|
||||
processRequest(client);
|
||||
// process only one time
|
||||
readState = 0;
|
||||
myReadBufferCount = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
// Streaming frames
|
||||
bufferSize = sendFrameCached(c, bufferSize);
|
||||
|
||||
// Check for streaming end
|
||||
if ( c == lc_S && lastChar == lc_s ) { // "sS" received
|
||||
//sendEndFrameStream();
|
||||
setServerMode(0);
|
||||
bufferSize = 0;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// if we got whole HTTP Head and still waiting for commands,
|
||||
// send HTTP answer
|
||||
if ( serverMode == 0 && c == lc_newline && lastChar == lc_return ) { // \r\n was send
|
||||
// send a standard http response header
|
||||
client.println(F("HTTP/1.1 200 OK\nContent-Type: text/html\r\n\n<html><head><title>Rainbowduino Webserver</title></head><body><br><hr/><h1><div align=center>Rainbowduino Webserver 1.0</div></h1><hr /><br><div align=left>Functions:</div><br><table border=1 width=500 cellpadding=5><tr><td>Blink:<br></td><td align=center><form method=get><input type=submit name=2 value=red></form><form method=get><input type=submit name=3 value=blue></form><form method=get><input type=submit name=4 value=green></form></td></tr><tr><td>Frametest<br></td><td align=center><form method=get><input type=submit name=5 value=send></form></td></tr><tr><td>Streamtest<br></td><td align=center><form method=get><input type=submit name=6 value=start></form></td></tr><tr><td>Print file to serial<br></td><td align=center><form method=get><input type=submit name=7 value=file></form></td></tr></table><br></body></html>"));
|
||||
// Close the connection
|
||||
client.stop();
|
||||
}
|
||||
|
||||
lastChar = c;
|
||||
}
|
||||
|
||||
// If we are in the streaming mode and don't receive any frames,
|
||||
// check for timeout
|
||||
if ( serverMode == 1 ) {
|
||||
// keep the connection to the Rainbowduino alive
|
||||
keepAliveFrame();
|
||||
}
|
||||
}
|
||||
|
||||
// give web browser time to receive the data
|
||||
delay(1);
|
||||
// close the connection
|
||||
client.stop();
|
||||
}
|
||||
|
||||
if ( serverMode == 1 && client == false) {
|
||||
// If client closed the connection and we are still in the
|
||||
// stream mode, reset to normal operation
|
||||
setServerMode(0);
|
||||
}
|
||||
|
||||
// ------------------------------------------------//
|
||||
// Display Animation
|
||||
displaySavedAnimation();
|
||||
|
||||
}
|
||||
1
Arduino/Webserver4Rainbow_v3.ino
Symbolic link
1
Arduino/Webserver4Rainbow_v3.ino
Symbolic link
@@ -0,0 +1 @@
|
||||
/Users/nrinas/ownCloud/Arduino/Webserver4Rainbow_v3/Webserver4Rainbow_v3.ino
|
||||
@@ -1,8 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7702" systemVersion="14D136" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" customObjectInstantitationMethod="direct">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9059" systemVersion="15B42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7702"/>
|
||||
<plugIn identifier="com.apple.SceneKitIBPlugin" version="7702"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9059"/>
|
||||
<plugIn identifier="com.apple.SceneKitIBPlugin" version="9059"/>
|
||||
<capability name="box content view" minToolsVersion="7.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
||||
@@ -512,9 +513,11 @@
|
||||
<sceneView autoenablesDefaultLighting="YES" id="536" customClass="GameView" customModule="Cube4Fun" customModuleProvider="target">
|
||||
<rect key="frame" x="0.0" y="0.0" width="764" height="530"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<animations/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</sceneView>
|
||||
</subviews>
|
||||
<animations/>
|
||||
</view>
|
||||
<point key="canvasLocation" x="-98" y="-41"/>
|
||||
</window>
|
||||
@@ -529,15 +532,16 @@
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<scrollView autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" id="oO5-Vk-UVI">
|
||||
<rect key="frame" x="20" y="50" width="535" height="381"/>
|
||||
<rect key="frame" x="20" y="109" width="535" height="322"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES"/>
|
||||
<clipView key="contentView" id="meO-mr-znt">
|
||||
<rect key="frame" x="1" y="0.0" width="238" height="134"/>
|
||||
<rect key="frame" x="1" y="0.0" width="533" height="321"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnReordering="NO" multipleSelection="NO" autosaveColumns="NO" headerView="cQF-Rb-Xe4" id="iWG-Dg-mvn">
|
||||
<rect key="frame" x="0.0" y="0.0" width="533" height="19"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<animations/>
|
||||
<size key="intercellSpacing" width="3" height="2"/>
|
||||
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
|
||||
@@ -614,24 +618,30 @@
|
||||
</connections>
|
||||
</tableView>
|
||||
</subviews>
|
||||
<animations/>
|
||||
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</clipView>
|
||||
<animations/>
|
||||
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="roi-jB-h4n">
|
||||
<rect key="frame" x="1" y="119" width="223" height="15"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<animations/>
|
||||
</scroller>
|
||||
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="Has-sv-N3p">
|
||||
<rect key="frame" x="224" y="17" width="15" height="102"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<animations/>
|
||||
</scroller>
|
||||
<tableHeaderView key="headerView" id="cQF-Rb-Xe4">
|
||||
<rect key="frame" x="0.0" y="0.0" width="238" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<animations/>
|
||||
</tableHeaderView>
|
||||
</scrollView>
|
||||
<button verticalHuggingPriority="750" id="36Q-Yp-HEO">
|
||||
<rect key="frame" x="14" y="13" width="68" height="32"/>
|
||||
<rect key="frame" x="17" y="13" width="68" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<animations/>
|
||||
<buttonCell key="cell" type="push" title="New" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="R8v-hS-hsl">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -643,14 +653,16 @@
|
||||
<button verticalHuggingPriority="750" id="nV0-RH-sJ4">
|
||||
<rect key="frame" x="459" y="13" width="102" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
|
||||
<animations/>
|
||||
<buttonCell key="cell" type="push" title="Download" bezelStyle="rounded" alignment="center" enabled="NO" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="PEl-nt-7zX">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" id="5ce-Cy-Wpt">
|
||||
<rect key="frame" x="220" y="13" width="58" height="32"/>
|
||||
<rect key="frame" x="189" y="46" width="76" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<animations/>
|
||||
<buttonCell key="cell" type="push" title="Up" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="OPV-0F-ohh">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -660,8 +672,9 @@
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" id="TEy-BF-z21">
|
||||
<rect key="frame" x="278" y="13" width="76" height="32"/>
|
||||
<rect key="frame" x="189" y="13" width="76" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<animations/>
|
||||
<buttonCell key="cell" type="push" title="Down" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="zMK-2I-8Bq">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -671,8 +684,9 @@
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" id="39v-uC-1F1">
|
||||
<rect key="frame" x="82" y="13" width="80" height="32"/>
|
||||
<rect key="frame" x="85" y="13" width="80" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<animations/>
|
||||
<buttonCell key="cell" type="push" title="Delete" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="kw2-Xt-Pfo">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -682,8 +696,9 @@
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" id="T8G-1e-2FV">
|
||||
<rect key="frame" x="374" y="13" width="85" height="32"/>
|
||||
<rect key="frame" x="459" y="46" width="102" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
|
||||
<animations/>
|
||||
<buttonCell key="cell" type="push" title="Upload" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Kli-kZ-6PU">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -692,7 +707,56 @@
|
||||
<action selector="exportAnimations:" target="zTF-MA-6NT" id="Wqf-T8-ibb"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" id="Thd-UB-Zaf">
|
||||
<rect key="frame" x="17" y="46" width="148" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
|
||||
<animations/>
|
||||
<buttonCell key="cell" type="push" title="Import" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="aXz-jN-odT">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="importAnimation:" target="zTF-MA-6NT" id="Iz6-11-eQE"/>
|
||||
</connections>
|
||||
</button>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="Rjf-HP-mWi">
|
||||
<rect key="frame" x="21" y="84" width="37" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<animations/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Local" id="1Ix-Pw-rTY">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<box verticalHuggingPriority="750" title="Box" boxType="separator" titlePosition="noTitle" id="gVn-VF-pHP">
|
||||
<rect key="frame" x="23" y="82" width="532" height="5"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<animations/>
|
||||
<color key="borderColor" white="0.0" alpha="0.41999999999999998" colorSpace="calibratedWhite"/>
|
||||
<color key="fillColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<font key="titleFont" metaFont="system"/>
|
||||
</box>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="h57-2k-SYn">
|
||||
<rect key="frame" x="506" y="84" width="51" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<animations/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Remote" id="X6u-DA-foY">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<box horizontalHuggingPriority="750" title="Box" boxType="separator" titlePosition="noTitle" id="JgC-r8-Chg">
|
||||
<rect key="frame" x="285" y="12" width="5" height="73"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<animations/>
|
||||
<color key="borderColor" white="0.0" alpha="0.41999999999999998" colorSpace="calibratedWhite"/>
|
||||
<color key="fillColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
<font key="titleFont" metaFont="system"/>
|
||||
</box>
|
||||
</subviews>
|
||||
<animations/>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="delegate" destination="zTF-MA-6NT" id="VOO-Mo-r6f"/>
|
||||
@@ -705,6 +769,7 @@
|
||||
<outlet property="ipAddr" destination="P2I-nN-SoZ" id="Q68-HD-BIM"/>
|
||||
<outlet property="levelInd" destination="QtW-Fr-2SX" id="UvC-wZ-hM0"/>
|
||||
<outlet property="myMenu" destination="29" id="4VP-Ge-aQq"/>
|
||||
<outlet property="passwd" destination="WNn-oy-OfQ" id="wt4-oy-zkf"/>
|
||||
<outlet property="port" destination="x0K-yJ-HcE" id="YGp-UU-Tb9"/>
|
||||
<outlet property="preferencesWindow" destination="rBP-b5-IAd" id="ALx-FA-6L2"/>
|
||||
<outlet property="window" destination="371" id="532"/>
|
||||
@@ -725,31 +790,43 @@
|
||||
<window identifier="Preferences" title="Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" hidesOnDeactivate="YES" oneShot="NO" releasedWhenClosed="NO" showsToolbarButton="NO" visibleAtLaunch="NO" animationBehavior="default" id="rBP-b5-IAd">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES"/>
|
||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
|
||||
<rect key="contentRect" x="131" y="158" width="393" height="181"/>
|
||||
<rect key="contentRect" x="131" y="158" width="393" height="213"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
|
||||
<view key="contentView" id="lCF-PB-zvB">
|
||||
<rect key="frame" x="0.0" y="0.0" width="393" height="181"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="393" height="213"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<box autoresizesSubviews="NO" wantsLayer="YES" title="Cube Connection" borderType="line" id="j0p-9o-m4u">
|
||||
<rect key="frame" x="17" y="16" width="359" height="145"/>
|
||||
<rect key="frame" x="17" y="16" width="359" height="177"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<view key="contentView">
|
||||
<rect key="frame" x="1" y="1" width="357" height="129"/>
|
||||
<view key="contentView" id="Rkv-a1-uBg">
|
||||
<rect key="frame" x="1" y="1" width="357" height="161"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="2zp-D1-Brz">
|
||||
<rect key="frame" x="16" y="93" width="75" height="17"/>
|
||||
<rect key="frame" x="16" y="125" width="75" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<animations/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="IP Address:" id="QYT-Fg-a2I">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="Fif-B2-ngg">
|
||||
<rect key="frame" x="245" y="93" width="34" height="17"/>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="ovd-nk-15f" userLabel="Password:">
|
||||
<rect key="frame" x="16" y="93" width="75" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<animations/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Password:" id="H5c-nY-rlz">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="Fif-B2-ngg">
|
||||
<rect key="frame" x="245" y="125" width="34" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<animations/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="Port:" id="8GK-Wg-2Dg">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
@@ -757,8 +834,9 @@
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<textField identifier="PORTNR_FIELD" verticalHuggingPriority="750" id="x0K-yJ-HcE">
|
||||
<rect key="frame" x="280" y="90" width="49" height="22"/>
|
||||
<rect key="frame" x="280" y="122" width="49" height="22"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<animations/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" title="8081" drawsBackground="YES" id="oeh-4x-nt8">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
|
||||
@@ -768,8 +846,8 @@
|
||||
<outlet property="delegate" destination="494" id="m2C-Hb-b4T"/>
|
||||
</connections>
|
||||
</textField>
|
||||
<progressIndicator maxValue="100" style="bar" id="QtW-Fr-2SX">
|
||||
<rect key="frame" x="18" y="13" width="321" height="20"/>
|
||||
<progressIndicator wantsLayer="YES" maxValue="100" style="bar" id="QtW-Fr-2SX">
|
||||
<rect key="frame" x="18" y="19" width="321" height="20"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<shadow key="shadow">
|
||||
<color key="color" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
|
||||
@@ -783,10 +861,12 @@
|
||||
</configuration>
|
||||
</ciFilter>
|
||||
</contentFilters>
|
||||
<animations/>
|
||||
</progressIndicator>
|
||||
<textField identifier="IPADDR_FIELD" verticalHuggingPriority="750" id="P2I-nN-SoZ">
|
||||
<rect key="frame" x="106" y="90" width="130" height="22"/>
|
||||
<rect key="frame" x="106" y="122" width="130" height="22"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<animations/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" title="192.168.2.10" drawsBackground="YES" id="a7v-ph-2VN">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
|
||||
@@ -796,9 +876,23 @@
|
||||
<outlet property="delegate" destination="494" id="5co-6S-1gM"/>
|
||||
</connections>
|
||||
</textField>
|
||||
<button verticalHuggingPriority="750" id="rTg-FP-cJJ">
|
||||
<rect key="frame" x="56" y="43" width="244" height="32"/>
|
||||
<textField identifier="PASSWD_FIELD" verticalHuggingPriority="750" id="WNn-oy-OfQ" userLabel="12345678">
|
||||
<rect key="frame" x="106" y="90" width="130" height="22"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<animations/>
|
||||
<textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" title="12345678" drawsBackground="YES" id="zqy-G8-fXS">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
<connections>
|
||||
<outlet property="delegate" destination="494" id="QQx-Ib-da9"/>
|
||||
</connections>
|
||||
</textField>
|
||||
<button verticalHuggingPriority="750" id="rTg-FP-cJJ">
|
||||
<rect key="frame" x="56" y="49" width="244" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<animations/>
|
||||
<buttonCell key="cell" type="push" title="Test" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="swa-BG-Tr6">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
@@ -807,17 +901,30 @@
|
||||
</connections>
|
||||
</buttonCell>
|
||||
</button>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="ilU-Tr-bBU">
|
||||
<rect key="frame" x="245" y="93" width="59" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<animations/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="(8 chars)" id="0FD-o8-6qk">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
</subviews>
|
||||
<animations/>
|
||||
</view>
|
||||
<animations/>
|
||||
<color key="borderColor" white="0.0" alpha="0.41999999999999998" colorSpace="calibratedWhite"/>
|
||||
<color key="fillColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
|
||||
</box>
|
||||
</subviews>
|
||||
<animations/>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="delegate" destination="494" id="MZz-Cx-z5T"/>
|
||||
</connections>
|
||||
<point key="canvasLocation" x="278.5" y="412.5"/>
|
||||
<point key="canvasLocation" x="278.5" y="428.5"/>
|
||||
</window>
|
||||
<userDefaultsController representsSharedInstance="YES" id="HV1-kQ-Mj9"/>
|
||||
</objects>
|
||||
|
||||
@@ -140,6 +140,10 @@ class AnimationsController: NSObject, NSTableViewDataSource, NSTableViewDelegate
|
||||
myTableView.reloadData()
|
||||
}
|
||||
|
||||
@IBAction func importAnimation(sender: AnyObject) {
|
||||
print("Animation import pressed")
|
||||
}
|
||||
|
||||
@IBAction func moveUpItem(send: AnyObject) {
|
||||
if ( __animations.getSelectedAnimationID() > 0 ) {
|
||||
__animations.moveUpSelected()
|
||||
|
||||
@@ -37,6 +37,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSTextFieldDelegate {
|
||||
@IBOutlet weak var levelInd: NSProgressIndicator!
|
||||
@IBOutlet weak var ipAddr: NSTextField!
|
||||
@IBOutlet weak var port: NSTextField!
|
||||
@IBOutlet weak var passwd: NSTextField!
|
||||
@IBOutlet weak var waitAnim: NSProgressIndicator!
|
||||
|
||||
func applicationDidFinishLaunching(aNotification: NSNotification) {
|
||||
@@ -48,6 +49,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSTextFieldDelegate {
|
||||
|
||||
port.stringValue = String(__prefData.portNR())
|
||||
ipAddr.stringValue = __prefData.ipAddr()
|
||||
passwd.stringValue = String(__prefData.passwdStr())
|
||||
if CubeNetworkObj.connected() {
|
||||
showConnActive(true)
|
||||
}else{
|
||||
@@ -103,7 +105,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSTextFieldDelegate {
|
||||
if CubeNetworkObj.connected() {
|
||||
CubeNetworkObj.closeConnection()
|
||||
}
|
||||
if CubeNetworkObj.openConnection(__prefData.ipAddr(), port: UInt32(__prefData.portNR())) {
|
||||
if CubeNetworkObj.openConnection(__prefData.ipAddr(), port: UInt32(__prefData.portNR()), passwd: __prefData.passwdStr()) {
|
||||
showConnActive(true)
|
||||
}else{
|
||||
showConnActive(false)
|
||||
@@ -139,6 +141,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSTextFieldDelegate {
|
||||
//^(6553[0-5]|655[0-2]\d|65[0-4]\d\d|6[0-4]\d{3}|[1-5]\d{4}|[1-9]\d{0,3}|0)$
|
||||
}
|
||||
|
||||
func validPasswdStr(myPasswd: String) -> Bool {
|
||||
var valid: Bool = false
|
||||
if myPasswd.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) == 8 {
|
||||
valid = true
|
||||
}
|
||||
return valid
|
||||
}
|
||||
|
||||
override func controlTextDidChange(obj: NSNotification) {
|
||||
let myField: NSTextField = obj.object as! NSTextField
|
||||
if myField.identifier == "IPADDR_FIELD" {
|
||||
@@ -153,6 +163,12 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSTextFieldDelegate {
|
||||
print("Changing port number")
|
||||
}
|
||||
}
|
||||
if myField.identifier == "PASSWD_FIELD" {
|
||||
if validPasswdStr(myField.stringValue) {
|
||||
__prefData.setPasswd(myField.stringValue)
|
||||
print("Changing password")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func cmdCopyPressed(send: AnyObject) {
|
||||
|
||||
@@ -35,6 +35,7 @@ TCPConnector* connector;
|
||||
|
||||
unsigned char buffer3D[64];
|
||||
unsigned char receiveBuffer[32];
|
||||
char _passwd[8];
|
||||
int bytesReceived;
|
||||
int i,x;
|
||||
unsigned char color;
|
||||
@@ -119,36 +120,40 @@ void msgCloseFrameStream() {
|
||||
|
||||
void msgOpenFrameStream() {
|
||||
if (stream) {
|
||||
buffer3D[0] = 'G';
|
||||
buffer3D[1] = 'E';
|
||||
buffer3D[2] = 'T';
|
||||
buffer3D[3] = ' ';
|
||||
buffer3D[4] = '/';
|
||||
buffer3D[5] = '?';
|
||||
buffer3D[6] = 'S';
|
||||
buffer3D[7] = 's';
|
||||
buffer3D[8] = ' ';
|
||||
stream->send(reinterpret_cast<const char*>(buffer3D), 9);
|
||||
char mySendBuffer[18];
|
||||
strlcpy(mySendBuffer, "GET /?Ss", 9);
|
||||
for (int i=8; i<16; i++) {
|
||||
mySendBuffer[i] = _passwd[i-8];
|
||||
}
|
||||
mySendBuffer[16] = ' ';
|
||||
mySendBuffer[17] = '\0';
|
||||
printf("%s\n", mySendBuffer);
|
||||
|
||||
for (int i=0 ; i<18;i++) {
|
||||
buffer3D[i] = mySendBuffer[i];
|
||||
}
|
||||
stream->send(reinterpret_cast<const char*>(buffer3D), 17);
|
||||
}
|
||||
}
|
||||
|
||||
void msgStartWrite(u_int32_t msgLength) {
|
||||
char mySendBuffer[22];
|
||||
unsigned char myBuffer[4];
|
||||
byte2uint32(myBuffer, msgLength);
|
||||
if (stream) {
|
||||
buffer3D[0] = 'G';
|
||||
buffer3D[1] = 'E';
|
||||
buffer3D[2] = 'T';
|
||||
buffer3D[3] = ' ';
|
||||
buffer3D[4] = '/';
|
||||
buffer3D[5] = '?';
|
||||
buffer3D[6] = 'W';
|
||||
buffer3D[7] = 'w';
|
||||
buffer3D[8] = myBuffer[0]; // int32 to byte array conversion
|
||||
buffer3D[9] = myBuffer[1];
|
||||
buffer3D[10] = myBuffer[2];
|
||||
buffer3D[11] = myBuffer[3];
|
||||
buffer3D[12] = ' ';
|
||||
strlcpy(mySendBuffer, "GET /?Ww", 9);
|
||||
for (int i=8; i<16; i++) {
|
||||
mySendBuffer[i] = _passwd[i-8];
|
||||
}
|
||||
mySendBuffer[16] = myBuffer[0]; // int32 to byte array conversion
|
||||
mySendBuffer[17] = myBuffer[1];
|
||||
mySendBuffer[18] = myBuffer[2];
|
||||
mySendBuffer[19] = myBuffer[3];
|
||||
mySendBuffer[20] = ' ';
|
||||
mySendBuffer[21] = '\0';
|
||||
for (int i=0 ; i<22;i++) {
|
||||
buffer3D[i] = mySendBuffer[i];
|
||||
}
|
||||
|
||||
printf("sending Length:\n");
|
||||
printf("0: %u\n", myBuffer[0]);
|
||||
@@ -156,7 +161,7 @@ void msgStartWrite(u_int32_t msgLength) {
|
||||
printf("2: %u\n", myBuffer[2]);
|
||||
printf("3: %u\n", myBuffer[3]);
|
||||
|
||||
stream->send(reinterpret_cast<const char*>(buffer3D), 13);
|
||||
stream->send(reinterpret_cast<const char*>(buffer3D), 21);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,17 +268,22 @@ void CubeNetwork::updateFrame(const unsigned char * frameSequence, unsigned int
|
||||
|
||||
}
|
||||
|
||||
bool CubeNetwork::openConnection(const char* ipAddr, unsigned int port) {
|
||||
bool CubeNetwork::openConnection(const char* ipAddr, unsigned int port, const char* myPasswd) {
|
||||
bool connectionEstablished = false;
|
||||
printf("Try to open the connection\n");
|
||||
//std::string ipAddr_str(reinterpret_cast<const char*>(ipAddr));
|
||||
//Poco::UInt16 portNr = port;
|
||||
connector = new TCPConnector();
|
||||
stream = connector->connect(ipAddr, port, 10); //Connect with 10 seconds timout
|
||||
if (stream) {
|
||||
msgOpenFrameStream();
|
||||
streamMode = 1;
|
||||
connectionEstablished = true;
|
||||
if ( strlen(myPasswd) == 8 ) {
|
||||
printf("Try to open the connection\n");
|
||||
connector = new TCPConnector();
|
||||
stream = connector->connect(ipAddr, port, 10); //Connect with 10 seconds timout
|
||||
if (stream) {
|
||||
strlcpy(_passwd, myPasswd, 9); // Save password
|
||||
msgOpenFrameStream();
|
||||
streamMode = 1;
|
||||
connectionEstablished = true;
|
||||
}
|
||||
}else{
|
||||
printf("No Password provided\n");
|
||||
}
|
||||
|
||||
return connectionEstablished;
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
#include <time.h> /* time */
|
||||
#include <chrono>
|
||||
#include "tcpconnector.h"
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
class CubeNetwork
|
||||
{
|
||||
@@ -40,7 +41,7 @@ public:
|
||||
//static void initObjects();
|
||||
static void updateFrame(const unsigned char * frameSequence = NULL, unsigned int frameCount = 0);
|
||||
static void sendBytes(const unsigned char* byteBuffer = NULL, u_int32_t byteLength=0);
|
||||
static bool openConnection(const char* ipAddr, unsigned int port);
|
||||
static bool openConnection(const char* ipAddr, unsigned int port, const char* myPasswd);
|
||||
//static void openConnection();
|
||||
static void closeConnection();
|
||||
};
|
||||
|
||||
@@ -122,7 +122,7 @@ class GameViewController: NSViewController { // SCNSceneRendererDelegate
|
||||
// myFrames = NSMutableData(bytes: emptyFrame, length: 64)
|
||||
// myFrameCount = 1
|
||||
// Open connection to the LED cube
|
||||
let established = CubeNetworkObj.openConnection(__prefData.ipAddr(), port: UInt32(__prefData.portNR()))
|
||||
let established = CubeNetworkObj.openConnection(__prefData.ipAddr(), port: UInt32(__prefData.portNR()), passwd: __prefData.passwdStr())
|
||||
if established {
|
||||
print("connection established")
|
||||
}else{
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
+ (void) updateFrame: (const unsigned char *) frameSequence count: (UInt32) frameCount;
|
||||
+ (void) sendBytes: (const unsigned char *) byteBuffer count: (u_int32_t) byteLength;
|
||||
//+ (void) initObjects;
|
||||
+ (bool) openConnection: (const char *) ipAddress port: (UInt32) port;
|
||||
+ (bool) openConnection: (const char *) ipAddress port: (UInt32) port passwd: (const char*) myPasswd;
|
||||
+ (void) closeConnection;
|
||||
+ (bool) connected;
|
||||
@end
|
||||
|
||||
@@ -39,10 +39,10 @@
|
||||
CubeNetwork::sendBytes(byteBuffer, byteLength);
|
||||
}
|
||||
//+ (void) openConnection
|
||||
+ (bool) openConnection: (const char *) ipAddress port: (UInt32) port
|
||||
+ (bool) openConnection: (const char *) ipAddress port: (UInt32) port passwd:(const char *)myPasswd
|
||||
{
|
||||
bool success = false;
|
||||
success = CubeNetwork::openConnection(ipAddress, port);
|
||||
success = CubeNetwork::openConnection(ipAddress, port, myPasswd);
|
||||
return success;
|
||||
}
|
||||
+ (void) closeConnection
|
||||
|
||||
@@ -25,9 +25,11 @@ class Preferences: NSObject {
|
||||
let _myPrefs: NSUserDefaults = NSUserDefaults()
|
||||
var _myIPAddr: String = String()
|
||||
var _myPortNr: Int = Int()
|
||||
var _myPasswd: String = String()
|
||||
|
||||
let ipaddr_txt: String = "IPADDR"
|
||||
let portnr_txt: String = "PORTNR"
|
||||
let passwd_txt: String = "PASSWD"
|
||||
// ipAddr
|
||||
|
||||
|
||||
@@ -48,6 +50,10 @@ class Preferences: NSObject {
|
||||
if myPort > 0 {
|
||||
_myPortNr = myPort
|
||||
}
|
||||
// Load Password
|
||||
if let myPasswd: String = _myPrefs.stringForKey(passwd_txt) {
|
||||
_myPasswd = myPasswd
|
||||
}
|
||||
}
|
||||
|
||||
func saveFile() {
|
||||
@@ -55,6 +61,8 @@ class Preferences: NSObject {
|
||||
_myPrefs.setObject(_myIPAddr, forKey: ipaddr_txt)
|
||||
// Save port number
|
||||
_myPrefs.setInteger(_myPortNr, forKey: portnr_txt)
|
||||
// Save Password
|
||||
_myPrefs.setObject(_myPasswd, forKey: passwd_txt)
|
||||
}
|
||||
|
||||
func ipAddr() -> (String) {
|
||||
@@ -74,4 +82,13 @@ class Preferences: NSObject {
|
||||
_myPortNr = portNr
|
||||
self.saveFile()
|
||||
}
|
||||
|
||||
func passwdStr() -> (String) {
|
||||
return _myPasswd
|
||||
}
|
||||
|
||||
func setPasswd(passwdStr: String) {
|
||||
_myPasswd = passwdStr
|
||||
self.saveFile()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user