Skip to content

Commit 29f4a4c

Browse files
committed
API search tags
- This is a work in progress to better refine search - Search results will not improve yet, but this is a necessary step
1 parent cd8b487 commit 29f4a4c

File tree

6 files changed

+1942
-31
lines changed

6 files changed

+1942
-31
lines changed
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
#include "Particle.h"
2+
#include "dct.h"
3+
4+
/* Function prototypes -------------------------------------------------------*/
5+
int tinkerDigitalRead(String pin);
6+
int tinkerDigitalWrite(String command);
7+
int tinkerAnalogRead(String pin);
8+
int tinkerAnalogWrite(String command);
9+
10+
SYSTEM_MODE(AUTOMATIC);
11+
SYSTEM_THREAD(ENABLED);
12+
13+
void setupDone()
14+
{
15+
#if defined(DCT_SETUP_DONE_OFFSET)
16+
// On Gen3 devices, set the setup done flag to true so the device exits
17+
// listening mode. This happens immediately on cellular devices or after
18+
// valid Wi-Fi credentials have been set on the Argon.
19+
uint8_t val = 0;
20+
if(!dct_read_app_data_copy(DCT_SETUP_DONE_OFFSET, &val, sizeof(val)) && val != 1)
21+
{
22+
val = 1;
23+
dct_write_app_data(&val, DCT_SETUP_DONE_OFFSET, sizeof(val));
24+
}
25+
#endif /* DCT_SETUP_DONE_OFFSET */
26+
}
27+
28+
/* This function is called once at start up ----------------------------------*/
29+
void setup()
30+
{
31+
//Setup the Tinker application here
32+
33+
//Register all the Tinker functions
34+
Particle.function("digitalread", tinkerDigitalRead);
35+
Particle.function("digitalwrite", tinkerDigitalWrite);
36+
37+
Particle.function("analogread", tinkerAnalogRead);
38+
Particle.function("analogwrite", tinkerAnalogWrite);
39+
40+
setupDone();
41+
}
42+
43+
/* This function loops forever --------------------------------------------*/
44+
void loop()
45+
{
46+
//This will run in a loop
47+
}
48+
49+
/*******************************************************************************
50+
* Function Name : tinkerDigitalRead
51+
* Description : Reads the digital value of a given pin
52+
* Input : Pin
53+
* Output : None.
54+
* Return : Value of the pin (0 or 1) in INT type
55+
Returns a negative number on failure
56+
*******************************************************************************/
57+
int tinkerDigitalRead(String pin)
58+
{
59+
//convert ASCII to integer
60+
int pinNumber = pin.charAt(1) - '0';
61+
//Sanity check to see if the pin numbers are within limits
62+
if (pinNumber < 0 || pinNumber > 7)
63+
return -1;
64+
65+
if (pin.startsWith("D"))
66+
{
67+
pinMode(pinNumber, INPUT_PULLDOWN);
68+
return digitalRead(pinNumber);
69+
}
70+
else if (pin.startsWith("A"))
71+
{
72+
pinMode(pinNumber + 10, INPUT_PULLDOWN);
73+
return digitalRead(pinNumber + 10);
74+
}
75+
#if Wiring_Cellular
76+
else if (pin.startsWith("B"))
77+
{
78+
if (pinNumber > 5)
79+
return -3;
80+
pinMode(pinNumber + 24, INPUT_PULLDOWN);
81+
return digitalRead(pinNumber + 24);
82+
}
83+
else if (pin.startsWith("C"))
84+
{
85+
if (pinNumber > 5)
86+
return -4;
87+
pinMode(pinNumber + 30, INPUT_PULLDOWN);
88+
return digitalRead(pinNumber + 30);
89+
}
90+
#endif
91+
return -2;
92+
}
93+
94+
/*******************************************************************************
95+
* Function Name : tinkerDigitalWrite
96+
* Description : Sets the specified pin HIGH or LOW
97+
* Input : Pin and value
98+
* Output : None.
99+
* Return : 1 on success and a negative number on failure
100+
*******************************************************************************/
101+
int tinkerDigitalWrite(String command)
102+
{
103+
bool value = 0;
104+
//convert ASCII to integer
105+
int pinNumber = command.charAt(1) - '0';
106+
//Sanity check to see if the pin numbers are within limits
107+
if (pinNumber < 0 || pinNumber > 7)
108+
return -1;
109+
110+
if (command.substring(3, 7) == "HIGH")
111+
value = 1;
112+
else if (command.substring(3, 6) == "LOW")
113+
value = 0;
114+
else
115+
return -2;
116+
117+
if (command.startsWith("D"))
118+
{
119+
pinMode(pinNumber, OUTPUT);
120+
digitalWrite(pinNumber, value);
121+
return 1;
122+
}
123+
else if (command.startsWith("A"))
124+
{
125+
pinMode(pinNumber + 10, OUTPUT);
126+
digitalWrite(pinNumber + 10, value);
127+
return 1;
128+
}
129+
#if Wiring_Cellular
130+
else if (command.startsWith("B"))
131+
{
132+
if (pinNumber > 5)
133+
return -4;
134+
pinMode(pinNumber + 24, OUTPUT);
135+
digitalWrite(pinNumber + 24, value);
136+
return 1;
137+
}
138+
else if (command.startsWith("C"))
139+
{
140+
if (pinNumber > 5)
141+
return -5;
142+
pinMode(pinNumber + 30, OUTPUT);
143+
digitalWrite(pinNumber + 30, value);
144+
return 1;
145+
}
146+
#endif
147+
else
148+
return -3;
149+
}
150+
151+
/*******************************************************************************
152+
* Function Name : tinkerAnalogRead
153+
* Description : Reads the analog value of a pin
154+
* Input : Pin
155+
* Output : None.
156+
* Return : Returns the analog value in INT type (0 to 4095)
157+
Returns a negative number on failure
158+
*******************************************************************************/
159+
int tinkerAnalogRead(String pin)
160+
{
161+
//convert ASCII to integer
162+
int pinNumber = pin.charAt(1) - '0';
163+
//Sanity check to see if the pin numbers are within limits
164+
if (pinNumber < 0 || pinNumber > 7)
165+
return -1;
166+
167+
if (pin.startsWith("D"))
168+
{
169+
return -3;
170+
}
171+
else if (pin.startsWith("A"))
172+
{
173+
return analogRead(pinNumber + 10);
174+
}
175+
#if Wiring_Cellular
176+
else if (pin.startsWith("B"))
177+
{
178+
if (pinNumber < 2 || pinNumber > 5)
179+
return -3;
180+
return analogRead(pinNumber + 24);
181+
}
182+
#endif
183+
return -2;
184+
}
185+
186+
/*******************************************************************************
187+
* Function Name : tinkerAnalogWrite
188+
* Description : Writes an analog value (PWM) to the specified pin
189+
* Input : Pin and Value (0 to 255)
190+
* Output : None.
191+
* Return : 1 on success and a negative number on failure
192+
*******************************************************************************/
193+
int tinkerAnalogWrite(String command)
194+
{
195+
String value = command.substring(3);
196+
197+
if (command.substring(0, 2) == "TX")
198+
{
199+
pinMode(TX, OUTPUT);
200+
analogWrite(TX, value.toInt());
201+
return 1;
202+
}
203+
else if (command.substring(0, 2) == "RX")
204+
{
205+
pinMode(RX, OUTPUT);
206+
analogWrite(RX, value.toInt());
207+
return 1;
208+
}
209+
210+
//convert ASCII to integer
211+
int pinNumber = command.charAt(1) - '0';
212+
//Sanity check to see if the pin numbers are within limits
213+
214+
if (pinNumber < 0 || pinNumber > 7)
215+
return -1;
216+
217+
if (command.startsWith("D"))
218+
{
219+
pinMode(pinNumber, OUTPUT);
220+
analogWrite(pinNumber, value.toInt());
221+
return 1;
222+
}
223+
else if (command.startsWith("A"))
224+
{
225+
pinMode(pinNumber + 10, OUTPUT);
226+
analogWrite(pinNumber + 10, value.toInt());
227+
return 1;
228+
}
229+
else if (command.substring(0, 2) == "TX")
230+
{
231+
pinMode(TX, OUTPUT);
232+
analogWrite(TX, value.toInt());
233+
return 1;
234+
}
235+
else if (command.substring(0, 2) == "RX")
236+
{
237+
pinMode(RX, OUTPUT);
238+
analogWrite(RX, value.toInt());
239+
return 1;
240+
}
241+
#if Wiring_Cellular
242+
else if (command.startsWith("B"))
243+
{
244+
if (pinNumber > 3)
245+
return -3;
246+
pinMode(pinNumber + 24, OUTPUT);
247+
analogWrite(pinNumber + 24, value.toInt());
248+
return 1;
249+
}
250+
else if (command.startsWith("C"))
251+
{
252+
if (pinNumber < 4 || pinNumber > 5)
253+
return -4;
254+
pinMode(pinNumber + 30, OUTPUT);
255+
analogWrite(pinNumber + 30, value.toInt());
256+
return 1;
257+
}
258+
#endif
259+
else
260+
return -2;
261+
}

src/assets/js/api-helper-extras.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ $(document).ready(function() {
119119
const deviceId = $(deviceLookupDeviceIdInputElem).val();
120120

121121
const isValid = (deviceId.length == 24) && (deviceId.match(/[A-Za-z0-9]+/) == deviceId);
122+
// console.log('deviceId=' + deviceId + ' isValid=' + isValid);
122123

123124
$(deviceLookupButtonElem).prop('disabled', !isValid);
124125
});
@@ -137,6 +138,10 @@ $(document).ready(function() {
137138

138139
setStatus('Claiming succeeded!');
139140
$(deviceLookupButtonElem).trigger('click');
141+
142+
apiHelper.deviceListRefresh(function() {
143+
apiHelper.setCommonDevice(deviceId);
144+
});
140145
}
141146
catch(e) {
142147
setStatus('Claiming failed.');
@@ -159,6 +164,10 @@ $(document).ready(function() {
159164
await apiHelper.particle.renameDevice({ deviceId, name, auth: apiHelper.auth.access_token });
160165

161166
setStatus('Renaming succeeded!');
167+
168+
apiHelper.deviceListRefresh(function() {
169+
apiHelper.setCommonDevice(deviceId);
170+
});
162171
}
163172
catch(e) {
164173
setStatus('Renaming failed.');
@@ -188,8 +197,7 @@ $(document).ready(function() {
188197
$(deviceLookupElem).find('.apiHelperDeviceLookupOrg').hide();
189198
$(deviceLookupElem).find('.apiHelperDeviceLookupClaimDiv').hide();
190199
$(deviceLookupElem).find('.apiHelperDeviceLookupRenameDeviceDiv').hide();
191-
192-
200+
193201
let deviceFound = false;
194202
let deviceInfo;
195203
let deviceMine = false;
@@ -356,6 +364,7 @@ $(document).ready(function() {
356364
if (deviceMine){
357365
$('.apiHelperDeviceLookupRenameDeviceName').val(deviceInfo.name);
358366
$(deviceLookupElem).find('.apiHelperDeviceLookupRenameDeviceDiv').show();
367+
apiHelper.setCommonDevice(deviceId);
359368
}
360369
}
361370
else {

src/assets/js/usb-serial.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,10 +686,14 @@ $(document).ready(function() {
686686
};
687687

688688
$(startButton).on('click', function() {
689+
$(startButton).prop('disabled', true);
690+
setStatus('Select device to configure...');
691+
689692
const listening = usbSerial.listeningCommand();
690693
$('.apiHelperWiFiSetupInstructions').hide();
691694
$('.apiHelperWiFiSetupInstructions').hide();
692-
$('.apiHelperWiFiSetupStatus').html('');
695+
696+
setStatus('Configuring device...');
693697

694698
listening.connect({
695699
showWifiListeningDevices:true,
@@ -726,6 +730,7 @@ $(document).ready(function() {
726730
// results.timeout
727731
setStatus('Timed out communicating with the device.<br/>Reset your device and enter listening mode again before attempting again.');
728732
}
733+
$(startButton).prop('disabled', false);
729734

730735
listening.disconnect();
731736
}

src/content/device-claiming.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,22 @@ the status LED blinks dark blue.
1818
{{> wifi-setup }}
1919

2020
{{> device-lookup hidden="true"}}
21+
22+
23+
## Marking Setup Done
24+
25+
On Gen 3 devices (Argon, Boron, B Series SoM, Tracker), you must clear the "Setup Done" flag
26+
in order to leave listening mode (blinking dark blue). This can be done using the
27+
[Particle CLI](/reference/developer-tools/cli/#particle-usb-setup-done), or you can use
28+
flash this firmware to your device.
29+
30+
This is the standard Tinker app with a bit of extra code to mark setup done on Gen 3 devices.
31+
32+
Flashing this to your device will also upgrade your device to the latest default release of
33+
Device OS. Even though you don't need to mark setup done on the Photon, you could still
34+
flash this firmware to a Photon to upgrade it.
35+
36+
Your device may blink magenta (red and blue at the same time), including having the LED turn
37+
off for many seconds at a time, and reboot several times. This is normal.
38+
39+
{{> codebox content="/assets/files/hardware-examples/tinker-setup-done.cpp" format="cpp" height="400" flash="true"}}

0 commit comments

Comments
 (0)