Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Adding support for the shake sensor #91

Merged
merged 95 commits into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from 89 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
cfb6b50
added temperature value
Jul 17, 2019
834974c
removed deead code
Jul 17, 2019
914539e
removed dummy
Jul 17, 2019
0ac8399
added type to the slider
Jul 18, 2019
f6ef3c5
remove unit notions
Jul 18, 2019
3f2d4a1
changes
Jul 18, 2019
5f07c08
Merge branch 'users/t-famoun/temperature_sensor' into users/t-famoun/…
Jul 18, 2019
2feafc1
merge with slider
Jul 18, 2019
48b265b
changes to the api
Jul 18, 2019
4f3a052
created new variable
Jul 18, 2019
58d00cb
solved conflicts
Jul 18, 2019
d2f2fc8
added degree sign
Jul 18, 2019
19fb713
removed extra spaces
Jul 18, 2019
b182527
more extra spaces removed
Jul 18, 2019
3129ea5
using varaiable for the slider color
Jul 18, 2019
3c36ae9
added null check
Jul 18, 2019
2b96786
merge with tep sens view
Jul 18, 2019
52b5dee
beautifying
Jul 18, 2019
f956493
beuatifying
Jul 18, 2019
829db51
merge with dev
Jul 18, 2019
bb322f3
solved conflicts
Jul 19, 2019
6e8a885
solving issues
Jul 20, 2019
773d0a6
Update src/view/components/toolbar/InputSlider.tsx
FMounz Jul 20, 2019
8e3d1f2
used prettier
Jul 20, 2019
1917101
update3d branch
Jul 20, 2019
86a02f1
removed dummy
Jul 20, 2019
fc2a780
prettier again
FMounz Jul 20, 2019
fa72884
following good unsollicited advices 1
FMounz Jul 21, 2019
38d4acd
cleaning up
FMounz Jul 21, 2019
5e90f7b
Merge branch 'users/t-famoun/temperaturSensorLogic' into users/t-famo…
FMounz Jul 21, 2019
061ec8e
adding light sensor cimponent
FMounz Jul 21, 2019
48c9977
adding temp sensor
FMounz Jul 21, 2019
e12f435
changes
FMounz Jul 21, 2019
2571ec6
added view for light sensor
FMounz Jul 21, 2019
bb9ae45
refectored process
FMounz Jul 21, 2019
85e625a
added api call
FMounz Jul 21, 2019
b06b5db
solved error
Jul 21, 2019
a1ecab0
added API call
Jul 21, 2019
e2c4bd8
adding support for stop button
Jul 21, 2019
cbd47fb
Merge branch 'users/t-famoun/temperaturSensorLogic' of https://github…
Jul 21, 2019
b51c215
Merge branch 'users/t-famoun/temperaturSensorLogic' into users/t-famo…
Jul 21, 2019
8f837fb
Update src/extension.ts
FMounz Jul 21, 2019
a6813b6
Update src/view/components/toolbar/TemperatureSensorBar.tsx
FMounz Jul 21, 2019
153a24a
rework setmessage
FMounz Jul 21, 2019
36204ff
making changes
FMounz Jul 21, 2019
35719ea
reformat
FMounz Jul 21, 2019
9e114a4
let's follow best practices
FMounz Jul 21, 2019
a5dbd9f
resolved issue with input
Jul 21, 2019
b4d2d6e
adapted to temop sensor changes
Jul 21, 2019
6dfc255
removed dead lines
Jul 21, 2019
7fb0b8c
,erged zith dev
FMounz Jul 22, 2019
1f8927f
added motion sensor control
FMounz Jul 22, 2019
795db38
added api call
FMounz Jul 22, 2019
98e5735
added scrollbar for sensors
Jul 29, 2019
9971cee
reduced size so people can see
Jul 29, 2019
f44f46d
added scrollbar
Jul 29, 2019
c98f599
Merge branch 'users/t-famoun/motion_sensor' into users/t-famoun/motio…
Jul 29, 2019
e5f5ef0
adding logic for sensor
Jul 29, 2019
be378cb
Merge branch 'users/t-famoun/motion_sensor' into users/t-famoun/motio…
Jul 29, 2019
6c29566
removed API call
Jul 29, 2019
a92c70e
merged with dev
Jul 31, 2019
dbdc106
solved font color for light theme
Jul 31, 2019
df1ad30
merged with dev
Jul 31, 2019
79825e6
merged with morio sensor view
Jul 31, 2019
0309e65
adding shake function
Jul 31, 2019
69ab946
adding event
Aug 1, 2019
0aeae7d
restaored api call
Aug 1, 2019
cb8820b
Merge branch 'users/t-famoun/motion_sensor_logic' into users/t-famoun…
Aug 1, 2019
3ea4dcc
added shake state with no out condition
Aug 1, 2019
be8622c
added shake button
Aug 1, 2019
c8df8dd
adding a sensor button
Aug 1, 2019
4a6722c
merged with dev
Aug 1, 2019
de287c6
adding accessibility function
Aug 2, 2019
bc68d06
merged with dev
Aug 2, 2019
a39624d
completed keypress
Aug 2, 2019
a8199d8
adding style
Aug 2, 2019
69850b9
moved button to top
Aug 2, 2019
546eec1
removed useless lines
Aug 2, 2019
9d4e5fe
dead code removed
Aug 2, 2019
309783c
cleaning up according to reviews
Aug 2, 2019
bbe1689
merged with dev
Aug 4, 2019
53d909b
solved issu from merge
Aug 6, 2019
085f4a1
solved more issues from merge
Aug 6, 2019
5826af3
added role
Aug 6, 2019
ef9c217
chenges sensorButton to functionnal component
Aug 6, 2019
cc663be
added test for shake sesor
Aug 7, 2019
632fa05
add focus border
Aug 7, 2019
0762eb0
change focus style
Aug 7, 2019
216e881
added style push
Aug 7, 2019
822a4a2
added outline on hover
Aug 7, 2019
b05c134
removed duplicate
Aug 7, 2019
1bffb1e
undo prettier formatting
Aug 7, 2019
6a74712
removed extra line
Aug 7, 2019
3c69d48
renamed util file
Aug 8, 2019
eaaf6f7
moved type decl
Aug 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/adafruit_circuitplayground/express.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def __init__(self):
'light': 0,
'motion_x': 0,
'motion_y': 0,
'motion_z': 0,
FMounz marked this conversation as resolved.
Show resolved Hide resolved
'shake': False,
'motion_z': 0
}

Expand Down Expand Up @@ -79,6 +81,9 @@ def light(self):
def __show(self):
utils.show(self.__state)

def shake(self, shake_threshold=30):
return self.__state['shake']
LukeSlev marked this conversation as resolved.
Show resolved Hide resolved

def play_file(self, file_name):
file_name = utils.remove_leading_slashes(file_name)
abs_path_parent_dir = os.path.abspath(
Expand Down
32 changes: 20 additions & 12 deletions src/adafruit_circuitplayground/test/test_express.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from ..express import Express
from ..pixel import Pixel


class TestExpress(object):

def setup_method(self):
Expand All @@ -17,23 +18,23 @@ def setup_method(self):
}
self.pixels = Pixel(self.__state)
self.__speaker_enabled = False

def test_button_a(self):
self.cpx._Express__state['button_a'] = True
assert True == self.cpx.button_a

def test_button_b(self):
self.cpx._Express__state['button_b'] = True
assert True == self.cpx.button_b

def test_red_led(self):
self.cpx._Express__state['red_led'] = True
assert True == self.cpx.red_led

def test_red_led_int(self):
self.cpx.red_led = 3
assert True == self.cpx.red_led

def test_red_led_string(self):
self.cpx.red_led = 'foo'
assert True == self.cpx.red_led
Expand All @@ -53,11 +54,15 @@ def test_set_item_list(self):
def test_set_item_hex(self):
self.cpx.pixels[0] = 0xFFFFFF
assert (255, 255, 255) == self.cpx._Express__state['pixels'][0]

def test_set_item_invalid(self):
with pytest.raises(ValueError):
self.cpx.pixels[0] = "hello"


def test_shake(self):
self.cpx._Express__state['shake'] = True
assert True == self.cpx.shake()

def test_play_file_mp4(self):
with pytest.raises(TypeError):
self.cpx.play_file('sample.mp4')
Expand All @@ -68,21 +73,24 @@ def test_fill(self):
assert expected_pixels == self.cpx._Express__state['pixels']

def test_extract_pixel_value_list(self):
assert (0, 255, 0) == self.cpx.pixels._Pixel__extract_pixel_value((0, 255, 0))

assert (0, 255, 0) == self.cpx.pixels._Pixel__extract_pixel_value(
FMounz marked this conversation as resolved.
Show resolved Hide resolved
(0, 255, 0))

def test_extract_pixel_value_list1(self):
assert (123, 123, 123) == self.cpx.pixels._Pixel__extract_pixel_value([123, 123, 123])
assert (123, 123, 123) == self.cpx.pixels._Pixel__extract_pixel_value(
[123, 123, 123])

def test_extract_pixel_value_int(self):
assert (0, 0, 255) == self.cpx.pixels._Pixel__extract_pixel_value(255)

def test_extract_pixel_value_tuple(self):
assert (0, 255, 0) == self.cpx.pixels._Pixel__extract_pixel_value((0, 255, 0))
assert (0, 255, 0) == self.cpx.pixels._Pixel__extract_pixel_value(
(0, 255, 0))

def test_extract_pixel_value_invalid_length(self):
with pytest.raises(ValueError):
self.cpx.pixels._Pixel__extract_pixel_value((1,2,3,4))
self.cpx.pixels._Pixel__extract_pixel_value((1, 2, 3, 4))

def test_extract_pixel_value_invalid_tuple_value(self):
with pytest.raises(ValueError):
self.cpx.pixels._Pixel__extract_pixel_value((0, 222, "hello"))
1 change: 1 addition & 0 deletions src/process_user_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'switch',
'temperature',
'light',
'shake',
'motion_x',
'motion_y',
'motion_z'
Expand Down
48 changes: 48 additions & 0 deletions src/view/components/toolbar/MotionSensorBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@

import * as React from "react";
import InputSlider from "./InputSlider";
import SensorButton from "./SensorButton";

import {
ISensorProps,
ISliderProps,
X_SLIDER_INDEX,
Z_SLIDER_INDEX,
Y_SLIDER_INDEX
} from "./Toolbar_utils";
FMounz marked this conversation as resolved.
Show resolved Hide resolved

import "../../styles/MotionSensorBar.css";
import { CONSTANTS } from "../../constants";

interface vscode {
postMessage(message: any): void;
}

declare const vscode: vscode;
FMounz marked this conversation as resolved.
Show resolved Hide resolved

const sendMessage = (state: any) => {
vscode.postMessage({ command: "sensor-changed", text: state });
};

const MOTION_SLIDER_PROPS_X: ISliderProps = {
maxValue: 125,
Expand Down Expand Up @@ -55,6 +69,15 @@ class MotionSensorBar extends React.Component {
<div className="header">
<div className="title">{MOTION_SENSOR_PROPERTIES.LABEL}</div>
</div>
<SensorButton
label="Shake"
type="shake"
onMouseUp={this.onMouseUp}
onMouseDown={this.onMouseDown}
onKeyUp={this.onKeyUp}
onKeyDown={this.onKeyDown}
/>
<br />
<InputSlider
minValue={
MOTION_SENSOR_PROPERTIES.sliderProps[X_SLIDER_INDEX].minValue
Expand Down Expand Up @@ -102,9 +125,34 @@ class MotionSensorBar extends React.Component {
MOTION_SENSOR_PROPERTIES.sliderProps[Z_SLIDER_INDEX].maxLabel
}
/>
<br />
</div>
);
}

private onMouseDown = () => this.handleOnclick(true, "shake");

private onKeyUp = (event: React.KeyboardEvent<HTMLButtonElement>) =>
this.onKeyEvent(event, false);

private onKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) =>
this.onKeyEvent(event, true);

private onMouseUp = () => this.handleOnclick(false, "shake");

private handleOnclick = (active: boolean, type: string) => {
const messageState = { [type]: active };
sendMessage(messageState);
};

private onKeyEvent(
event: React.KeyboardEvent<HTMLButtonElement>,
active: boolean
) {
if ([event.keyCode, event.key].includes(CONSTANTS.KEYBOARD_KEYS.ENTER)) {
this.handleOnclick(active, "shake");
}
}
}

export default MotionSensorBar;
20 changes: 20 additions & 0 deletions src/view/components/toolbar/SensorButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from "react";
import { ISensorButtonProps } from "./Toolbar_utils";
import "../../styles/SensorButton.css";

const SensorButton: React.FC<ISensorButtonProps> = props => {
return (
<button
onMouseUp={props.onMouseUp}
onMouseDown={props.onMouseDown}
onKeyUp={props.onKeyUp}
onKeyDown={props.onKeyDown}
aria-label={`${props.type} sensor button`}
className="sensor-button"
>
{props.label}
</button>
);
};

export default SensorButton;
9 changes: 9 additions & 0 deletions src/view/components/toolbar/Toolbar_utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ export interface ISliderProps {
type: string;
}

export interface ISensorButtonProps {
label: string;
type: string;
onMouseUp: () => void;
onMouseDown: () => void;
onKeyUp: (event: React.KeyboardEvent<HTMLButtonElement>) => void;
onKeyDown: (event: React.KeyboardEvent<HTMLButtonElement>) => void;
}

export interface ISensorProps {
LABEL: string;
sliderProps: ISliderProps[];
Expand Down
3 changes: 0 additions & 3 deletions src/view/styles/ModalButton.css

This file was deleted.

25 changes: 25 additions & 0 deletions src/view/styles/SensorButton.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.sensor-button {
color: var(--vscode-badge-foreground);
text-align: center;
background-color: var(--vscode-button-background);
width: 343px;
height: 32px;
border: none;
font-weight: bolder;
float: left;
padding-left: 20px;
margin-bottom: 20px;
margin-top: 20px;
}

.sensor-button:focus,
.sensor-button:active {
outline-width: thick;
outline-offset: 4px;
outline: 2px solid var(--vscode-focusBorder);
background-color: var(--vscode-button-hoverBackground);
}
.sensor-button:hover {
outline: none;
background-color: var(--vscode-button-hoverBackground);
}