sj201r5 support. sudo pip3 install rpi_ws281x adafruit-circuitpython-neopixel and sudo python3 -m pip install --force-reinstall adafruit-blinka are required. also you will need to change config file to change default
parent
d5dd463eef
commit
cab5f76c80
|
@ -19,6 +19,13 @@ from mycroft.configuration import Configuration
|
|||
|
||||
class Capabilities:
|
||||
capabilities = {
|
||||
"sj201r5": {
|
||||
"Led": {"name": "led_dummy", "type": "MycroftLed"},
|
||||
"Switch": {"name": "switch_gpio", "type": "MycroftSwitch"},
|
||||
"Volume": {"name": "volume_sj201r4", "type": "MycroftVolume"},
|
||||
"Fan": {"name": "fan_sj201r5", "type": "MycroftFan"},
|
||||
"Palette": {"name": "default_palette", "type": "MycroftPalette"},
|
||||
},
|
||||
"sj201r4": {
|
||||
"Led": {"name": "led_sj201r4", "type": "MycroftLed"},
|
||||
"Switch": {"name": "switch_gpio", "type": "MycroftSwitch"},
|
||||
|
@ -59,4 +66,4 @@ class Capabilities:
|
|||
},
|
||||
}
|
||||
|
||||
default_board_type = "sj201r4"
|
||||
default_board_type = "sj201r5"
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
import os
|
||||
import subprocess
|
||||
import RPi.GPIO as GPIO
|
||||
from time import sleep
|
||||
from mycroft.util.log import LOG
|
||||
|
||||
class FanControl:
|
||||
# hardware speed range is appx 30-255
|
||||
# we convert from 0 to 100
|
||||
HDW_MIN = 100
|
||||
HDW_MAX = 0
|
||||
SFW_MIN = 0
|
||||
SFW_MAX = 100
|
||||
|
||||
def __init__(self):
|
||||
self.fan_speed = 0
|
||||
ledpin = 13 # PWM pin connected to LED
|
||||
GPIO.setwarnings(False) # disable warnings
|
||||
GPIO.setmode(GPIO.BCM) # set pin numbering system
|
||||
GPIO.setup(ledpin,GPIO.OUT) # set direction
|
||||
self.pi_pwm = GPIO.PWM(ledpin,1000) # create PWM instance with frequency
|
||||
self.pi_pwm.start(0) # start PWM of required Duty Cycle
|
||||
self.set_fan_speed(self.fan_speed)
|
||||
|
||||
def execute_cmd(self, cmd):
|
||||
process = subprocess.Popen(
|
||||
cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
|
||||
out, err = process.communicate()
|
||||
|
||||
try:
|
||||
out = out.decode("utf8")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
err = err.decode("utf8")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return out, err
|
||||
|
||||
def cToF(self, temp):
|
||||
return (temp * 1.8) + 32
|
||||
|
||||
def speed_to_hdw_val(self, speed):
|
||||
return float( 100.0 - (speed % 101) )
|
||||
|
||||
def hdw_val_to_speed(self, hdw_val):
|
||||
return abs( float( hdw_val - 100.0 ) )
|
||||
|
||||
def hdw_set_speed(self, hdw_speed):
|
||||
self.pi_pwm.ChangeDutyCycle(hdw_speed) # provide duty cycle in the range 0-100
|
||||
|
||||
def set_fan_speed(self, speed):
|
||||
self.fan_speed = self.speed_to_hdw_val(speed)
|
||||
self.hdw_set_speed(self.fan_speed)
|
||||
|
||||
def get_fan_speed(self):
|
||||
return self.hdw_val_to_speed(self.fan_speed)
|
||||
|
||||
def get_cpu_temp(self):
|
||||
cmd = ["cat", "/sys/class/thermal/thermal_zone0/temp"]
|
||||
out, err = self.execute_cmd(cmd)
|
||||
return float(out.strip()) / 1000
|
||||
|
|
@ -16,14 +16,9 @@ from mycroft.enclosure.hardware.MockSMBus import MockSMBus
|
|||
from mycroft.enclosure.hardware.MycroftLed.MycroftLed import MycroftLed
|
||||
from mycroft.util.log import LOG
|
||||
|
||||
|
||||
class Led(MycroftLed):
|
||||
"""A dummy LED control class used for testing.
|
||||
|
||||
This class has been kept as close as possible to the SJ201 version for
|
||||
testing purposes.
|
||||
"""
|
||||
|
||||
real_num_leds = 12 # physical
|
||||
num_leds = 10 # logical
|
||||
black = (0, 0, 0) # TODO pull from pallette
|
||||
|
@ -53,10 +48,6 @@ class Led(MycroftLed):
|
|||
green_val = int(color[1])
|
||||
blue_val = int(color[2])
|
||||
|
||||
self.bus.write_i2c_block_data(
|
||||
self.device_addr, pixel, [red_val, green_val, blue_val]
|
||||
)
|
||||
|
||||
def _set_led_with_brightness(self, pixel, color, blevel):
|
||||
self._set_led(pixel, list(map(self.adjust_brightness, color, (blevel,) * 3)))
|
||||
|
||||
|
@ -77,9 +68,6 @@ class Led(MycroftLed):
|
|||
"""fill all leds with the same color"""
|
||||
rgb = [int(self.adjust_brightness(c, self.brightness)) for c in color[:3]]
|
||||
|
||||
# Write all colors at once
|
||||
self.bus.write_i2c_block_data(self.device_addr, 0, rgb * self.num_leds)
|
||||
|
||||
def set_leds(self, new_leds):
|
||||
"""set leds from tuple array"""
|
||||
for x in range(0, self.num_leds):
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
# Copyright 2020 Mycroft AI Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import board
|
||||
import neopixel
|
||||
from mycroft.enclosure.hardware.MycroftLed.MycroftLed import MycroftLed
|
||||
from mycroft.util.log import LOG
|
||||
|
||||
class Led(MycroftLed):
|
||||
real_num_leds = 12 # physical
|
||||
num_leds = 10 # logical
|
||||
black = (0, 0, 0) # TODO pull from pallette
|
||||
|
||||
def __init__(self):
|
||||
LOG.error("SJ201R5!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!INIT")
|
||||
pixel_pin = board.D12
|
||||
ORDER = neopixel.GRB
|
||||
self.brightness = 0.2
|
||||
|
||||
self.pixels = neopixel.NeoPixel(
|
||||
pixel_pin,
|
||||
real_num_leds,
|
||||
brightness=self.brightness,
|
||||
auto_write=False,
|
||||
pixel_order=ORDER
|
||||
)
|
||||
|
||||
self.capabilities = {
|
||||
"num_leds": self.num_leds,
|
||||
"brightness": "(0.0-1.0)",
|
||||
"led_colors": "MycroftPalette",
|
||||
"reserved_leds": list(range(self.num_leds, self.real_num_leds)),
|
||||
}
|
||||
|
||||
def adjust_brightness(self, cval, bval):
|
||||
return min(255, cval * bval)
|
||||
|
||||
def get_capabilities(self):
|
||||
return self.capabilities
|
||||
|
||||
def _set_led(self, pixel, color):
|
||||
"""internal interface
|
||||
permits access to the
|
||||
reserved leds"""
|
||||
red_val = int(color[0])
|
||||
green_val = int(color[1])
|
||||
blue_val = int(color[2])
|
||||
self.pixels[pixel] = (red_val, green_val, blue_val)
|
||||
self.pixels.show()
|
||||
|
||||
def _set_led_with_brightness(self, pixel, color, blevel):
|
||||
self._set_led(pixel, list(map(self.adjust_brightness, color, (blevel,) * 3)))
|
||||
|
||||
def show(self):
|
||||
"""show buffered leds, only used
|
||||
for older slower devices"""
|
||||
pass
|
||||
|
||||
def set_led(self, pixel, color):
|
||||
"""external interface enforces led
|
||||
reservation and honors brightness"""
|
||||
self._set_led(
|
||||
pixel % self.num_leds,
|
||||
list(map(self.adjust_brightness, color, (self.brightness,) * 3)),
|
||||
)
|
||||
|
||||
def fill(self, color):
|
||||
"""fill all leds with the same color"""
|
||||
rgb = [int(self.adjust_brightness(c, self.brightness)) for c in color[:3]]
|
||||
self.pixels.fill(rgb)
|
||||
|
||||
|
||||
def set_leds(self, new_leds):
|
||||
"""set leds from tuple array"""
|
||||
for x in range(0, self.num_leds):
|
||||
self.set_led(x, new_leds[x])
|
Loading…
Reference in New Issue