Initialization
Creates a new instance of the myVibe SDK application interface. This is the main entry point for using the SDK.
Parameters
Name | Type | Description |
---|---|---|
config | Object | Configuration object for the app |
config.name | String | The name of your micro-application (required) |
config.version | String | The version of your micro-application (optional, defaults to "1.0.0") |
config.permissions | Array<String> |
Array of permission names your app requires (optional, defaults to ["basic"]) Available permissions: "basic", "vibration", "patterns", "audio", "bluetooth", "storage", "notification" |
Example
// Initialize the myVibe SDK
const myVibeApp = new MyVibeSDK.App({
name: "My Awesome Vibration App",
version: "1.0.0",
permissions: ["vibration", "patterns", "notification"]
});
Returns
Device Control
Sets the vibration intensity of the connected device. Values are automatically clamped between 0 and 100.
Parameters
Name | Type | Description |
---|---|---|
intensity | Number | Vibration intensity from 0 (off) to 100 (maximum) |
Example
// Set vibration to 50% intensity
myVibeApp.setVibration(50);
// Maximum intensity
myVibeApp.setVibration(100);
Returns
Stops all vibration on the connected device. This will also stop any running patterns.
Example
// Stop all vibration
myVibeApp.stopVibration();
Returns
Gets information about the currently connected device or null if no device is connected.
Example
// Get device information
const device = myVibeApp.getDeviceInfo();
if (device) {
console.log(`Connected to ${device.name}`);
console.log(`Device type: ${device.type}`);
console.log(`Battery level: ${device.batteryLevel}%`);
}
Returns
{
name: String, // Device name
id: String, // Unique device ID
type: String, // Device type/model
features: Array, // Array of supported features
batteryLevel: Number // Current battery level (0-100)
}
Gets the current battery level of the connected device or null if no device is connected.
Example
// Get battery level
const batteryLevel = myVibeApp.getBatteryLevel();
if (batteryLevel !== null) {
console.log(`Battery level: ${batteryLevel}%`);
if (batteryLevel < 20) {
alert("Battery level is low!");
}
}
Returns
Pattern Controls
Creates a vibration pattern that can be played later. Validates the pattern configuration.
Parameters
Name | Type | Description |
---|---|---|
patternConfig | Object | The pattern configuration object |
patternConfig.name | String | Name of the pattern |
patternConfig.steps | Array<Object> | Array of step objects, each with intensity and duration |
patternConfig.steps[].intensity | Number | Intensity for this step (0-100) |
patternConfig.steps[].duration | Number | Duration of this step in milliseconds |
patternConfig.repeat | Number | Number of times to repeat the pattern (optional, defaults to 1) |
Example
// Create a simple pulse pattern
const pulsePattern = myVibeApp.createPattern({
name: "Pulse",
steps: [
{ intensity: 100, duration: 500 },
{ intensity: 0, duration: 300 },
{ intensity: 100, duration: 500 },
{ intensity: 0, duration: 300 }
],
repeat: 3
});
Returns
Plays a vibration pattern on the connected device. Stops any currently playing pattern.
Parameters
Name | Type | Description |
---|---|---|
pattern | Object | A pattern object, either created with createPattern() or defined inline |
options | Object | Options for pattern playback (optional) |
Example
// Play a pattern defined inline
myVibeApp.playPattern({
name: "Wave",
steps: [
{ intensity: 20, duration: 300 },
{ intensity: 40, duration: 300 },
{ intensity: 60, duration: 300 },
{ intensity: 80, duration: 300 },
{ intensity: 100, duration: 500 },
{ intensity: 80, duration: 300 },
{ intensity: 60, duration: 300 },
{ intensity: 40, duration: 300 },
{ intensity: 20, duration: 300 }
],
repeat: 2
});
// Or play a previously created pattern
myVibeApp.playPattern(pulsePattern);
Returns
Pauses the currently playing pattern. The pattern can be resumed later.
Example
// Pause the current pattern
myVibeApp.pausePattern();
Returns
Resumes a paused pattern from where it was paused.
Example
// Resume a paused pattern
myVibeApp.resumePattern();
Returns
Stops the currently playing pattern. Unlike pause, the pattern cannot be resumed after stopping.
Example
// Stop the current pattern
myVibeApp.stopPattern();
Returns
Events
Registers a callback function that will be called when a device is connected. If a device is already connected when this is called, the callback will be triggered immediately.
Parameters
Name | Type | Description |
---|---|---|
callback | Function | The callback function to call when a device connects. The callback receives the device object as a parameter. |
Example
// Register a callback for device connection
myVibeApp.onDeviceConnected(device => {
console.log(`Connected to ${device.name}`);
updateUI(device);
});
Returns
Registers a callback function that will be called when a device is disconnected.
Parameters
Name | Type | Description |
---|---|---|
callback | Function | The callback function to call when a device disconnects. The callback receives the device object that was disconnected. |
Example
// Register a callback for device disconnection
myVibeApp.onDeviceDisconnected(device => {
console.log(`Disconnected from ${device.name}`);
updateUIDisconnected();
});
Returns
Registers a callback function that will be called when the device battery level is low (typically below 20%).
Parameters
Name | Type | Description |
---|---|---|
callback | Function | The callback function to call when battery is low. The callback receives the current battery level as a parameter. |
Example
// Register a callback for low battery
myVibeApp.onBatteryLow(level => {
console.log(`Low battery alert: ${level}%`);
showLowBatteryWarning(level);
});
Returns
Registers a callback function that will be called when a pattern has completed playing.
Parameters
Name | Type | Description |
---|---|---|
callback | Function | The callback function to call when a pattern completes. The callback receives the pattern object as a parameter. |
Example
// Register a callback for pattern completion
myVibeApp.onPatternComplete(pattern => {
console.log(`Pattern "${pattern.name}" completed`);
updateUIPatternStopped();
});
Returns
Utilities
Checks if the app has a specific permission.
Parameters
Name | Type | Description |
---|---|---|
permission | String | The permission name to check |
Example
// Check if the app has a specific permission
if (myVibeApp.hasPermission('patterns')) {
// Show pattern controls
showPatternUI();
} else {
// Hide pattern controls
hidePatternUI();
}