Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
macie
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
imagelab
macie
Commits
4ed5e157
Commit
4ed5e157
authored
Nov 16, 2020
by
sorgre
Browse files
Options
Downloads
Patches
Plain Diff
Working version!
parent
b4278963
Branches
master
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
macie.py
+52
-0
52 additions, 0 deletions
macie.py
neopx/neopx.ino
+100
-0
100 additions, 0 deletions
neopx/neopx.ino
with
152 additions
and
0 deletions
macie.py
0 → 100644
+
52
−
0
View file @
4ed5e157
import
serial
,
time
import
serial.tools.list_ports
class
macie
:
def
__init__
(
self
,
read_timeout
=
3
,
baud_rate
=
115200
):
self
.
device
=
None
for
port
in
serial
.
tools
.
list_ports
.
grep
(
"
arduino
"
):
device
=
serial
.
Serial
(
port
.
device
,
115200
,
timeout
=
3
)
time
.
sleep
(
2
)
# Give the device a chance!
first_line
=
device
.
readline
()
if
first_line
==
b
'
<macie is ready to work>
\r\n
'
:
self
.
device
=
device
break
else
:
device
.
close
()
if
self
.
device
is
None
:
raise
RuntimeError
(
"
Could not connect to a macie!
"
)
self
.
device
.
readlines
()
# Make sure to empty read buffer
def
check_result
(
self
):
return_value
=
self
.
device
.
read
()
if
return_value
==
b
''
:
print
(
'
Warning: macie timed out.
'
)
elif
return_value
!=
b
'
\0
'
:
raise
RuntimeError
(
"
Command timeout: Unknown problem in macie!
"
)
def
trigger_led
(
self
,
led_index
):
self
.
device
.
write
(
str
(
led_index
).
encode
()
+
b
'
\n
'
)
self
.
check_result
()
def
flood_light
(
self
,
leds
=
"
w
"
):
if
leds
==
"
w
"
or
leds
==
"
W
"
:
self
.
device
.
write
(
b
'
f
'
)
if
leds
==
"
rgbw
"
or
leds
==
"
RGBW
"
:
self
.
device
.
write
(
b
'
F
'
)
self
.
check_result
()
def
dark
(
self
):
self
.
device
.
write
(
b
'
b
'
)
self
.
check_result
()
mace
=
macie
()
for
i
in
range
(
15
):
mace
.
trigger_led
(
i
)
mace
.
flood_light
()
mace
.
flood_light
(
"
RGBW
"
)
mace
.
dark
()
This diff is collapsed.
Click to expand it.
neopx/neopx.ino
0 → 100644
+
100
−
0
View file @
4ed5e157
#include
<Adafruit_NeoPixel.h>
#define LED_PIN 7
#define LED_COUNT 15
Adafruit_NeoPixel
strip
(
LED_COUNT
,
LED_PIN
,
NEO_RBGW
+
NEO_KHZ800
);
uint32_t
all_white
=
Adafruit_NeoPixel
::
Color
(
255
,
255
,
255
,
255
);
uint32_t
white
=
Adafruit_NeoPixel
::
Color
(
0
,
0
,
0
,
255
);
void
setup
()
{
Serial
.
begin
(
115200
);
// set up Serial library at 9600 bps
strip
.
begin
();
strip
.
clear
();
strip
.
show
();
Serial
.
println
(
"<macie is ready to work>"
);
}
void
loop
()
{
static
const
uint8_t
buffer_size
=
3
;
static
char
data_buffer
[
buffer_size
];
static
uint8_t
buffer_idx
=
0
;
static
bool
reading_data
=
true
;
if
(
Serial
.
available
()
>
0
&&
reading_data
)
{
char
next_data
=
Serial
.
read
();
// single character commands
if
(
buffer_idx
==
0
&&
next_data
==
'b'
)
{
strip
.
clear
();
strip
.
show
();
Serial
.
write
(
'\0'
);
return
;
}
if
(
buffer_idx
==
0
&&
next_data
==
'B'
)
{
strip
.
clear
();
strip
.
show
();
Serial
.
write
(
'\0'
);
return
;
}
if
(
buffer_idx
==
0
&&
next_data
==
'F'
)
{
strip
.
fill
(
all_white
);
strip
.
show
();
return
;
}
if
(
buffer_idx
==
0
&&
next_data
==
'f'
)
{
strip
.
fill
(
white
);
strip
.
show
();
Serial
.
write
(
'\0'
);
return
;
}
// multi character commands
static
char
eol
=
'\n'
;
if
(
next_data
!=
eol
)
{
data_buffer
[
buffer_idx
]
=
next_data
;
buffer_idx
++
;
if
(
buffer_idx
>=
buffer_size
)
buffer_idx
=
buffer_size
-
1
;
// Just reuse the last char
}
else
{
// End of line---stop reading!
data_buffer
[
buffer_idx
]
=
'\0'
;
buffer_idx
=
0
;
reading_data
=
false
;
}
if
(
!
reading_data
)
{
reading_data
=
true
;
if
(
data_buffer
[
0
]
<
'0'
||
data_buffer
[
0
]
>
'9'
)
// Non-digit
return
;
int
x
=
data_buffer
[
0
]
-
'0'
;
if
(
data_buffer
[
1
]
!=
'\0'
)
{
// multi-digit
if
(
data_buffer
[
1
]
<
'0'
||
data_buffer
[
1
]
>
'9'
)
// Non-digit
return
;
x
*=
10
;
x
+=
data_buffer
[
1
]
-
'0'
;
if
(
data_buffer
[
2
]
!=
'\0'
)
{
// multi-digit
if
(
data_buffer
[
2
]
<
'0'
||
data_buffer
[
2
]
>
'9'
)
// Non-digit
return
;
x
*=
10
;
x
+=
data_buffer
[
2
]
-
'0'
;
}
if
(
data_buffer
[
3
]
!=
'\0'
)
return
;
}
strip
.
clear
();
strip
.
setPixelColor
(
x
,
0
,
0
,
0
,
255
);
strip
.
show
();
Serial
.
write
(
'\0'
);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment