Skip to content

Commit

Permalink
API search tags
Browse files Browse the repository at this point in the history
- This is a work in progress to better refine search
- Search results will not improve yet, but this is a necessary step
  • Loading branch information
rickkas7 committed Apr 8, 2021
1 parent cd8b487 commit 29f4a4c
Show file tree
Hide file tree
Showing 6 changed files with 1,942 additions and 31 deletions.
261 changes: 261 additions & 0 deletions src/assets/files/hardware-examples/tinker-setup-done.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
#include "Particle.h"
#include "dct.h"

/* Function prototypes -------------------------------------------------------*/
int tinkerDigitalRead(String pin);
int tinkerDigitalWrite(String command);
int tinkerAnalogRead(String pin);
int tinkerAnalogWrite(String command);

SYSTEM_MODE(AUTOMATIC);
SYSTEM_THREAD(ENABLED);

void setupDone()
{
#if defined(DCT_SETUP_DONE_OFFSET)
// On Gen3 devices, set the setup done flag to true so the device exits
// listening mode. This happens immediately on cellular devices or after
// valid Wi-Fi credentials have been set on the Argon.
uint8_t val = 0;
if(!dct_read_app_data_copy(DCT_SETUP_DONE_OFFSET, &val, sizeof(val)) && val != 1)
{
val = 1;
dct_write_app_data(&val, DCT_SETUP_DONE_OFFSET, sizeof(val));
}
#endif /* DCT_SETUP_DONE_OFFSET */
}

/* This function is called once at start up ----------------------------------*/
void setup()
{
//Setup the Tinker application here

//Register all the Tinker functions
Particle.function("digitalread", tinkerDigitalRead);
Particle.function("digitalwrite", tinkerDigitalWrite);

Particle.function("analogread", tinkerAnalogRead);
Particle.function("analogwrite", tinkerAnalogWrite);

setupDone();
}

/* This function loops forever --------------------------------------------*/
void loop()
{
//This will run in a loop
}

/*******************************************************************************
* Function Name : tinkerDigitalRead
* Description : Reads the digital value of a given pin
* Input : Pin
* Output : None.
* Return : Value of the pin (0 or 1) in INT type
Returns a negative number on failure
*******************************************************************************/
int tinkerDigitalRead(String pin)
{
//convert ASCII to integer
int pinNumber = pin.charAt(1) - '0';
//Sanity check to see if the pin numbers are within limits
if (pinNumber < 0 || pinNumber > 7)
return -1;

if (pin.startsWith("D"))
{
pinMode(pinNumber, INPUT_PULLDOWN);
return digitalRead(pinNumber);
}
else if (pin.startsWith("A"))
{
pinMode(pinNumber + 10, INPUT_PULLDOWN);
return digitalRead(pinNumber + 10);
}
#if Wiring_Cellular
else if (pin.startsWith("B"))
{
if (pinNumber > 5)
return -3;
pinMode(pinNumber + 24, INPUT_PULLDOWN);
return digitalRead(pinNumber + 24);
}
else if (pin.startsWith("C"))
{
if (pinNumber > 5)
return -4;
pinMode(pinNumber + 30, INPUT_PULLDOWN);
return digitalRead(pinNumber + 30);
}
#endif
return -2;
}

/*******************************************************************************
* Function Name : tinkerDigitalWrite
* Description : Sets the specified pin HIGH or LOW
* Input : Pin and value
* Output : None.
* Return : 1 on success and a negative number on failure
*******************************************************************************/
int tinkerDigitalWrite(String command)
{
bool value = 0;
//convert ASCII to integer
int pinNumber = command.charAt(1) - '0';
//Sanity check to see if the pin numbers are within limits
if (pinNumber < 0 || pinNumber > 7)
return -1;

if (command.substring(3, 7) == "HIGH")
value = 1;
else if (command.substring(3, 6) == "LOW")
value = 0;
else
return -2;

if (command.startsWith("D"))
{
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, value);
return 1;
}
else if (command.startsWith("A"))
{
pinMode(pinNumber + 10, OUTPUT);
digitalWrite(pinNumber + 10, value);
return 1;
}
#if Wiring_Cellular
else if (command.startsWith("B"))
{
if (pinNumber > 5)
return -4;
pinMode(pinNumber + 24, OUTPUT);
digitalWrite(pinNumber + 24, value);
return 1;
}
else if (command.startsWith("C"))
{
if (pinNumber > 5)
return -5;
pinMode(pinNumber + 30, OUTPUT);
digitalWrite(pinNumber + 30, value);
return 1;
}
#endif
else
return -3;
}

/*******************************************************************************
* Function Name : tinkerAnalogRead
* Description : Reads the analog value of a pin
* Input : Pin
* Output : None.
* Return : Returns the analog value in INT type (0 to 4095)
Returns a negative number on failure
*******************************************************************************/
int tinkerAnalogRead(String pin)
{
//convert ASCII to integer
int pinNumber = pin.charAt(1) - '0';
//Sanity check to see if the pin numbers are within limits
if (pinNumber < 0 || pinNumber > 7)
return -1;

if (pin.startsWith("D"))
{
return -3;
}
else if (pin.startsWith("A"))
{
return analogRead(pinNumber + 10);
}
#if Wiring_Cellular
else if (pin.startsWith("B"))
{
if (pinNumber < 2 || pinNumber > 5)
return -3;
return analogRead(pinNumber + 24);
}
#endif
return -2;
}

/*******************************************************************************
* Function Name : tinkerAnalogWrite
* Description : Writes an analog value (PWM) to the specified pin
* Input : Pin and Value (0 to 255)
* Output : None.
* Return : 1 on success and a negative number on failure
*******************************************************************************/
int tinkerAnalogWrite(String command)
{
String value = command.substring(3);

if (command.substring(0, 2) == "TX")
{
pinMode(TX, OUTPUT);
analogWrite(TX, value.toInt());
return 1;
}
else if (command.substring(0, 2) == "RX")
{
pinMode(RX, OUTPUT);
analogWrite(RX, value.toInt());
return 1;
}

//convert ASCII to integer
int pinNumber = command.charAt(1) - '0';
//Sanity check to see if the pin numbers are within limits

if (pinNumber < 0 || pinNumber > 7)
return -1;

if (command.startsWith("D"))
{
pinMode(pinNumber, OUTPUT);
analogWrite(pinNumber, value.toInt());
return 1;
}
else if (command.startsWith("A"))
{
pinMode(pinNumber + 10, OUTPUT);
analogWrite(pinNumber + 10, value.toInt());
return 1;
}
else if (command.substring(0, 2) == "TX")
{
pinMode(TX, OUTPUT);
analogWrite(TX, value.toInt());
return 1;
}
else if (command.substring(0, 2) == "RX")
{
pinMode(RX, OUTPUT);
analogWrite(RX, value.toInt());
return 1;
}
#if Wiring_Cellular
else if (command.startsWith("B"))
{
if (pinNumber > 3)
return -3;
pinMode(pinNumber + 24, OUTPUT);
analogWrite(pinNumber + 24, value.toInt());
return 1;
}
else if (command.startsWith("C"))
{
if (pinNumber < 4 || pinNumber > 5)
return -4;
pinMode(pinNumber + 30, OUTPUT);
analogWrite(pinNumber + 30, value.toInt());
return 1;
}
#endif
else
return -2;
}
13 changes: 11 additions & 2 deletions src/assets/js/api-helper-extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ $(document).ready(function() {
const deviceId = $(deviceLookupDeviceIdInputElem).val();

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

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

setStatus('Claiming succeeded!');
$(deviceLookupButtonElem).trigger('click');

apiHelper.deviceListRefresh(function() {
apiHelper.setCommonDevice(deviceId);
});
}
catch(e) {
setStatus('Claiming failed.');
Expand All @@ -159,6 +164,10 @@ $(document).ready(function() {
await apiHelper.particle.renameDevice({ deviceId, name, auth: apiHelper.auth.access_token });

setStatus('Renaming succeeded!');

apiHelper.deviceListRefresh(function() {
apiHelper.setCommonDevice(deviceId);
});
}
catch(e) {
setStatus('Renaming failed.');
Expand Down Expand Up @@ -188,8 +197,7 @@ $(document).ready(function() {
$(deviceLookupElem).find('.apiHelperDeviceLookupOrg').hide();
$(deviceLookupElem).find('.apiHelperDeviceLookupClaimDiv').hide();
$(deviceLookupElem).find('.apiHelperDeviceLookupRenameDeviceDiv').hide();



let deviceFound = false;
let deviceInfo;
let deviceMine = false;
Expand Down Expand Up @@ -356,6 +364,7 @@ $(document).ready(function() {
if (deviceMine){
$('.apiHelperDeviceLookupRenameDeviceName').val(deviceInfo.name);
$(deviceLookupElem).find('.apiHelperDeviceLookupRenameDeviceDiv').show();
apiHelper.setCommonDevice(deviceId);
}
}
else {
Expand Down
7 changes: 6 additions & 1 deletion src/assets/js/usb-serial.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,14 @@ $(document).ready(function() {
};

$(startButton).on('click', function() {
$(startButton).prop('disabled', true);
setStatus('Select device to configure...');

const listening = usbSerial.listeningCommand();
$('.apiHelperWiFiSetupInstructions').hide();
$('.apiHelperWiFiSetupInstructions').hide();
$('.apiHelperWiFiSetupStatus').html('');

setStatus('Configuring device...');

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

listening.disconnect();
}
Expand Down
19 changes: 19 additions & 0 deletions src/content/device-claiming.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,22 @@ the status LED blinks dark blue.
{{> wifi-setup }}

{{> device-lookup hidden="true"}}


## Marking Setup Done

On Gen 3 devices (Argon, Boron, B Series SoM, Tracker), you must clear the "Setup Done" flag
in order to leave listening mode (blinking dark blue). This can be done using the
[Particle CLI](/reference/developer-tools/cli/#particle-usb-setup-done), or you can use
flash this firmware to your device.

This is the standard Tinker app with a bit of extra code to mark setup done on Gen 3 devices.

Flashing this to your device will also upgrade your device to the latest default release of
Device OS. Even though you don't need to mark setup done on the Photon, you could still
flash this firmware to a Photon to upgrade it.

Your device may blink magenta (red and blue at the same time), including having the LED turn
off for many seconds at a time, and reboot several times. This is normal.

{{> codebox content="/assets/files/hardware-examples/tinker-setup-done.cpp" format="cpp" height="400" flash="true"}}
Loading

0 comments on commit 29f4a4c

Please sign in to comment.