Skip to content

Commit

Permalink
Merge pull request #17 from oroca/develop
Browse files Browse the repository at this point in the history
스크래치 3.0 업데이트
  • Loading branch information
hancheol-cho authored Apr 3, 2019
2 parents b7cf2d3 + 97737bb commit eb13a1b
Show file tree
Hide file tree
Showing 15 changed files with 183 additions and 116 deletions.
39 changes: 28 additions & 11 deletions examples/BLE/EduBot_App/EduBot_App.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <image/EduBoy.h>


//EduBot edubot;

#define MOTOR_SERVICE_UUID "e005"
#define MOTOR_CHARACTERISTIC_SET_STEP_UUID "34443c33-3356-11e9-b210-d663bd873d93"
Expand Down Expand Up @@ -214,7 +215,7 @@ void hsvTorgb(float h_in, float s_in, float v_in, uint8_t &r_out, uint8_t &g_out
class MyMiscSetColorLEDCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string value = pCharacteristic->getValue();
if(value.length() == 6) {
if(value.length() == 6) {
uint8_t left_r = value[0];
uint8_t left_g = value[1];
uint8_t left_b = value[2];
Expand Down Expand Up @@ -242,7 +243,7 @@ class MyMiscSetColorLEDCallbacks: public BLECharacteristicCallbacks {
class MyMiscPlaySoundCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string value = pCharacteristic->getValue();
if(value.length() == 6) {
if(value.length() == 1) {

}
}
Expand All @@ -252,17 +253,24 @@ class MyMiscSetTextOLEDCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string value = pCharacteristic->getValue();

display_text = value.c_str();
request_display_text = 1;
if(value != "_!_!_!") {
display_text = value.c_str();
request_display_text = 1;
}
else {
status_text_displayed = 1;
}
}
};

class MyMiscSetImageOLEDCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string value = pCharacteristic->getValue();

display_image_index = value[0];
request_display_image = 1;
if(value.length() == 1) {
display_image_index = value[0];
request_display_image = 1;
}
}
};

Expand All @@ -272,7 +280,7 @@ void setup() {
edubot.begin(115200);
Serial.println("===============\nStarting BLE work!");

BLEDevice::init("OROCA_EduBot");
BLEDevice::init("OROCA EduBot");
BLEServer *mServer = BLEDevice::createServer();
mServer->setCallbacks(new MyBLEServerCallbacks());

Expand Down Expand Up @@ -455,7 +463,7 @@ void loop() {
status_led_count++;
if(status_led_count > 50) {
if(device_connected) {
edubot.ledOff();
edubot.ledOn();

if(status_text_displayed) {
edubot.lcd.setCursor(0, 32);
Expand Down Expand Up @@ -531,16 +539,17 @@ void loop() {

// Update Sensors
status_update_sensors_count++;
//if(status_update_sensors_count > 5)
{
if(status_update_sensors_count > 5) {

value_sensor_floor_sensors[0] = edubot.floor_sensor.getRightOut();
value_sensor_floor_sensors[1] = edubot.floor_sensor.getRightIn();
value_sensor_floor_sensors[2] = edubot.floor_sensor.getLeftIn();
value_sensor_floor_sensors[3] = edubot.floor_sensor.getLeftOut();
mCharSensorFloorSensors->setValue((uint8_t*)&value_sensor_floor_sensors, 4);

value_sensor_distance_sensors[0] = edubot.tof_L.distance_mm;
value_sensor_distance_sensors[1] = edubot.tof_R.distance_mm;
mCharSensorDistanceSensors->setValue((uint8_t*)&value_sensor_distance_sensors, 4);

value_sensor_imu_sensor[0] = (int16_t)(edubot.imu.getRoll() * 100.0);
value_sensor_imu_sensor[1] = (int16_t)(edubot.imu.getPitch() * 100.0);
Expand All @@ -552,11 +561,19 @@ void loop() {
value_sensor_imu_sensor[7] = (int16_t)(edubot.imu.getGyroY() * 100.0);
value_sensor_imu_sensor[8] = (int16_t)(edubot.imu.getGyroZ() * 100.0);

mCharSensorImuSensor->setValue((uint8_t*)&value_sensor_imu_sensor, 18);

if(device_connected) {
mCharSensorFloorSensors->notify();
mCharSensorDistanceSensors->notify();
mCharSensorImuSensor->notify();
}

status_update_sensors_count = 0;
}

status_update_all_count++;
if(status_update_all_count > 2) {
if(status_update_all_count > 5) {
memcpy(&value_sensor_all_data[0], value_misc_status_info, 4);
memcpy(&value_sensor_all_data[4], value_sensor_floor_sensors, 4);
memcpy(&value_sensor_all_data[8], value_sensor_distance_sensors, 4);
Expand Down
61 changes: 25 additions & 36 deletions examples/EduBot_Main/EduBot_Main.ino
Original file line number Diff line number Diff line change
@@ -1,47 +1,36 @@
#include <EduBot.h>


extern void scratch_setup();
extern void scratch_loop();
extern void linetrace_setup();
extern void linetrace_loop();
extern void stepmotor_setup();
extern void stepmotor_loop();
extern void getacc_setup();
extern void getacc_loop();
extern void getgyro_setup();
extern void getgyro_loop();
extern void getrpy_setup();
extern void getrpy_loop();
extern void tof_setup();
extern void tof_loop();
extern void audio_setup();
extern void audio_loop();
extern void neopixel_setup();
extern void neopixel_loop();
extern void irremote_setup();
extern void irremote_loop();
extern void battery_setup();
extern void battery_loop();
extern void bitblue_setup();
extern void bitblue_loop();
namespace AppScratch { extern void setup(); extern void loop(); }
namespace AppLineTrace { extern void setup(); extern void loop(); }
namespace AppStepMotor { extern void setup(); extern void loop(); }
namespace AppGetAcc { extern void setup(); extern void loop(); }
namespace AppGetGyro { extern void setup(); extern void loop(); }
namespace AppGetRpy { extern void setup(); extern void loop(); }
namespace AppTof { extern void setup(); extern void loop(); }
namespace AppAudio { extern void setup(); extern void loop(); }
namespace AppNeoPixel { extern void setup(); extern void loop(); }
namespace AppIrRemote { extern void setup(); extern void loop(); }
namespace AppBattery { extern void setup(); extern void loop(); }
namespace AppBitBlue { extern void setup(); extern void loop(); }


void setup() {
// put your setup code here, to run once:
edubot.begin(115200);

edubot.menuAdd("스크래치 3.0", scratch_setup, scratch_loop);
edubot.menuAdd("BitBlue", bitblue_setup, bitblue_loop);
edubot.menuAdd("LineTrace", linetrace_setup, linetrace_loop);
edubot.menuAdd("StepMotor", stepmotor_setup, stepmotor_loop);
edubot.menuAdd("GetAcc", getacc_setup, getacc_loop);
edubot.menuAdd("GetGyro", getgyro_setup, getgyro_loop);
edubot.menuAdd("GetRPY", getrpy_setup, getrpy_loop);
edubot.menuAdd("ToF", tof_setup, tof_loop);
edubot.menuAdd("Audio", audio_setup, audio_loop);
edubot.menuAdd("NeoPixel", neopixel_setup, neopixel_loop);
edubot.menuAdd("IrRemote", irremote_setup, irremote_loop);
edubot.menuAdd("Battery", battery_setup, battery_loop);
edubot.menuAdd("스크래치 3.0", AppScratch::setup, AppScratch::loop);
edubot.menuAdd("BitBlue", AppBitBlue::setup, AppBitBlue::loop);
edubot.menuAdd("LineTrace", AppLineTrace::setup, AppLineTrace::loop);
edubot.menuAdd("StepMotor", AppStepMotor::setup, AppStepMotor::loop);
edubot.menuAdd("GetAcc", AppGetAcc::setup, AppGetAcc::loop);
edubot.menuAdd("GetGyro", AppGetGyro::setup, AppGetGyro::loop);
edubot.menuAdd("GetRPY", AppGetRpy::setup, AppGetRpy::loop);
edubot.menuAdd("ToF", AppTof::setup, AppTof::loop);
edubot.menuAdd("Audio", AppAudio::setup, AppAudio::loop);
edubot.menuAdd("NeoPixel", AppNeoPixel::setup, AppNeoPixel::loop);
edubot.menuAdd("IrRemote", AppIrRemote::setup, AppIrRemote::loop);
edubot.menuAdd("Battery", AppBattery::setup, AppBattery::loop);
}

void loop() {
Expand Down
9 changes: 7 additions & 2 deletions examples/EduBot_Main/src/Audio.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#include <EduBot.h>



namespace AppAudio
{

extern const int16_t data[];


void audio_setup() {
void setup() {
// put your setup code here, to run once:
edubot.begin(115200);

edubot.audio.playBuff((uint8_t *)data, 19226*2, true);
}

void audio_loop() {
void loop() {
// put your main code here, to run repeatedly:

edubot.lcd.clearDisplay();
Expand Down Expand Up @@ -2437,3 +2441,4 @@ const int16_t data[NUM_ELEMENTS] = {
0, 0};// 19224-19225


}
9 changes: 7 additions & 2 deletions examples/EduBot_Main/src/Battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@



void battery_setup() {
namespace AppBattery
{

void setup() {
// put your setup code here, to run once:

edubot.begin(115200);
}

void battery_loop() {
void loop() {
// put your main code here, to run repeatedly
float vol;

Expand All @@ -18,4 +21,6 @@ void battery_loop() {
edubot.lcd.printf(0, 16,"%1.1f V", vol/10);
edubot.lcd.display();
delay(100);
}

}
16 changes: 10 additions & 6 deletions examples/EduBot_Main/src/BitBlue.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/* Authors: byeongkyu, baram */

#define EDUBOT_DRIVER_BLE

#include <EduBot.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
#include <BLE2902.h>
#include <image/EduBoy.h>



namespace AppBitBlue
{

#define HM10_SERVICE_UUID "0000ffe0-0000-1000-8000-00805f9b34fb"
#define HM10_CHARACTERISTIC_UUID "0000ffe1-0000-1000-8000-00805f9b34fb"
Expand Down Expand Up @@ -84,7 +86,7 @@ static void drawLcdConnected(bool connected);
static void loopUpdate(bool run);


void bitblue_setup() {
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);

Expand Down Expand Up @@ -128,7 +130,7 @@ void bitblue_setup() {
}


void bitblue_loop() {
void loop() {
// put your main code here, to run repeatedly:
static uint8_t state = 0;
static bool pre_connected = device_connected;
Expand Down Expand Up @@ -243,3 +245,5 @@ void loopUpdate(bool run)
}
}
}

}
9 changes: 6 additions & 3 deletions examples/EduBot_Main/src/GetAcc.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include <EduBot.h>


namespace AppGetAcc
{


void getacc_setup() {
void setup() {
// put your setup code here, to run once:
edubot.begin(115200);
}

void getacc_loop() {
void loop() {
// put your main code here, to run repeatedly:
static uint32_t pre_time;

Expand All @@ -32,4 +33,6 @@ void getacc_loop() {
Serial.print(edubot.imu.getAccZ());
Serial.println();
}
}

}
9 changes: 7 additions & 2 deletions examples/EduBot_Main/src/GetGyro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@



void getgyro_setup() {
namespace AppGetGyro
{

void setup() {
// put your setup code here, to run once:
edubot.begin(115200);
}

void getgyro_loop() {
void loop() {
// put your main code here, to run repeatedly:
static uint32_t pre_time;

Expand All @@ -31,4 +34,6 @@ void getgyro_loop() {
Serial.print(edubot.imu.getGyroZ());
Serial.println();
}
}

}
8 changes: 6 additions & 2 deletions examples/EduBot_Main/src/GetRPY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@



namespace AppGetRpy
{

void getrpy_setup() {
void setup() {
// put your setup code here, to run once:
edubot.begin(115200);
}

void getrpy_loop() {
void loop() {
// put your main code here, to run repeatedly:
static uint32_t pre_time;

Expand All @@ -31,4 +33,6 @@ void getrpy_loop() {
Serial.print(edubot.imu.getYaw());
Serial.println();
}
}

}
8 changes: 6 additions & 2 deletions examples/EduBot_Main/src/IrRemote.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#include <EduBot.h>


namespace AppIrRemote
{

void irremote_setup() {
void setup() {
// put your setup code here, to run once:

edubot.begin(115200);
edubot.tofEnd();
}

void irremote_loop() {
void loop() {
// put your main code here, to run repeatedly

if (edubot.ir_remote.available() > 0)
Expand All @@ -27,4 +29,6 @@ void irremote_loop() {
edubot.lcd.printf(0, 16,"0x%X", key_code);
edubot.lcd.display();
}
}

}
Loading

0 comments on commit eb13a1b

Please sign in to comment.