Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Remove static Audio instance (#155)
Browse files Browse the repository at this point in the history
* Issue #153
Currently there have 2 user threads, one for Arduino 1 for telemetry data collection. Both of them would send data to remote services via the WiFi module.
If there 2 threads are trying to send data at the same time then it will block the whole system,
after add lock for any network operation problem solved.
So root cause should be: the underline wifi driver is not thread safety, as we don't have the source code of the wifi driver I will check with MXChip for further investigation.

* folder struct change

* Remove the telemetry thread to save resource

* minor changes

* Remove static Audio instance as this is not a mandatory component for all apps

* fix typo
  • Loading branch information
Arthur Ma authored and lirenhe committed Apr 29, 2017
1 parent 7e45ef5 commit b501856
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ int AudioClass::getCurrentSize()
return m_record_cursor - m_wavFile;
}

AudioClass Audio;

/*------------------------------------------------------------------------------
Callbacks implementation:
the callbacks API are defined __weak in the stm32412g_discovery_audio.c file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,4 @@ class AudioClass {
void genericWAVHeader(WaveHeader* header, int pcmDataSize, uint32_t sampleRate, int sampleBitDepth, uint8_t channels);
};

extern AudioClass Audio;

#endif
8 changes: 4 additions & 4 deletions AZ3166/AZ3166-1.0.0/cores/arduino/system/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "Arduino.h"
#include "mico_system.h"
#include "console_cli.h"
Expand Down Expand Up @@ -66,7 +66,7 @@ static bool IsAPMode()
return false;
}

static int GetMacWichoutColon(char* buff)
static int GetMACWithoutColon(char* buff)
{
const char* mac = WiFiInterface()->get_mac_address();
int j = 0;
Expand All @@ -93,7 +93,7 @@ static void EnterConfigurationiMode()
}

char id[24] = "id:";
id[3 + GetMacWichoutColon(id + 3)] = 0;
id[3 + GetMACWithoutColon(id + 3)] = 0;
Screen.print(1, id);

// Enter configuration mode
Expand All @@ -113,7 +113,7 @@ static void EnterAPMode()
}

char ap_name[24] = "AZ-";
ap_name[3 + GetMacWichoutColon(ap_name + 3)] = 0;
ap_name[3 + GetMACWithoutColon(ap_name + 3)] = 0;

if (!InitSystemWiFiAP())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#define RGB_LED_BRIGHTNESS 16
#define LOOP_DELAY 50
#define HEARTBEAT_INTERVAL (30000 / LOOP_DELAY)
#define HEARTBEAT_INTERVAL (60000 / LOOP_DELAY)

// 0 - idle
// 1 - shaking
Expand Down Expand Up @@ -128,9 +128,17 @@ static void DoHeartBeat(void)
Serial.println(">>Heartbeat<<");
eventSent = false;
iothub_client_sample_send_event((const unsigned char *)"{\"topic\":\"iot\", \"DeviceID\":\"Heartbeat\", \"event\":\"heartbeat\"}");
while (!eventSent)
for (int i =0; i < 20; i++)
{
iothub_client_sample_mqtt_loop();
if (eventSent)
{
break;
}
}
if (!eventSent)
{
Serial.println("Failed to get response from IoT hub: timeout.");
}
heartbeat = 0;
digitalWrite(LED_BUILTIN, HIGH);
Expand Down

0 comments on commit b501856

Please sign in to comment.