Skip to content

Port of code from Task 1 to Task 2 #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 24, 2020
Merged
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
85 changes: 71 additions & 14 deletions BUILD_DIR/t4_sensor2.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#include <p33EP512GP806.h>
#include <stdio.h>
#include <stdlib.h>
#include "pic24_all.h"
#include <string.h>
#include <p33EP512GP806.h>
#include "pic24_ports_config.h"

#include <esos.h>
#include "esos_pic24.h"
#include <esos_task.h>
#include "esos_comm.h"
#include "esos_f14ui.h"
#include "esos_pic24.h"
#include "esos_sensor.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define LOOP_DELAY 1000
#define ONESHOT '1'
#define AVG '2'
#define MIN '3'
Expand All @@ -24,7 +27,6 @@
#define SAMPLES64 '6'
#define SAMPLES_ONESHOT '7'


// defined in "esos_sensor.h"
static esos_sensor_process_t sensor_processing_mode;

Expand All @@ -39,11 +41,11 @@ ESOS_CHILD_TASK(menu) {

ESOS_TASK_BEGIN();
for (;;) {
ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM(); // wait until we can grab the output stream
ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM(); // wait until we can grab the output stream
// print a very pretty menu
ESOS_TASK_WAIT_ON_SEND_STRING(
"\n"
"+===========================+\n\
"\n"
"+===========================+\n\
| Select Processing mode |\n\
| 1. one-shot |\n\
| 2. average |\n\
Expand Down Expand Up @@ -134,16 +136,71 @@ ESOS_CHILD_TASK(menu) {
ESOS_TASK_END();
}

ESOS_USER_TASK(placeholderTask) {


BOOL b_keepLooping = FALSE;

ESOS_USER_TASK(loop) {

static uint16_t u16_data;
ESOS_TASK_HANDLE th_child;

ESOS_TASK_BEGIN();
ESOS_TASK_SPAWN_AND_WAIT(th_child, menu);
ESOS_TASK_BEGIN(); {
for (;;) {
ESOS_TASK_WAIT_UNTIL(esos_uiF14_isSW1Pressed() || esos_uiF14_isSW2Pressed());

if (esos_uiF14_isSW2Pressed()) {
b_keepLooping = TRUE;
}

else {
b_keepLooping = FALSE;
}

ESOS_TASK_WAIT_UNTIL(esos_uiF14_isSW1Released() && esos_uiF14_isSW2Released());

do {
//claim the ADC
ESOS_TASK_WAIT_ON_AVAILABLE_SENSOR(ESOS_SENSOR_CH02, ESOS_SENSOR_VREF_3V3);

//Now we have exclusive use, grab data
ESOS_TASK_WAIT_SENSOR_QUICK_READ(u16_data);

//Grab the output
ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM();
ESOS_TASK_WAIT_ON_SEND_STRING("Hex: ");
ESOS_TASK_WAIT_ON_SEND_UINT32_AS_HEX_STRING(u16_data);
ESOS_TASK_WAIT_ON_SEND_STRING("\n");
ESOS_TASK_SIGNAL_AVAILABLE_OUT_COMM();

ESOS_TASK_WAIT_TICKS(LOOP_DELAY / 2);

if (esos_uiF14_isSW1Pressed()) {
ESOS_TASK_WAIT_UNTIL(esos_uiF14_isSW1Released());
b_keepLooping = FALSE;
}

if (esos_uiF14_isSW2Pressed()) {
ESOS_TASK_WAIT_UNTIL(esos_uiF14_isSW2Released());
b_keepLooping = FALSE;
}

if (esos_uiF14_isSW3Pressed()){ //sw1 will stop the sw2 initiated continous looping
ESOS_TASK_WAIT_UNTIL(esos_uiF14_isSW3Released());
b_keepLooping = FALSE;
ESOS_TASK_SPAWN_AND_WAIT(th_child, menu);
}
ESOS_TASK_WAIT_TICKS(LOOP_DELAY /2); //the other half of the loop sw2 sensor reading delay
}while(b_keepLooping); //keep doing the DO loop if sw2 initiated it

//Release the potentiometer
ESOS_SENSOR_CLOSE();
}
}
ESOS_TASK_END();

}

void user_init(void){
config_esos_uiF14();
esos_RegisterTask(placeholderTask);
esos_RegisterTask(loop);
}