98 lines
2.8 KiB
Python
Executable File
98 lines
2.8 KiB
Python
Executable File
#!/usr/bin/env python
|
|
##########################################################################
|
|
# sj201-reset-led
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
##########################################################################
|
|
'''
|
|
Color ring test interface for Mycroft SJ201 over Pi I2C
|
|
|
|
'''
|
|
import os
|
|
import time
|
|
|
|
class mycroftSJ201:
|
|
DeviceAddr = 0x04
|
|
num_pixels = 12
|
|
|
|
def setColor(self, pixel,colors ):
|
|
redVal = colors[0]
|
|
greenVal = colors[1]
|
|
blueVal = colors[2]
|
|
|
|
commandOS = "i2cset -a -y 1 %d %d %d %d %d i " % (
|
|
self.DeviceAddr,
|
|
pixel,
|
|
redVal,
|
|
greenVal,
|
|
blueVal)
|
|
|
|
#print(commandOS)
|
|
os.system(commandOS)
|
|
|
|
|
|
def readMemory(self):
|
|
commandOS = " i2cget " + str(self.DeviceAddr) + " 0 16"
|
|
#print(commandOS)
|
|
os.system(commandOS)
|
|
|
|
for x in range(4):
|
|
os.system(self.vfctrl +" GET_I2C ")
|
|
|
|
def wheel(self, pos):
|
|
# Input a value 0 to 255 to get a color value.
|
|
# The colours are a transition r - g - b - back to r.
|
|
if pos < 0 or pos > 255:
|
|
return (0, 0, 0)
|
|
if pos < 85:
|
|
return (255 - pos * 3, pos * 3, 0)
|
|
if pos < 170:
|
|
pos -= 85
|
|
return (0, 255 - pos * 3, pos * 3)
|
|
pos -= 170
|
|
return (pos * 3, 0, 255 - pos * 3)
|
|
|
|
def rainbow_cycle(self, wait):
|
|
for j in range(255):
|
|
for i in range(self.num_pixels):
|
|
rc_index = (i * 256 // self.num_pixels) + j
|
|
colors = self.wheel(rc_index & 255)
|
|
self.setColor(i,colors)
|
|
|
|
def color_chase(self, color, wait):
|
|
for i in range(self.num_pixels):
|
|
self.setColor(i,color)
|
|
time.sleep(wait)
|
|
|
|
def setState(self, stateNum):
|
|
self.setColor( stateNum + 12, (255, 0, 0, 0) )
|
|
|
|
|
|
sj = mycroftSJ201()
|
|
|
|
pixel = 1
|
|
redVal = 49
|
|
greenVal = 30
|
|
blueVal = 255
|
|
RED = (255, 0, 0, 0)
|
|
YELLOW = (255, 150, 0, 0)
|
|
GREEN = (0, 255, 0, 0)
|
|
CYAN = (0, 255, 255, 0)
|
|
BLUE = (0, 0, 255, 0)
|
|
PURPLE = (180, 0, 255, 0)
|
|
BLACK = (0, 0, 0, 0)
|
|
|
|
sj.color_chase(RED,0)
|
|
time.sleep(1)
|
|
sj.color_chase(BLACK,0)
|