Skip to content

Commit 999226a

Browse files
Merge pull request #4 from GeorgeYakovlev/master
Modify Parse library to support both Zero and Yun
2 parents 2fc5fd5 + e099c2f commit 999226a

35 files changed

+1364
-101
lines changed
File renamed without changes.

examples/setup/Setup.ino renamed to examples/Arduino Yun/setup/Setup.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <Bridge.h>
22

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

66
void downloadPackage(String file) {
77
Serial.println("Download: " + location + file + revision + ".ipk");
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <SPI.h>
2+
#include <WiFi101.h>
3+
#include <Parse.h>
4+
5+
char ssid[] = ""; // your network SSID (name)
6+
char pass[] = ""; // your network password (use for WPA, or use as key for WEP)
7+
8+
int status = WL_IDLE_STATUS;
9+
10+
void setup() {
11+
//Initialize serial and wait for port to open:
12+
Serial.begin(115200);
13+
while (!Serial) {
14+
; // wait for serial port to connect. Needed for Leonardo only
15+
}
16+
17+
// check for the presence of the shield:
18+
if (WiFi.status() == WL_NO_SHIELD) {
19+
Serial.println("WiFi shield not present");
20+
// don't continue:
21+
while (true);
22+
}
23+
24+
// attempt to connect to Wifi network:
25+
while (status != WL_CONNECTED) {
26+
Serial.print("Attempting to connect to SSID: ");
27+
Serial.println(ssid);
28+
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
29+
status = WiFi.begin(ssid, pass);
30+
// wait 10 seconds for connection:
31+
delay(10000);
32+
}
33+
34+
}
35+
36+
void loop() {
37+
38+
}

library.properties

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name=Parse Arduino SDK
2-
version=1.0.2
2+
version=1.0.3
33
author=Parse, LLC.
44
maintainer=Parse, LLC.
55
sentence=A library that provides access to Parse
6-
paragraph=Provides convenience methods to access the REST API on Parse.com from Arduino
7-
url=https://github.com/ParsePlatform/Parse-SDK-Arduino
8-
architectures=avr
6+
paragraph=Provides convenience methods to access the REST API on Parse.com from Arduino.
7+
url=https://github.com/ParsePlatform/parse-embedded-sdks
8+
architectures=avr,samd
+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
Copyright (c) 2015 Arduino LLC. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#if defined (ARDUINO_SAMD_ZERO)
20+
21+
#include "FlashStorage.h"
22+
23+
static const uint32_t pageSizes[] = { 8, 16, 32, 64, 128, 256, 512, 1024 };
24+
25+
FlashClass::FlashClass(const void *flash_addr, uint32_t size) :
26+
PAGE_SIZE(pageSizes[NVMCTRL->PARAM.bit.PSZ]),
27+
PAGES(NVMCTRL->PARAM.bit.NVMP),
28+
MAX_FLASH(PAGE_SIZE * PAGES),
29+
ROW_SIZE(PAGE_SIZE * 4),
30+
flash_address((volatile void *)flash_addr),
31+
flash_size(size)
32+
{
33+
}
34+
35+
static inline uint32_t read_unaligned_uint32(const void *data)
36+
{
37+
union {
38+
uint32_t u32;
39+
uint8_t u8[4];
40+
} res;
41+
const uint8_t *d = (const uint8_t *)data;
42+
res.u8[0] = d[0];
43+
res.u8[1] = d[1];
44+
res.u8[2] = d[2];
45+
res.u8[3] = d[3];
46+
return res.u32;
47+
}
48+
49+
void FlashClass::write(const volatile void *flash_ptr, const void *data, uint32_t size)
50+
{
51+
// Calculate data boundaries
52+
size = (size + 3) / 4;
53+
volatile uint32_t *dst_addr = (volatile uint32_t *)flash_ptr;
54+
const uint8_t *src_addr = (uint8_t *)data;
55+
56+
// Disable automatic page write
57+
NVMCTRL->CTRLB.bit.MANW = 1;
58+
59+
// Do writes in pages
60+
while (size) {
61+
// Execute "PBC" Page Buffer Clear
62+
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_PBC;
63+
while (NVMCTRL->INTFLAG.bit.READY == 0) { }
64+
65+
// Fill page buffer
66+
uint32_t i;
67+
for (i=0; i<(PAGE_SIZE/4) && size; i++) {
68+
*dst_addr = read_unaligned_uint32(src_addr);
69+
src_addr += 4;
70+
dst_addr++;
71+
size--;
72+
}
73+
74+
// Execute "WP" Write Page
75+
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_WP;
76+
while (NVMCTRL->INTFLAG.bit.READY == 0) { }
77+
}
78+
}
79+
80+
void FlashClass::erase(const volatile void *flash_ptr, uint32_t size)
81+
{
82+
const uint8_t *ptr = (const uint8_t *)flash_ptr;
83+
while (size > ROW_SIZE) {
84+
erase(ptr);
85+
ptr += ROW_SIZE;
86+
size -= ROW_SIZE;
87+
}
88+
erase(ptr);
89+
}
90+
91+
void FlashClass::erase(const volatile void *flash_ptr)
92+
{
93+
NVMCTRL->ADDR.reg = ((uint32_t)flash_ptr) / 2;
94+
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_ER;
95+
while (!NVMCTRL->INTFLAG.bit.READY) { }
96+
}
97+
98+
void FlashClass::read(const volatile void *flash_ptr, void *data, uint32_t size)
99+
{
100+
memcpy(data, (const void *)flash_ptr, size);
101+
}
102+
103+
#endif // defined (ARDUINO_SAMD_ZERO)
+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
Copyright (c) 2015 Arduino LLC. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#pragma once
20+
21+
#include <Arduino.h>
22+
23+
// Concatenate after macro expansion
24+
#define PPCAT_NX(A, B) A ## B
25+
#define PPCAT(A, B) PPCAT_NX(A, B)
26+
27+
#define Flash(name, size) \
28+
__attribute__((__aligned__(256))) \
29+
static const uint8_t PPCAT(_data,name)[(size+255)/256*256] = { }; \
30+
FlashClass name(PPCAT(_data,name), size);
31+
32+
#define FlashStorage(name, T) \
33+
__attribute__((__aligned__(256))) \
34+
static const uint8_t PPCAT(_data,name)[(sizeof(T)+255)/256*256] = { }; \
35+
FlashStorageClass<T> name(PPCAT(_data,name));
36+
37+
class FlashClass {
38+
public:
39+
FlashClass(const void *flash_addr = NULL, uint32_t size = 0);
40+
41+
void write(const void *data) { write(flash_address, data, flash_size); }
42+
void erase() { erase(flash_address, flash_size); }
43+
void read(void *data) { read(flash_address, data, flash_size); }
44+
45+
void write(const volatile void *flash_ptr, const void *data, uint32_t size);
46+
void erase(const volatile void *flash_ptr, uint32_t size);
47+
void read(const volatile void *flash_ptr, void *data, uint32_t size);
48+
49+
private:
50+
void erase(const volatile void *flash_ptr);
51+
52+
const uint32_t PAGE_SIZE, PAGES, MAX_FLASH, ROW_SIZE;
53+
const volatile void *flash_address;
54+
const uint32_t flash_size;
55+
};
56+
57+
template<class T>
58+
class FlashStorageClass {
59+
public:
60+
FlashStorageClass(const void *flash_addr) : flash(flash_addr, sizeof(T)) { };
61+
62+
// Write data into flash memory.
63+
// Compiler is able to optimize parameter copy.
64+
inline void write(T data) { flash.erase(); flash.write(&data); }
65+
66+
// Read data from flash into variable.
67+
inline void read(T *data) { flash.read(data); }
68+
69+
// Overloaded version of read.
70+
// Compiler is able to optimize copy-on-return.
71+
inline T read() { T data; read(&data); return data; }
72+
73+
private:
74+
FlashClass flash;
75+
};
76+

src/internal/ConnectionClient.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef __CONNECTION_CLIENT_H__
2+
#define __CONNECTION_CLIENT_H__
3+
4+
5+
#include <Arduino.h>
6+
7+
#ifdef ARDUINO_SAMD_ZERO
8+
9+
#include <WiFi101.h>
10+
typedef WiFiClient ConnectionClient;
11+
12+
#elif ARDUINO_AVR_YUN
13+
14+
#include <Bridge.h>
15+
typedef Process ConnectionClient;
16+
17+
#endif
18+
19+
#endif //__CONNECTION_CLIENT_H__

src/internal/ParseClient.h

+25-11
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
#ifndef ParseClient_h
2323
#define ParseClient_h
2424

25-
#if defined (ARDUINO_AVR_YUN) || defined (ARDUINO_AVR_TRE)
25+
//#if defined (ARDUINO_AVR_YUN) || defined (ARDUINO_AVR_TRE)
2626

27+
#include "ConnectionClient.h"
2728
#include "ParseResponse.h"
2829
#include "ParsePush.h"
29-
#include <Process.h>
3030

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

3636
/*! \class ParseClient
3737
* \brief Class responsible for Parse connection
38-
*
39-
* NOTE: A global ParseClient object with the name "Parse" is defined in the SDK,
40-
* use it in your sketch instead of defining your own ParseClient object.
4138
*/
4239
class ParseClient {
4340
private:
44-
const char* installationId;
45-
const char* sessionToken;
46-
void read(Process* client, char* buf, int size);
47-
Process pushClient;
48-
Process requestClient;
41+
char applicationId[41]; // APPLICATION_ID_MAX_LEN
42+
char clientKey[41]; // CLIENT_KEY_MAX_LEN
43+
char installationId[37]; // INSTALLATION_ID_MAX_LEN
44+
char sessionToken[41]; // SESSION_TOKEN_MAX_LEN
45+
46+
ConnectionClient client;
47+
ConnectionClient pushClient;
48+
49+
unsigned long lastHeartbeat;
50+
51+
void read(ConnectionClient* client, char* buf, int len);
52+
53+
#if defined (ARDUINO_SAMD_ZERO)
54+
char lastPushTime[41]; // PUSH_TIME_MAX_LEN
55+
bool dataIsDirty;
56+
char pushBuff[5];
57+
58+
void saveKeys();
59+
void restoreKeys();
60+
void saveLastPushTime(char *time);
61+
#endif
4962

5063
public:
5164
/*! \fn ParseClient()
@@ -57,6 +70,7 @@ class ParseClient {
5770
*/
5871
~ParseClient();
5972

73+
6074
/*! \fn begin(const char *applicationId, const char *clientKey)
6175
* \brief Initialize the Parse client and user session
6276
*
@@ -216,5 +230,5 @@ class ParseClient {
216230
*/
217231
extern ParseClient Parse;
218232

219-
#endif //ARDUINO_AVR_YUN
233+
//#endif //ARDUINO_AVR_YUN
220234
#endif

src/internal/ParseCloudFunction.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*
2020
*/
2121

22-
#include "ParseClient.h"
2322
#include "ParseCloudFunction.h"
2423

2524
ParseCloudFunction::ParseCloudFunction() : ParseObjectCreate() {

src/internal/ParseInternal.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef __PARSE_INTERNAL_H__
2+
#define __PARSE_INTERNAL_H__
3+
4+
#include <Arduino.h>
5+
#include "ParseUtils.h"
6+
7+
#endif //__PARSE_INTERNAL_H__

src/internal/ParseObjectCreate.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*
2020
*/
2121

22+
#include "ParseInternal.h"
2223
#include "ParseClient.h"
2324
#include "ParseObjectCreate.h"
2425

src/internal/ParseObjectDelete.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*
2020
*/
2121

22+
#include "ParseInternal.h"
2223
#include "ParseClient.h"
2324
#include "ParseObjectDelete.h"
2425

src/internal/ParseObjectDelete.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ParseObjectDelete : public ParseRequest {
4444
*
4545
* \return response of request.
4646
*/
47-
ParseResponse send() override;
47+
ParseResponse send();
4848
};
4949

5050
#endif

src/internal/ParseObjectGet.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*
2020
*/
2121

22+
#include "ParseInternal.h"
2223
#include "ParseClient.h"
2324
#include "ParseObjectGet.h"
2425

src/internal/ParseObjectGet.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ParseObjectGet : public ParseRequest {
4444
*
4545
* \result response of request
4646
*/
47-
ParseResponse send() override;
47+
ParseResponse send();
4848
};
4949

5050
#endif

src/internal/ParseObjectUpdate.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*
2020
*/
2121

22+
#include "ParseInternal.h"
2223
#include "ParseClient.h"
2324
#include "ParseObjectUpdate.h"
2425

0 commit comments

Comments
 (0)