-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial project layout and MoppyMessage implementation
Created folder structure, MoppyLib project, and MoppyMessage implementation
- Loading branch information
Showing
11 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# MoppyLib | ||
Library for core Moppy logic. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# MoppyControlGUI | ||
Java GUI for controlling a Moppy network. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# MoppyDeviceGUI | ||
A simulated moppy device that can be used for testing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# FloppyDrives.ino | ||
Arduino sketch for controlling floppy drives using Moppy. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
apply plugin: 'java' | ||
|
||
sourceCompatibility = '1.8' | ||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' | ||
|
||
// NetBeans will automatically add "run" and "debug" tasks relying on the | ||
// "mainClass" property. You may however define the property prior executing | ||
// tasks by passing a "-PmainClass=<QUALIFIED_CLASS_NAME>" argument. | ||
// | ||
// Note however, that you may define your own "run" and "debug" task if you | ||
// prefer. In this case NetBeans will not add these tasks but you may rely on | ||
// your own implementation. | ||
if (!hasProperty('mainClass')) { | ||
ext.mainClass = '' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
// You may define additional repositories, or even remove "mavenCentral()". | ||
// Read more about repositories here: | ||
// http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:repositories | ||
} | ||
|
||
dependencies { | ||
// TODO: Add dependencies here ... | ||
// You can read more about how to add dependency here: | ||
// http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:how_to_declare_your_dependencies | ||
testCompile group: 'junit', name: 'junit', version: '4.10' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootProject.name = 'MoppyLib' |
74 changes: 74 additions & 0 deletions
74
Java/MoppyLib/src/main/java/com/moppy/core/comm/MoppyMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.moppy.core.comm; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* Represents a message suitable for sending to a Moppy network. | ||
* | ||
* NOTE: Java treats ALL bytes as signed, but we're using them unsigned. Casts / conversions will be required! | ||
*/ | ||
public class MoppyMessage { | ||
private final byte[] messageBytes; | ||
|
||
public static final byte START_BYTE = (byte)0x4d; | ||
public static final byte SYSTEM_ADDRESS = (byte)0x00; | ||
|
||
public static final MoppyMessage SYS_PING = new MoppyMessage(new byte[]{ | ||
START_BYTE, // Start byte | ||
SYSTEM_ADDRESS, // System address | ||
0x01, // Message body size | ||
CommandByte.SYS_PING}); // Ping command | ||
public static final MoppyMessage SYS_RESET = new MoppyMessage(new byte[]{START_BYTE, SYSTEM_ADDRESS, 0x01, CommandByte.SYS_RESET}); | ||
public static final MoppyMessage SYS_START = new MoppyMessage(new byte[]{START_BYTE, SYSTEM_ADDRESS, 0x01, CommandByte.SYS_START}); | ||
public static final MoppyMessage SYS_STOP = new MoppyMessage(new byte[]{START_BYTE, SYSTEM_ADDRESS, 0x01, CommandByte.SYS_STOP}); | ||
|
||
|
||
protected MoppyMessage(byte[] messageBytes) { | ||
if (messageBytes.length < 4) { | ||
throw new IllegalArgumentException("Not enough bytes for a MoppyMessage!"); | ||
} | ||
|
||
this.messageBytes = messageBytes; | ||
} | ||
|
||
public static class CommandByte { | ||
public static byte SYS_PING = (byte)0x80; | ||
public static byte SYS_PONG = (byte)0x81; | ||
public static byte SYS_RESET = (byte)0x82; | ||
public static byte SYS_START = (byte)0x83; | ||
public static byte SYS_STOP = (byte)0x84; | ||
|
||
public static byte DEV_RESET = 0x00; | ||
public static byte DEV_PLAYNOTE = 0x01; | ||
public static byte DEV_STOPNOTE = 0x02; | ||
public static byte DEV_BENDPITCH = 0x03; | ||
} | ||
|
||
public byte[] getMessageBytes(){ | ||
return messageBytes; | ||
} | ||
|
||
public byte getDeviceAddress() { | ||
return messageBytes[1]; | ||
} | ||
|
||
public boolean isSystemMessage() { | ||
return getDeviceAddress() == SYSTEM_ADDRESS; | ||
} | ||
|
||
public byte getSubAddress() { | ||
if (isSystemMessage()) { | ||
throw new IllegalStateException("This is a system message and has no sub-address"); | ||
} else { | ||
return messageBytes[2]; | ||
} | ||
} | ||
|
||
public byte[] getMessageBody() { | ||
int bodyLength = isSystemMessage() ? messageBytes[2] : messageBytes[3]; | ||
int bodyStart = isSystemMessage() ? 3 : 4; | ||
return Arrays.copyOfRange(messageBytes, bodyStart, bodyStart + bodyLength); | ||
} | ||
|
||
|
||
} |
34 changes: 34 additions & 0 deletions
34
Java/MoppyLib/src/main/java/com/moppy/core/comm/MoppyMessageFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.moppy.core.comm; | ||
|
||
import static com.moppy.core.comm.MoppyMessage.CommandByte.DEV_PLAYNOTE; | ||
import static com.moppy.core.comm.MoppyMessage.CommandByte.DEV_RESET; | ||
import static com.moppy.core.comm.MoppyMessage.CommandByte.DEV_STOPNOTE; | ||
import static com.moppy.core.comm.MoppyMessage.CommandByte.SYS_PONG; | ||
import static com.moppy.core.comm.MoppyMessage.START_BYTE; | ||
import static com.moppy.core.comm.MoppyMessage.SYSTEM_ADDRESS; | ||
|
||
/** | ||
* Class for building common MoppyMessages. | ||
*/ | ||
public class MoppyMessageFactory { | ||
public static MoppyMessage systemPong(byte deviceAddress, byte numberOfSubAddresses) { | ||
return new MoppyMessage(new byte[]{START_BYTE, SYSTEM_ADDRESS, 0x03, SYS_PONG, deviceAddress, numberOfSubAddresses}); | ||
} | ||
|
||
public static MoppyMessage deviceReset(byte deviceAddress) { | ||
return new MoppyMessage(new byte[]{START_BYTE, deviceAddress, 0x00, 0x01, DEV_RESET}); | ||
} | ||
|
||
public static MoppyMessage devicePlayNote(byte deviceAddress, byte subAddress, byte noteNumber) { | ||
return new MoppyMessage(new byte[]{START_BYTE, deviceAddress, subAddress, 0x02, DEV_PLAYNOTE, noteNumber}); | ||
} | ||
|
||
public static MoppyMessage deviceStopNote(byte deviceAddress, byte subAddress, byte noteNumber) { | ||
return new MoppyMessage(new byte[]{START_BYTE, deviceAddress, subAddress, 0x02, DEV_STOPNOTE, noteNumber}); | ||
} | ||
|
||
public static MoppyMessage devicePitchBend(byte deviceAddress, byte subAddress, short bendAmount) { | ||
return new MoppyMessage(new byte[]{START_BYTE, deviceAddress, subAddress, 0x03, DEV_STOPNOTE, | ||
(byte)((bendAmount >> 8) & 0xff), (byte)(bendAmount & 0xff)}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Placeholder to show where Python Moppy projects should go. Can be removed once the first project exists. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Placeholder to show where Raspberry Pi Moppy projects should go. Can be removed once the first project exists. |