Skip to content

Commit

Permalink
feat: CORE-5635 - support device orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-crllm committed Dec 18, 2023
1 parent 96aca44 commit added9d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ const split = require('split')
* @property {integer} offRateMicrocents - The amount per second, in microcents (USD), that this instance charges to be stored.
*/

/**
* @typedef {number} RotationType
*
* Valid values are 1-4 where each number corresponds to a device orientation.
* 1. Portrait: The device is held upright, with the top edge at the top.
* 2. Portrait Vertically Inverted (Upside-Down): The device is held upright, but with the top edge at the bottom.
* 3. Landscape (Top of Device to the Left): The device is turned sideways with the top edge facing left.
* 4. Landscape (Top of Device to the Right): The device is turned sideways with the top edge facing right.
*/

/**
* Instances of this class are returned from {@link Project#instances}, {@link
* Project#getInstance}, and {@link Project#createInstance}. They should not be
Expand Down Expand Up @@ -147,6 +157,13 @@ class Instance extends EventEmitter {
return this.info.type
}

/**
* The instance orientation
*/
get orientation() {
return this.info.orientation
}

/**
* The pending task that is being requested by the user and is being executed by the backend.
* This field is null when no tasks are pending. The returned object has two fields: name and options.
Expand Down Expand Up @@ -239,6 +256,21 @@ class Instance extends EventEmitter {
})
}

/**
* Change device orientation.
* @param {RotationType} rotation - The new rotation for the instance.
* @example await instance.rotate(1);
*/
async rotate(rotation) {
await this._fetch('/rotate', {
method: 'POST',
json: {
orientation: rotation
},
response: 'raw'
})
}

/**
* Get peripheral/sensor data
* @return {Promise<PeripheralData>}
Expand Down

0 comments on commit added9d

Please sign in to comment.