Skip to content

Commit

Permalink
Neopixel stuff (#58)
Browse files Browse the repository at this point in the history
Added neopixel code
  • Loading branch information
rf152 committed Jan 3, 2023
1 parent 3e18a20 commit cb3ffbe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
22 changes: 1 addition & 21 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
using namespace std::placeholders;
bool exit_loop = false;
libconfig::Config cfg;
std::ofstream neopixel;
std::string neopixelpath;
char pixelStatus;

static void sigint_handler(int)
{
Expand Down Expand Up @@ -134,7 +131,7 @@ void mirrored_rotation(VideoOptions *options)
static void event_loop(LibcameraEncoder &app)
{
VideoOptions const *options = app.GetOptions();
std::unique_ptr<Output> output = std::unique_ptr<Output>(new NdiOutput(options));
std::unique_ptr<Output> output = std::unique_ptr<Output>(new NdiOutput(options, _getValue("neopixel_path", "/tmp/neopixel.state")));
app.SetEncodeOutputReadyCallback(std::bind(&Output::OutputReady, output.get(), _1, _2, _3, _4));


Expand All @@ -152,22 +149,6 @@ static void event_loop(LibcameraEncoder &app)

CompletedRequestPtr &completed_request = std::get<CompletedRequestPtr>(msg.payload);
app.EncodeBuffer(completed_request, app.VideoStream());

if(output.get().isProgram())
{
pixelStatus = 'L';
}
else if (output.get().isPreview())
{
pixelStatus = 'P';
}
else
{
pixelStatus = 'N';
}
neopixel.open(neopixelpath);
neopixel << pixelStatus;
neopixel.close();
}
}

Expand Down Expand Up @@ -198,7 +179,6 @@ int main(int argc, char *argv[])
options->metering = _getValue("meteringmode", "average");
mirrored_rotation(options);
options->Print();
neopixelpath = cfg.lookup("neopixel_path");
event_loop(app);
}
catch (std::exception const &e)
Expand Down
23 changes: 22 additions & 1 deletion src/ndi_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "ndi_output.hpp"

NdiOutput::NdiOutput(VideoOptions const *options)
NdiOutput::NdiOutput(VideoOptions const *options, std::string neopixelPath)
: Output(options)
{
this->NDI_send_create_desc.p_ndi_name = "Video Feed";
Expand All @@ -22,6 +22,8 @@ NdiOutput::NdiOutput(VideoOptions const *options)
this->NDI_video_frame.yres = options->height;
this->NDI_video_frame.FourCC = NDIlib_FourCC_type_I420;
this->NDI_video_frame.line_stride_in_bytes = options->width;

this->neopixelpath = neopixelPath;
}

NdiOutput::~NdiOutput()
Expand All @@ -36,6 +38,25 @@ void NdiOutput::outputBuffer(void *mem, size_t size, int64_t timestamp_us, uint3
NDIlib_send_get_tally(this->pNDI_send, &NDI_tally, 0);
this->program = NDI_tally.on_program;
this->preview = NDI_tally.on_preview;

char pixelStatus;
std::ofstream neopixel;

if(this->isProgram())
{
pixelStatus = 'L';
}
else if (this->isPreview())
{
pixelStatus = 'P';
}
else
{
pixelStatus = 'N';
}
neopixel.open(neopixelpath);
neopixel << pixelStatus;
neopixel.close();
}


Expand Down
3 changes: 2 additions & 1 deletion src/ndi_output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class NdiOutput : public Output
{
public:
NdiOutput(VideoOptions const *options);
NdiOutput(VideoOptions const *options, std::string neopixelPath);
~NdiOutput();

bool isProgram();
Expand All @@ -29,4 +29,5 @@ class NdiOutput : public Output
NDIlib_video_frame_v2_t NDI_video_frame;
bool preview;
bool program;
std::string neopixelpath;
};

0 comments on commit cb3ffbe

Please sign in to comment.