コード例 #1
0
ファイル: wsServer.py プロジェクト: TheKingDave/LedStorm
 def column_color(self, data, column):
     red = map_num(data, 0, 255, self.start_col.get_red(), self.end_col.get_red())
     green = map_num(data, 0, 255, self.start_col.get_green(), self.end_col.get_green())
     blue = map_num(data, 0, 255, self.start_col.get_blue(), self.end_col.get_blue())
     col = ownColor(red, green, blue)
     col.to_range(data)
     return col
コード例 #2
0
 def print_display(self, dis, bg_col=ownColor(0, 0, 0)):
     str_ = ""
     for i in range(len(dis)):
         if i % self.config.get_option("display_width") == 0:
             str_ += "\n"
         str_ += " " + ("0" if dis[i].equals(bg_col) else "1")
     self.log.info(str_)
コード例 #3
0
 def center(self, line, bg_color=ownColor(0, 0, 0)):
     ret = []
     for i in range((self.config.get_option("display_width")-len(line)) /2):
         ret.append(bg_color)
     ret.extend(line)
     while len(ret) < self.config.get_option("display_width"):
         ret.append(bg_color)
     return ret
コード例 #4
0
ファイル: wsServer.py プロジェクト: TheKingDave/LedStorm
    def handle_data(self, data):
        clockThread.set_running(False)
        color_mode = config.get_option("color_mode")

        #if color_mode != data["color_mode"]:
        #    return

        music_data = data["music_data"]

        if color_mode == "rainbow":
            col_calc = RainbowColor
        else:
            col_calc = StartEndColor

        dis = []
        for i in range(config.get_option("led_count")):
            dis.append(ownColor(0, 0, 0))

        display_width = config.get_option("display_width")
        display_height = config.get_option("display_height")

        extra = data["extras"] if "extras" in data else dict()

        esp_col = ownColor(0, 0, 0)
        esp_max = 0

        col_calc = col_calc(display_width, extra)
        for i in range(display_width):
            cur_data = int(min(255, max(0, music_data[i])))
            height = max(0, min(display_height, map_num(cur_data, 0, 255, 0, display_height)))
            col_color = col_calc.column_color(cur_data, i)

            if(cur_data > esp_max):
                esp_max = cur_data
                esp_col = col_color

            for a in range(display_height):
                pixel = ((display_width - i) + (a * display_width)) * -1
                dis[pixel] = col_calc.pixel_color(col_color, a<=height, i, a, pixel)

        esp.send("#" + esp_col.to_hex())
        display.show(dis)
コード例 #5
0
    def string_to_display(self, text="", color=ownColor(0, 0, 255), bg_color=ownColor(0, 0, 0)):
        ret = []
        height = self.letters["height"]
        from_top = (self.config.get_option("display_height")-height) / 2
        for i in range(from_top*self.config.get_option("display_width")):
            ret.append(bg_color)

        for i in range(height):
            line = []
            for l in text:
                for a in self.letters["letters"][l][i]:
                    if a == 0:
                        line.append(bg_color)
                    else:
                        line.append(color)
                line.append(bg_color)
            line = self.center(line, bg_color)
            ret.extend(line)

        while len(ret) < self.config.get_option("led_count"):
            ret.append(bg_color)

        return ret
コード例 #6
0
    def show(self, display):
        if self.strip.numPixels() != len(display):
            return

        if self.config.get_option("display_active") is True:
            for i in range(len(display)):
                self.strip.setPixelColor(self.strip.numPixels() - i - 1, display[i].to_color())
        else:
            for i in range(len(display)):
                self.strip.setPixelColor(i, ownColor(0, 0, 0).to_color())

        self.strip.show()

        if self.ws_server is not None:
            json_data = None
            for conn, client in self.ws_server.connections.items():
                if client.connectionType == "display":
                    if json_data is None:
                        json_data = []
                        for i in reversed(range(len(display))):
                            json_data.append(display[i].to_json())

                    client.sendMessage(unicode(json.dumps({"type": "data", "data": json_data})))
コード例 #7
0
 def __del__(self):
     for led in range(self.strip.numPixels()):
         self.strip.setPixelColor(led, ownColor(0, 0, 0).to_color())
     self.strip.show()
コード例 #8
0
 def column_color(self, data, column):
     return ownColor(255, 255, 255)
コード例 #9
0
 def pixel_color(self, column_color, row_on, column, row, pixel):
     return column_color if row_on else ownColor(0, 0, 0)
コード例 #10
0
ファイル: wsServer.py プロジェクト: TheKingDave/LedStorm
 def column_color(self, data, column):
     return ownColor(0, 0, 0)
コード例 #11
0
ファイル: wsServer.py プロジェクト: TheKingDave/LedStorm
    server = SimpleWebSocketServer("", 8000, WsServer)

    log.log("Load config")
    config = Config("config.json", False, False)

    config.set_option_handler("ownColor", ownColor.load_from_json, ownColor.get_from_color)
    config.set_option_types(["clock_color", "clock_bg_color", "start_color", "end_color"], "ownColor")
    config.add_not_saves(["led_count", "display_active"])

    # Setup default config settings
    config.set_default("max_allowed_clients", 5)                # Max allowed clients (controller, display, data)
    # Not implemented
    #config.set_default("threading_on", True)                    # If threading for data request should be turned on
    #config.set_default("threading_max_threads", 50)             # Max allowed data request threads
    config.set_default("clock_brightness", 1)                   # Clock brightness
    config.set_default("clock_color", ownColor(0, 0, 255))      # Clock digit color
    config.set_default("clock_bg_color", ownColor(0, 0, 0))     # Clock bg color
    config.set_default("display_width", 25)                     # Display width
    config.set_default("display_height", 8)                     # Display height
    config.set_default("start_color", ownColor(0, 255, 0))      # color mode start_end start color
    config.set_default("end_color", ownColor(255, 0, 0))        # color mode start_end end color
    config.set_option("color_mode", "start_end")                # Visulization color mode
    config.set_default("led_bright", 255)                       # LED strip brightness
    config.set_default("power_switch_pin", 23)                  # Power switch pin
    config.set_default("power_switch_invert", True)             # If power switch signal should be inverted
    config.set_default("led_pin", 18)                           # GPIO pin connected to the pixels (must support PWM!).
    config.set_default("led_freq", 800000)                      # LED signal frequency in hertz (usually 800khz)
    config.set_default("led_dma", 5)                            # DMA channel to use for generating signal (try 5)
    config.set_default("led_invert", False)                     # True to invert the signal (when using NPN transistor level shift)
    config.set_default("display_file", "display.json")          # File where display string->led convertion is saved
    config.load()