From 24dc99cb66f2ed755faa1e975679fd2cb72f5cc7 Mon Sep 17 00:00:00 2001 From: talksik Date: Thu, 25 Jan 2024 14:05:23 -0800 Subject: [PATCH] main code --- .clang-format | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++ .gitignore | 1 + Main.c | 80 +++++++++++++++++++++ README.md | 0 run.sh | 9 +++ 5 files changed, 282 insertions(+) create mode 100644 .clang-format create mode 100644 .gitignore create mode 100644 Main.c create mode 100644 README.md create mode 100755 run.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..d23cc24 --- /dev/null +++ b/.clang-format @@ -0,0 +1,192 @@ +--- +Language: Cpp +# BasedOnStyle: Microsoft +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveMacros: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: false +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: false + AfterExternBlock: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: true +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +QualifierAlignment: Leave +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +PackConstructorInitializers: BinPack +BasedOnStyle: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +AllowAllConstructorInitializersOnNextLine: true +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseLabels: false +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentExternBlock: AfterExternBlock +IndentRequires: false +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +LambdaBodyIndentation: Signature +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 1000 +PenaltyIndentedWhitespace: 0 +PointerAlignment: Right +PPIndentWidth: -1 +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + BeforeNonEmptyParentheses: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME +... + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c098216 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Main diff --git a/Main.c b/Main.c new file mode 100644 index 0000000..0505a95 --- /dev/null +++ b/Main.c @@ -0,0 +1,80 @@ + +#include +#include +#include + +// these are based on the wiringPi pin numbers +#define YELLOW_PIN 26 // GPIO 12 +#define GREEN_PIN 27 // GPIO 16 +#define BLUE_PIN 28 // GPIO 20 +#define RED_PIN 29 // GPIO 21 + +#define MOTION_SENSOR_PIN 2 // GPIO 27 + +#define VIBRATION_PIN 0 // GPIO 17 + +#define BUTTON_PIN 1 // GPIO 18 + +enum LED_STATE +{ + BLANK = 0, + YELLOW, + GREEN, + BLUE, + RED, + NUM_LEDS +}; + +int main(int argc, char *argv[]) +{ + printf("Starting program \n"); + printf("Number of arguments: %d\n", argc); + + printf("Program name: %s\n", argv[0]); // argv[0] holds the program name + + for (int i = 1; i < argc; i++) + { // Iterate through arguments starting from index 1 + printf("Argument %d: %s\n", i, argv[i]); + } + + wiringPiSetup(); + + pinMode(YELLOW_PIN, OUTPUT); + pinMode(GREEN_PIN, OUTPUT); + pinMode(BLUE_PIN, OUTPUT); + pinMode(RED_PIN, OUTPUT); + + pinMode(BUTTON_PIN, INPUT); + pullUpDnControl(BUTTON_PIN, PUD_UP); + + pinMode(MOTION_SENSOR_PIN, INPUT); + + pinMode(VIBRATION_PIN, OUTPUT); + + enum LED_STATE ledState = BLANK; + digitalWrite(YELLOW_PIN, LOW); + digitalWrite(GREEN_PIN, LOW); + digitalWrite(BLUE_PIN, LOW); + digitalWrite(RED_PIN, LOW); + bool buttonPressed = false; + + while (1) + { + if (digitalRead(MOTION_SENSOR_PIN) == HIGH) + { + printf("Motion detected!\n"); + + digitalWrite(YELLOW_PIN, HIGH); + + digitalWrite(VIBRATION_PIN, HIGH); + delay(2000); + digitalWrite(VIBRATION_PIN, LOW); + } + else + { + digitalWrite(YELLOW_PIN, LOW); + } + } + + return 0; +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..6f135a1 --- /dev/null +++ b/run.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -eo pipefail + +echo "Compiling and running C code..." + +gcc -o Main Main.c -lwiringPi + +./Main