v1.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
system.h
1 /* -*- mode: C; c-basic-offset: 4; intent-tabs-mode: nil -*-
2  *
3  * Sifteo SDK
4  *
5  * Copyright <c> 2012 Sifteo, Inc.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  */
25 
26 #pragma once
27 #ifdef NOT_USERSPACE
28 # error This is a userspace-only header, not allowed by the current build.
29 #endif
30 
31 #include <sifteo/abi.h>
32 #include <sifteo/macros.h>
33 
34 namespace Sifteo {
35 
48 class System {
49  public:
50 
56  HardwareNone = _SYS_HW_VERSION_NONE,
57  HardwareGen2 = _SYS_HW_VERSION_GEN_2,
58  HardwareGen2_5 = _SYS_HW_VERSION_GEN_2_5
59  };
60 
68  static void exit() {
69  _SYS_exit();
70  }
71 
78  static void abort() {
79  _SYS_abort();
80  }
81 
97  static void yield() {
98  _SYS_yield();
99  }
100 
119  static void paint() {
120  _SYS_paint();
121  }
122 
140  static void paintUnlimited() {
141  _SYS_paintUnlimited();
142  }
143 
170  static void finish() {
171  _SYS_finish();
172  }
173 
179  static bool isDebug() {
180  return _SYS_lti_isDebug();
181  }
182 
192  static bool isSimDebug()
193  {
194  unsigned flag = 0;
195  SCRIPT_FMT(LUA, "Runtime():poke(%p, 1)", &flag);
196  return flag;
197  }
198 
212  static float batteryLevel() {
213  return _SYS_sysBatteryLevel() / float(_SYS_BATTERY_MAX);
214  }
215 
229  static void shutdown(bool now = false) {
230  return _SYS_shutdown(now ? 0 : _SYS_SHUTDOWN_WITH_UI);
231  }
232 
241  static void keepAwake() {
242  _SYS_keepAwake();
243  }
244 
265  static void setCubeRange(unsigned minimum, unsigned maximum) {
266  _SYS_setCubeRange(minimum, maximum);
267  }
268 
272  static void setCubeRange(unsigned count) {
273  _SYS_setCubeRange(count, count);
274  }
275 
287  static uint32_t osVersion() {
288 
289  if ((_SYS_getFeatures() & _SYS_FEATURE_SYS_VERSION) != 0) {
290  return _SYS_version() & _SYS_OS_VERSION_MASK;
291  }
292 
293  return _SYS_OS_VERSION_NONE;
294  }
295 
305  static uint8_t hardwareVersion() {
306 
307  if ((_SYS_getFeatures() & _SYS_FEATURE_SYS_VERSION) != 0) {
308  return _SYS_version() >> _SYS_HW_VERSION_SHIFT;
309  }
310 
311  return _SYS_HW_VERSION_NONE;
312  }
313 };
314 
319 } // namespace Sifteo
The original Sifteo Base.
Definition: system.h:57
static uint8_t hardwareVersion()
Returns the hardware revision for the Sifteo base this application is running on. ...
Definition: system.h:305
#define SCRIPT_FMT(_type,...)
Like SCRIPT(), but this variant supports format specifiers.
Definition: macros.h:303
static void exit()
Leave the game immediately.
Definition: system.h:68
static void yield()
Temporarily give up control of the CPU.
Definition: system.h:97
static uint32_t osVersion()
Returns the system's operating system version.
Definition: system.h:287
static void keepAwake()
Prevent the system from shutting down due to inactivity.
Definition: system.h:241
Default response for firmware versions that do not support retrieving the HW version.
Definition: system.h:56
HardwareVersion
Definition: system.h:55
static void finish()
Wait for any previous paint() to finish.
Definition: system.h:170
static float batteryLevel()
Get the system's battery level.
Definition: system.h:212
static void paintUnlimited()
Draw the next frame, without an upper limit on frame rate.
Definition: system.h:140
static void setCubeRange(unsigned minimum, unsigned maximum)
Set the range of cubes supported.
Definition: system.h:265
static void shutdown(bool now=false)
Shut down the system.
Definition: system.h:229
static void abort()
Exit with a fault, for fatal error handling.
Definition: system.h:78
The Sifteo Base with Bluetooth capabilities.
Definition: system.h:58
Definition: array.h:34
Global operations that apply to the system as a whole.
Definition: system.h:48
static bool isDebug()
Is this a debug build?
Definition: system.h:179
static void paint()
Draw the next frame.
Definition: system.h:119
static bool isSimDebug()
Is this a debug build running in simulation?
Definition: system.h:192
static void setCubeRange(unsigned count)
Helper to specify a cube range with identical minimum and maximum counts.
Definition: system.h:272