including light effects from different project
This commit is contained in:
+197
-43
@@ -1,42 +1,12 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
/**
|
||||
* @file watchMain.cpp
|
||||
* @author Gustice
|
||||
* @brief ChaosWatch Application
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
* @copyright Copyright (c) 2024
|
||||
*/
|
||||
/* eth2ap (Ethernet to Wi-Fi AP packet forwarding) Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_eth_driver.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_private/wifi.h"
|
||||
#include "ethernet_init.h"
|
||||
#include "esp_netif.h"
|
||||
#include "esp_eth.h"
|
||||
|
||||
// Component header
|
||||
#include "Task.hpp"
|
||||
#include "PwmExpanderPca9685.hpp"
|
||||
#include "StepperDrv8833.hpp"
|
||||
#include "stepperMotor.hpp"
|
||||
#include "cliWrapper.hpp"
|
||||
#include "udpSockets.hpp"
|
||||
#include "tcpSockets.hpp"
|
||||
#include "Queue.hpp"
|
||||
#include "Artnet.h"
|
||||
#include "watchMain.hpp"
|
||||
|
||||
static const char *TAG = "Watch";
|
||||
static esp_eth_handle_t s_eth_handle = NULL;
|
||||
@@ -46,12 +16,6 @@ extern "C" { // This switch allows the ROS C-implementation to find this main
|
||||
void app_main(void);
|
||||
}
|
||||
|
||||
struct Color {
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
};
|
||||
|
||||
struct DeviceState {
|
||||
int jumps;
|
||||
int pictogram;
|
||||
@@ -150,7 +114,7 @@ static void telnetSocketTask(int addrFamily) {
|
||||
|
||||
|
||||
constexpr uint32_t DmxUniverse = 0;
|
||||
constexpr int DmxChannelCount = 9; //
|
||||
constexpr int DmxChannelCount = 9;
|
||||
|
||||
uint8_t scaledRgbChannel(uint8_t value, float scale) {
|
||||
return static_cast<uint8_t>(value * scale);
|
||||
@@ -344,6 +308,30 @@ static void initialize_ethernet(void)
|
||||
ESP_ERROR_CHECK(esp_eth_start(s_eth_handle));
|
||||
}
|
||||
|
||||
namespace Effect {
|
||||
extern const WaveForm_t OffsetPulseWave{gau8_offsetPulse, cu16_TemplateLength};
|
||||
extern const WaveForm_t InitSlopeWave{gau8_initSlope, cu16_TemplateLength};
|
||||
extern const WaveForm_t OffsetSlopeWave{gau8_offsetSlope, cu16_TemplateLength};
|
||||
extern const WaveForm_t FullSlopeWave{gau8_fullSlope, cu16_TemplateLength};
|
||||
extern const WaveForm_t FullPulseWave{gau8_fullPulse, cu16_TemplateLength};
|
||||
|
||||
const Macro macDemoStart = {
|
||||
{64, 1, &InitSlopeWave, StateMachine::UpdateWave, 0xFF},
|
||||
{32, 1, StateMachine::UpdateIdle, 0xFF},
|
||||
};
|
||||
|
||||
const Macro macDemoPulse = {
|
||||
{64, 1, &InitSlopeWave, StateMachine::UpdateWave, 0xFF},
|
||||
{32, 2, StateMachine::UpdateIdle, 0xFF},
|
||||
{64, 1, &OffsetPulseWave, StateMachine::UpdateWave, 0xFF},
|
||||
};
|
||||
|
||||
const Macro macDemoFlicker = {
|
||||
{64, 1, &InitSlopeWave, StateMachine::UpdateWave, 0xFF},
|
||||
{32, 1, StateMachine::UpdateFlicker, 0xFF},
|
||||
};
|
||||
}
|
||||
|
||||
void LightingTask() {
|
||||
ESP_LOGI(TAG, "Start Lighting");
|
||||
|
||||
@@ -376,6 +364,70 @@ void LightingTask() {
|
||||
}
|
||||
fos::Task::delayMs(100);
|
||||
}
|
||||
|
||||
|
||||
// ESP_LOGI(TAG, "Start Lighting");
|
||||
|
||||
// static I2cMaster master(I2C_NUM_0, GPIO_NUM_10, GPIO_NUM_11);
|
||||
// static PmwExpanderPca9685 pca9685(master);
|
||||
// PmwExpanderPca9685::GrayValues values;
|
||||
|
||||
// AddressableLeRtz ledBar(GPIO_NUM_15, AddressableLeRtz::Type::Rgb, 6);
|
||||
// std::vector<Color> pictoSpots(6);
|
||||
// for (auto &&led : pictoSpots) {
|
||||
// led.set(0, 0, 0);
|
||||
// }
|
||||
|
||||
// auto const &colorSource = activeState.color;
|
||||
// std::array<Effect::EffectProcessor, 6> processors{
|
||||
// Effect::EffectProcessor(8),
|
||||
// Effect::EffectProcessor(8),
|
||||
// Effect::EffectProcessor(8),
|
||||
// Effect::EffectProcessor(8),
|
||||
// Effect::EffectProcessor(8),
|
||||
// Effect::EffectProcessor(8)};
|
||||
|
||||
// processors[0].setEffect(Effect::macDemoStart, &colorSource, 16);
|
||||
// processors[1].setEffect(Effect::macDemoStart, &colorSource, 32);
|
||||
// processors[2].setEffect(Effect::macDemoPulse, &colorSource, 48);
|
||||
// processors[3].setEffect(Effect::macDemoPulse, &colorSource, 64);
|
||||
// processors[4].setEffect(Effect::macStartFlicker, &colorSource, 80);
|
||||
// processors[5].setEffect(Effect::macStartIdle, &colorSource, 96);
|
||||
|
||||
// int idx = 0;
|
||||
// values.fill(0);
|
||||
// while (true) {
|
||||
// values[0] = activeState.color.getRed() * 257;
|
||||
// values[1] = activeState.color.getGreen() * 257;
|
||||
// values[2] = activeState.color.getBlue() * 257;
|
||||
// pca9685.sendImage(values);
|
||||
|
||||
// for (size_t i = 0; i < 600; i++) {
|
||||
// Task::delayMs(20);
|
||||
// for (size_t i = 0; i < pictoSpots.size(); i++) {
|
||||
// pictoSpots[i] = processors[i].tick();
|
||||
// }
|
||||
// ledBar.send(pictoSpots);
|
||||
// }
|
||||
|
||||
// processors[1].setEffect(Effect::macDark, &colorSource, 32);
|
||||
// processors[2].setEffect(Effect::macDark, &colorSource, 48);
|
||||
// processors[3].setEffect(Effect::macDark, &colorSource, 64);
|
||||
// processors[4].setEffect(Effect::macDark, &colorSource, 80);
|
||||
|
||||
// for (size_t i = 0; i < 50; i++) {
|
||||
// Task::delayMs(20);
|
||||
// for (size_t i = 0; i < pictoSpots.size(); i++) {
|
||||
// pictoSpots[i] = processors[i].tick();
|
||||
// }
|
||||
// ledBar.send(pictoSpots);
|
||||
// }
|
||||
|
||||
// processors[1].setEffect(Effect::macDemoStart, &colorSource, 32);
|
||||
// processors[2].setEffect(Effect::macDemoPulse, &colorSource, 48);
|
||||
// processors[3].setEffect(Effect::macDemoPulse, &colorSource, 64);
|
||||
// processors[4].setEffect(Effect::macStartFlicker, &colorSource, 80);
|
||||
// }
|
||||
}
|
||||
|
||||
void MovementTask() {
|
||||
@@ -415,6 +467,108 @@ void MovementTask() {
|
||||
while (true) {
|
||||
fos::Task::delayMs(100);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ESP_LOGI(TAG, "Start Stepper");
|
||||
// StepperDriverTb6612::Pins stepperPins{
|
||||
// LEDC_TIMER_0,
|
||||
// LEDC_CHANNEL_0,
|
||||
// GPIO_NUM_23,
|
||||
// {GPIO_NUM_22, GPIO_NUM_21},
|
||||
// LEDC_CHANNEL_1,
|
||||
// GPIO_NUM_20,
|
||||
// {GPIO_NUM_19, GPIO_NUM_18},
|
||||
// };
|
||||
// constexpr int MicroSteps = 32;
|
||||
// StepperDriverTb6612 stepperDriver(stepperPins, MicroSteps);
|
||||
// stepperDriver.setPos(0);
|
||||
|
||||
// StepperMotor::Config stepperCfg{1.8F, MicroSteps};
|
||||
// InputPort initSens(GPIO_NUM_3);
|
||||
// initSens.setLogic(GpioPort::Logic::Inverted);
|
||||
// StepperMotor stepper(stepperCfg, stepperDriver, initSens);
|
||||
|
||||
// ESP_LOGI(TAG, "Find Home");
|
||||
|
||||
// stepper.findRef();
|
||||
// ESP_LOGI(TAG, "Fist Position is %f.2", stepper.getScaledPos() * 6);
|
||||
// Task::delayMs(1000);
|
||||
|
||||
// AddressableLeRtz ledRing(GPIO_NUM_9, AddressableLeRtz::Type::Rgb, 12);
|
||||
// std::vector<Color> ledStrip(12);
|
||||
// for (auto &&led : ledStrip) {
|
||||
// led.set(0, 0, 0);
|
||||
// }
|
||||
|
||||
// uint32_t ledPos = 0;
|
||||
// ledStrip[0].set(
|
||||
// activeState.color.getRed(),
|
||||
// activeState.color.getGreen(),
|
||||
// activeState.color.getBlue(),
|
||||
// 0);
|
||||
// ledRing.send(ledStrip);
|
||||
|
||||
// while (true) {
|
||||
// ESP_LOGD(TAG, "Waiting for command");
|
||||
// auto cmd = commandQueue.dequeue();
|
||||
// if (cmd->type == MoveType::Step) {
|
||||
// if (stepper.isIdle()) {
|
||||
// auto delta = cmd->deltaPic;
|
||||
// auto profile = cmd->profile;
|
||||
|
||||
// for (auto &&led : ledStrip) {
|
||||
// led.set(0, 0, 0);
|
||||
// }
|
||||
// ledPos = (ledPos + delta) % 6;
|
||||
// activeState.pictogram = ledPos;
|
||||
|
||||
// ledStrip[ledPos * 2].set(
|
||||
// cmd->color.getRed(),
|
||||
// cmd->color.getGreen(),
|
||||
// cmd->color.getBlue(),
|
||||
// 0);
|
||||
// ledRing.send(ledStrip);
|
||||
// MqttClient::publishPosition(ledPos);
|
||||
|
||||
// delta = std::min<uint8_t>(delta, 7);
|
||||
// Syslog::logv(Syslog::Severity::Notice, "Running Stepper by %i steps with prof=%i a=%.2f w=%.2f", delta, profile, activeState.accel, activeState.speed);
|
||||
// stepper.moveBy(delta * std::numbers::pi / 3,
|
||||
// profile, activeState.accel, activeState.speed);
|
||||
// }
|
||||
// } else if (cmd->type == MoveType::AllPictograms) {
|
||||
// activeState.pictogram = -1;
|
||||
// stepper.findRef();
|
||||
// Task::delayMs(1000);
|
||||
// for (size_t i = 0; i < 6; i++) {
|
||||
// for (auto &&led : ledStrip) {
|
||||
// led.set(0, 0, 0);
|
||||
// }
|
||||
// ledStrip[i * 2].set(0, 0, 16);
|
||||
// ledRing.send(ledStrip);
|
||||
// stepper.moveBy(std::numbers::pi / 3);
|
||||
// while (!stepper.isIdle()) {
|
||||
// Task::delayMs(100);
|
||||
// }
|
||||
// ESP_LOGI(TAG, "Position is %f.2", stepper.getScaledPos() * 6);
|
||||
// }
|
||||
// } else if (cmd->type == MoveType::Arbitrary) {
|
||||
// activeState.pictogram = -1;
|
||||
// ESP_LOGI(TAG, "Full Turn");
|
||||
// stepper.demoFullTurn();
|
||||
// Task::delayMs(4000);
|
||||
|
||||
// while (true) {
|
||||
// if (stepper.isIdle()) {
|
||||
// ESP_LOGI(TAG, "Position is %f.2", stepper.getScaledPos() * 6);
|
||||
// Task::delayMs(500);
|
||||
// stepper.createDemoProfile();
|
||||
// }
|
||||
// Task::delayMs(20);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
void IoTest()
|
||||
|
||||
Reference in New Issue
Block a user