Skip to content

Commit

Permalink
inference working
Browse files Browse the repository at this point in the history
  • Loading branch information
karaulj committed Jun 22, 2021
1 parent df553a0 commit 2648ee2
Show file tree
Hide file tree
Showing 30 changed files with 9,965 additions and 81 deletions.
6 changes: 6 additions & 0 deletions components/device_profile/BlueDeviceProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@

static const char *TAG = "BlueDeviceProfile";


void BlueDeviceProfile::profileSelectedCallback()
{
ESP_LOGI(TAG, "Blue profile selected");
xQueueSend(ledCmdQueue, (void*)&RGB_CMD_BLUE_PROFILE, 1/portTICK_PERIOD_MS);
}
7 changes: 7 additions & 0 deletions components/device_profile/GreenDeviceProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
static const char *TAG = "GreenDeviceProfile";


void GreenDeviceProfile::profileSelectedCallback()
{
ESP_LOGI(TAG, "Green profile selected");
xQueueSend(ledCmdQueue, (void*)&RGB_CMD_GREEN_PROFILE, 1/portTICK_PERIOD_MS);
}


void GreenDeviceProfile::gestureClickCallback()
{
ESP_LOGI(TAG, "%s: sendPlayPause", __func__);
Expand Down
7 changes: 7 additions & 0 deletions components/device_profile/IDeviceProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ static const char *TAG = "IDeviceProfile";
uint32_t IDeviceProfile::cnt = 0;


void IDeviceProfile::profileSelectedCallback()
{
xQueueSend(ledCmdQueue, (void*)&RGB_CMD_GESTURE_NOT_IMPL, 1/portTICK_PERIOD_MS);
ESP_LOGW(TAG, "%s not implemented for profile with id %d", __func__, id);
}


void IDeviceProfile::gestureClickCallback()
{
xQueueSend(ledCmdQueue, (void*)&RGB_CMD_GESTURE_NOT_IMPL, 1/portTICK_PERIOD_MS);
Expand Down
15 changes: 15 additions & 0 deletions components/device_profile/RedDeviceProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,24 @@
static const char *TAG = "RedDeviceProfile";


void RedDeviceProfile::profileSelectedCallback()
{
ESP_LOGI(TAG, "Red profile selected");
xQueueSend(ledCmdQueue, (void*)&RGB_CMD_RED_PROFILE, 1/portTICK_PERIOD_MS);
}


void RedDeviceProfile::gestureClickCallback()
{
ESP_LOGI(TAG, "%s: batteryLevel", __func__);
// battery level
xQueueSend(ledCmdQueue, (void*)&RGB_CMD_BATTERY_LEVEL, 1/portTICK_PERIOD_MS);
}


void RedDeviceProfile::gestureUpCallback()
{
ESP_LOGI(TAG, "%s: bleStatus", __func__);
// BLE HID status
xQueueSend(
ledCmdQueue,
Expand All @@ -46,6 +55,7 @@ void RedDeviceProfile::gestureUpCallback()

void RedDeviceProfile::gestureDownCallback()
{
ESP_LOGI(TAG, "%s: batteryChargingStatus", __func__);
// battery charging status
xQueueSend(
ledCmdQueue,
Expand All @@ -55,8 +65,11 @@ void RedDeviceProfile::gestureDownCallback()
);
}


void RedDeviceProfile::gestureLeftCallback()
{
ESP_LOGI(TAG, "%s: accelLEDFade", __func__);

// turn off inference task so we can use the Z button
vTaskSuspend(joystickInferenceTaskHandle);

Expand All @@ -80,6 +93,8 @@ void RedDeviceProfile::gestureLeftCallback()

void RedDeviceProfile::gestureRightCallback()
{
ESP_LOGI(TAG, "%s: joystickLEDFade", __func__);

// use Z button
vTaskSuspend(joystickInferenceTaskHandle);

Expand Down
1 change: 1 addition & 0 deletions components/device_profile/include/BlueDeviceProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class BlueDeviceProfile: public IDeviceProfile
{
public:
void profileSelectedCallback();
void gestureClickCallback();
void gestureUpCallback();
void gestureDownCallback();
Expand Down
1 change: 1 addition & 0 deletions components/device_profile/include/GreenDeviceProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class GreenDeviceProfile : public IDeviceProfile
{
public:
void profileSelectedCallback();
void gestureClickCallback();
void gestureUpCallback();
void gestureDownCallback();
Expand Down
1 change: 1 addition & 0 deletions components/device_profile/include/IDeviceProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class IDeviceProfile
const uint32_t id = cnt++;
virtual ~IDeviceProfile() {cnt--;};

virtual void profileSelectedCallback();
virtual void gestureClickCallback();
virtual void gestureUpCallback();
virtual void gestureDownCallback();
Expand Down
1 change: 1 addition & 0 deletions components/device_profile/include/RedDeviceProfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class RedDeviceProfile: public IDeviceProfile
{
public:
void profileSelectedCallback();
void gestureClickCallback();
void gestureUpCallback();
void gestureDownCallback();
Expand Down
10 changes: 10 additions & 0 deletions components/rgb_led/include/rgb_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ const rgb_cmd_t RGB_CMD_ACCEL_FADE_100_MS = 0x75;
const rgb_cmd_t RGB_CMD_JOYSTICK_RG_FADE = 0x80;
const rgb_cmd_t RGB_CMD_JOYSTICK_RB_FADE = 0x81;
const rgb_cmd_t RGB_CMD_JOYSTICK_GB_FADE = 0x82;
// profile selection
const rgb_cmd_t RGB_CMD_RED_PROFILE = 0x90;
const rgb_cmd_t RGB_CMD_GREEN_PROFILE = 0x91;
const rgb_cmd_t RGB_CMD_BLUE_PROFILE = 0x92;



// All RGB command functions declared here
Expand Down Expand Up @@ -84,6 +89,11 @@ extern void rgbcAccelFade100ms(RGB_CC_LED* led);
extern void rgbcJoystick_RG_Fade(RGB_CC_LED* led);
extern void rgbcJoystick_RB_Fade(RGB_CC_LED* led);
extern void rgbcJoystick_GB_Fade(RGB_CC_LED* led);
// profile selection
extern void rgbcRedProfile(RGB_CC_LED* led);
extern void rgbcGreenProfile(RGB_CC_LED* led);
extern void rgbcBlueProfile(RGB_CC_LED* led);



#endif /* COMPONENTS_RGB_CC_LED_INCLUDE_RGB_COMMANDS_H_ */
45 changes: 31 additions & 14 deletions components/rgb_led/rgb_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ void rgbcSystemInit(RGB_CC_LED* led)
led->setColor(0, 0, 0, 200, 200, 200);
vTaskDelay(250 / portTICK_PERIOD_MS);
}

void rgbcRestart(RGB_CC_LED* led)
{
for (int i=0; i<3; i++)
Expand All @@ -37,7 +36,6 @@ void rgbcRestart(RGB_CC_LED* led)
vTaskDelay(200 / portTICK_PERIOD_MS);
}
}

void rgbcClearAll(RGB_CC_LED* led)
{
led->setColor(0, 0, 0);
Expand All @@ -57,7 +55,6 @@ void rgbcBleConnected(RGB_CC_LED* led)
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}

void rgbcBleDisconnected(RGB_CC_LED* led)
{
led->setColor(0, 0, RGB_CC_LED_MAX/2);
Expand All @@ -72,7 +69,6 @@ void rgbcBleDisconnected(RGB_CC_LED* led)
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}

void rgbcBlePairingModeActive(RGB_CC_LED* led)
{
for (int i=0; i<3; i++)
Expand All @@ -95,12 +91,10 @@ void rgbcDeviceMode(RGB_CC_LED* led)
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}

void rgbcGestureActive(RGB_CC_LED* led)
{
led->setColor(0, 0, RGB_CC_LED_MAX/4);
led->setColor(RGB_CC_LED_MAX/8, RGB_CC_LED_MAX/8, RGB_CC_LED_MAX/8);
}

void rgbcGestureFound(RGB_CC_LED* led)
{
for (int i=0; i<2; i++)
Expand All @@ -111,7 +105,6 @@ void rgbcGestureFound(RGB_CC_LED* led)
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}

void rgbcGestureNotFound(RGB_CC_LED* led)
{
for (int i=0; i<2; i++)
Expand All @@ -122,15 +115,13 @@ void rgbcGestureNotFound(RGB_CC_LED* led)
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}

void rgbcGestureNotImpl(RGB_CC_LED* led)
{
led->setColor(RGB_CC_LED_MAX/4, 0, RGB_CC_LED_MAX/2); // dark purple
vTaskDelay(600 / portTICK_PERIOD_MS);
rgbcClearAll(led);
vTaskDelay(150 / portTICK_PERIOD_MS);
}

void rgbcCancelGesture(RGB_CC_LED* led)
{
led->setColor(RGB_CC_LED_MAX/2, 0, 0);
Expand Down Expand Up @@ -158,7 +149,6 @@ void rgbcBatteryRange(RGB_CC_LED* led)
vTaskDelay(1000 / portTICK_PERIOD_MS);
rgbcClearAll(led);
}

void rgbcBatteryLevel(RGB_CC_LED* led, color_level_t level)
{
led->setColor(RGB_CC_LED_MAX, 0, 0);
Expand All @@ -172,7 +162,6 @@ void rgbcBatteryLevel(RGB_CC_LED* led, color_level_t level)
vTaskDelay(1000 / portTICK_PERIOD_MS);
rgbcClearAll(led);
}

void rgbcBatteryCharging(RGB_CC_LED* led)
{
for (int i=0; i<3; i++)
Expand All @@ -183,7 +172,6 @@ void rgbcBatteryCharging(RGB_CC_LED* led)
vTaskDelay(250 / portTICK_PERIOD_MS);
}
}

void rgbcBatteryNotCharging(RGB_CC_LED* led)
{
for (int i=0; i<3; i++)
Expand Down Expand Up @@ -236,4 +224,33 @@ void rgbcJoystick_RG_Fade(RGB_CC_LED* led) { rgbcJoystick_Fade(led, 0x01); }
void rgbcJoystick_RB_Fade(RGB_CC_LED* led) { rgbcJoystick_Fade(led, 0x02); }
void rgbcJoystick_GB_Fade(RGB_CC_LED* led) { rgbcJoystick_Fade(led, 0x04); }


void rgbcRedProfile(RGB_CC_LED* led)
{
for (int i=0; i<2; i++)
{
led->setColor(RGB_CC_LED_MAX/4, 0, 0);
vTaskDelay(100 / portTICK_PERIOD_MS);
rgbcClearAll(led);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}
void rgbcGreenProfile(RGB_CC_LED* led)
{
for (int i=0; i<2; i++)
{
led->setColor(0, RGB_CC_LED_MAX/4, 0);
vTaskDelay(100 / portTICK_PERIOD_MS);
rgbcClearAll(led);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}
void rgbcBlueProfile(RGB_CC_LED* led)
{
for (int i=0; i<2; i++)
{
led->setColor(0, 0, RGB_CC_LED_MAX/4);
vTaskDelay(100 / portTICK_PERIOD_MS);
rgbcClearAll(led);
vTaskDelay(100 / portTICK_PERIOD_MS);
}
}
39 changes: 39 additions & 0 deletions components/tfmicro/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#
# This component was generated for the 'hello_world' TF Micro example.
#

# Make sure that the IDF Path environment variable is defined
if(NOT DEFINED ENV{IDF_PATH})
message(FATAL_ERROR "The IDF_PATH environment variable must point to the location of the ESP-IDF.")
endif()

idf_component_register(
SRCS gesture_model_tflite.cc Joystick_CNN_Model.cpp tensorflow/lite/micro/simple_memory_allocator.cc tensorflow/lite/micro/mock_micro_graph.cc tensorflow/lite/micro/micro_error_reporter.cc tensorflow/lite/micro/memory_helpers.cc tensorflow/lite/micro/test_helpers.cc tensorflow/lite/micro/micro_utils.cc tensorflow/lite/micro/recording_micro_allocator.cc tensorflow/lite/micro/micro_time.cc tensorflow/lite/micro/debug_log.cc tensorflow/lite/micro/micro_string.cc tensorflow/lite/micro/recording_simple_memory_allocator.cc tensorflow/lite/micro/micro_profiler.cc tensorflow/lite/micro/all_ops_resolver.cc tensorflow/lite/micro/micro_graph.cc tensorflow/lite/micro/micro_interpreter.cc tensorflow/lite/micro/micro_allocator.cc tensorflow/lite/micro/system_setup.cc tensorflow/lite/micro/memory_planner/linear_memory_planner.cc tensorflow/lite/micro/memory_planner/greedy_memory_planner.cc tensorflow/lite/c/common.c tensorflow/lite/core/api/error_reporter.cc tensorflow/lite/core/api/flatbuffer_conversions.cc tensorflow/lite/core/api/op_resolver.cc tensorflow/lite/core/api/tensor_utils.cc tensorflow/lite/kernels/internal/quantization_util.cc tensorflow/lite/kernels/kernel_util.cc tensorflow/lite/schema/schema_utils.cc tensorflow/lite/micro/kernels/activations.cc tensorflow/lite/micro/kernels/add.cc tensorflow/lite/micro/kernels/add_n.cc tensorflow/lite/micro/kernels/arg_min_max.cc tensorflow/lite/micro/kernels/batch_to_space_nd.cc tensorflow/lite/micro/kernels/cast.cc tensorflow/lite/micro/kernels/ceil.cc tensorflow/lite/micro/kernels/circular_buffer.cc tensorflow/lite/micro/kernels/comparisons.cc tensorflow/lite/micro/kernels/concatenation.cc tensorflow/lite/micro/kernels/conv.cc tensorflow/lite/micro/kernels/conv_common.cc tensorflow/lite/micro/kernels/cumsum.cc tensorflow/lite/micro/kernels/depth_to_space.cc tensorflow/lite/micro/kernels/depthwise_conv.cc tensorflow/lite/micro/kernels/depthwise_conv_common.cc tensorflow/lite/micro/kernels/dequantize.cc tensorflow/lite/micro/kernels/detection_postprocess.cc tensorflow/lite/micro/kernels/elementwise.cc tensorflow/lite/micro/kernels/elu.cc tensorflow/lite/micro/kernels/ethosu.cc tensorflow/lite/micro/kernels/exp.cc tensorflow/lite/micro/kernels/expand_dims.cc tensorflow/lite/micro/kernels/fill.cc tensorflow/lite/micro/kernels/floor.cc tensorflow/lite/micro/kernels/floor_div.cc tensorflow/lite/micro/kernels/floor_mod.cc tensorflow/lite/micro/kernels/fully_connected.cc tensorflow/lite/micro/kernels/fully_connected_common.cc tensorflow/lite/micro/kernels/gather.cc tensorflow/lite/micro/kernels/gather_nd.cc tensorflow/lite/micro/kernels/hard_swish.cc tensorflow/lite/micro/kernels/if.cc tensorflow/lite/micro/kernels/kernel_runner.cc tensorflow/lite/micro/kernels/kernel_util.cc tensorflow/lite/micro/kernels/l2norm.cc tensorflow/lite/micro/kernels/l2_pool_2d.cc tensorflow/lite/micro/kernels/leaky_relu.cc tensorflow/lite/micro/kernels/logical.cc tensorflow/lite/micro/kernels/logistic.cc tensorflow/lite/micro/kernels/log_softmax.cc tensorflow/lite/micro/kernels/maximum_minimum.cc tensorflow/lite/micro/kernels/mul.cc tensorflow/lite/micro/kernels/neg.cc tensorflow/lite/micro/kernels/pack.cc tensorflow/lite/micro/kernels/pad.cc tensorflow/lite/micro/kernels/pooling.cc tensorflow/lite/micro/kernels/prelu.cc tensorflow/lite/micro/kernels/quantize.cc tensorflow/lite/micro/kernels/quantize_common.cc tensorflow/lite/micro/kernels/reduce.cc tensorflow/lite/micro/kernels/reshape.cc tensorflow/lite/micro/kernels/resize_bilinear.cc tensorflow/lite/micro/kernels/resize_nearest_neighbor.cc tensorflow/lite/micro/kernels/round.cc tensorflow/lite/micro/kernels/shape.cc tensorflow/lite/micro/kernels/softmax.cc tensorflow/lite/micro/kernels/softmax_common.cc tensorflow/lite/micro/kernels/space_to_batch_nd.cc tensorflow/lite/micro/kernels/split.cc tensorflow/lite/micro/kernels/split_v.cc tensorflow/lite/micro/kernels/squeeze.cc tensorflow/lite/micro/kernels/strided_slice.cc tensorflow/lite/micro/kernels/sub.cc tensorflow/lite/micro/kernels/svdf.cc tensorflow/lite/micro/kernels/svdf_common.cc tensorflow/lite/micro/kernels/tanh.cc tensorflow/lite/micro/kernels/transpose.cc tensorflow/lite/micro/kernels/transpose_conv.cc tensorflow/lite/micro/kernels/unpack.cc tensorflow/lite/micro/kernels/zeros_like.cc
INCLUDE_DIRS . third_party/gemmlowp third_party/flatbuffers/include third_party/ruy)

# Reduce the level of paranoia to be able to compile TF sources
target_compile_options(${COMPONENT_LIB} PRIVATE
-Wno-maybe-uninitialized
-Wno-missing-field-initializers
-Wno-type-limits)

target_compile_options(${COMPONENT_LIB} PRIVATE -Wimplicit-function-declaration -Werror -fno-unwind-tables -ffunction-sections -fdata-sections -fmessage-length=0 -DTF_LITE_STATIC_MEMORY -DTF_LITE_DISABLE_X86_NEON -O3 -Wsign-compare -Wdouble-promotion -Wshadow -Wunused-variable -Wmissing-field-initializers -Wunused-function -Wswitch -Wvla -Wall -Wextra -Wstrict-aliasing -Wno-unused-parameter -DLINUX -DTF_LITE_USE_CTIME)
#target_compile_options(${COMPONENT_LIB} PRIVATE -Wimplicit-function-declaration -std=c11 -Werror -fno-unwind-tables -ffunction-sections -fdata-sections -fmessage-length=0 -DTF_LITE_STATIC_MEMORY -DTF_LITE_DISABLE_X86_NEON -O3 -Wsign-compare -Wdouble-promotion -Wshadow -Wunused-variable -Wmissing-field-initializers -Wunused-function -Wswitch -Wvla -Wall -Wextra -Wstrict-aliasing -Wno-unused-parameter -DLINUX -DTF_LITE_USE_CTIME)
target_compile_options(${COMPONENT_LIB} PRIVATE $<$<COMPILE_LANGUAGE:CXX>: -std=c++11 -fno-rtti -fno-exceptions -fno-threadsafe-statics -Werror -fno-unwind-tables -ffunction-sections -fdata-sections -fmessage-length=0 -DTF_LITE_STATIC_MEMORY -DTF_LITE_DISABLE_X86_NEON -O3 -Wsign-compare -Wdouble-promotion -Wshadow -Wunused-variable -Wmissing-field-initializers -Wunused-function -Wswitch -Wvla -Wall -Wextra -Wstrict-aliasing -Wno-unused-parameter -DLINUX -DTF_LITE_USE_CTIME >)
target_compile_options(${COMPONENT_LIB} INTERFACE $<$<IN_LIST:-DTF_LITE_STATIC_MEMORY,$<TARGET_PROPERTY:${COMPONENT_LIB},COMPILE_OPTIONS>>:-DTF_LITE_STATIC_MEMORY>)
target_link_libraries(${COMPONENT_LIB} PRIVATE -lm)
Loading

0 comments on commit 2648ee2

Please sign in to comment.