Skip to content

Pulling in work from Miranda and Andrew #25

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 9 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
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
37 changes: 33 additions & 4 deletions BUILD_DIR/t4_sensor1.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,44 @@
#include <p33EP512GP806.h>
#include <pic24_all.h>
#include <esos_f14ui.h>

#include <esos_comm.h>
#include <esos_sensor.h>



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

#define LOOP_DELAY 1000

char buffer[30];
BOOL b_keepLooping = FALSE;

ESOS_CHILD_TASK(barGraph_child, uint16_t u16_num2graph){ //visual display of data
static uint8_t u8_barGraph_value = 0;
static uint8_t i;
static uint8_t j;
ESOS_TASK_BEGIN();
ESOS_TASK_WAIT_ON_SEND_STRING(" |"); //draws a 20 '_' long line with a moving '|'
u8_barGraph_value = u16_num2graph / 50; //max output 2^10 ~= 1000; /50 gives increments of 20
for (i=0; i<u8_barGraph_value; i++){
ESOS_TASK_WAIT_ON_SEND_STRING("_");
}
ESOS_TASK_WAIT_ON_SEND_STRING("|"); //after appropriate '_'s this is the values line
for (j=0; j<(20-u8_barGraph_value); j++){ //finish the 20 '_'s
ESOS_TASK_WAIT_ON_SEND_STRING("_");
}
ESOS_TASK_WAIT_ON_SEND_STRING("|\n");
ESOS_TASK_END();
}

ESOS_USER_TASK(loop) {
static uint16_t u16_data;

static ESOS_TASK_HANDLE th_child; //declare storage for handle to child task
ESOS_TASK_BEGIN();{
for (;;) { //same as while(true)

ESOS_TASK_WAIT_UNTIL(esos_uiF14_isSW1Pressed() || esos_uiF14_isSW2Pressed()); /on either switch, start the DO loop
ESOS_TASK_WAIT_UNTIL(esos_uiF14_isSW1Pressed() || esos_uiF14_isSW2Pressed()); //on either switch, start the DO loop
if (esos_uiF14_isSW2Pressed()){
b_keepLooping = TRUE; //if sw2 then keep looping; checked at the bottom while statement
}
Expand All @@ -38,7 +59,12 @@ ESOS_USER_TASK(loop) {
//wait for UART availability to send output to Bully Bootloader
ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM();

sprintf(buffer, "%d\n", u16_data);
ESOS_TASK_WAIT_ON_SEND_UINT16_AS_HEX_STRING(u16_data); //extra zeros but acceptable

ESOS_ALLOCATE_CHILD_TASK(th_child);
ESOS_TASK_SPAWN_AND_WAIT(th_child, barGraph_child, u16_data);

ESOS_TASK_WAIT_ON_SEND_STRING("\n");
ESOS_TASK_WAIT_ON_SEND_STRING(buffer); //wait for data in buffer to be sent and release UART
ESOS_TASK_SIGNAL_AVAILABLE_OUT_COMM();
ESOS_TASK_WAIT_TICKS(LOOP_DELAY /2); /*this is half of the 1 second delay between samples
Expand All @@ -63,11 +89,14 @@ ESOS_USER_TASK(loop) {
ESOS_TASK_END();
}


void user_init(void){
config_esos_uiF14();

// Config heartbeat
esos_uiF14_flashLED3(500);

esos_RegisterTask(loop);


}
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);
}
Binary file added Docs/F14 PCB parts list.xlsx
Binary file not shown.
14 changes: 14 additions & 0 deletions esos/include/esos_comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ uint8_t __esos_u8_GetLSBHexCharFromUint8(uint8_t u8_x);
ESOS_CHILD_TASK( __esos_OutChar, uint8_t u8_c);
ESOS_CHILD_TASK( __esos_OutUint8AsDecString, uint8_t u8_x);
ESOS_CHILD_TASK( __esos_OutUint8AsHexString, uint8_t u8_x);
ESOS_CHILD_TASK( __esos_OutUint16AsHexString, uint16_t u16_x);
ESOS_CHILD_TASK( __esos_OutUint32AsHexString, uint32_t u32_x);
ESOS_CHILD_TASK( __esos_OutCharBuffer, uint8_t* pu8_out, uint8_t u8_len);
ESOS_CHILD_TASK( __esos_getBuffer, uint8_t* pau8_buff, uint8_t u8_size);
Expand Down Expand Up @@ -414,6 +415,19 @@ uint8_t __esos_unsafe_GetUint8(void);
* \sa ESOS_TASK_SPAWN_AND_WAIT
* \hideinitializer
*/
#define ESOS_TASK_WAIT_ON_SEND_UINT16_AS_HEX_STRING( u16_out) \
ESOS_TASK_SPAWN_AND_WAIT( (ESOS_TASK_HANDLE)&__stChildTaskTx, __esos_OutUint16AsHexString, (u16_out) )


/**
* Create, spawn and wait on a child task to put 2 bytes (uint16) to the ESOS "out" communications buffer as a human-readable
* decimal string. Results will look like "253"
*
* \note This call will block the current task until the data is absorbed by the ESOS communications subsystem
* \param u8_out data to write to "out" stream
* \sa ESOS_TASK_SPAWN_AND_WAIT
* \hideinitializer
*/
#define ESOS_TASK_WAIT_ON_SEND_UINT8_AS_DEC_STRING( u8_out) \
ESOS_TASK_SPAWN_AND_WAIT( (ESOS_TASK_HANDLE)&__stChildTaskTx, __esos_OutUint8AsDecString,(u8_out))
/**
Expand Down
27 changes: 27 additions & 0 deletions esos/src/esos_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,33 @@ ESOS_CHILD_TASK( __esos_OutUint8AsDecString, uint8_t u8_x) {
ESOS_TASK_END();
} // end __esos_OutUint8AsDecString

ESOS_CHILD_TASK( __esos_OutUint16AsHexString, uint16_t u16_x) {
static uint8_t au8_String[11];
static uint8_t u8_c;
static uint16_t u16_tmp;

ESOS_TASK_BEGIN();
au8_String[0] = '0';
au8_String[1] = 'x';
u8_c = (u16_x >> 8);
au8_String[2] = __esos_u8_GetMSBHexCharFromUint8(u8_c);
au8_String[3] = __esos_u8_GetLSBHexCharFromUint8(u8_c);
u8_c = u16_x;
au8_String[4] = __esos_u8_GetMSBHexCharFromUint8(u8_c);
au8_String[5] = __esos_u8_GetLSBHexCharFromUint8(u8_c);
au8_String[6] = 0;
u8_c = 0;

while (u8_c < 6) {
__ESOS_COMM_TXFIFO_PREP();
ESOS_TASK_WAIT_WHILE( u16_tmp == __st_TxBuffer.u16_Tail );
__ESOS_COMM_WRITE_TXFIFO( au8_String[u8_c++] ); //write to buffer
__esos_hw_signal_start_tx();
} //end while()
ESOS_TASK_END();

} // end __esos_OutUint16AsHexString()

ESOS_CHILD_TASK( __esos_OutUint32AsHexString, uint32_t u32_x) {
static uint8_t au8_String[11];
static uint8_t u8_c;
Expand Down