Skip to content

Commit

Permalink
FreeLSS 1.11 - Added the ability to connect to Hidden WiFi access poi…
Browse files Browse the repository at this point in the history
…nts. Added support for running without the camera being attached.
  • Loading branch information
hairu committed Oct 24, 2015
1 parent 4ec39ff commit 8289d95
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 64 deletions.
5 changes: 3 additions & 2 deletions src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Camera.h"
#include "MmalStillCamera.h"
#include "MmalVideoCamera.h"
#include "MockCamera.h"
#include "PresetManager.h"
#include "Thread.h"

Expand Down Expand Up @@ -78,8 +79,9 @@ Camera * Camera::getInstance()
}
catch (...)
{
// Initialize the mock camera if there was a problem
m_instance = new MockCamera(m_reqImageWidth, m_reqImageHeight);
m_cs.leave();
throw;
}
m_cs.leave();

Expand All @@ -88,7 +90,6 @@ Camera * Camera::getInstance()

void Camera::release()
{

m_cs.enter();
try
{
Expand Down
31 changes: 21 additions & 10 deletions src/HttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,27 +278,37 @@ static std::string ConnectWifi(RequestInfo * reqInfo)
return "Password is required";
}

std::string essidIndexStr = reqInfo->arguments[WebContent::WIFI_ESSID];
if (essidIndexStr.empty())
std::string essid = reqInfo->arguments[WebContent::WIFI_ESSID_HIDDEN];
int index = -1;
if (essid.empty())
{
return "Missing ESSID";
std::string essidIndexStr = reqInfo->arguments[WebContent::WIFI_ESSID];
if (essidIndexStr.empty())
{
return "Missing ESSID";
}

index = ToInt(essidIndexStr);
}

std::string message;
int index = ToInt(essidIndexStr);
WifiConfig * wifi = WifiConfig::get();

try
{
std::vector<WifiConfig::AccessPoint> accessPoints = wifi->getAccessPoints();
if (index < 0 || index >= (int)accessPoints.size())
if (essid.empty())
{
throw Exception("Invalid access point index");
std::vector<WifiConfig::AccessPoint> accessPoints = wifi->getAccessPoints();
if (index < 0 || index >= (int)accessPoints.size())
{
throw Exception("Invalid access point index");
}
essid = accessPoints[index].essid;
}

// Connect via WiFi
wifi->connect(accessPoints[index].essid, password);
message = "Connecting to " + accessPoints[index].essid + "...";
wifi->connect(essid, password);
message = "Connecting to " + essid + "...";
}
catch (Exception& ex)
{
Expand Down Expand Up @@ -1053,7 +1063,8 @@ static int ProcessPageRequest(RequestInfo * reqInfo)
message = ConnectWifi(reqInfo);
}

std::string page = WebContent::network(message);
bool hiddenEssid = ! reqInfo->arguments["hidden"].empty();
std::string page = WebContent::network(message, hiddenEssid);
MHD_Response *response = MHD_create_response_from_buffer (page.size(), (void *) page.c_str(), MHD_RESPMEM_MUST_COPY);
MHD_add_response_header (response, "Content-Type", "text/html");
ret = MHD_queue_response (reqInfo->connection, MHD_HTTP_OK, response);
Expand Down
4 changes: 2 additions & 2 deletions src/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ The origin is the center of the turn table.

// Non-configurable settings
#define FREELSS_VERSION_MAJOR 1
#define FREELSS_VERSION_MINOR 10
#define FREELSS_VERSION_NAME "FreeLSS 1.10"
#define FREELSS_VERSION_MINOR 11
#define FREELSS_VERSION_NAME "FreeLSS 1.11"

#define PI 3.14159265359

Expand Down
104 changes: 104 additions & 0 deletions src/MockCamera.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
****************************************************************************
* Copyright (c) 2015 Uriah Liggett <[email protected]> *
* This file is part of FreeLSS. *
* *
* FreeLSS is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* FreeLSS is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with FreeLSS. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************
*/

#include "Main.h"
#include "MockCamera.h"


namespace freelss
{

MockCamera::MockCamera(int imageWidth, int imageHeight) :
m_imageWidth(imageWidth),
m_imageHeight(imageHeight)
{
std::cout << "Creating Mock camera, width=" << m_imageWidth << ", height=" << m_imageHeight << std::endl;
}

Image * MockCamera::acquireImage()
{
std::auto_ptr<Image> image(new Image(m_imageWidth, m_imageHeight, getImageComponents()));

// Make the image black
unsigned rowSpacing = image->getWidth() * image->getNumComponents();
unsigned char * pixels = image->getPixels();
memset(pixels, 0, image->getPixelBufferSize());

int xWidth = ROUND(image->getWidth() / 100.0f);
float aspect = (float)image->getWidth() / (float) image->getHeight();
for (unsigned y = 0; y < image->getHeight(); y++)
{
int x = (int)(y * aspect) - xWidth / 2;
int endX = x + xWidth;
while (x < endX)
{
if (x >= 0 && x < (int)image->getWidth())
{
// Diagonal #1
pixels[x * image->getNumComponents()] = 255;

// Diagonal #2
pixels[rowSpacing - x * image->getNumComponents()] = 255;
}

x++;
}

pixels += rowSpacing;
}

return image.release();
}

void MockCamera::releaseImage(Image * image)
{
delete image;
}

int MockCamera::getImageHeight() const
{
return m_imageHeight;
}

int MockCamera::getImageWidth() const
{
return m_imageWidth;
}

int MockCamera::getImageComponents() const
{
return 3;
}

real MockCamera::getSensorWidth() const
{
return 3.629;
}

real MockCamera::getSensorHeight() const
{
return 2.722;
}

real MockCamera::getFocalLength() const
{
return 3.6;
}
} // end ns scanner
64 changes: 64 additions & 0 deletions src/MockCamera.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
****************************************************************************
* Copyright (c) 2015 Uriah Liggett <[email protected]> *
* This file is part of FreeLSS. *
* *
* FreeLSS is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* FreeLSS is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with FreeLSS. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************
*/

#pragma once
#include "Image.h"
#include "Camera.h"


namespace freelss
{


/** Reads an image use the raspberry pi's MMAL interfaces */
class MockCamera : public Camera
{
public:
MockCamera(int imageWidth, int imageHeight);

Image * acquireImage();

void releaseImage(Image * image);

/** Returns the height of the image that this camera takes. */
int getImageHeight() const;

/** Returns the width of the image that this camera takes */
int getImageWidth() const;

/** Returns the number of image components */
int getImageComponents() const;

/** Returns the width of the sensor in mm */
real getSensorWidth() const;

/** Returns the height of the sensor in mm */
real getSensorHeight() const;

/** Returns the focal length of the camera in mm */
real getFocalLength() const;

private:

int m_imageWidth;
int m_imageHeight;
};

}
40 changes: 1 addition & 39 deletions src/ObjectBaseCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void ObjectBaseCreator::createBase(FaceMap & outFaces, std::vector<DataPoint>& r
DataPoint pt = basePoints[idx];

center.point.x += pt.point.x;
center.point.z += pt.point.y;
center.point.z += pt.point.z;

pointSubset.push_back(pt);
}
Expand Down Expand Up @@ -212,44 +212,6 @@ void ObjectBaseCreator::subdivide(std::vector<unsigned>& triangles, std::vector<
}
}

/*
void ObjectBaseCreator::subdivide(std::vector<unsigned>& triangles, std::vector<DataPoint>& results)
{
real32 oneThird = 1.0f / 3.0f;
size_t numTriIndices = triangles.size();
for (size_t idx = 0; idx + 2 < numTriIndices; idx += 3)
{
unsigned i1 = triangles[idx];
unsigned i2 = triangles[idx + 1];
unsigned i3 = triangles[idx + 2];
if (i1 < results.size() && i2 < results.size() && i3 < results.size())
{
DataPoint p1 = results[i1];
DataPoint p2 = results[i2];
DataPoint p3 = results[i3];
// Create a point in the center of the triangle
DataPoint newPt = p1;
newPt.point.x = (p1.point.x + p2.point.x + p3.point.x) * oneThird;
newPt.point.y = 0;
newPt.point.z = (p1.point.z + p2.point.z + p3.point.z) * oneThird;
newPt.index = (unsigned) results.size();
// Create triangles from this new point
updateTriangle(idx, p2, p1, newPt, triangles);
addTriangle(p3, p2, newPt, triangles);
addTriangle(p1, p3, newPt, triangles);
results.push_back(newPt);
}
else
{
std::cerr << "!! Invalid triangle index from set of " << results.size() << "(" << i1 << "," << i2 << "," << i3 << ")" << std::endl;
}
}
}
*/

void ObjectBaseCreator::updateTriangle(unsigned idx1, const DataPoint& pt1, const DataPoint& pt2, const DataPoint& pt3, std::vector<unsigned>& triangles)
{
triangles[idx1] = pt1.index;
Expand Down
31 changes: 22 additions & 9 deletions src/WebContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ const std::string WebContent::ENABLE_LIGHTING = "ENABLE_LIGHTING";
const std::string WebContent::LIGHTING_PIN = "LIGHTING_PIN";
const std::string WebContent::CREATE_BASE_FOR_OBJECT = "CREATE_BASE_FOR_OBJECT";
const std::string WebContent::WIFI_ESSID = "WIFI_ESSID";
const std::string WebContent::WIFI_ESSID_HIDDEN = "WIFI_ESSID_HIDDEN";
const std::string WebContent::WIFI_PASSWORD = "WIFI_PASSWORD";
const std::string WebContent::KERNEL_VERSION = "KERNEL_VERSION";
const std::string WebContent::ENABLE_AUTHENTICATION = "ENABLE_AUTHENTICATION";
Expand Down Expand Up @@ -723,12 +724,15 @@ std::string WebContent::security(const std::string& message)

return sstr.str();
}
std::string WebContent::network(const std::string& message)
std::string WebContent::network(const std::string& message, bool hiddenEssidInput)
{
WifiConfig * wifi = WifiConfig::get();

// Perform a scan
wifi->scan();
if (!hiddenEssidInput)
{
wifi->scan();
}

std::vector<std::string> interfaces = wifi->getAllInterfaces();
std::vector<WifiConfig::AccessPoint> accessPoints = wifi->getAccessPoints();
Expand Down Expand Up @@ -766,15 +770,24 @@ std::string WebContent::network(const std::string& message)
}
}

sstr << "<div><div class=\"settingsText\">Wireless Network</div>";
sstr << "<select name=\"" << WebContent::WIFI_ESSID << "\">";
for (size_t iAp = 0; iAp < accessPoints.size(); iAp++)
if (!hiddenEssidInput)
{
sstr << "<option value=\"" << iAp << "\">" << accessPoints[iAp].essid << "</option>\r\n";
}
sstr << "<div><div class=\"settingsText\">Wireless Network</div>";
sstr << "<select name=\"" << WebContent::WIFI_ESSID << "\">";
for (size_t iAp = 0; iAp < accessPoints.size(); iAp++)
{
sstr << "<option value=\"" << iAp << "\">" << accessPoints[iAp].essid << "</option>\r\n";
}

sstr << "</select></div>";
sstr << "<div class=\"settingsDescr\">The wireless network to connect to.</div>\n";
sstr << "</select>&nbsp;&nbsp;<a href=\"?hidden=true\"><small><small>Hidden</small></small></a></div>";

sstr << "";
sstr << "<div class=\"settingsDescr\">" << WIFI_ESSID_DESCR << "</div>\n";
}
else
{
sstr << setting(WebContent::WIFI_ESSID_HIDDEN, "Wireless Network", "", WIFI_ESSID_DESCR);
}

sstr << setting(WebContent::WIFI_PASSWORD, "Wireless Password", "", WIFI_PASSWORD_DESCR);
sstr << "<p><input type=\"hidden\" name=\"cmd\" value=\"connect\">\
Expand Down
3 changes: 2 additions & 1 deletion src/WebContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class WebContent
static std::string viewScan(const std::string& plyFilename);
static std::string showUpdate(SoftwareUpdate * update, const std::string& message);
static std::string updateApplied(SoftwareUpdate * update, const std::string& message, bool success);
static std::string network(const std::string& message);
static std::string network(const std::string& message, bool hiddenEssidInput);
static std::string security(const std::string& message);

static const std::string PROFILE_NAME;
Expand Down Expand Up @@ -91,6 +91,7 @@ class WebContent
static const std::string LIGHTING_PIN;
static const std::string CREATE_BASE_FOR_OBJECT;
static const std::string WIFI_ESSID;
static const std::string WIFI_ESSID_HIDDEN;
static const std::string WIFI_PASSWORD;
static const std::string KERNEL_VERSION;
static const std::string MENU2;
Expand Down
Loading

0 comments on commit 8289d95

Please sign in to comment.