This commit is contained in:
workinghard
2015-04-20 20:20:10 -07:00
parent 524683db2d
commit 855cd3dade
18 changed files with 293 additions and 243 deletions

View File

@@ -71,7 +71,7 @@ class Animations: NSObject {
//var ms = Int((time % 1) * 1000) //var ms = Int((time % 1) * 1000)
if ( _playAllFrames ) { if ( _playAllFrames ) {
println("Delta: \(deltaTime) Speed: \(__animations.animationSpeedInt())") //println("Delta: \(deltaTime) Speed: \(__animations.animationSpeedInt())")
if ( deltaTime >= __animations.animationSpeedInt() ){ if ( deltaTime >= __animations.animationSpeedInt() ){
_previousUpdateTime = time; _previousUpdateTime = time;
if (self.getAnimationFrameID() >= self.getAnimationFrameCount()) { if (self.getAnimationFrameID() >= self.getAnimationFrameCount()) {
@@ -99,6 +99,7 @@ class Animations: NSObject {
} }
func getAnimation(id: Int) -> (NSDictionary) { func getAnimation(id: Int) -> (NSDictionary) {
println(_animationArray.count)
let myAnimation = _animationArray[id] as NSDictionary let myAnimation = _animationArray[id] as NSDictionary
return myAnimation return myAnimation
} }
@@ -188,7 +189,7 @@ class Animations: NSObject {
} }
func newAnimation() -> (NSMutableDictionary) { func newAnimation() -> (NSMutableDictionary) {
println("create new animation") println("create new animation")
return [AnimName: "Animation1", AnimKey: "1=anim1", AnimDuration: 1, AnimSpeed: 500, AnimFrames: self.newFrame()] return [AnimName: "Animation1", AnimKey: "1=anim1", AnimDuration: 10, AnimSpeed: 500, AnimFrames: self.newFrame()]
} }
func newFrame() -> (NSMutableData) { func newFrame() -> (NSMutableData) {
println("create new frame") println("create new frame")

View File

@@ -163,7 +163,7 @@ class AnimationsController: NSObject, NSTableViewDataSource, NSTableViewDelegate
println("Import button pressed") println("Import button pressed")
// for each animation // for each animation
for ( var i = 0; i < __animations.count(); i++ ) { for ( var i = 0; i < __animations.count(); ++i ) {
// Create header line per animation // Create header line per animation
// Syntax: ,F<key:12Byte>,<playtime:2Byte><speed:2Byte><frames:2Byte>\n // Syntax: ,F<key:12Byte>,<playtime:2Byte><speed:2Byte><frames:2Byte>\n
@@ -173,8 +173,11 @@ class AnimationsController: NSObject, NSTableViewDataSource, NSTableViewDelegate
let key = __animations.getAnimationKey(i) let key = __animations.getAnimationKey(i)
let keyArray: NSData = key.dataUsingEncoding(NSASCIIStringEncoding, allowLossyConversion: true)! let keyArray: NSData = key.dataUsingEncoding(NSASCIIStringEncoding, allowLossyConversion: true)!
let keyBytes: UnsafePointer<UInt8> = UnsafePointer<UInt8>(keyArray.bytes) let keyBytes: UnsafePointer<UInt8> = UnsafePointer<UInt8>(keyArray.bytes)
for (var j = 0; j < keyArray.length; j++) { for (var j = 0; j < keyArray.length; ++j) {
sendData.append(UInt8(keyBytes[j]))
if keyBytes[j] != UInt8(ascii: "\n") && keyBytes[j] != UInt8(ascii: "\r" ) { // ignore line breaks in the key
sendData.append(UInt8(keyBytes[j]))
}
} }
sendData.append(UInt8(ascii: ",")) sendData.append(UInt8(ascii: ","))
@@ -198,7 +201,7 @@ class AnimationsController: NSObject, NSTableViewDataSource, NSTableViewDelegate
// Append frame, separated by new-Line // Append frame, separated by new-Line
let animData = __animations.getAnimData(i) let animData = __animations.getAnimData(i)
for ( var count = 1; count <= __animations.getAnimDataLength(i); count++) { for ( var count = 1; count <= __animations.getAnimDataLength(i); ++count) {
sendData.append(animData[count-1]) sendData.append(animData[count-1])
// End line for each frame // End line for each frame
if ( (count % 64) == 0 ) { if ( (count % 64) == 0 ) {

View File

@@ -10,22 +10,37 @@ import Cocoa
var _animationsWindow: NSWindow = NSWindow() var _animationsWindow: NSWindow = NSWindow()
var _cubeWindow: NSWindow = NSWindow() var _cubeWindow: NSWindow = NSWindow()
var _prefWindow: NSWindow = NSWindow()
var __animations: Animations = Animations() var __animations: Animations = Animations()
var __prefData: Preferences = Preferences()
@NSApplicationMain @NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate { class AppDelegate: NSObject, NSApplicationDelegate, NSTextFieldDelegate {
@IBOutlet weak var window: NSWindow! @IBOutlet weak var window: NSWindow!
@IBOutlet weak var animationsWindow: NSWindow! @IBOutlet weak var animationsWindow: NSWindow!
@IBOutlet weak var preferencesWindow: NSWindow! @IBOutlet weak var preferencesWindow: NSWindow!
@IBOutlet weak var myMenu: NSMenu! @IBOutlet weak var myMenu: NSMenu!
@IBOutlet weak var levelInd: NSProgressIndicator!
@IBOutlet weak var ipAddr: NSTextField!
@IBOutlet weak var port: NSTextField!
@IBOutlet weak var waitAnim: NSProgressIndicator!
func applicationDidFinishLaunching(aNotification: NSNotification) { func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application // Insert code here to initialize your application
_animationsWindow = animationsWindow _animationsWindow = animationsWindow
_cubeWindow = window _cubeWindow = window
_prefWindow = preferencesWindow
//__animations.initialize() //__animations.initialize()
port.stringValue = String(__prefData.portNR())
ipAddr.stringValue = __prefData.ipAddr()
if CubeNetworkObj.connected() {
showConnActive(true)
}else{
showConnActive(false)
}
} }
func applicationShouldTerminate(sender: NSApplication) -> NSApplicationTerminateReply { func applicationShouldTerminate(sender: NSApplication) -> NSApplicationTerminateReply {
@@ -70,4 +85,61 @@ class AppDelegate: NSObject, NSApplicationDelegate {
preferencesWindow.setIsVisible(true) preferencesWindow.setIsVisible(true)
} }
@IBAction func testIPConnection(send: AnyObject) {
//println("TestIP Button clicked")
if CubeNetworkObj.connected() {
CubeNetworkObj.closeConnection()
}
if CubeNetworkObj.openConnection(__prefData.ipAddr(), port: UInt32(__prefData.portNR())) {
showConnActive(true)
}else{
showConnActive(false)
}
}
func showConnActive(active: Bool) {
if active {
levelInd.doubleValue = 100.0
}else{
levelInd.doubleValue = 0.0
}
}
func validIPAddress(ipaddr: String) -> Bool {
var valid: Bool = false
let validIpAddressRegex = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
if ipaddr != "" {
if (ipaddr.rangeOfString(validIpAddressRegex, options: .RegularExpressionSearch) != nil) {
valid = true;
}
}
return valid
}
func validPortNr(portNr: Int) -> Bool {
var valid: Bool = false
if portNr < 65536 && portNr > 0 {
valid = true
}
return valid
//^(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)$
}
override func controlTextDidChange(obj: NSNotification) {
let myField: NSTextField = obj.object as! NSTextField
if myField.identifier == "IPADDR_FIELD" {
if validIPAddress(myField.stringValue) {
__prefData.setIPAddr(myField.stringValue)
println("Changing ip address field")
}
}
if myField.identifier == "PORTNR_FIELD" {
if validPortNr(myField.integerValue) {
__prefData.setPortNr(myField.integerValue)
println("Changing port number")
}
}
}
} }

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7531" systemVersion="14D131" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" customObjectInstantitationMethod="direct"> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7531" systemVersion="14D136" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" customObjectInstantitationMethod="direct">
<dependencies> <dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7531"/> <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7531"/>
<plugIn identifier="com.apple.SceneKitIBPlugin" version="7531"/> <plugIn identifier="com.apple.SceneKitIBPlugin" version="7531"/>
@@ -130,21 +130,21 @@
<menuItem title="Edit" id="217"> <menuItem title="Edit" id="217">
<menu key="submenu" title="Edit" id="205"> <menu key="submenu" title="Edit" id="205">
<items> <items>
<menuItem title="Undo" keyEquivalent="z" id="207"> <menuItem title="Undo" hidden="YES" enabled="NO" keyEquivalent="z" id="207">
<connections> <connections>
<action selector="undo:" target="-1" id="223"/> <action selector="undo:" target="-1" id="223"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem title="Redo" keyEquivalent="Z" id="215"> <menuItem title="Redo" hidden="YES" enabled="NO" keyEquivalent="Z" id="215">
<modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/> <modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/>
<connections> <connections>
<action selector="redo:" target="-1" id="231"/> <action selector="redo:" target="-1" id="231"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem isSeparatorItem="YES" id="206"> <menuItem isSeparatorItem="YES" hidden="YES" id="206">
<modifierMask key="keyEquivalentModifierMask" command="YES"/> <modifierMask key="keyEquivalentModifierMask" command="YES"/>
</menuItem> </menuItem>
<menuItem title="Cut" keyEquivalent="x" id="199"> <menuItem title="Cut" hidden="YES" enabled="NO" keyEquivalent="x" id="199">
<connections> <connections>
<action selector="cut:" target="-1" id="228"/> <action selector="cut:" target="-1" id="228"/>
</connections> </connections>
@@ -159,13 +159,7 @@
<action selector="paste:" target="-1" id="226"/> <action selector="paste:" target="-1" id="226"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem title="Paste and Match Style" keyEquivalent="V" id="485"> <menuItem title="Clear All" id="202">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<connections>
<action selector="pasteAsPlainText:" target="-1" id="486"/>
</connections>
</menuItem>
<menuItem title="Delete" id="202">
<connections> <connections>
<action selector="delete:" target="-1" id="235"/> <action selector="delete:" target="-1" id="235"/>
</connections> </connections>
@@ -175,162 +169,6 @@
<action selector="selectAll:" target="-1" id="232"/> <action selector="selectAll:" target="-1" id="232"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem isSeparatorItem="YES" id="214">
<modifierMask key="keyEquivalentModifierMask" command="YES"/>
</menuItem>
<menuItem title="Find" id="218">
<menu key="submenu" title="Find" id="220">
<items>
<menuItem title="Find…" tag="1" keyEquivalent="f" id="209">
<connections>
<action selector="performFindPanelAction:" target="-1" id="241"/>
</connections>
</menuItem>
<menuItem title="Find and Replace…" tag="12" keyEquivalent="f" id="534">
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
<connections>
<action selector="performFindPanelAction:" target="-1" id="535"/>
</connections>
</menuItem>
<menuItem title="Find Next" tag="2" keyEquivalent="g" id="208">
<connections>
<action selector="performFindPanelAction:" target="-1" id="487"/>
</connections>
</menuItem>
<menuItem title="Find Previous" tag="3" keyEquivalent="G" id="213">
<modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/>
<connections>
<action selector="performFindPanelAction:" target="-1" id="488"/>
</connections>
</menuItem>
<menuItem title="Use Selection for Find" tag="7" keyEquivalent="e" id="221">
<connections>
<action selector="performFindPanelAction:" target="-1" id="489"/>
</connections>
</menuItem>
<menuItem title="Jump to Selection" keyEquivalent="j" id="210">
<connections>
<action selector="centerSelectionInVisibleArea:" target="-1" id="245"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Spelling and Grammar" id="216">
<menu key="submenu" title="Spelling and Grammar" id="200">
<items>
<menuItem title="Show Spelling and Grammar" keyEquivalent=":" id="204">
<connections>
<action selector="showGuessPanel:" target="-1" id="230"/>
</connections>
</menuItem>
<menuItem title="Check Document Now" keyEquivalent=";" id="201">
<connections>
<action selector="checkSpelling:" target="-1" id="225"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="453"/>
<menuItem title="Check Spelling While Typing" id="219">
<connections>
<action selector="toggleContinuousSpellChecking:" target="-1" id="222"/>
</connections>
</menuItem>
<menuItem title="Check Grammar With Spelling" id="346">
<connections>
<action selector="toggleGrammarChecking:" target="-1" id="347"/>
</connections>
</menuItem>
<menuItem title="Correct Spelling Automatically" id="454">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleAutomaticSpellingCorrection:" target="-1" id="456"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Substitutions" id="348">
<menu key="submenu" title="Substitutions" id="349">
<items>
<menuItem title="Show Substitutions" id="457">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="orderFrontSubstitutionsPanel:" target="-1" id="458"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="459"/>
<menuItem title="Smart Copy/Paste" tag="1" keyEquivalent="f" id="350">
<connections>
<action selector="toggleSmartInsertDelete:" target="-1" id="355"/>
</connections>
</menuItem>
<menuItem title="Smart Quotes" tag="2" keyEquivalent="g" id="351">
<connections>
<action selector="toggleAutomaticQuoteSubstitution:" target="-1" id="356"/>
</connections>
</menuItem>
<menuItem title="Smart Dashes" id="460">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleAutomaticDashSubstitution:" target="-1" id="461"/>
</connections>
</menuItem>
<menuItem title="Smart Links" tag="3" keyEquivalent="G" id="354">
<modifierMask key="keyEquivalentModifierMask" shift="YES" command="YES"/>
<connections>
<action selector="toggleAutomaticLinkDetection:" target="-1" id="357"/>
</connections>
</menuItem>
<menuItem title="Text Replacement" id="462">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleAutomaticTextReplacement:" target="-1" id="463"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Transformations" id="450">
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Transformations" id="451">
<items>
<menuItem title="Make Upper Case" id="452">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="uppercaseWord:" target="-1" id="464"/>
</connections>
</menuItem>
<menuItem title="Make Lower Case" id="465">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="lowercaseWord:" target="-1" id="468"/>
</connections>
</menuItem>
<menuItem title="Capitalize" id="466">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="capitalizeWord:" target="-1" id="467"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
<menuItem title="Speech" id="211">
<menu key="submenu" title="Speech" id="212">
<items>
<menuItem title="Start Speaking" id="196">
<connections>
<action selector="startSpeaking:" target="-1" id="233"/>
</connections>
</menuItem>
<menuItem title="Stop Speaking" id="195">
<connections>
<action selector="stopSpeaking:" target="-1" id="227"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
</items> </items>
</menu> </menu>
</menuItem> </menuItem>
@@ -641,7 +479,7 @@
<modifierMask key="keyEquivalentModifierMask"/> <modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Help" systemMenu="help" id="491"> <menu key="submenu" title="Help" systemMenu="help" id="491">
<items> <items>
<menuItem title="SceneKit Mac Template Help" keyEquivalent="?" id="492"> <menuItem title="Cube4Fun Help" keyEquivalent="?" id="492">
<connections> <connections>
<action selector="showHelp:" target="-1" id="493"/> <action selector="showHelp:" target="-1" id="493"/>
</connections> </connections>
@@ -854,7 +692,10 @@
<customObject id="494" customClass="AppDelegate" customModule="Cube4Fun" customModuleProvider="target"> <customObject id="494" customClass="AppDelegate" customModule="Cube4Fun" customModuleProvider="target">
<connections> <connections>
<outlet property="animationsWindow" destination="P9J-nG-QID" id="T26-Ji-oQm"/> <outlet property="animationsWindow" destination="P9J-nG-QID" id="T26-Ji-oQm"/>
<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="myMenu" destination="29" id="4VP-Ge-aQq"/>
<outlet property="port" destination="x0K-yJ-HcE" id="YGp-UU-Tb9"/>
<outlet property="preferencesWindow" destination="rBP-b5-IAd" id="ALx-FA-6L2"/> <outlet property="preferencesWindow" destination="rBP-b5-IAd" id="ALx-FA-6L2"/>
<outlet property="window" destination="371" id="532"/> <outlet property="window" destination="371" id="532"/>
</connections> </connections>
@@ -880,22 +721,13 @@
<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="181"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<subviews> <subviews>
<box autoresizesSubviews="NO" title="Cube Connection" borderType="line" id="j0p-9o-m4u"> <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="145"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<view key="contentView"> <view key="contentView">
<rect key="frame" x="1" y="1" width="357" height="129"/> <rect key="frame" x="1" y="1" width="357" height="129"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<textField verticalHuggingPriority="750" id="P2I-nN-SoZ">
<rect key="frame" x="97" y="90" width="130" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="a7v-ph-2VN">
<font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="2zp-D1-Brz"> <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="93" width="75" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
@@ -914,32 +746,57 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell> </textFieldCell>
</textField> </textField>
<button verticalHuggingPriority="750" id="rTg-FP-cJJ"> <textField identifier="PORTNR_FIELD" verticalHuggingPriority="750" id="x0K-yJ-HcE">
<rect key="frame" x="91" y="49" width="244" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<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"/>
</buttonCell>
</button>
<levelIndicator verticalHuggingPriority="750" id="XB5-E8-zg1">
<rect key="frame" x="18" y="12" width="321" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<levelIndicatorCell key="cell" alignment="left" maxValue="1" criticalValue="1" id="u4h-Q5-xzG"/>
</levelIndicator>
<progressIndicator hidden="YES" horizontalHuggingPriority="750" verticalHuggingPriority="750" maxValue="100" displayedWhenStopped="NO" bezeled="NO" indeterminate="YES" controlSize="small" style="spinning" id="H64-jS-YOR">
<rect key="frame" x="45" y="58" width="16" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
</progressIndicator>
<textField verticalHuggingPriority="750" id="x0K-yJ-HcE">
<rect key="frame" x="280" y="90" width="49" height="22"/> <rect key="frame" x="280" y="90" width="49" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" drawsBackground="YES" id="oeh-4x-nt8"> <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"/> <font key="font" metaFont="system"/>
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/> <color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/> <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell> </textFieldCell>
<connections>
<outlet property="delegate" destination="494" id="m2C-Hb-b4T"/>
</connections>
</textField> </textField>
<progressIndicator maxValue="100" style="bar" id="QtW-Fr-2SX">
<rect key="frame" x="18" y="13" width="321" height="20"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<shadow key="shadow">
<color key="color" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
</shadow>
<contentFilters>
<ciFilter name="CIFalseColor">
<configuration>
<ciColor key="inputColor0" red="0.0" green="0.50196081399917603" blue="0.25098040699958801" alpha="1"/>
<ciColor key="inputColor1" red="0.0" green="0.50196081399917603" blue="0.0" alpha="1"/>
<null key="inputImage"/>
</configuration>
</ciFilter>
</contentFilters>
</progressIndicator>
<textField identifier="IPADDR_FIELD" verticalHuggingPriority="750" id="P2I-nN-SoZ">
<rect key="frame" x="106" y="90" width="130" height="22"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<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"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<connections>
<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"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<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"/>
<connections>
<action selector="testIPConnection:" target="494" id="8rr-Tg-ND8"/>
</connections>
</buttonCell>
</button>
</subviews> </subviews>
</view> </view>
<color key="borderColor" white="0.0" alpha="0.41999999999999998" colorSpace="calibratedWhite"/> <color key="borderColor" white="0.0" alpha="0.41999999999999998" colorSpace="calibratedWhite"/>
@@ -952,5 +809,6 @@
</connections> </connections>
<point key="canvasLocation" x="278.5" y="412.5"/> <point key="canvasLocation" x="278.5" y="412.5"/>
</window> </window>
<userDefaultsController representsSharedInstance="YES" id="HV1-kQ-Mj9"/>
</objects> </objects>
</document> </document>

BIN
Cube4Fun/Cube6-128j.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
Cube4Fun/Cube6-16j.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
Cube4Fun/Cube6-256j.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
Cube4Fun/Cube6-32j.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
Cube4Fun/Cube6-64j.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -6,14 +6,6 @@
// Copyright (c) 2015 DerNik. All rights reserved. // Copyright (c) 2015 DerNik. All rights reserved.
// //
#include <iostream>
#include "Poco/Net/SocketAddress.h"
#include "Poco/Net/DialogSocket.h"
#include "Poco/Net/NetException.h"
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
#include <chrono>
#include "CubeNetwork.h" #include "CubeNetwork.h"
@@ -25,7 +17,7 @@
using Poco::Net::DialogSocket; using Poco::Net::DialogSocket;
using Poco::Net::SocketAddress; using Poco::Net::SocketAddress;
using Poco::Exception;
unsigned char buffer3D[64]; unsigned char buffer3D[64];
unsigned char receiveBuffer[32]; unsigned char receiveBuffer[32];
@@ -94,6 +86,8 @@ bool frame1[3][64] = { {1,0,0,1,
1,0,0,1, 1,0,0,1,
0,0,0,0}}; 0,0,0,0}};
bool connectionEstablished = false;
void byte2uint32(unsigned char* bytes, u_int32_t msgLength) { void byte2uint32(unsigned char* bytes, u_int32_t msgLength) {
unsigned char *vp = (unsigned char *)&msgLength; unsigned char *vp = (unsigned char *)&msgLength;
bytes[0] = vp[0]; // int32 to byte array conversion bytes[0] = vp[0]; // int32 to byte array conversion
@@ -112,21 +106,21 @@ void msgCloseFrameStream() {
} }
} }
void fillBufferWithMsgStartStream() {
buffer3D[0] = 'G';
buffer3D[1] = 'E';
buffer3D[2] = 'T';
buffer3D[3] = ' ';
buffer3D[4] = '/';
buffer3D[5] = '?';
buffer3D[6] = 'S';
buffer3D[7] = 's';
buffer3D[8] = ' ';
}
void msgOpenFrameStream() { void msgOpenFrameStream() {
fillBufferWithMsgStartStream(); try {
ds.sendBytes(buffer3D, 9); buffer3D[0] = 'G';
buffer3D[1] = 'E';
buffer3D[2] = 'T';
buffer3D[3] = ' ';
buffer3D[4] = '/';
buffer3D[5] = '?';
buffer3D[6] = 'S';
buffer3D[7] = 's';
buffer3D[8] = ' ';
ds.sendBytes(buffer3D, 9);
}catch (const Poco::Net::NetException & e){
std::cerr << e.displayText() << std::endl;
}
} }
void msgStartWrite(u_int32_t msgLength) { void msgStartWrite(u_int32_t msgLength) {
@@ -147,6 +141,12 @@ void msgStartWrite(u_int32_t msgLength) {
buffer3D[11] = myBuffer[3]; buffer3D[11] = myBuffer[3];
buffer3D[12] = ' '; buffer3D[12] = ' ';
printf("sending Length:\n");
printf("0: %u\n", myBuffer[0]);
printf("1: %u\n", myBuffer[1]);
printf("2: %u\n", myBuffer[2]);
printf("3: %u\n", myBuffer[3]);
ds.sendBytes(buffer3D, 13); ds.sendBytes(buffer3D, 13);
}catch (const Poco::Net::NetException & e){ }catch (const Poco::Net::NetException & e){
std::cerr << e.displayText() << std::endl; std::cerr << e.displayText() << std::endl;
@@ -232,6 +232,7 @@ void CubeNetwork::updateFrame() {
void CubeNetwork::sendBytes(const unsigned char* byteBuffer, unsigned int byteLength) { void CubeNetwork::sendBytes(const unsigned char* byteBuffer, unsigned int byteLength) {
printf("sendBytes called\n"); printf("sendBytes called\n");
if ( connectionEstablished) {
if ( streamMode == 1 ) { if ( streamMode == 1 ) {
// End the frameStreammode first // End the frameStreammode first
msgCloseFrameStream(); msgCloseFrameStream();
@@ -245,6 +246,7 @@ void CubeNetwork::sendBytes(const unsigned char* byteBuffer, unsigned int byteLe
msgStartWrite(byteLength); msgStartWrite(byteLength);
unsigned char myBuffer[4]; unsigned char myBuffer[4];
int ret = ds.receiveRawBytes(myBuffer, 4); int ret = ds.receiveRawBytes(myBuffer, 4);
printf("received Length:\n");
printf("0: %u\n", myBuffer[0]); printf("0: %u\n", myBuffer[0]);
printf("1: %u\n", myBuffer[1]); printf("1: %u\n", myBuffer[1]);
printf("2: %u\n", myBuffer[2]); printf("2: %u\n", myBuffer[2]);
@@ -263,10 +265,13 @@ void CubeNetwork::sendBytes(const unsigned char* byteBuffer, unsigned int byteLe
std::cerr << e.displayText() << std::endl; std::cerr << e.displayText() << std::endl;
} }
} }
}
} }
void CubeNetwork::updateFrame(const unsigned char * frameSequence, unsigned int frameCount) { void CubeNetwork::updateFrame(const unsigned char * frameSequence, unsigned int frameCount) {
if (connectionEstablished) {
// check for empty pointer // check for empty pointer
if ( frameSequence != NULL ) { if ( frameSequence != NULL ) {
//for (startFrame = 0; startFrame<lastByte;startFrame++) { //for (startFrame = 0; startFrame<lastByte;startFrame++) {
@@ -278,21 +283,37 @@ void CubeNetwork::updateFrame(const unsigned char * frameSequence, unsigned int
ds.sendBytes(buffer3D, 64); ds.sendBytes(buffer3D, 64);
//} //}
} }
}
} }
void CubeNetwork::openConnection() { bool CubeNetwork::openConnection(const char* ipAddr, unsigned int port) {
connectionEstablished = false;
printf("Try to open the connection\n");
std::string ipAddr_str(reinterpret_cast<const char*>(ipAddr));
Poco::UInt16 portNr = port;
try { try {
printf("Try to open the connection\n"); ds.connect(SocketAddress(ipAddr_str, portNr), Poco::Timespan(10, 0));
ds.connect(SocketAddress("192.168.1.79", 8081));
msgOpenFrameStream(); msgOpenFrameStream();
streamMode = 1; streamMode = 1;
}catch (const Poco::Net::NetException & e){ connectionEstablished = true;
}catch (Poco::Net::NetException & e){
std::cerr << e.displayText() << std::endl; std::cerr << e.displayText() << std::endl;
ds.close();
}catch (Poco::TimeoutException & e) {
std::cerr << e.displayText() << std::endl;
ds.close();
}catch (Exception e){
std::cerr << e.displayText() << std::endl;
ds.close();
} }
return connectionEstablished;
} }
void CubeNetwork::closeConnection() { void CubeNetwork::closeConnection() {
try { try {
connectionEstablished = false;
msgCloseFrameStream(); msgCloseFrameStream();
ds.close(); ds.close();
}catch (const Poco::Net::NetException & e){ }catch (const Poco::Net::NetException & e){
@@ -301,6 +322,11 @@ void CubeNetwork::closeConnection() {
streamMode = 0; streamMode = 0;
} }
bool CubeNetwork::connected() {
return connectionEstablished;
}
/*
void CubeNetwork::initObjects() { void CubeNetwork::initObjects() {
srand((unsigned int)time(NULL)); srand((unsigned int)time(NULL));
@@ -326,5 +352,5 @@ void CubeNetwork::initObjects() {
} }
*/
//void Performance_CPlusPlus::sortArray(unsigned int num_elements) //void Performance_CPlusPlus::sortArray(unsigned int num_elements)

View File

@@ -9,16 +9,26 @@
#ifndef __Cube4Fun__CubeNetwork__ #ifndef __Cube4Fun__CubeNetwork__
#define __Cube4Fun__CubeNetwork__ #define __Cube4Fun__CubeNetwork__
#include <iostream>
#include "Poco/Foundation.h"
#include "Poco/Net/SocketAddress.h"
#include "Poco/Net/DialogSocket.h"
#include "Poco/Net/NetException.h"
#include "Poco/Exception.h"
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
#include <chrono>
class CubeNetwork class CubeNetwork
{ {
public: public:
static bool connected();
static void initObjects(); //static void initObjects();
static void updateFrame(const unsigned char * frameSequence = NULL, unsigned int frameCount = 0); 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 void sendBytes(const unsigned char* byteBuffer = NULL, u_int32_t byteLength=0);
static void openConnection(); static bool openConnection(const char* ipAddr, unsigned int port);
//static void openConnection();
static void closeConnection(); static void closeConnection();
}; };
#endif /* defined(__Cube4Fun__CubeNetwork__) */ #endif /* defined(__Cube4Fun__CubeNetwork__) */

View File

@@ -110,7 +110,12 @@ class GameViewController: NSViewController { // SCNSceneRendererDelegate
// myFrames = NSMutableData(bytes: emptyFrame, length: 64) // myFrames = NSMutableData(bytes: emptyFrame, length: 64)
// myFrameCount = 1 // myFrameCount = 1
// Open connection to the LED cube // Open connection to the LED cube
CubeNetworkObj.openConnection() let established = CubeNetworkObj.openConnection(__prefData.ipAddr(), port: UInt32(__prefData.portNR()))
if established {
println("connection established")
}else{
println("connection failed")
}
__animations.sendFrame() __animations.sendFrame()
// Fallback timer if nothing render at the moment // Fallback timer if nothing render at the moment

View File

@@ -25,7 +25,7 @@
<key>LSMinimumSystemVersion</key> <key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string> <string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key> <key>NSHumanReadableCopyright</key>
<string>Copyright © 2015 DerNik. All rights reserved.</string> <string>Copyright © 2015 Nikolai Rinas. All rights reserved.</string>
<key>NSMainNibFile</key> <key>NSMainNibFile</key>
<string>MainMenu</string> <string>MainMenu</string>
<key>NSPrincipalClass</key> <key>NSPrincipalClass</key>

View File

@@ -11,7 +11,8 @@
@interface CubeNetworkObj : NSObject @interface CubeNetworkObj : NSObject
+ (void) updateFrame: (const unsigned char *) frameSequence count: (UInt32) frameCount; + (void) updateFrame: (const unsigned char *) frameSequence count: (UInt32) frameCount;
+ (void) sendBytes: (const unsigned char *) byteBuffer count: (u_int32_t) byteLength; + (void) sendBytes: (const unsigned char *) byteBuffer count: (u_int32_t) byteLength;
+ (void) initObjects; //+ (void) initObjects;
+ (void) openConnection; + (bool) openConnection: (const char *) ipAddress port: (UInt32) port;
+ (void) closeConnection; + (void) closeConnection;
+ (bool) connected;
@end @end

View File

@@ -5,10 +5,12 @@
@implementation CubeNetworkObj @implementation CubeNetworkObj
/*
+ (void) initObjects + (void) initObjects
{ {
CubeNetwork::initObjects(); CubeNetwork::initObjects();
} }
*/
+ (void) updateFrame: (const unsigned char *) frameSequence count: (UInt32) frameCount + (void) updateFrame: (const unsigned char *) frameSequence count: (UInt32) frameCount
{ {
CubeNetwork::updateFrame(frameSequence, frameCount); CubeNetwork::updateFrame(frameSequence, frameCount);
@@ -17,14 +19,21 @@
{ {
CubeNetwork::sendBytes(byteBuffer, byteLength); CubeNetwork::sendBytes(byteBuffer, byteLength);
} }
+ (void) openConnection //+ (void) openConnection
+ (bool) openConnection: (const char *) ipAddress port: (UInt32) port
{ {
CubeNetwork::openConnection(); bool success = false;
success = CubeNetwork::openConnection(ipAddress, port);
return success;
} }
+ (void) closeConnection + (void) closeConnection
{ {
CubeNetwork::closeConnection(); CubeNetwork::closeConnection();
} }
+ (bool) connected
{
return CubeNetwork::connected();
}
@end @end

Binary file not shown.

BIN
Cube4Fun/Poco/libPocoNet.a Normal file

Binary file not shown.

View File

@@ -0,0 +1,65 @@
//
// Preferences.swift
// Cube4Fun
//
// Created by Nik on 18.04.15.
// Copyright (c) 2015 DerNik. All rights reserved.
//
import Foundation
class Preferences: NSObject {
let _myPrefs: NSUserDefaults = NSUserDefaults()
var _myIPAddr: String = String()
var _myPortNr: Int = Int()
let ipaddr_txt: String = "IPADDR"
let portnr_txt: String = "PORTNR"
// ipAddr
override init() {
super.init()
// Load defaults
self.loadFile()
}
func loadFile() {
// Load ip address
if let myIPAddr: String = _myPrefs.stringForKey(ipaddr_txt) {
_myIPAddr = myIPAddr
}
// Load custom port
let myPort: Int = _myPrefs.integerForKey(portnr_txt)
if myPort > 0 {
_myPortNr = myPort
}
}
func saveFile() {
// Save ip address
_myPrefs.setObject(_myIPAddr, forKey: ipaddr_txt)
// Save port number
_myPrefs.setInteger(_myPortNr, forKey: portnr_txt)
}
func ipAddr() -> (String) {
return _myIPAddr
}
func setIPAddr(ipAddr: String) {
_myIPAddr = ipAddr
self.saveFile()
}
func portNR() -> (Int) {
return _myPortNr
}
func setPortNr(portNr: Int) {
_myPortNr = portNr
self.saveFile()
}
}