Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Hacksaar
Sphinx
Commits
cf7db343
Commit
cf7db343
authored
Mar 08, 2015
by
Ralf
Browse files
make things work
parent
f17468e6
Changes
5
Show whitespace changes
Inline
Side-by-side
actor.py
View file @
cf7db343
...
@@ -44,8 +44,8 @@ class Actor:
...
@@ -44,8 +44,8 @@ class Actor:
def
__init__
(
self
,
i2c
):
def
__init__
(
self
,
i2c
):
self
.
_CMDs
=
{
self
.
_CMDs
=
{
Actor
.
CMD_UNLOCK
:
Actor
.
CMD
(
"unlock"
,
pin
=
Pin
(
0x21
,
3
),
tid
=
0
,
todo
=
[(
True
,
0.1
),
(
False
,
0.1
)],
i2c
=
i2c
,
invert
=
True
),
Actor
.
CMD_UNLOCK
:
Actor
.
CMD
(
"unlock"
,
pin
=
Pin
(
0x21
,
2
),
tid
=
0
,
todo
=
[(
True
,
0.1
),
(
False
,
0.1
)],
i2c
=
i2c
,
invert
=
True
),
Actor
.
CMD_LOCK
:
Actor
.
CMD
(
"lock"
,
pin
=
Pin
(
0x21
,
2
),
tid
=
0
,
todo
=
[(
True
,
0.1
),
(
False
,
0.1
)],
i2c
=
i2c
,
invert
=
True
),
Actor
.
CMD_LOCK
:
Actor
.
CMD
(
"lock"
,
pin
=
Pin
(
0x21
,
3
),
tid
=
0
,
todo
=
[(
True
,
0.1
),
(
False
,
0.1
)],
i2c
=
i2c
,
invert
=
True
),
Actor
.
CMD_BUZZ
:
Actor
.
CMD
(
"buzz"
,
pin
=
Pin
(
0x21
,
1
),
tid
=
1
,
todo
=
[(
True
,
2.5
),
(
False
,
0.1
)],
i2c
=
i2c
,
invert
=
False
),
Actor
.
CMD_BUZZ
:
Actor
.
CMD
(
"buzz"
,
pin
=
Pin
(
0x21
,
1
),
tid
=
1
,
todo
=
[(
True
,
2.5
),
(
False
,
0.1
)],
i2c
=
i2c
,
invert
=
False
),
}
}
# launch threads, all running the "_execute" method
# launch threads, all running the "_execute" method
...
...
busfahrer.py
View file @
cf7db343
from
smbus
import
SMBus
from
smbus
import
SMBus
from
libtuer
import
logger
from
threading
import
RLock
from
threading
import
RLock
class
Pin
:
class
Pin
:
...
@@ -26,14 +27,13 @@ class I2C:
...
@@ -26,14 +27,13 @@ class I2C:
with
self
.
_lock
:
with
self
.
_lock
:
self
.
_active
=
True
self
.
_active
=
True
for
addr
,
byte
in
self
.
_bytes
.
items
():
for
addr
,
byte
in
self
.
_bytes
.
items
():
logger
.
debug
(
"I2C: Initial value for 0x{:x}: {:08b}"
.
format
(
addr
,
byte
))
self
.
setPins
(
addr
,
byte
)
self
.
setPins
(
addr
,
byte
)
def
setPins
(
self
,
addr
,
stateByte
):
def
setPins
(
self
,
addr
,
stateByte
):
'''Set all pins of the given address'''
'''Set all pins of the given address'''
with
self
.
_lock
:
with
self
.
_lock
:
logger
.
debug
(
"I2C: Setting 0x{:x} to {:08b}"
.
format
(
addr
,
stateByte
))
if
self
.
_active
:
if
self
.
_active
:
#logger.debug("I2C: Setting 0x{:x} to {:08b}".format(addr, stateByte))
self
.
_bus
.
write_byte
(
addr
,
stateByte
)
self
.
_bus
.
write_byte
(
addr
,
stateByte
)
self
.
_bytes
[
addr
]
=
stateByte
self
.
_bytes
[
addr
]
=
stateByte
...
...
pins.py
View file @
cf7db343
...
@@ -55,6 +55,9 @@ class PinsWatcher():
...
@@ -55,6 +55,9 @@ class PinsWatcher():
'door_closed'
:
PinWatcher
(
Pin
(
0x20
,
1
),
4
,
i2c
,
invert
=
True
),
'door_closed'
:
PinWatcher
(
Pin
(
0x20
,
1
),
4
,
i2c
,
invert
=
True
),
'door_locked'
:
PinWatcher
(
Pin
(
0x20
,
0
),
4
,
i2c
,
invert
=
True
),
'door_locked'
:
PinWatcher
(
Pin
(
0x20
,
0
),
4
,
i2c
,
invert
=
True
),
'space_active'
:
PinWatcher
(
Pin
(
0x20
,
3
),
4
,
i2c
,
invert
=
True
),
'space_active'
:
PinWatcher
(
Pin
(
0x20
,
3
),
4
,
i2c
,
invert
=
True
),
# we don't actually read these, but it's important to pull them up for the engine to work
'unlock_feedback'
:
PinWatcher
(
Pin
(
0x20
,
4
),
4
,
i2c
,
invert
=
True
),
'lock_feedback'
:
PinWatcher
(
Pin
(
0x20
,
5
),
4
,
i2c
,
invert
=
True
),
}
}
self
.
_sm
=
state_machine
self
.
_sm
=
state_machine
self
.
_i2c
=
i2c
self
.
_i2c
=
i2c
...
...
pins.txt
View file @
cf7db343
Device 0x21 (Output)
Device 0x21 (Output)
Bit0 - NC
Bit0 - NC
Bit1 - Relays (Tueroeffner) (immer auf 0, auf 1 zum summen)
Bit1 - Relays (Tueroeffner) (immer auf 0, auf 1 zum summen)
Bit2 - T2 Tuer
zu
(immer auf 1, impuls auf 0 für signal)
Bit2 - T2 Tuer
auf
(immer auf 1, impuls auf 0 für signal)
Bit3 - T1 Tuer
auf
Bit3 - T1 Tuer
zu
Bit4 - LED0 (1 ist an)
Bit4 - LED0 (1 ist an)
Bit5 - LED1
Bit5 - LED1
Bit6 - LED2
Bit6 - LED2
...
@@ -12,7 +12,7 @@ Bit0 - Tuer Schloss
...
@@ -12,7 +12,7 @@ Bit0 - Tuer Schloss
Bit1 - Tuer Rahmen
Bit1 - Tuer Rahmen
Bit2 - In Klingel
Bit2 - In Klingel
Bit3 - In Switch
Bit3 - In Switch
Bit4 -
NC
Bit4 -
T1 Feedback
Bit5 -
NC
Bit5 -
T2 Feedback
Bit6 -
T1 Feedback
Bit6 -
NC
Bit7 -
T2 Feedback
Bit7 -
NC
spaceapi.py
View file @
cf7db343
...
@@ -27,10 +27,10 @@ class SpaceApi:
...
@@ -27,10 +27,10 @@ class SpaceApi:
response
=
urllib
.
request
.
urlopen
(
url
,
timeout
=
5.0
)
response
=
urllib
.
request
.
urlopen
(
url
,
timeout
=
5.0
)
responseText
=
response
.
read
().
decode
(
'utf-8'
).
strip
()
responseText
=
response
.
read
().
decode
(
'utf-8'
).
strip
()
if
response
.
getcode
()
==
200
and
responseText
==
"UpdateSuccessful"
:
return
True
if
response
.
getcode
()
==
200
and
responseText
==
"UpdateSuccessful"
:
return
True
logger
.
error
(
"SpaceAPI returned unexpected code
%d, content %s"
%
(
response
.
getcode
(),
responseText
))
logger
.
error
(
"SpaceAPI
:
returned unexpected code
{}:
\n
{}"
.
format
(
response
.
getcode
(),
responseText
))
return
False
return
False
except
urllib
.
request
.
URLError
as
e
:
except
urllib
.
request
.
URLError
as
e
:
logger
.
error
(
"SpaceAPI update returned error:
%s"
%
str
(
e
))
logger
.
error
(
"SpaceAPI
:
update returned error:
{}"
.
format
(
str
(
e
))
)
return
False
return
False
# set_state is the asynchronous version of _set_state (see __init__)
# set_state is the asynchronous version of _set_state (see __init__)
...
@@ -43,7 +43,7 @@ class SpaceApi:
...
@@ -43,7 +43,7 @@ class SpaceApi:
now
=
time
.
time
()
now
=
time
.
time
()
if
self
.
_local_state
is
not
None
and
(
self
.
_local_state
!=
self
.
_remote_state
or
now
>
self
.
_last_set_at
+
HEARTBEAT_TIME
):
if
self
.
_local_state
is
not
None
and
(
self
.
_local_state
!=
self
.
_remote_state
or
now
>
self
.
_last_set_at
+
HEARTBEAT_TIME
):
# take action!
# take action!
(
logger
.
info
if
self
.
_local_state
!=
self
.
_remote_state
else
logger
.
debug
)(
"S
etting SpaceAPI to %d"
%
self
.
_local_state
)
(
logger
.
info
if
self
.
_local_state
!=
self
.
_remote_state
else
logger
.
debug
)(
"S
paceAPI: Setting to {}"
.
format
(
self
.
_local_state
)
)
success
=
self
.
_do_request
(
self
.
_local_state
)
success
=
self
.
_do_request
(
self
.
_local_state
)
if
success
:
if
success
:
self
.
_remote_state
=
self
.
_local_state
self
.
_remote_state
=
self
.
_local_state
...
@@ -52,4 +52,4 @@ class SpaceApi:
...
@@ -52,4 +52,4 @@ class SpaceApi:
else
:
else
:
self
.
_fail_count
+=
1
self
.
_fail_count
+=
1
if
self
.
_fail_count
in
(
5
,
100
):
if
self
.
_fail_count
in
(
5
,
100
):
logger
.
critical
(
"
Updating the SpaceAPI
failed
%d
times in a row"
%
self
.
_fail_count
)
logger
.
critical
(
"
SpaceAPI: Updating
failed
{}
times in a row"
.
format
(
self
.
_fail_count
)
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment