forked from ashtuchkin/vive-diy-position-sensor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Wifi output to Particle platform.
- Loading branch information
1 parent
d586c72
commit 8536d80
Showing
7 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "output_wifi.h" | ||
|
||
OutputNodeWifi::OutputNodeWifi(uint32_t idx, const OutputDef& def) | ||
: OutputNode(idx, def) | ||
, udp_stream_{} { | ||
local_port_ = 33000; | ||
remote_port_ = 3300; | ||
} | ||
|
||
void OutputNodeWifi::start() { | ||
OutputNode::start(); | ||
udp_stream_.begin(local_port_); | ||
uint32_t local_ip = WiFi.localIP().raw().ipv4; | ||
uint32_t subnet_mask = WiFi.subnetMask().raw().ipv4; | ||
uint32_t broadcast_ip = local_ip | ~subnet_mask; | ||
remote_ip_ = broadcast_ip; | ||
} | ||
|
||
size_t OutputNodeWifi::write(const uint8_t *buffer, size_t size) { | ||
size_t ret = udp_stream_.sendPacket(buffer, size, remote_ip_, remote_port_); | ||
if (ret < 0) | ||
Serial.printf("Error sending UDP packet: %d\n", ret); | ||
return ret; | ||
} | ||
|
||
int OutputNodeWifi::read() { | ||
if (!udp_stream_.available()) | ||
udp_stream_.parsePacket(); | ||
return udp_stream_.read(); | ||
} | ||
|
||
OutputNode::CreatorRegistrar OutputNodeWifi::creator_([](uint32_t idx, const OutputDef& def) -> std::unique_ptr<OutputNode> { | ||
if (idx == 2) | ||
return std::make_unique<OutputNodeWifi>(idx, def); | ||
return nullptr; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
#include "output_serial.h" | ||
#include <application.h> | ||
|
||
class OutputNodeWifi : public OutputNode { | ||
public: | ||
OutputNodeWifi(uint32_t idx, const OutputDef& def); | ||
|
||
protected: | ||
virtual void start(); | ||
virtual size_t write(const uint8_t *buffer, size_t size); | ||
virtual int read(); | ||
static CreatorRegistrar creator_; | ||
|
||
uint16_t local_port_, remote_port_; | ||
IPAddress remote_ip_; | ||
UDP udp_stream_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters