Corrections.
[SquirrelJME.git] / modules / nokia-api / src / main / java / com / nokia / mid / ui / DeviceControl.java
blobb5fd4856c9509fb818114a357b7187ea71902139
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package com.nokia.mid.ui;
12 import cc.squirreljme.jvm.mle.constants.UIMetricType;
13 import cc.squirreljme.runtime.cldc.annotation.Api;
14 import cc.squirreljme.runtime.cldc.debug.Debugging;
15 import cc.squirreljme.runtime.lcdui.mle.UIBackend;
16 import cc.squirreljme.runtime.lcdui.mle.UIBackendFactory;
17 import cc.squirreljme.runtime.lcdui.mle.Vibration;
19 /**
20 * This is used to utilize special hardware that exists on the device for
21 * user feedback.
23 * @since 2019/10/05
25 public class DeviceControl
27 /**
28 * Flashes the LED on the device.
30 * @param __ms The number of milliseconds to flash for.
31 * @throws IllegalArgumentException If the duration is negative.
32 * @since 2019/10/05
34 @Api
35 public static void flashLights(long __ms)
36 throws IllegalArgumentException
38 // {@squirreljme.error EB2z Cannot blink for a negative duration.}
39 if (__ms < 0)
40 throw new IllegalArgumentException("EB2z");
42 throw Debugging.todo();
44 // Blink!
45 Assembly.sysCall(SystemCallIndex.DEVICE_FEEDBACK,
46 DeviceFeedbackType.BLINK_LED, ((__ms > (long)Integer.MAX_VALUE) ?
47 Integer.MAX_VALUE : (int)__ms));*/
50 /**
51 * Sets the level of the backlight.
53 * @param __num The light number, this is always zero for the backlight.
54 * @param __lvl The level to set within the range of {@code [0, 100]}
55 * @throws IllegalArgumentException If the light number is not zero or
56 * the level is out of range.
57 * @since 2019/10/05
59 @Api
60 public static void setLights(int __num, int __lvl)
61 throws IllegalArgumentException
63 // {@squirreljme.error EB31 Only light number zero is supported.
64 // (The light number)}
65 if (__num != 0)
66 throw new IllegalArgumentException("EB31 " + __num);
68 // {@squirreljme.error EB32 Light level out of range. (The level)}
69 if (__lvl < 0 || __lvl > 100)
70 throw new IllegalArgumentException("EB32 " + __lvl);
72 // If controlling the backlight is supported, allow it to be changed
73 UIBackend backend = UIBackendFactory.getInstance(true);
74 if (backend.metric(backend.displays()[0],
75 UIMetricType.SUPPORTS_BACKLIGHT_CONTROL) == 0)
76 return;
78 throw Debugging.todo();
80 // Get maximum backlight level, stop if it is zero which means the
81 // property is not supported or there is no backlight that can be
82 // controlled
83 throw Debugging.todo();
85 int max = Assembly.sysCallV(SystemCallIndex.FRAMEBUFFER,
86 Framebuffer.CONTROL_BACKLIGHT_LEVEL_MAX);
87 if (max == 0)
88 return;
90 // Set the desired level as a percentage of the max
91 int val = (max * __lvl) / 100;
92 Assembly.sysCall(SystemCallIndex.FRAMEBUFFER,
93 Framebuffer.CONTROL_BACKLIGHT_LEVEL_SET,
94 (val < 0 ? 0 : (val > max ? max : val)));*/
97 /**
98 * Starts vibrating at the given frequency for the given duration.
100 * @param __freq The frequency of the vibration, must be in the range of
101 * {@code [0, 100]}.
102 * @param __ms The length to vibrate for in milliseconds.
103 * @throws IllegalArgumentException If the duration is negative or the
104 * frequency is out of range.
105 * @since 2019/10/05
107 @Api
108 public static void startVibra(int __freq, long __ms)
109 throws IllegalArgumentException
111 // {@squirreljme.error EB33 Cannot vibrate for a negative duration.}
112 if (__ms < 0)
113 throw new IllegalArgumentException("EB33");
115 // {@squirreljme.error EB34 Frequency out of range. (The frequency)}
116 if (__freq < 0 || __freq > 100)
117 throw new IllegalArgumentException("EB34 " + __freq);
119 // Perform the vibration
120 Vibration.vibrate((int)Math.min(Integer.MAX_VALUE, __ms));
124 * Stops any vibration that is happening.
126 * @since 2019/10/05
128 @Api
129 public static void stopVibra()
131 Vibration.vibrate(0);