Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <Bridge.h>

String revision = "1.0.2-1_ar71xx";
String location = "https://raw.githubusercontent.com/ParsePlatform/parse-embedded-sdks/1.0.2/yun/linux_package/";
String revision = "1.0.3-1_ar71xx";
String location = "https://raw.githubusercontent.com/ParsePlatform/parse-embedded-sdks/1.0.3/yun/linux_package/";

void downloadPackage(String file) {
Serial.println("Download: " + location + file + revision + ".ipk");
Expand Down
File renamed without changes.
38 changes: 38 additions & 0 deletions examples/Arduino Zero + WiFi101/quickstart/QuickStart.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <SPI.h>
#include <WiFi101.h>
#include <Parse.h>

char ssid[] = ""; // your network SSID (name)
char pass[] = ""; // your network password (use for WPA, or use as key for WEP)

int status = WL_IDLE_STATUS;

void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while (true);
}

// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}

}

void loop() {

}
8 changes: 4 additions & 4 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name=Parse Arduino SDK
version=1.0.2
version=1.0.3
author=Parse, LLC.
maintainer=Parse, LLC.
sentence=A library that provides access to Parse
paragraph=Provides convenience methods to access the REST API on Parse.com from Arduino
url=https://github.com/ParsePlatform/Parse-SDK-Arduino
architectures=avr
paragraph=Provides convenience methods to access the REST API on Parse.com from Arduino.
url=https://github.com/ParsePlatform/parse-embedded-sdks
architectures=avr,samd
103 changes: 103 additions & 0 deletions src/external/FlashStorage/FlashStorage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
Copyright (c) 2015 Arduino LLC. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#if defined (ARDUINO_SAMD_ZERO)

#include "FlashStorage.h"

static const uint32_t pageSizes[] = { 8, 16, 32, 64, 128, 256, 512, 1024 };

FlashClass::FlashClass(const void *flash_addr, uint32_t size) :
PAGE_SIZE(pageSizes[NVMCTRL->PARAM.bit.PSZ]),
PAGES(NVMCTRL->PARAM.bit.NVMP),
MAX_FLASH(PAGE_SIZE * PAGES),
ROW_SIZE(PAGE_SIZE * 4),
flash_address((volatile void *)flash_addr),
flash_size(size)
{
}

static inline uint32_t read_unaligned_uint32(const void *data)
{
union {
uint32_t u32;
uint8_t u8[4];
} res;
const uint8_t *d = (const uint8_t *)data;
res.u8[0] = d[0];
res.u8[1] = d[1];
res.u8[2] = d[2];
res.u8[3] = d[3];
return res.u32;
}

void FlashClass::write(const volatile void *flash_ptr, const void *data, uint32_t size)
{
// Calculate data boundaries
size = (size + 3) / 4;
volatile uint32_t *dst_addr = (volatile uint32_t *)flash_ptr;
const uint8_t *src_addr = (uint8_t *)data;

// Disable automatic page write
NVMCTRL->CTRLB.bit.MANW = 1;

// Do writes in pages
while (size) {
// Execute "PBC" Page Buffer Clear
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_PBC;
while (NVMCTRL->INTFLAG.bit.READY == 0) { }

// Fill page buffer
uint32_t i;
for (i=0; i<(PAGE_SIZE/4) && size; i++) {
*dst_addr = read_unaligned_uint32(src_addr);
src_addr += 4;
dst_addr++;
size--;
}

// Execute "WP" Write Page
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_WP;
while (NVMCTRL->INTFLAG.bit.READY == 0) { }
}
}

void FlashClass::erase(const volatile void *flash_ptr, uint32_t size)
{
const uint8_t *ptr = (const uint8_t *)flash_ptr;
while (size > ROW_SIZE) {
erase(ptr);
ptr += ROW_SIZE;
size -= ROW_SIZE;
}
erase(ptr);
}

void FlashClass::erase(const volatile void *flash_ptr)
{
NVMCTRL->ADDR.reg = ((uint32_t)flash_ptr) / 2;
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_ER;
while (!NVMCTRL->INTFLAG.bit.READY) { }
}

void FlashClass::read(const volatile void *flash_ptr, void *data, uint32_t size)
{
memcpy(data, (const void *)flash_ptr, size);
}

#endif // defined (ARDUINO_SAMD_ZERO)
76 changes: 76 additions & 0 deletions src/external/FlashStorage/FlashStorage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright (c) 2015 Arduino LLC. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#pragma once

#include <Arduino.h>

// Concatenate after macro expansion
#define PPCAT_NX(A, B) A ## B
#define PPCAT(A, B) PPCAT_NX(A, B)

#define Flash(name, size) \
__attribute__((__aligned__(256))) \
static const uint8_t PPCAT(_data,name)[(size+255)/256*256] = { }; \
FlashClass name(PPCAT(_data,name), size);

#define FlashStorage(name, T) \
__attribute__((__aligned__(256))) \
static const uint8_t PPCAT(_data,name)[(sizeof(T)+255)/256*256] = { }; \
FlashStorageClass<T> name(PPCAT(_data,name));

class FlashClass {
public:
FlashClass(const void *flash_addr = NULL, uint32_t size = 0);

void write(const void *data) { write(flash_address, data, flash_size); }
void erase() { erase(flash_address, flash_size); }
void read(void *data) { read(flash_address, data, flash_size); }

void write(const volatile void *flash_ptr, const void *data, uint32_t size);
void erase(const volatile void *flash_ptr, uint32_t size);
void read(const volatile void *flash_ptr, void *data, uint32_t size);

private:
void erase(const volatile void *flash_ptr);

const uint32_t PAGE_SIZE, PAGES, MAX_FLASH, ROW_SIZE;
const volatile void *flash_address;
const uint32_t flash_size;
};

template<class T>
class FlashStorageClass {
public:
FlashStorageClass(const void *flash_addr) : flash(flash_addr, sizeof(T)) { };

// Write data into flash memory.
// Compiler is able to optimize parameter copy.
inline void write(T data) { flash.erase(); flash.write(&data); }

// Read data from flash into variable.
inline void read(T *data) { flash.read(data); }

// Overloaded version of read.
// Compiler is able to optimize copy-on-return.
inline T read() { T data; read(&data); return data; }

private:
FlashClass flash;
};

19 changes: 19 additions & 0 deletions src/internal/ConnectionClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef __CONNECTION_CLIENT_H__
#define __CONNECTION_CLIENT_H__


#include <Arduino.h>

#ifdef ARDUINO_SAMD_ZERO

#include <WiFi101.h>
typedef WiFiClient ConnectionClient;

#elif ARDUINO_AVR_YUN

#include <Bridge.h>
typedef Process ConnectionClient;

#endif

#endif //__CONNECTION_CLIENT_H__
36 changes: 25 additions & 11 deletions src/internal/ParseClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
#ifndef ParseClient_h
#define ParseClient_h

#if defined (ARDUINO_AVR_YUN) || defined (ARDUINO_AVR_TRE)
//#if defined (ARDUINO_AVR_YUN) || defined (ARDUINO_AVR_TRE)

#include "ConnectionClient.h"
#include "ParseResponse.h"
#include "ParsePush.h"
#include <Process.h>

/*! \file ParseClient.h
* \brief ParseClient object for the Yun
Expand All @@ -35,17 +35,30 @@

/*! \class ParseClient
* \brief Class responsible for Parse connection
*
* NOTE: A global ParseClient object with the name "Parse" is defined in the SDK,
* use it in your sketch instead of defining your own ParseClient object.
*/
class ParseClient {
private:
const char* installationId;
const char* sessionToken;
void read(Process* client, char* buf, int size);
Process pushClient;
Process requestClient;
char applicationId[41]; // APPLICATION_ID_MAX_LEN
char clientKey[41]; // CLIENT_KEY_MAX_LEN
char installationId[37]; // INSTALLATION_ID_MAX_LEN
char sessionToken[41]; // SESSION_TOKEN_MAX_LEN

ConnectionClient client;
ConnectionClient pushClient;

unsigned long lastHeartbeat;

void read(ConnectionClient* client, char* buf, int len);

#if defined (ARDUINO_SAMD_ZERO)
char lastPushTime[41]; // PUSH_TIME_MAX_LEN
bool dataIsDirty;
char pushBuff[5];

void saveKeys();
void restoreKeys();
void saveLastPushTime(char *time);
#endif

public:
/*! \fn ParseClient()
Expand All @@ -57,6 +70,7 @@ class ParseClient {
*/
~ParseClient();


/*! \fn begin(const char *applicationId, const char *clientKey)
* \brief Initialize the Parse client and user session
*
Expand Down Expand Up @@ -216,5 +230,5 @@ class ParseClient {
*/
extern ParseClient Parse;

#endif //ARDUINO_AVR_YUN
//#endif //ARDUINO_AVR_YUN
#endif
1 change: 0 additions & 1 deletion src/internal/ParseCloudFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*
*/

#include "ParseClient.h"
#include "ParseCloudFunction.h"

ParseCloudFunction::ParseCloudFunction() : ParseObjectCreate() {
Expand Down
7 changes: 7 additions & 0 deletions src/internal/ParseInternal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef __PARSE_INTERNAL_H__
#define __PARSE_INTERNAL_H__

#include <Arduino.h>
#include "ParseUtils.h"

#endif //__PARSE_INTERNAL_H__
1 change: 1 addition & 0 deletions src/internal/ParseObjectCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
*/

#include "ParseInternal.h"
#include "ParseClient.h"
#include "ParseObjectCreate.h"

Expand Down
1 change: 1 addition & 0 deletions src/internal/ParseObjectDelete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
*/

#include "ParseInternal.h"
#include "ParseClient.h"
#include "ParseObjectDelete.h"

Expand Down
2 changes: 1 addition & 1 deletion src/internal/ParseObjectDelete.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ParseObjectDelete : public ParseRequest {
*
* \return response of request.
*/
ParseResponse send() override;
ParseResponse send();
};

#endif
1 change: 1 addition & 0 deletions src/internal/ParseObjectGet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
*/

#include "ParseInternal.h"
#include "ParseClient.h"
#include "ParseObjectGet.h"

Expand Down
2 changes: 1 addition & 1 deletion src/internal/ParseObjectGet.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ParseObjectGet : public ParseRequest {
*
* \result response of request
*/
ParseResponse send() override;
ParseResponse send();
};

#endif
1 change: 1 addition & 0 deletions src/internal/ParseObjectUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
*/

#include "ParseInternal.h"
#include "ParseClient.h"
#include "ParseObjectUpdate.h"

Expand Down
Loading